ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
gps_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/gps"
33 #include "util/testing.h"
34 
35 #include "base/gps.h"
36 
37 using namespace colmap;
38 
39 BOOST_AUTO_TEST_CASE(TestEllToXYZGRS80) {
40  std::vector<Eigen::Vector3d> ell;
41  ell.emplace_back(48 + 8. / 60 + 51.70361 / 3600,
42  11 + 34. / 60 + 10.51777 / 3600, 561.1851);
43  ell.emplace_back(48 + 8. / 60 + 52.40575 / 3600,
44  11 + 34. / 60 + 11.77179 / 3600, 561.1509);
45  std::vector<Eigen::Vector3d> ref_xyz;
46  ref_xyz.emplace_back(4.1772397090808507e6, 0.85515377993121441e6,
47  4.7282674046563692e6);
48  ref_xyz.emplace_back(4.1772186604902023e6, 0.8551759313518483e6,
49  4.7282818502697079e6);
50 
52 
53  const auto xyz = gps_tform.EllToXYZ(ell);
54 
55  for (size_t i = 0; i < ell.size(); ++i) {
56  BOOST_CHECK(std::abs(xyz[i](0) - ref_xyz[i](0)) < 1e-8);
57  BOOST_CHECK(std::abs(xyz[i](1) - ref_xyz[i](1)) < 1e-8);
58  BOOST_CHECK(std::abs(xyz[i](2) - ref_xyz[i](2)) < 1e-8);
59  }
60 }
61 
62 BOOST_AUTO_TEST_CASE(TestEllToXYZWGS84) {
63  std::vector<Eigen::Vector3d> ell;
64  ell.emplace_back(48 + 8. / 60 + 51.70361 / 3600,
65  11 + 34. / 60 + 10.51777 / 3600, 561.1851);
66  ell.emplace_back(48 + 8. / 60 + 52.40575 / 3600,
67  11 + 34. / 60 + 11.77179 / 3600, 561.1509);
68  std::vector<Eigen::Vector3d> ref_xyz;
69  ref_xyz.emplace_back(4.1772397090808507e6, 0.85515377993121441e6,
70  4.7282674046563692e6);
71  ref_xyz.emplace_back(4.1772186604902023e6, 0.8551759313518483e6,
72  4.7282818502697079e6);
73 
75 
76  const auto xyz = gps_tform.EllToXYZ(ell);
77 
78  for (size_t i = 0; i < ell.size(); ++i) {
79  BOOST_CHECK(std::abs(xyz[i](0) - ref_xyz[i](0)) < 1e-8);
80  BOOST_CHECK(std::abs(xyz[i](1) - ref_xyz[i](1)) < 1e-8);
81  BOOST_CHECK(std::abs(xyz[i](2) - ref_xyz[i](2)) < 1e-8);
82  }
83 }
84 
85 BOOST_AUTO_TEST_CASE(TestXYZToEll_GRS80) {
86  std::vector<Eigen::Vector3d> xyz;
87  xyz.emplace_back(4.1772397090808507e6, 0.85515377993121441e6,
88  4.7282674046563692e6);
89  xyz.emplace_back(4.1772186604902023e6, 0.8551759313518483e6,
90  4.7282818502697079e6);
91  std::vector<Eigen::Vector3d> ref_ell;
92  ref_ell.emplace_back(48 + 8. / 60 + 51.70361 / 3600,
93  11 + 34. / 60 + 10.51777 / 3600, 561.1851);
94  ref_ell.emplace_back(48 + 8. / 60 + 52.40575 / 3600,
95  11 + 34. / 60 + 11.77179 / 3600, 561.1509);
96 
98 
99  const auto ell = gps_tform.XYZToEll(xyz);
100 
101  for (size_t i = 0; i < xyz.size(); ++i) {
102  BOOST_CHECK(std::abs(ell[i](0) - ref_ell[i](0)) < 1e-5);
103  BOOST_CHECK(std::abs(ell[i](1) - ref_ell[i](1)) < 1e-5);
104  BOOST_CHECK(std::abs(ell[i](2) - ref_ell[i](2)) < 1e-5);
105  }
106 }
107 
108 BOOST_AUTO_TEST_CASE(TestXYZToEll_WGS84) {
109  std::vector<Eigen::Vector3d> xyz;
110  xyz.emplace_back(4.1772397090808507e6, 0.85515377993121441e6,
111  4.7282674046563692e6);
112  xyz.emplace_back(4.1772186604902023e6, 0.8551759313518483e6,
113  4.7282818502697079e6);
114  std::vector<Eigen::Vector3d> ref_ell;
115  ref_ell.emplace_back(48 + 8. / 60 + 51.70361 / 3600,
116  11 + 34. / 60 + 10.51777 / 3600, 561.1851);
117  ref_ell.emplace_back(48 + 8. / 60 + 52.40575 / 3600,
118  11 + 34. / 60 + 11.77179 / 3600, 561.1509);
119 
121 
122  const auto ell = gps_tform.XYZToEll(xyz);
123 
124  for (size_t i = 0; i < xyz.size(); ++i) {
125  BOOST_CHECK(std::abs(ell[i](0) - ref_ell[i](0)) < 1e-5);
126  BOOST_CHECK(std::abs(ell[i](1) - ref_ell[i](1)) < 1e-5);
127  BOOST_CHECK(std::abs(ell[i](2) - ref_ell[i](2)) < 1e-5);
128  }
129 }
130 
131 BOOST_AUTO_TEST_CASE(TestXYZToEllToXYZ_GRS80) {
132  std::vector<Eigen::Vector3d> xyz;
133  xyz.emplace_back(4.177239709080851e6, 0.855153779931214e6,
134  4.728267404656370e6);
135  xyz.emplace_back(4.177218660490202e6, 0.855175931351848e6,
136  4.728281850269709e6);
137 
139 
140  const auto ell = gps_tform.XYZToEll(xyz);
141  const auto xyz2 = gps_tform.EllToXYZ(ell);
142 
143  for (size_t i = 0; i < xyz.size(); ++i) {
144  BOOST_CHECK(std::abs(xyz[i](0) - xyz2[i](0)) < 1e-5);
145  BOOST_CHECK(std::abs(xyz[i](1) - xyz2[i](1)) < 1e-5);
146  BOOST_CHECK(std::abs(xyz[i](2) - xyz2[i](2)) < 1e-5);
147  }
148 }
149 
150 BOOST_AUTO_TEST_CASE(TestXYZToEllToXYZ_WGS84) {
151  std::vector<Eigen::Vector3d> xyz;
152  xyz.emplace_back(4.177239709080851e6, 0.855153779931214e6,
153  4.728267404656370e6);
154  xyz.emplace_back(4.177218660490202e6, 0.855175931351848e6,
155  4.728281850269709e6);
156 
158 
159  const auto ell = gps_tform.XYZToEll(xyz);
160  const auto xyz2 = gps_tform.EllToXYZ(ell);
161 
162  for (size_t i = 0; i < xyz.size(); ++i) {
163  BOOST_CHECK(std::abs(xyz[i](0) - xyz2[i](0)) < 1e-5);
164  BOOST_CHECK(std::abs(xyz[i](1) - xyz2[i](1)) < 1e-5);
165  BOOST_CHECK(std::abs(xyz[i](2) - xyz2[i](2)) < 1e-5);
166  }
167 }
std::vector< Eigen::Vector3d > EllToXYZ(const std::vector< Eigen::Vector3d > &ell) const
Definition: gps.cc:57
std::vector< Eigen::Vector3d > XYZToEll(const std::vector< Eigen::Vector3d > &xyz) const
Definition: gps.cc:82
const double * e
BOOST_AUTO_TEST_CASE(TestEllToXYZGRS80)
Definition: gps_test.cc:39