ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
point3d_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 "base/point3d"
33 #include "util/testing.h"
34 
35 #include "base/point3d.h"
36 
37 using namespace colmap;
38 
39 BOOST_AUTO_TEST_CASE(TestDefault) {
40  Point3D point3D;
41  BOOST_CHECK_EQUAL(point3D.X(), 0);
42  BOOST_CHECK_EQUAL(point3D.Y(), 0);
43  BOOST_CHECK_EQUAL(point3D.Z(), 0);
44  BOOST_CHECK_EQUAL(point3D.XYZ()[0], point3D.X());
45  BOOST_CHECK_EQUAL(point3D.XYZ()[1], point3D.Y());
46  BOOST_CHECK_EQUAL(point3D.XYZ()[2], point3D.Z());
47  BOOST_CHECK_EQUAL(point3D.Color()[0], 0);
48  BOOST_CHECK_EQUAL(point3D.Color()[1], 0);
49  BOOST_CHECK_EQUAL(point3D.Color()[2], 0);
50  BOOST_CHECK_EQUAL(point3D.Error(), -1.0);
51  BOOST_CHECK_EQUAL(point3D.HasError(), false);
52  BOOST_CHECK_EQUAL(point3D.Track().Length(), 0);
53 }
54 
56  Point3D point3D;
57  BOOST_CHECK_EQUAL(point3D.X(), 0);
58  BOOST_CHECK_EQUAL(point3D.Y(), 0);
59  BOOST_CHECK_EQUAL(point3D.Z(), 0);
60  BOOST_CHECK_EQUAL(point3D.XYZ()[0], point3D.X());
61  BOOST_CHECK_EQUAL(point3D.XYZ()[1], point3D.Y());
62  BOOST_CHECK_EQUAL(point3D.XYZ()[2], point3D.Z());
63  point3D.SetXYZ(Eigen::Vector3d(0.1, 0.2, 0.3));
64  BOOST_CHECK_EQUAL(point3D.X(), 0.1);
65  BOOST_CHECK_EQUAL(point3D.Y(), 0.2);
66  BOOST_CHECK_EQUAL(point3D.Z(), 0.3);
67  BOOST_CHECK_EQUAL(point3D.XYZ()[0], point3D.X());
68  BOOST_CHECK_EQUAL(point3D.XYZ()[1], point3D.Y());
69  BOOST_CHECK_EQUAL(point3D.XYZ()[2], point3D.Z());
70  point3D.XYZ() = Eigen::Vector3d(0.2, 0.3, 0.4);
71  BOOST_CHECK_EQUAL(point3D.X(), 0.2);
72  BOOST_CHECK_EQUAL(point3D.Y(), 0.3);
73  BOOST_CHECK_EQUAL(point3D.Z(), 0.4);
74  BOOST_CHECK_EQUAL(point3D.XYZ()[0], point3D.X());
75  BOOST_CHECK_EQUAL(point3D.XYZ()[1], point3D.Y());
76  BOOST_CHECK_EQUAL(point3D.XYZ()[2], point3D.Z());
77 }
78 
80  Point3D point3D;
81  BOOST_CHECK_EQUAL(point3D.Color()[0], 0);
82  BOOST_CHECK_EQUAL(point3D.Color()[1], 0);
83  BOOST_CHECK_EQUAL(point3D.Color()[2], 0);
84  point3D.SetColor(Eigen::Vector3ub(1, 2, 3));
85  BOOST_CHECK_EQUAL(point3D.Color()[0], 1);
86  BOOST_CHECK_EQUAL(point3D.Color()[1], 2);
87  BOOST_CHECK_EQUAL(point3D.Color()[2], 3);
88 }
89 
91  Point3D point3D;
92  BOOST_CHECK_EQUAL(point3D.Error(), -1.0);
93  BOOST_CHECK_EQUAL(point3D.HasError(), false);
94  point3D.SetError(1.0);
95  BOOST_CHECK_EQUAL(point3D.Error(), 1.0);
96  BOOST_CHECK_EQUAL(point3D.HasError(), true);
97  point3D.SetError(-1.0);
98  BOOST_CHECK_EQUAL(point3D.Error(), -1.0);
99  BOOST_CHECK_EQUAL(point3D.HasError(), false);
100 }
101 
103  Point3D point3D;
104  BOOST_CHECK_EQUAL(point3D.Track().Length(), 0);
105  point3D.SetTrack(Track());
106  BOOST_CHECK_EQUAL(point3D.Track().Length(), 0);
107  Track track;
108  track.AddElement(0, 1);
109  track.AddElement(0, 2);
110  point3D.SetTrack(track);
111  BOOST_CHECK_EQUAL(point3D.Track().Length(), 2);
112  track.AddElement(0, 3);
113  BOOST_CHECK_EQUAL(point3D.Track().Length(), 2);
114 }
double Y() const
Definition: point3d.h:84
void SetError(const double error)
Definition: point3d.h:104
void SetTrack(const class Track &track)
Definition: point3d.h:110
const Eigen::Vector3d & XYZ() const
Definition: point3d.h:74
const class Track & Track() const
Definition: point3d.h:106
double X() const
Definition: point3d.h:82
double Z() const
Definition: point3d.h:86
void SetColor(const Eigen::Vector3ub &color)
Definition: point3d.h:98
bool HasError() const
Definition: point3d.h:102
void SetXYZ(const Eigen::Vector3d &xyz)
Definition: point3d.h:88
double Error() const
Definition: point3d.h:100
const Eigen::Vector3ub & Color() const
Definition: point3d.h:90
void AddElement(const TrackElement &element)
Definition: track.h:103
size_t Length() const
Definition: track.h:82
Matrix< uint8_t, 3, 1 > Vector3ub
Definition: types.h:42
BOOST_AUTO_TEST_CASE(TestDefault)
Definition: point3d_test.cc:39