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
35 : {
36 : public:
37 : ROIFinder();
38 1 : 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 : ROIFinder( const ROIFinder& ) = delete;
60 : ROIFinder& operator=( const ROIFinder& ) = delete;
61 :
62 : struct Area;
63 :
64 : const void* _getInfoKey( ) const;
65 :
66 : /** Called from getReadbackInfo. Calculates per-block statistic before
67 : actuall read-back */
68 : void _readbackInfo( util::ObjectManager& glObjects );
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 : /** Updates dimensions and resizes arrays */
75 : void _resize( const PixelViewport& pvp );
76 :
77 : /** Histogram based based AABB calculation of a region. */
78 : PixelViewport _getObjectPVP( const PixelViewport& pvp,
79 : const uint8_t* src );
80 :
81 : /** Result is returned via _finalAreas array */
82 : uint8_t _splitArea( Area& area );
83 :
84 : /** Finds empty area in sub area. Used during optimal split search */
85 : void _updateSubArea( const uint8_t type );
86 :
87 : /** Find areas in current mask*/
88 : void _findAreas( PixelViewports& resultPVPs );
89 :
90 : /** Only used in debug build, to invalidate unused areas */
91 : void _invalidateAreas( Area* areas, uint8_t num );
92 :
93 : /** Dimensions of regions around currntly found hole. Used
94 : to estimate optimal split */
95 : struct Dims
96 : {
97 : uint8_t x1, x2, x3;
98 : uint8_t y1, y2, y3;
99 : uint8_t w1, w2, w3, w4, w5, w6, w7, w8;
100 : uint8_t h1, h2, h3, h4, h5, h6, h7, h8;
101 : } _dim;
102 :
103 : /** Describes region that is used to search holes withing */
104 : struct Area
105 : {
106 21 : Area()
107 21 : : emptySize( 0 ), valid( false )
108 21 : {}
109 0 : explicit Area( PixelViewport pvp_ )
110 0 : : emptySize( 0 ), pvp ( pvp_ ), valid( false )
111 0 : {}
112 :
113 : int32_t emptySize; //!< number of empty blocks
114 : PixelViewport pvp; //!< PVP of area
115 : PixelViewport hole; //!< largest hole
116 :
117 : bool valid; //!< Used in debug build only
118 : };
119 :
120 : Area _tmpAreas[17]; //!< possible arreas
121 : Area _finalAreas[4]; //!< links to picked areas from _tmpAreas
122 :
123 : std::vector< Area > _areasToCheck;//!< Areas used to search for holes
124 :
125 : PixelViewport _pvp; //<! current, alligned to grid, PVP
126 : PixelViewport _pvpOriginal;//<! original PVP
127 :
128 : ROIEmptySpaceFinder _emptyFinder;//!< class to search for holes
129 :
130 : int32_t _w; //!< alligned to grid width
131 : int32_t _h; //!< alligned to grid height
132 : int32_t _wh; //!< _w * _h
133 : int32_t _wb; //!< _w + 1 (only 1 block currently is used as border)
134 : int32_t _hb; //!< _h + 1 (only 1 block currently is used as border)
135 : int32_t _wbhb; //!< _wb * _wh (total number of blocks in _mask)
136 :
137 : Vectorub _mask; //!< mask of occupied blocks (main data)
138 :
139 : std::vector<float> _perBlockInfo; //!< buffer for data from GPU
140 :
141 : uint8_t _histX[256]; //!< histogram to find BB along X axis
142 : uint8_t _histY[256]; //!< histogram to find BB along Y axis
143 :
144 : Image _tmpImg; //!< used for dumping debug info
145 :
146 : ROITracker _roiTracker; //!< disables ROI when ROI is inefficient
147 : };
148 : }
149 :
150 : #endif // EQ_ROI_FINDER_H
|