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
59 TEST_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) {
98 std::stringstream buffer;
99 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
100 std::string filename = buffer.str();
101 std::ofstream file(filename);
102 if (file.is_open()) {
103 (ecef_M_ned * ned_M_cv).save(file);
111 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
113 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
115 std::cout <<
"Lon-Lat ecef_M_enu:\n" << ecef_M_enu << std::endl;
117 CHECK(ecef_M_enu.isValid());
118 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
119 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
125 const std::string folder =
"ENU/lon-lat/";
128 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
129 std::stringstream buffer;
130 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
131 std::string filename = buffer.str();
132 std::ofstream file(filename);
133 if (file.is_open()) {
134 (ecef_M_enu * enu_M_cv).save(file);
142 TEST_CASE(
"Equidistributed sphere point",
"[math_equi_sphere_pts]")
144 const unsigned int maxPoints = 200;
146 const double radius = 5;
150 std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
152 CHECK(!ecef_M_ned_vec.empty());
153 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
155 std::cout <<
"Equidistributed ecef_M_ned:\n" << ecef_M_ned << std::endl;
157 CHECK(ecef_M_ned.isValid());
158 CHECK(ecef_M_ned.getRotationMatrix().isARotationMatrix());
159 CHECK(
vpMath::equal(ecef_M_ned.getTranslationVector().sumSquare(), radius * radius));
168 const std::string folder =
"NED/equi/";
171 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
172 std::stringstream buffer;
173 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
174 std::string filename = buffer.str();
175 std::ofstream file(filename);
176 if (file.is_open()) {
177 (ecef_M_ned * ned_M_cv).save(file);
185 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
187 CHECK(!ecef_M_enu_vec.empty());
188 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
190 std::cout <<
"Equidistributed ecef_M_enu:\n" << ecef_M_enu << std::endl;
192 CHECK(ecef_M_enu.isValid());
193 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
194 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
201 const std::string folder =
"ENU/equi/";
204 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
205 std::stringstream buffer;
206 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
207 std::string filename = buffer.str();
208 std::ofstream file(filename);
209 if (file.is_open()) {
210 (ecef_M_enu * enu_M_cv).save(file);
217 TEST_CASE(
"Look-at",
"[math_look_at]")
220 vpColVector from_blender = { 8.867762565612793, -1.1965436935424805, 2.1211400032043457 };
223 blender_M_gl[0][0] = 0;
224 blender_M_gl[0][2] = 1;
225 blender_M_gl[1][0] = 1;
226 blender_M_gl[1][1] = 0;
227 blender_M_gl[2][1] = 1;
228 blender_M_gl[2][2] = 0;
239 std::cout <<
"\ngl_M_cam:\n" << gl_M_cam << std::endl;
247 std::cout <<
"\nbl_M_cv:\n" << bl_M_cv << std::endl;
251 8.867762565612793, 0.9910191297531128, -0.030843468382954597,
252 0.13011434674263, -1.1965436935424805, -5.4016709327697754e-08,
253 -0.9730352163314819, -0.23065657913684845, 2.121140241622925 });
254 std::cout <<
"\nbl_M_cv_gt:\n" << bl_M_cv_gt << std::endl;
256 const double tolerance = 1e-6;
257 for (
unsigned int i = 0; i < 3; i++) {
258 for (
unsigned int j = 0; j < 4; j++) {
259 CHECK(
vpMath::equal(bl_M_cv[i][j], bl_M_cv_gt[i][j], tolerance));
264 int main(
int argc,
char *argv[])
266 Catch::Session session;
267 session.applyCommandLine(argc, argv);
268 int numFailed = session.run();
274 int 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< 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 std::vector< double > linspace(T start_in, T end_in, unsigned int num_in)
static vpHomogeneousMatrix ned2ecef(double lonDeg, double latDeg, double radius)
vpRotationMatrix t() const