ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
triangulation_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/triangulation"
33 #include "util/testing.h"
34 
35 #include <Eigen/Core>
36 
38 #include "base/triangulation.h"
39 
40 using namespace colmap;
41 
42 BOOST_AUTO_TEST_CASE(TestTriangulatePoint) {
43  std::vector<Eigen::Vector3d> points3D(6);
44  points3D[0] = Eigen::Vector3d(0, 0.1, 0.1);
45  points3D[1] = Eigen::Vector3d(0, 1, 3);
46  points3D[2] = Eigen::Vector3d(0, 1, 2);
47  points3D[3] = Eigen::Vector3d(0.01, 0.2, 3);
48  points3D[4] = Eigen::Vector3d(-1, 0.1, 1);
49  points3D[5] = Eigen::Vector3d(0.1, 0.1, 0.2);
50 
51  Eigen::Matrix3x4d proj_matrix1 = Eigen::MatrixXd::Identity(3, 4);
52 
53  for (double qz = 0; qz < 1; qz += 0.2) {
54  for (double tx = 0; tx < 10; tx += 2) {
55  SimilarityTransform3 tform(1, Eigen::Vector4d(0.2, 0.3, 0.4, qz),
56  Eigen::Vector3d(tx, 2, 3));
57 
58  Eigen::Matrix3x4d proj_matrix2 = tform.Matrix().topLeftCorner<3, 4>();
59 
60  for (size_t i = 0; i < points3D.size(); ++i) {
61  const Eigen::Vector3d& point3D = points3D[i];
62  const Eigen::Vector4d point3D1(point3D(0), point3D(1), point3D(2), 1);
63  Eigen::Vector3d point2D1 = proj_matrix1 * point3D1;
64  Eigen::Vector3d point2D2 = proj_matrix2 * point3D1;
65  point2D1 /= point2D1(2);
66  point2D2 /= point2D2(2);
67 
68  const Eigen::Vector2d point2D1_N(point2D1(0), point2D1(1));
69  const Eigen::Vector2d point2D2_N(point2D2(0), point2D2(1));
70 
71  const Eigen::Vector3d tri_point3D = TriangulatePoint(
72  proj_matrix1, proj_matrix2, point2D1_N, point2D2_N);
73 
74  BOOST_CHECK((point3D - tri_point3D).norm() < 1e-10);
75  }
76  }
77  }
78 }
79 
80 BOOST_AUTO_TEST_CASE(TestCalculateTriangulationAngle) {
81  const Eigen::Vector3d tvec1(0, 0, 0);
82  const Eigen::Vector3d tvec2(0, 1, 0);
83 
84  BOOST_CHECK_CLOSE(
85  CalculateTriangulationAngle(tvec1, tvec2, Eigen::Vector3d(0, 0, 100)),
86  0.009999666687, 1e-8);
87  BOOST_CHECK_CLOSE(
88  CalculateTriangulationAngle(tvec1, tvec2, Eigen::Vector3d(0, 0, 50)),
89  0.019997333973, 1e-8);
90  BOOST_CHECK_CLOSE(CalculateTriangulationAngles(
91  tvec1, tvec2, {Eigen::Vector3d(0, 0, 50)})[0],
92  0.019997333973, 1e-8);
93 }
Eigen::Matrix4d Matrix() const
const double * e
Matrix< double, 3, 4 > Matrix3x4d
Definition: types.h:39
std::vector< double > CalculateTriangulationAngles(const Eigen::Vector3d &proj_center1, const Eigen::Vector3d &proj_center2, const std::vector< Eigen::Vector3d > &points3D)
Eigen::Vector3d TriangulatePoint(const Eigen::Matrix3x4d &proj_matrix1, const Eigen::Matrix3x4d &proj_matrix2, const Eigen::Vector2d &point1, const Eigen::Vector2d &point2)
double CalculateTriangulationAngle(const Eigen::Vector3d &proj_center1, const Eigen::Vector3d &proj_center2, const Eigen::Vector3d &point3D)
BOOST_AUTO_TEST_CASE(TestTriangulatePoint)