39#include <visp3/core/vpConfig.h>
41#if defined(VISP_HAVE_CATCH2)
43#include <visp3/core/vpHomogeneousMatrix.h>
44#include <visp3/core/vpMath.h>
46#include <catch_amalgamated.hpp>
52#include <visp3/core/vpIoTools.h>
55#ifdef ENABLE_VISP_NAMESPACE
59TEST_CASE(
"Lon-Lat generator",
"[math_lonlat]")
61 const int lonStart = 0, lonEnd = 360, nlon = 20;
62 const int latStart = 0, latEnd = 90, nLat = 10;
65 const double radius = 5;
67 std::vector<std::pair<double, double> > lonlatVec;
68 lonlatVec.reserve(longitudes.size() * latitudes.size());
69 for (
auto lon : longitudes) {
70 for (
auto lat : latitudes) {
71 lonlatVec.emplace_back(lon, lat);
77 std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
79 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
81 std::cout <<
"Lon-Lat ecef_M_ned:\n" << ecef_M_ned << std::endl;
83 CHECK(ecef_M_ned.isValid());
84 CHECK(ecef_M_ned.getRotationMatrix().isARotationMatrix());
85 CHECK(
vpMath::equal(ecef_M_ned.getTranslationVector().sumSquare(), radius * radius));
94 const std::string folder =
"NED/lon-lat/";
97 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
99 std::ofstream file(filename);
100 if (file.is_open()) {
101 (ecef_M_ned * ned_M_cv).save(file);
109 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
111 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
113 std::cout <<
"Lon-Lat ecef_M_enu:\n" << ecef_M_enu << std::endl;
115 CHECK(ecef_M_enu.isValid());
116 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
117 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
123 const std::string folder =
"ENU/lon-lat/";
126 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
128 std::ofstream file(filename);
129 if (file.is_open()) {
130 (ecef_M_enu * enu_M_cv).save(file);
138TEST_CASE(
"Equidistributed sphere point",
"[math_equi_sphere_pts]")
140 const unsigned int maxPoints = 200;
142 const double radius = 5;
146 std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
148 CHECK(!ecef_M_ned_vec.empty());
149 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
151 std::cout <<
"Equidistributed ecef_M_ned:\n" << ecef_M_ned << std::endl;
153 CHECK(ecef_M_ned.isValid());
154 CHECK(ecef_M_ned.getRotationMatrix().isARotationMatrix());
155 CHECK(
vpMath::equal(ecef_M_ned.getTranslationVector().sumSquare(), radius * radius));
164 const std::string folder =
"NED/equi/";
167 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
169 std::ofstream file(filename);
170 if (file.is_open()) {
171 (ecef_M_ned * ned_M_cv).save(file);
179 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
181 CHECK(!ecef_M_enu_vec.empty());
182 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
184 std::cout <<
"Equidistributed ecef_M_enu:\n" << ecef_M_enu << std::endl;
186 CHECK(ecef_M_enu.isValid());
187 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
188 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
195 const std::string folder =
"ENU/equi/";
198 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
199 std::stringstream buffer;
201 std::ofstream file(filename);
202 if (file.is_open()) {
203 (ecef_M_enu * enu_M_cv).save(file);
210TEST_CASE(
"Look-at",
"[math_look_at]")
213 vpColVector from_blender = { 8.867762565612793, -1.1965436935424805, 2.1211400032043457 };
216 blender_M_gl[0][0] = 0;
217 blender_M_gl[0][2] = 1;
218 blender_M_gl[1][0] = 1;
219 blender_M_gl[1][1] = 0;
220 blender_M_gl[2][1] = 1;
221 blender_M_gl[2][2] = 0;
232 std::cout <<
"\ngl_M_cam:\n" << gl_M_cam << std::endl;
240 std::cout <<
"\nbl_M_cv:\n" << bl_M_cv << std::endl;
244 8.867762565612793, 0.9910191297531128, -0.030843468382954597,
245 0.13011434674263, -1.1965436935424805, -5.4016709327697754e-08,
246 -0.9730352163314819, -0.23065657913684845, 2.121140241622925 });
247 std::cout <<
"\nbl_M_cv_gt:\n" << bl_M_cv_gt << std::endl;
249 const double tolerance = 1
e-6;
250 for (
unsigned int i = 0;
i < 3;
i++) {
251 for (
unsigned int j = 0;
j < 4;
j++) {
252 CHECK(
vpMath::equal(bl_M_cv[i][j], bl_M_cv_gt[i][j], tolerance));
257int main(
int argc,
char *argv[])
259 Catch::Session session;
260 session.applyCommandLine(argc, argv);
261 int numFailed = session.run();
267int main() {
return EXIT_SUCCESS; }
Implementation of column vector and the associated operations.
Implementation of an homogeneous matrix and operations on such kind of matrices.
vpRotationMatrix getRotationMatrix() const
static std::vector< double > linspace(T start_in, T end_in, unsigned int num_in)
static std::vector< vpHomogeneousMatrix > getLocalTangentPlaneTransformations(const std::vector< std::pair< double, double > > &lonlatVec, double radius, LongLattToHomogeneous func)
static vpHomogeneousMatrix lookAt(const vpColVector &from, const vpColVector &to, vpColVector tmp)
static bool equal(double x, double y, double threshold=0.001)
static vpHomogeneousMatrix enu2ecef(double lonDeg, double latDeg, double radius)
static std::vector< std::pair< double, double > > computeRegularPointsOnSphere(unsigned int maxPoints)
static vpHomogeneousMatrix ned2ecef(double lonDeg, double latDeg, double radius)