ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
geometry_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 BOOST_TEST_MAIN
33 #define BOOST_TEST_MODULE "retrieval/geometry"
34 #include <boost/test/unit_test.hpp>
35 
36 #include <Eigen/Dense>
37 #include <iostream>
38 
39 #include "retrieval/geometry.h"
40 
41 using namespace colmap::retrieval;
42 
43 BOOST_AUTO_TEST_CASE(TestIdentity) {
44  for (float x = 0; x < 3; ++x) {
45  for (float y = 0; y < 3; ++y) {
46  for (float scale = 1; scale < 5; ++scale) {
47  for (float orientation = 0; orientation < 3; ++orientation) {
48  FeatureGeometry feature1;
49  feature1.x = x;
50  feature1.y = y;
51  feature1.scale = scale;
52  feature1.orientation = orientation;
53  FeatureGeometry feature2;
54  feature2.x = x;
55  feature2.y = y;
56  feature2.scale = scale;
57  feature2.orientation = orientation;
58  const auto tform_matrix =
60  BOOST_CHECK(
61  tform_matrix.isApprox(Eigen::Matrix<float, 2, 3>::Identity()));
62  const auto tform =
63  FeatureGeometry::TransformFromMatch(feature1, feature2);
64  BOOST_CHECK_CLOSE(tform.scale, 1, 1e-6);
65  BOOST_CHECK_CLOSE(tform.angle, 0, 1e-6);
66  BOOST_CHECK_CLOSE(tform.tx, 0, 1e-6);
67  BOOST_CHECK_CLOSE(tform.ty, 0, 1e-6);
68  }
69  }
70  }
71  }
72 }
73 
74 BOOST_AUTO_TEST_CASE(TestTranslation) {
75  for (float x = 0; x < 3; ++x) {
76  for (float y = 0; y < 3; ++y) {
77  FeatureGeometry feature1;
78  feature1.scale = 1;
79  FeatureGeometry feature2;
80  feature2.x = x;
81  feature2.y = y;
82  feature2.scale = 1;
83  feature2.orientation = 0;
84  const auto tform_matrix =
86  BOOST_CHECK(
87  tform_matrix.leftCols<2>().isApprox(Eigen::Matrix2f::Identity()));
88  BOOST_CHECK(tform_matrix.rightCols<1>().isApprox(Eigen::Vector2f(x, y)));
89  const auto tform =
90  FeatureGeometry::TransformFromMatch(feature1, feature2);
91  BOOST_CHECK_CLOSE(tform.scale, 1, 1e-6);
92  BOOST_CHECK_CLOSE(tform.angle, 0, 1e-6);
93  BOOST_CHECK_CLOSE(tform.tx, x, 1e-6);
94  BOOST_CHECK_CLOSE(tform.ty, y, 1e-6);
95  }
96  }
97 }
98 
100  for (float scale = 1; scale < 5; ++scale) {
101  FeatureGeometry feature1;
102  feature1.scale = 1;
103  FeatureGeometry feature2;
104  feature2.scale = scale;
105  feature2.orientation = 0;
106  const auto tform_matrix =
107  FeatureGeometry::TransformMatrixFromMatch(feature1, feature2);
108  BOOST_CHECK(tform_matrix.leftCols<2>().isApprox(
109  scale * Eigen::Matrix2f::Identity()));
110  BOOST_CHECK(tform_matrix.rightCols<1>().isApprox(Eigen::Vector2f(0, 0)));
111  const auto tform = FeatureGeometry::TransformFromMatch(feature1, feature2);
112  BOOST_CHECK_CLOSE(tform.scale, scale, 1e-6);
113  BOOST_CHECK_CLOSE(tform.angle, 0, 1e-6);
114  BOOST_CHECK_CLOSE(tform.tx, 0, 1e-6);
115  BOOST_CHECK_CLOSE(tform.ty, 0, 1e-6);
116  }
117 }
118 
119 BOOST_AUTO_TEST_CASE(TestOrientation) {
120  for (float orientation = 0; orientation < 3; ++orientation) {
121  FeatureGeometry feature1;
122  feature1.scale = 1;
123  feature1.orientation = 0;
124  FeatureGeometry feature2;
125  feature2.scale = 1;
126  feature2.orientation = orientation;
127  const auto tform_matrix =
128  FeatureGeometry::TransformMatrixFromMatch(feature1, feature2);
129  BOOST_CHECK_CLOSE(tform_matrix.leftCols<2>().determinant(), 1, 1e-5);
130  BOOST_CHECK(tform_matrix.rightCols<1>().isApprox(Eigen::Vector2f(0, 0)));
131  const auto tform = FeatureGeometry::TransformFromMatch(feature1, feature2);
132  BOOST_CHECK_CLOSE(tform.scale, 1, 1e-6);
133  BOOST_CHECK_CLOSE(tform.angle, orientation, 1e-6);
134  BOOST_CHECK_CLOSE(tform.tx, 0, 1e-6);
135  BOOST_CHECK_CLOSE(tform.ty, 0, 1e-6);
136  }
137 }
const double * e
BOOST_AUTO_TEST_CASE(TestIdentity)
normal_z y
normal_z x
static FeatureGeometryTransform TransformFromMatch(const FeatureGeometry &feature1, const FeatureGeometry &feature2)
Definition: geometry.cc:37
static Eigen::Matrix< float, 2, 3 > TransformMatrixFromMatch(const FeatureGeometry &feature1, const FeatureGeometry &feature2)
Definition: geometry.cc:59