height_converter_test.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. // BSD 3-Clause License
  2. //
  3. // Copyright (c) 2022, Map IV, Inc.
  4. // All rights reserved.
  5. //
  6. // Redistribution and use in source and binary forms, with or without
  7. // modification, are permitted provided that the following conditions are met:
  8. //
  9. // 1. Redistributions of source code must retain the above copyright notice, this
  10. // list of conditions and the following disclaimer.
  11. //
  12. // 2. Redistributions in binary form must reproduce the above copyright notice,
  13. // this list of conditions and the following disclaimer in the documentation
  14. // and/or other materials provided with the distribution.
  15. //
  16. // 3. Neither the name of the copyright holder nor the names of its
  17. // contributors may be used to endorse or promote products derived from
  18. // this software without specific prior written permission.
  19. //
  20. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. #include "llh_converter/height_converter.hpp"
  31. #include "llh_converter/llh_converter.hpp"
  32. #include <iostream>
  33. #include <iomanip>
  34. void test(const double& result, const double& answer)
  35. {
  36. int i_result = std::round(result * 10000);
  37. int i_answer = std::round(answer * 10000);
  38. if (i_result == i_answer)
  39. {
  40. std::cout << "\033[32;1mTEST SUCCESS: " << result << " == " << answer << "\033[m" << std::endl;
  41. }
  42. else
  43. {
  44. std::cout << "\033[31;1mTEST FAILED : " << result << " != " << answer << "\033[m" << std::endl;
  45. }
  46. }
  47. int main(int argc, char** argv)
  48. {
  49. llh_converter::HeightConverter hc;
  50. // GSIGEO Test
  51. hc.setGeoidType(llh_converter::GeoidType::GSIGEO2011);
  52. hc.loadGSIGEOGeoidFile();
  53. std::cout << "Testing (" << std::setw(6) << 35 << ", " << std::setw(6) << 135 << ") ... ";
  54. test(hc.getGeoidDeg(35, 135), 37.0557);
  55. std::cout << "Testing (" << std::setw(6) << 35.01 << ", " << std::setw(6) << 135.01 << ") ... ";
  56. test(hc.getGeoidDeg(35.01, 135.01), 37.0925);
  57. std::cout << "Testing (" << std::setw(6) << 35.5 << ", " << std::setw(6) << 135.5 << ") ... ";
  58. test(hc.getGeoidDeg(35.5, 135.5), 36.8691);
  59. std::cout << "Testing (" << std::setw(6) << 35 << ", " << std::setw(6) << 137 << ") ... ";
  60. test(hc.getGeoidDeg(35, 137), 38.4267);
  61. std::cout << "Testing (" << std::setw(6) << 39.2 << ", " << std::setw(6) << 140.9 << ") ... ";
  62. test(hc.getGeoidDeg(39.2, 140.9), 41.7035);
  63. std::cout << "Testing (" << std::setw(6) << 43.3 << ", " << std::setw(6) << 141.8 << ") ... ";
  64. test(hc.getGeoidDeg(43.3, 141.8), 31.3455);
  65. std::cout << "Testing (" << std::setw(6) << 43 << ", " << std::setw(6) << 141 << ") ... ";
  66. test(hc.getGeoidDeg(43, 141), 33.5306);
  67. std::cout << "Testing (" << std::setw(6) << 33.1 << ", " << std::setw(6) << 131.1 << ") ... ";
  68. test(hc.getGeoidDeg(33.1, 131.1), 33.0331);
  69. std::cout << "Testing (" << std::setw(6) << 26.6 << ", " << std::setw(6) << 128.1 << ") ... ";
  70. test(hc.getGeoidDeg(26.6, 128.1), 32.2696);
  71. // convertHeight Test
  72. test(hc.convertHeightDeg(35, 135, 0, llh_converter::ConvertType::ORTHO2ELLIPS), 37.0557);
  73. test(hc.convertHeightDeg(35, 135, 0, llh_converter::ConvertType::ELLIPS2ORTHO), -37.0557);
  74. // LLHConverter test
  75. llh_converter::LLHConverter llh_converter;
  76. llh_converter::LLHParam param;
  77. param.use_mgrs = true;
  78. param.height_convert_type = llh_converter::ConvertType::NONE;
  79. param.geoid_type = llh_converter::GeoidType::EGM2008;
  80. double test_lat = 35.5, test_lon = 135.5;
  81. double x, y, z;
  82. std::cout << "TEST MGRS" << std::endl;
  83. llh_converter.convertDeg2XYZ(test_lat, test_lon, 50, x, y, z, param);
  84. std::cout << std::setprecision(15) << x << ", " << y << ", " << z << std::endl;
  85. // Test JPRCS
  86. param.use_mgrs = false;
  87. param.plane_num = 5;
  88. std::cout << "TEST JPRCS" << std::endl;
  89. llh_converter.convertDeg2XYZ(test_lat, test_lon, 50, x, y, z, param);
  90. std::cout << std::setprecision(15) << x << ", " << y << ", " << z << std::endl;
  91. return 0;
  92. }