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_EMPTY_SPACE_FINDER_H
20 : #define EQ_ROI_EMPTY_SPACE_FINDER_H
21 :
22 : #include <eq/types.h>
23 : #include <vector>
24 :
25 : namespace eq
26 : {
27 : /** @internal Finds largest empty regions. */
28 : class ROIEmptySpaceFinder
29 : {
30 : public:
31 2 : ROIEmptySpaceFinder()
32 2 : : _w(0)
33 : , _h(0)
34 : , _limAbs(200)
35 : , _limRel(.002f)
36 2 : , _mask(0)
37 : {
38 2 : }
39 :
40 2 : virtual ~ROIEmptySpaceFinder() {}
41 : /** Updated data structure from a given mask. Limits should be
42 : re-initialized after calling this function */
43 : void update(const uint8_t* mask, const int32_t w, const int32_t h);
44 :
45 : /** Returns maximal empty pvp within a given pvp.
46 : Uses mask data from update to check if single block is empty! */
47 : PixelViewport getLargestEmptyArea(const PixelViewport& pvp) const;
48 :
49 0 : void setLimits(const int16_t absolute, const float relative)
50 : {
51 0 : _limAbs = absolute;
52 0 : _limRel = relative;
53 0 : }
54 :
55 : private:
56 : uint16_t _getArea(const int32_t x, const int32_t y, const int32_t w,
57 : const int32_t h) const;
58 :
59 : uint16_t _getArea(const int32_t w, const int32_t h,
60 : const uint16_t* data) const;
61 :
62 : /** Updates dimensions, resizes data if needed */
63 : void _resize(const int32_t w, const int32_t h);
64 :
65 : bool _updateMaximalEmptyRegion(const int32_t x, const int32_t y,
66 : const int32_t w, const int32_t h,
67 : PixelViewport& pvp,
68 : const uint16_t* data) const;
69 :
70 : int32_t _w;
71 : int32_t _h;
72 :
73 : int16_t _limAbs;
74 : float _limRel;
75 :
76 : Vectorus _data;
77 : const uint8_t* _mask;
78 : };
79 : }
80 :
81 : #endif // EQ_ROI_EMPTY_SPACE_FINDER_H
|