39 #include <visp3/core/vpConfig.h>
41 #ifdef VISP_HAVE_CATCH2
43 #include <visp3/core/vpHomogeneousMatrix.h>
44 #include <visp3/core/vpMath.h>
46 #define CATCH_CONFIG_RUNNER
53 #include <visp3/core/vpIoTools.h>
56 #ifdef ENABLE_VISP_NAMESPACE
60 TEST_CASE(
"Lon-Lat generator",
"[math_lonlat]")
62 const int lonStart = 0, lonEnd = 360, nlon = 20;
63 const int latStart = 0, latEnd = 90, nLat = 10;
66 const double radius = 5;
68 std::vector<std::pair<double, double> > lonlatVec;
69 lonlatVec.reserve(longitudes.size() * latitudes.size());
70 for (
auto lon : longitudes) {
71 for (
auto lat : latitudes) {
72 lonlatVec.emplace_back(lon, lat);
78 std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
80 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
82 std::cout <<
"Lon-Lat ecef_M_ned:\n" << ecef_M_ned << std::endl;
84 CHECK(ecef_M_ned.isValid());
85 CHECK(ecef_M_ned.getRotationMatrix().isARotationMatrix());
86 CHECK(
vpMath::equal(ecef_M_ned.getTranslationVector().sumSquare(), radius * radius));
95 const std::string folder =
"NED/lon-lat/";
98 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
99 std::stringstream buffer;
100 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
101 std::string filename = buffer.str();
102 std::ofstream file(filename);
103 if (file.is_open()) {
104 (ecef_M_ned * ned_M_cv).save(file);
112 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
114 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
116 std::cout <<
"Lon-Lat ecef_M_enu:\n" << ecef_M_enu << std::endl;
118 CHECK(ecef_M_enu.isValid());
119 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
120 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
126 const std::string folder =
"ENU/lon-lat/";
129 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
130 std::stringstream buffer;
131 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
132 std::string filename = buffer.str();
133 std::ofstream file(filename);
134 if (file.is_open()) {
135 (ecef_M_enu * enu_M_cv).save(file);
143 TEST_CASE(
"Equidistributed sphere point",
"[math_equi_sphere_pts]")
145 const unsigned int maxPoints = 200;
147 const double radius = 5;
151 std::vector<vpHomogeneousMatrix> ecef_M_ned_vec =
153 CHECK(!ecef_M_ned_vec.empty());
154 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
156 std::cout <<
"Equidistributed ecef_M_ned:\n" << ecef_M_ned << std::endl;
158 CHECK(ecef_M_ned.isValid());
159 CHECK(ecef_M_ned.getRotationMatrix().isARotationMatrix());
160 CHECK(
vpMath::equal(ecef_M_ned.getTranslationVector().sumSquare(), radius * radius));
169 const std::string folder =
"NED/equi/";
172 for (
const auto &ecef_M_ned : ecef_M_ned_vec) {
173 std::stringstream buffer;
174 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
175 std::string filename = buffer.str();
176 std::ofstream file(filename);
177 if (file.is_open()) {
178 (ecef_M_ned * ned_M_cv).save(file);
186 std::vector<vpHomogeneousMatrix> ecef_M_enu_vec =
188 CHECK(!ecef_M_enu_vec.empty());
189 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
191 std::cout <<
"Equidistributed ecef_M_enu:\n" << ecef_M_enu << std::endl;
193 CHECK(ecef_M_enu.isValid());
194 CHECK(ecef_M_enu.getRotationMatrix().isARotationMatrix());
195 CHECK(
vpMath::equal(ecef_M_enu.getTranslationVector().sumSquare(), radius * radius));
202 const std::string folder =
"ENU/equi/";
205 for (
const auto &ecef_M_enu : ecef_M_enu_vec) {
206 std::stringstream buffer;
207 buffer << folder <<
"ecef_M_cv_" << std::setw(4) << std::setfill(
'0') << i++ <<
".txt";
208 std::string filename = buffer.str();
209 std::ofstream file(filename);
210 if (file.is_open()) {
211 (ecef_M_enu * enu_M_cv).save(file);
218 TEST_CASE(
"Look-at",
"[math_look_at]")
221 vpColVector from_blender = { 8.867762565612793, -1.1965436935424805, 2.1211400032043457 };
224 blender_M_gl[0][0] = 0;
225 blender_M_gl[0][2] = 1;
226 blender_M_gl[1][0] = 1;
227 blender_M_gl[1][1] = 0;
228 blender_M_gl[2][1] = 1;
229 blender_M_gl[2][2] = 0;
240 std::cout <<
"\ngl_M_cam:\n" << gl_M_cam << std::endl;
248 std::cout <<
"\nbl_M_cv:\n" << bl_M_cv << std::endl;
252 8.867762565612793, 0.9910191297531128, -0.030843468382954597,
253 0.13011434674263, -1.1965436935424805, -5.4016709327697754e-08,
254 -0.9730352163314819, -0.23065657913684845, 2.121140241622925 });
255 std::cout <<
"\nbl_M_cv_gt:\n" << bl_M_cv_gt << std::endl;
257 const double tolerance = 1e-6;
258 for (
unsigned int i = 0; i < 3; i++) {
259 for (
unsigned int j = 0; j < 4; j++) {
260 CHECK(
vpMath::equal(bl_M_cv[i][j], bl_M_cv_gt[i][j], tolerance));
265 int main(
int argc,
char *argv[])
267 Catch::Session session;
270 session.applyCommandLine(argc, argv);
272 int numFailed = session.run();
282 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