LCOV - code coverage report
Current view: top level - eq/client - roiFinder.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 4 7 57.1 %
Date: 2014-06-18 Functions: 2 4 50.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c)      2009, Maxim Makhinya
       3             :  *               2010-2014, Stefan Eilemann <eile@eyescale.ch>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #ifndef EQ_ROI_FINDER_H
      20             : #define EQ_ROI_FINDER_H
      21             : 
      22             : #include "roiEmptySpaceFinder.h"
      23             : #include "roiTracker.h"
      24             : 
      25             : #include "image.h"   // member
      26             : #include <eq/util/objectManager.h> // member
      27             : 
      28             : namespace eq
      29             : {
      30             : /**
      31             :  * Processes current rendering target and selects areas for read back.
      32             :  * @internal
      33             :  */
      34             : class ROIFinder : public boost::noncopyable
      35             : {
      36             : public:
      37             :     ROIFinder();
      38           3 :     virtual ~ROIFinder() {}
      39             : 
      40             :     /**
      41             :      * Processes current rendering target and selects areas for read back.
      42             :      *
      43             :      * @param buffers   current buffers (BUFFER_COLOR / BUFFER_DEPTH).
      44             :      * @param pvp       viewport to analyse.
      45             :      * @param zoom      current zoom
      46             :      * @param stage     compositing stage (to track separate statistics).
      47             :      * @param frameID   ID of current frame (to track separate statistics).
      48             :      * @param glObjects object manager.
      49             :      *
      50             :      * @return Areas for readback
      51             :      */
      52             :     PixelViewports findRegions( const uint32_t         buffers,
      53             :                                 const PixelViewport&   pvp,
      54             :                                 const Zoom&            zoom,
      55             :                                 const uint32_t         stage,
      56             :                                 const uint128_t&       frameID,
      57             :                                 util::ObjectManager&   glObjects );
      58             : private:
      59             :     struct Area;
      60             : 
      61             :     const void* _getInfoKey( ) const;
      62             : 
      63             :     /** Called from getReadbackInfo. Calculates per-block statistic before
      64             :         actuall read-back */
      65             :     void _readbackInfo( util::ObjectManager& glObjects );
      66             : 
      67             :     /** Dumpes image that contain _mask and found regions */
      68             :     void _dumpDebug( const GLEWContext* gl, const uint32_t stage = 0 );
      69             : 
      70             :     /** Clears masks, filles per-block occupancy _mask from _perBlockInfo,
      71             :         that was previously read-back from GPU in _readbackInfo */
      72             :     void _init( );
      73             : 
      74             :     /** For debugging purposes */
      75             :     void _fillWithColor( const PixelViewport& pvp, uint8_t* dst,
      76             :                          const uint8_t val );
      77             : 
      78             :     /** Updates dimensions and resizes arrays */
      79             :     void _resize( const PixelViewport& pvp );
      80             : 
      81             :     /** Histogram based based AABB calculation of a region. */
      82             :     PixelViewport _getObjectPVP( const PixelViewport& pvp,
      83             :                                  const uint8_t* src );
      84             : 
      85             :     /** Result is returned via _finalAreas array */
      86             :     uint8_t _splitArea( Area& area );
      87             : 
      88             :     /** Finds empty area in sub area. Used during optimal split search */
      89             :     void _updateSubArea( const uint8_t type );
      90             : 
      91             :     /** Find areas in current mask*/
      92             :     void _findAreas( PixelViewports& resultPVPs );
      93             : 
      94             :     /** Only used in debug build, to invalidate unused areas */
      95             :     void _invalidateAreas( Area* areas, uint8_t num );
      96             : 
      97             :     /** Dimensions of regions around currntly found hole. Used
      98             :         to estimate optimal split */
      99             :     struct Dims
     100             :     {
     101             :         uint8_t x1, x2, x3;
     102             :         uint8_t y1, y2, y3;
     103             :         uint8_t w1, w2, w3, w4, w5, w6, w7, w8;
     104             :         uint8_t h1, h2, h3, h4, h5, h6, h7, h8;
     105             :     } _dim;
     106             : 
     107             :     /** Describes region that is used to search holes withing */
     108             :     struct Area
     109             :     {
     110          63 :         Area()
     111          63 :             : valid( false )
     112          63 :         {};
     113           0 :         Area( PixelViewport pvp_ )
     114           0 :             : emptySize( 0 ), pvp ( pvp_ ), valid( false )
     115           0 :         {}
     116             : 
     117             :         int32_t       emptySize; //!< number of empty blocks
     118             :         PixelViewport pvp;       //!< PVP of area
     119             :         PixelViewport hole;      //!< largest hole
     120             : 
     121             :         bool          valid; //!< Used in debug build only
     122             :     };
     123             : 
     124             :     Area _tmpAreas[17];  //!< possible arreas
     125             :     Area _finalAreas[4]; //!< links to picked areas from _tmpAreas
     126             : 
     127             :     std::vector< Area > _areasToCheck;//!< Areas used to search for holes
     128             : 
     129             :     PixelViewport       _pvp;        //<! current, alligned to grid, PVP
     130             :     PixelViewport       _pvpOriginal;//<! original PVP
     131             : 
     132             :     ROIEmptySpaceFinder _emptyFinder;//!< class to search for holes
     133             : 
     134             :     int32_t _w;     //!< alligned to grid width
     135             :     int32_t _h;     //!< alligned to grid height
     136             :     int32_t _wh;    //!< _w * _h
     137             :     int32_t _wb;    //!< _w + 1 (only 1 block currently is used as border)
     138             :     int32_t _hb;    //!< _h + 1 (only 1 block currently is used as border)
     139             :     int32_t _wbhb;  //!< _wb * _wh (total number of blocks in _mask)
     140             : 
     141             :     Vectorub _tmpMask; //!< used only to dump found areas in _dumpDebug
     142             :     Vectorub _mask;    //!< mask of occupied blocks (main data)
     143             : 
     144             :     std::vector<float> _perBlockInfo; //!< buffer for data from GPU
     145             : 
     146             :     uint8_t _histX[256]; //!< histogram to find BB along X axis
     147             :     uint8_t _histY[256]; //!< histogram to find BB along Y axis
     148             : 
     149             :     Image _tmpImg;   //!< used for dumping debug info
     150             : 
     151             :     ROITracker _roiTracker; //!< disables ROI when ROI is inefficient
     152             : };
     153             : }
     154             : 
     155             : #endif // EQ_ROI_FINDER_H
     156             : 

Generated by: LCOV version 1.10