ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
mat_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/mat_test"
33 #include "util/testing.h"
34 
35 #include "mvs/mat.h"
36 
37 using namespace colmap::mvs;
38 
40  Mat<int> mat;
41  BOOST_CHECK_EQUAL(mat.GetWidth(), 0);
42  BOOST_CHECK_EQUAL(mat.GetHeight(), 0);
43  BOOST_CHECK_EQUAL(mat.GetDepth(), 0);
44  BOOST_CHECK_EQUAL(mat.GetNumBytes(), 0);
45 }
46 
47 BOOST_AUTO_TEST_CASE(TestNonEmpty) {
48  Mat<int> mat(1, 2, 3);
49  BOOST_CHECK_EQUAL(mat.GetWidth(), 1);
50  BOOST_CHECK_EQUAL(mat.GetHeight(), 2);
51  BOOST_CHECK_EQUAL(mat.GetDepth(), 3);
52  BOOST_CHECK_EQUAL(mat.GetNumBytes(), 24);
53 }
54 
55 BOOST_AUTO_TEST_CASE(TestGetSet) {
56  Mat<int> mat(1, 2, 3);
57 
58  BOOST_CHECK_EQUAL(mat.GetNumBytes(), 24);
59 
60  mat.Set(0, 0, 0, 1);
61  mat.Set(0, 0, 1, 2);
62  mat.Set(0, 0, 2, 3);
63  mat.Set(1, 0, 0, 4);
64  mat.Set(1, 0, 1, 5);
65  mat.Set(1, 0, 2, 6);
66 
67  BOOST_CHECK_EQUAL(mat.Get(0, 0, 0), 1);
68  BOOST_CHECK_EQUAL(mat.Get(0, 0, 1), 2);
69  BOOST_CHECK_EQUAL(mat.Get(0, 0, 2), 3);
70  BOOST_CHECK_EQUAL(mat.Get(1, 0, 0), 4);
71  BOOST_CHECK_EQUAL(mat.Get(1, 0, 1), 5);
72  BOOST_CHECK_EQUAL(mat.Get(1, 0, 2), 6);
73 
74  int slice[3];
75  mat.GetSlice(0, 0, slice);
76  BOOST_CHECK_EQUAL(slice[0], 1);
77  BOOST_CHECK_EQUAL(slice[1], 2);
78  BOOST_CHECK_EQUAL(slice[2], 3);
79  mat.GetSlice(1, 0, slice);
80  BOOST_CHECK_EQUAL(slice[0], 4);
81  BOOST_CHECK_EQUAL(slice[1], 5);
82  BOOST_CHECK_EQUAL(slice[2], 6);
83 }
84 
86  Mat<int> mat(1, 2, 3);
87 
88  BOOST_CHECK_EQUAL(mat.GetNumBytes(), 24);
89 
90  mat.Fill(10);
91  mat.Set(0, 0, 0, 10);
92  mat.Set(0, 0, 1, 10);
93  mat.Set(0, 0, 2, 10);
94  mat.Set(1, 0, 0, 10);
95  mat.Set(1, 0, 1, 10);
96  mat.Set(1, 0, 2, 10);
97 }
size_t GetWidth() const
Definition: mat.h:71
size_t GetDepth() const
Definition: mat.h:81
size_t GetNumBytes() const
Definition: mat.h:86
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
T Get(const size_t row, const size_t col, const size_t slice=0) const
Definition: mat.h:91
size_t GetHeight() const
Definition: mat.h:76
void GetSlice(const size_t row, const size_t col, T *values) const
Definition: mat.h:96
BOOST_AUTO_TEST_CASE(TestEmpty)
Definition: mat_test.cc:39