Ocean
TestFramePyramid.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  *
4  * This source code is licensed under the MIT license found in the
5  * LICENSE file in the root directory of this source tree.
6  */
7 
8 #ifndef META_OCEAN_TEST_TESTCV_TEST_FRAME_PYRAMID_H
9 #define META_OCEAN_TEST_TESTCV_TEST_FRAME_PYRAMID_H
10 
12 
13 #include "ocean/base/Frame.h"
14 #include "ocean/base/Worker.h"
15 
16 #include "ocean/cv/FramePyramid.h"
17 
18 namespace Ocean
19 {
20 
21 namespace Test
22 {
23 
24 namespace TestCV
25 {
26 
27 /**
28  * This class implements tests for the functionality of frame pyramids.
29  * @see Ocean::CV::FramePyramid
30  * @ingroup testcv
31  */
32 class OCEAN_TEST_CV_EXPORT TestFramePyramid : protected CV::FramePyramid
33 {
34  protected:
35 
36  /**
37  * Default value to create as many layers as possible.
38  */
39  static constexpr unsigned int ALL_LAYERS = (unsigned int)(-1);
40 
41  public:
42 
43  /**
44  * Tests the functionality of frame pyramids
45  * @param testDuration Number of seconds for each test
46  * @param worker The worker object to distribute the computational load
47  * @return True, if succeeded
48  */
49  static bool test(const double testDuration, Worker& worker);
50 
51  /**
52  * Tests the ideal layers functions.
53  * @param testDuration Number of seconds for each test
54  * @return True, if succeeded
55  */
56  static bool testIdealLayers(const double testDuration);
57 
58  /**
59  * Tests the isOwner() function.
60  * @param testDuration Number of seconds for each test, with range (0, infinity)
61  * @return True, if succeeded
62  */
63  static bool testIsOwner(const double testDuration);
64 
65  /**
66  * Tests the calculateMemorySize() function.
67  * @param testDuration Number of seconds for each test, with range (0, infinity)
68  * @return True, if succeeded
69  */
70  static bool testCalculateMemorySize(const double testDuration);
71 
72  /**
73  * Tests the creation of a frame pyramid using the constructor.
74  * @param testDuration Number of seconds for each test, with range (0, infinity)
75  * @param worker The worker object to distribute the computation
76  * @return True, if succeeded
77  */
78  static bool testCreationFramePyramidWithConstructor(const double testDuration, Worker& worker);
79 
80  /**
81  * Tests the creation of a frame pyramid using the constructor for a specific frame with specific number of resulting layers.
82  * @param width The width of the test frame in pixel, width range [1, infinity)
83  * @param height The width of the test frame in pixel, height range [1, infinity)
84  * @param channels The width of the test frame in pixel, channels range [1, infinity)
85  * @param layers The number of pyramid layers to be created, with range [1, infinity)
86  * @param testDuration Number of seconds for each test, with range (0, infinity)
87  * @param worker The worker object to distribute the computation
88  * @return True, if succeeded
89  */
90  static bool testCreationFramePyramidWithConstructor(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker& worker);
91 
92  /**
93  * Tests the creation of a frame pyramid using the replace() function.
94  * @param testDuration Number of seconds for each test, with range (0, infinity)
95  * @param worker The worker object to distribute the computation
96  * @return True, if succeeded
97  */
98  static bool testCreationFramePyramidWithReplace(const double testDuration, Worker& worker);
99 
100  /**
101  * Tests the creation of a frame pyramid using the replace() function for a specific frame with specific number of resulting layers.
102  * @param width The width of the test frame in pixel, width range [1, infinity)
103  * @param height The width of the test frame in pixel, height range [1, infinity)
104  * @param channels The width of the test frame in pixel, channels range [1, infinity)
105  * @param layers The number of pyramid layers to be created, with range [1, infinity)
106  * @param testDuration Number of seconds for each test, with range (0, infinity)
107  * @param worker The worker object to distribute the computation
108  * @return True, if succeeded
109  */
110  static bool testCreationFramePyramidWithReplace(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker& worker);
111 
112  /**
113  * Tests the creation of a frame pyramid with extreme parameters.
114  * @return True, if the test succeeded; otherwise, false is returned.
115  */
117 
118  /**
119  * Tests the construction of a new frame pyramid from an existing frame.
120  * @param testDuration Requested duration of test loop in seconds
121  * @param worker Optional worker instance
122  * @return True, if the test succeeded; otherwise, false is returned
123  */
124  static bool testConstructFromFrameMultiLayer(const double testDuration, Worker& worker);
125 
126  /**
127  * Tests the construction of a new frame pyramid from an existing frame.
128  * @param width The width of the source image in pixel, with range [1, infinity)
129  * @param height The height of the source image in pixel, with range [1, infinity)
130  * @param layerCount Number of layers to create, with range [1, infinity)
131  * @param testDuration Requested duration of test loop in seconds
132  * @param worker The worker object to distribute the computation
133  * @return True, if the test succeeded; otherwise, false is returned
134  */
135  static bool testConstructFromFrameMultiLayer(const unsigned int width, const unsigned int height, const unsigned int layerCount, const double testDuration, Worker& worker);
136 
137  /**
138  * Tests the construction of a new frame pyramid from an existing source pyramid.
139  * @param testDuration Requested duration of test loop in seconds
140  * @param worker The worker object to distribute the computation
141  * @return True, if the test succeeded; otherwise, false is returned.
142  */
143  static bool testConstructFromPyramid(const double testDuration, Worker& worker);
144 
145  /**
146  * Tests the replacement of a frame pyramid using a frame type.
147  * @param testDuration Requested duration of test loop in seconds
148  * @return True, if the test succeeded; otherwise, false is returned.
149  */
150  static bool testReplaceWithFrameType(const double testDuration);
151 
152  /**
153  * Tests the replacement of a frame pyramid using a frame type.
154  * @param testDuration Requested duration of test loop in seconds
155  * @param worker The worker object to distribute the computation
156  * @return True, if the test succeeded; otherwise, false is returned.
157  */
158  static bool testReplaceWithFrame(const double testDuration, Worker& worker);
159 
160  /**
161  * Tests the replacement of a frame pyramid using a 1-1 downsampling.
162  * @param testDuration Requested duration of test loop in seconds
163  * @param worker The worker object to distribute the computation
164  * @return True, if the test succeeded; otherwise, false is returned.
165  */
166  static bool testReplace11(const double testDuration, Worker& worker);
167 
168  /**
169  * Tests the constructor of a frame pyramid using a 1-1 downsampling.
170  * @param testDuration Requested duration of test loop in seconds
171  * @param worker The worker object to distribute the computation
172  * @return True, if the test succeeded; otherwise, false is returned.
173  */
174  static bool testConstructor11(const double testDuration, Worker& worker);
175 
176  /**
177  * Tests the reduceLayers() function.
178  * @param testDuration Number of seconds for each test, with range (0, infinity)
179  * @return True, if succeeded
180  */
181  static bool testReduceLayers(const double testDuration);
182 
183  protected:
184 
185  /**
186  * Validates the visual content of a frame pyramid.
187  * @param frame The frame from which the frame pyramid has been created, must be valid
188  * @param framePyramid The frame pyramid to be validated, must be valid
189  * @param downsamplingMode The downsampling mode that has been applied when creating the pyramid, either DM_FILTER_11 or DM_FILTER_14641
190  * @param layers The explicit number of pyramid layers to be checked, with range [1, infinity)
191  * @param allowCompatibleFrameType True, to allow a compatible frame type; False, to expect a perfectly matching frame type
192  * @return True, if succeeded
193  */
194  static bool validateFramePyramid(const Frame& frame, const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const unsigned int layers, const bool allowCompatibleFrameType = false);
195 
196  /**
197  * Validates the visual content of a frame pyramid.
198  * @param frame The frame from which the frame pyramid has been created, must be valid
199  * @param framePyramid The frame pyramid to be validated, must be valid
200  * @param downsamplingFunction The function which has been used to downsample the pyramid layers, must be valid
201  * @param layers The explicit number of pyramid layers to be checked, with range [1, infinity)
202  * @param allowCompatibleFrameType True, to allow a compatible frame type; False, to expect a perfectly matching frame type
203  * @return True, if succeeded
204  */
205  static bool validateFramePyramid(const Frame& frame, const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingFunction& downsamplingFunction, const unsigned int layers, const bool allowCompatibleFrameType = false);
206 
207  /**
208  * Validates if the frame pyramid was created correctly with the specified settings.
209  * @param framePyramid The frame pyramid to validate, must be valid
210  * @param downsamplingMode The downsampling mode that has been applied when creating the pyramid, either DM_FILTER_11 or DM_FILTER_14641
211  * @param frame The frame that was used to create the frame pyramid, must be valid
212  * @param numberLayers The number of layers the pyramid needs to have, with range [1, infinity)
213  * @param readOnlyLayers The indices of all layers which are expected to be read-only, all other layers are expected to be writable
214  * @param ownerLayers The indices of all layers which are expected to own the memory
215  * @param outsideMemoryBlockLayers The indices of all layers which are expected to have their memory outside of the pyramid's memory block
216  * @return True, if the pyramid is correct
217  */
218  static bool validateConstructFromFrame(const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const Frame& frame, const unsigned int numberLayers, const UnorderedIndexSet32& readOnlyLayers, const UnorderedIndexSet32& ownerLayers, const UnorderedIndexSet32& outsideMemoryBlockLayers);
219 
220  /**
221  * Validates if the frame pyramid was created correctly with the specified settings.
222  * @param framePyramid The frame pyramid to validate, must be valid
223  * @param downsamplingFunction The function which has been used to downsample the pyramid layers, must be valid
224  * @param frame The frame that was used to create the frame pyramid, must be valid
225  * @param numberLayers The number of layers the pyramid needs to have, with range [1, infinity)
226  * @param readOnlyLayers The indices of all layers which are expected to be read-only, all other layers are expected to be writable
227  * @param ownerLayers The indices of all layers which are expected to own the memory
228  * @param outsideMemoryBlockLayers The indices of all layers which are expected to have their memory outside of the pyramid's memory block
229  * @return True, if the pyramid is correct
230  */
231  static bool validateConstructFromFrame(const CV::FramePyramid& framePyramid, const CV::FramePyramid::DownsamplingFunction& downsamplingFunction, const Frame& frame, const unsigned int numberLayers, const UnorderedIndexSet32& readOnlyLayers, const UnorderedIndexSet32& ownerLayers, const UnorderedIndexSet32& outsideMemoryBlockLayers);
232 
233  /**
234  * Returns the maximum layer count for the given frame width and height
235  * @param width Frame width in pixel
236  * @param height Frame height in pixel
237  * @return The maximum number of pyramid layers that can be generate for this frame
238  */
239  static unsigned int determineMaxLayerCount(unsigned int width, unsigned int height);
240 
241  /**
242  * Verifies the ownership properties of a frame pyramid.
243  * @param framePyramid The frame pyramid to verify, can be invalid
244  * @param isValid True, if the frame pyramid is expected to be valid
245  * @param isOwner True, if the entire frame pyramid is expected to own the memory of all pyramid layers; False, if at least one layer is not owned
246  * @param layerIsOwner The explicit indices of all pyramid layers for which the pyramid is owning the memory, all other layers don't own the memory, empty to skip this check
247  * @return True, if all properties match
248  */
249  static bool verifyPyramidOwnership(const CV::FramePyramid& framePyramid, const bool isValid, const bool isOwner, const Indices32& layerIsOwner = Indices32());
250 };
251 
252 }
253 
254 }
255 
256 }
257 
258 #endif // META_OCEAN_TEST_TESTCV_TEST_FRAME_PYRAMID_H
This class implements a frame pyramid.
Definition: FramePyramid.h:37
std::function< bool(const Frame &sourceLayer, Frame &targetLayer, Worker *worker)> DownsamplingFunction
Definition of a function allowing to downsample a frame.
Definition: FramePyramid.h:82
DownsamplingMode
Definition of individual down sampling modes.
Definition: FramePyramid.h:44
This class implements Ocean's image class.
Definition: Frame.h:1792
This class implements tests for the functionality of frame pyramids.
Definition: TestFramePyramid.h:33
static bool testConstructor11(const double testDuration, Worker &worker)
Tests the constructor of a frame pyramid using a 1-1 downsampling.
static bool testCreationFramePyramidWithConstructor(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the constructor for a specific frame with specific number...
static bool testCalculateMemorySize(const double testDuration)
Tests the calculateMemorySize() function.
static bool testConstructFromFrameMultiLayer(const unsigned int width, const unsigned int height, const unsigned int layerCount, const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing frame.
static bool testConstructFromPyramid(const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing source pyramid.
static bool validateConstructFromFrame(const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const Frame &frame, const unsigned int numberLayers, const UnorderedIndexSet32 &readOnlyLayers, const UnorderedIndexSet32 &ownerLayers, const UnorderedIndexSet32 &outsideMemoryBlockLayers)
Validates if the frame pyramid was created correctly with the specified settings.
static bool verifyPyramidOwnership(const CV::FramePyramid &framePyramid, const bool isValid, const bool isOwner, const Indices32 &layerIsOwner=Indices32())
Verifies the ownership properties of a frame pyramid.
static bool testCreationFramePyramidWithConstructor(const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the constructor.
static bool testCreationFramePyramidWithReplace(const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the replace() function.
static bool validateFramePyramid(const Frame &frame, const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingMode downsamplingMode, const unsigned int layers, const bool allowCompatibleFrameType=false)
Validates the visual content of a frame pyramid.
static bool testReplace11(const double testDuration, Worker &worker)
Tests the replacement of a frame pyramid using a 1-1 downsampling.
static bool validateConstructFromFrame(const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingFunction &downsamplingFunction, const Frame &frame, const unsigned int numberLayers, const UnorderedIndexSet32 &readOnlyLayers, const UnorderedIndexSet32 &ownerLayers, const UnorderedIndexSet32 &outsideMemoryBlockLayers)
Validates if the frame pyramid was created correctly with the specified settings.
static bool testReplaceWithFrameType(const double testDuration)
Tests the replacement of a frame pyramid using a frame type.
static bool testIsOwner(const double testDuration)
Tests the isOwner() function.
static bool testIdealLayers(const double testDuration)
Tests the ideal layers functions.
static unsigned int determineMaxLayerCount(unsigned int width, unsigned int height)
Returns the maximum layer count for the given frame width and height.
static bool testConstructFromFrameMultiLayer(const double testDuration, Worker &worker)
Tests the construction of a new frame pyramid from an existing frame.
static bool testReduceLayers(const double testDuration)
Tests the reduceLayers() function.
static bool testCreateFramePyramidExtreme()
Tests the creation of a frame pyramid with extreme parameters.
static bool testReplaceWithFrame(const double testDuration, Worker &worker)
Tests the replacement of a frame pyramid using a frame type.
static bool test(const double testDuration, Worker &worker)
Tests the functionality of frame pyramids.
static bool testCreationFramePyramidWithReplace(const unsigned int width, const unsigned int height, const unsigned int channels, const unsigned int layers, const double testDuration, Worker &worker)
Tests the creation of a frame pyramid using the replace() function for a specific frame with specific...
static bool validateFramePyramid(const Frame &frame, const CV::FramePyramid &framePyramid, const CV::FramePyramid::DownsamplingFunction &downsamplingFunction, const unsigned int layers, const bool allowCompatibleFrameType=false)
Validates the visual content of a frame pyramid.
This class implements a worker able to distribute function calls over different threads.
Definition: Worker.h:33
std::vector< Index32 > Indices32
Definition of a vector holding 32 bit index values.
Definition: Base.h:96
std::unordered_set< Index32 > UnorderedIndexSet32
Definition of an unordered_set holding 32 bit indices.
Definition: Base.h:126
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15