ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
normal_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/normal_map_test"
33 #include "util/testing.h"
34 
35 #include "mvs/normal_map.h"
36 
37 using namespace colmap;
38 using namespace colmap::mvs;
39 
41  NormalMap normal_map;
42  BOOST_CHECK_EQUAL(normal_map.GetWidth(), 0);
43  BOOST_CHECK_EQUAL(normal_map.GetHeight(), 0);
44  BOOST_CHECK_EQUAL(normal_map.GetDepth(), 3);
45 }
46 
47 BOOST_AUTO_TEST_CASE(TestNonEmpty) {
48  NormalMap normal_map(1, 2);
49  BOOST_CHECK_EQUAL(normal_map.GetWidth(), 1);
50  BOOST_CHECK_EQUAL(normal_map.GetHeight(), 2);
51  BOOST_CHECK_EQUAL(normal_map.GetDepth(), 3);
52 }
53 
54 BOOST_AUTO_TEST_CASE(TestRescale) {
55  NormalMap normal_map(6, 7);
56  normal_map.Rescale(0.5);
57  BOOST_CHECK_EQUAL(normal_map.GetWidth(), 3);
58  BOOST_CHECK_EQUAL(normal_map.GetHeight(), 4);
59  BOOST_CHECK_EQUAL(normal_map.GetDepth(), 3);
60 }
61 
62 BOOST_AUTO_TEST_CASE(TestDownsize) {
63  NormalMap normal_map(6, 7);
64  normal_map.Downsize(2, 4);
65  BOOST_CHECK_EQUAL(normal_map.GetWidth(), 2);
66  BOOST_CHECK_EQUAL(normal_map.GetHeight(), 2);
67  BOOST_CHECK_EQUAL(normal_map.GetDepth(), 3);
68 }
69 
70 BOOST_AUTO_TEST_CASE(TestToBitmap) {
71  NormalMap normal_map(2, 2);
72  normal_map.Set(0, 0, 0, 0);
73  normal_map.Set(0, 0, 1, 0);
74  normal_map.Set(0, 0, 2, 1);
75  normal_map.Set(0, 1, 0, 0);
76  normal_map.Set(0, 1, 1, 1);
77  normal_map.Set(0, 1, 2, 0);
78  normal_map.Set(1, 0, 0, 1);
79  normal_map.Set(1, 0, 1, 0);
80  normal_map.Set(1, 0, 2, 0);
81  normal_map.Set(1, 1, 0, 1 / std::sqrt(2.0f));
82  normal_map.Set(1, 1, 1, 1 / std::sqrt(2.0f));
83  normal_map.Set(1, 1, 2, 0);
84  const Bitmap bitmap = normal_map.ToBitmap();
85  BOOST_CHECK_EQUAL(bitmap.Width(), normal_map.GetWidth());
86  BOOST_CHECK_EQUAL(bitmap.Height(), normal_map.GetHeight());
87  BOOST_CHECK_EQUAL(bitmap.IsRGB(), true);
89  BOOST_CHECK(bitmap.GetPixel(0, 0, &color));
90  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(128, 128, 0));
91  BOOST_CHECK(bitmap.GetPixel(0, 1, &color));
92  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(0, 128, 0));
93  BOOST_CHECK(bitmap.GetPixel(1, 0, &color));
94  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(128, 0, 0));
95  BOOST_CHECK(bitmap.GetPixel(1, 1, &color));
96  BOOST_CHECK_EQUAL(color, BitmapColor<uint8_t>(37, 37, 0));
97 }
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
size_t GetWidth() const
Definition: mat.h:71
size_t GetDepth() const
Definition: mat.h:81
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
void Rescale(const float factor)
Definition: normal_map.cc:50
void Downsize(const size_t max_width, const size_t max_height)
Definition: normal_map.cc:88
Bitmap ToBitmap() const
Definition: normal_map.cc:97
BOOST_AUTO_TEST_CASE(TestEmpty)