ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
depth_map_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2018, ETH Zurich and UNC Chapel Hill.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 //
7 // * Redistributions of source code must retain the above copyright
8 // notice, this list of conditions and the following disclaimer.
9 //
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 //
14 // * Neither the name of ETH Zurich and UNC Chapel Hill nor the names of
15 // its contributors may be used to endorse or promote products derived
16 // from this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 // POSSIBILITY OF SUCH DAMAGE.
29 //
30 // Author: Johannes L. Schoenberger (jsch-at-demuc-dot-de)
31 
32 #define TEST_NAME "mvs/depth_map_test"
33 #include "util/testing.h"
34 
35 #include "mvs/depth_map.h"
36 
37 using namespace colmap;
38 using namespace colmap::mvs;
39 
41  DepthMap depth_map;
42  BOOST_CHECK_EQUAL(depth_map.GetWidth(), 0);
43  BOOST_CHECK_EQUAL(depth_map.GetHeight(), 0);
44  BOOST_CHECK_EQUAL(depth_map.GetDepth(), 1);
45  BOOST_CHECK_EQUAL(depth_map.GetDepthMin(), -1);
46  BOOST_CHECK_EQUAL(depth_map.GetDepthMax(), -1);
47 }
48 
49 BOOST_AUTO_TEST_CASE(TestNonEmpty) {
50  DepthMap depth_map(1, 2, 0, 1);
51  BOOST_CHECK_EQUAL(depth_map.GetWidth(), 1);
52  BOOST_CHECK_EQUAL(depth_map.GetHeight(), 2);
53  BOOST_CHECK_EQUAL(depth_map.GetDepth(), 1);
54  BOOST_CHECK_EQUAL(depth_map.GetDepthMin(), 0);
55  BOOST_CHECK_EQUAL(depth_map.GetDepthMax(), 1);
56 }
57 
58 BOOST_AUTO_TEST_CASE(TestRescale) {
59  DepthMap depth_map(6, 7, 0, 1);
60  depth_map.Rescale(0.5);
61  BOOST_CHECK_EQUAL(depth_map.GetWidth(), 3);
62  BOOST_CHECK_EQUAL(depth_map.GetHeight(), 4);
63  BOOST_CHECK_EQUAL(depth_map.GetDepth(), 1);
64  BOOST_CHECK_EQUAL(depth_map.GetDepthMin(), 0);
65  BOOST_CHECK_EQUAL(depth_map.GetDepthMax(), 1);
66 }
67 
68 BOOST_AUTO_TEST_CASE(TestDownsize) {
69  DepthMap depth_map(6, 7, 0, 1);
70  depth_map.Downsize(2, 4);
71  BOOST_CHECK_EQUAL(depth_map.GetWidth(), 2);
72  BOOST_CHECK_EQUAL(depth_map.GetHeight(), 2);
73  BOOST_CHECK_EQUAL(depth_map.GetDepth(), 1);
74  BOOST_CHECK_EQUAL(depth_map.GetDepthMin(), 0);
75  BOOST_CHECK_EQUAL(depth_map.GetDepthMax(), 1);
76 }
77 
78 BOOST_AUTO_TEST_CASE(TestToBitmap) {
79  DepthMap depth_map(2, 2, 0.1, 0.9);
80  depth_map.Fill(0.9);
81  depth_map.Set(0, 0, 0, 0.1);
82  depth_map.Set(0, 1, 0, 0.5);
83  const Bitmap bitmap = depth_map.ToBitmap(0, 100);
84  BOOST_CHECK_EQUAL(bitmap.Width(), depth_map.GetWidth());
85  BOOST_CHECK_EQUAL(bitmap.Height(), depth_map.GetHeight());
86  BOOST_CHECK_EQUAL(bitmap.IsRGB(), true);
88  BOOST_CHECK(bitmap.GetPixel(0, 0, &color));
89  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(0, 0, 128));
90  BOOST_CHECK(bitmap.GetPixel(0, 1, &color));
91  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(128, 0, 0));
92  BOOST_CHECK(bitmap.GetPixel(1, 0, &color));
93  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(128, 255, 127));
94  BOOST_CHECK(bitmap.GetPixel(1, 1, &color));
95  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(128, 0, 0));
96 }
math::float4 color
bool GetPixel(const int x, const int y, BitmapColor< uint8_t > *color) const
Definition: bitmap.cc:178
bool IsRGB() const
Definition: bitmap.h:261
int Width() const
Definition: bitmap.h:249
int Height() const
Definition: bitmap.h:250
void Downsize(const size_t max_width, const size_t max_height)
Definition: depth_map.cc:75
float GetDepthMin() const
Definition: depth_map.h:50
Bitmap ToBitmap(const float min_percentile, const float max_percentile) const
Definition: depth_map.cc:84
float GetDepthMax() const
Definition: depth_map.h:52
void Rescale(const float factor)
Definition: depth_map.cc:57
size_t GetWidth() const
Definition: mat.h:71
size_t GetDepth() const
Definition: mat.h:81
void Fill(const T value)
Definition: mat.h:131
void Set(const size_t row, const size_t col, const T value)
Definition: mat.h:118
size_t GetHeight() const
Definition: mat.h:76
BOOST_AUTO_TEST_CASE(TestEmpty)