Main MRPT website > C++ reference for MRPT 1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include <mrpt/system/os.h>
11 #include <mrpt/system/datetime.h>
12 #include <mrpt/poses/CPose3D.h>
15 #include <mrpt/math/interp_fit.hpp>
16 #include <mrpt/math/utils.h>
17 #include <mrpt/random.h>
19 #include <iostream>
20 
21 using namespace mrpt::gui;
22 using namespace mrpt::random;
23 using namespace mrpt::math;
24 using namespace std;
25 
26 // ------------------------------------------------------
27 // TestCapture
28 // ------------------------------------------------------
30 {
32  mrpt::system::TTimeStamp ts = iniTs;
33  mrpt::system::TTimeStamp ots = iniTs;
34  mrpt::poses::CPose3D pose(0, 0, 0, 0, 0, 0);
36  std::vector<mrpt::poses::CPose3D> p;
37  mrpt::poses::CPose3D outPose(0, 0, 0, 0, 0, 0);
38  bool valid;
39 
40  FILE* f = mrpt::system::os::fopen("interpolation.txt", "wt");
41 
42  // Set the maximum value of the interval time for considering interpolation
43  poseInt.setMaxTimeInterpolation(1.0);
44 
45  poseInt.insert(ts, pose); // First point
46 
47  ts += 1e7;
48  pose.setFromValues(1, 1, 0, 0, 1, 0);
49  poseInt.insert(ts, pose); // Second point
50 
51  ts += 1e7;
52  pose.setFromValues(2, 2.5, 1, 0, 1.3, 0);
53  poseInt.insert(ts, pose); // Third point
54 
55  ts += 1e7;
56  pose.setFromValues(3, 1.7, 2, 0, 1.57, 0);
57  poseInt.insert(ts, pose); // Fourth point
58 
59  unsigned int i;
60  for (i = 0, ots = iniTs; ots <= iniTs + 3e7; ots += 1e6, i++)
61  {
62  poseInt.interpolate(ots, outPose, valid);
63  p.push_back(outPose);
65  f, "%d %f %f %f %f %f %f\n", i, outPose.x(), outPose.y(),
66  outPose.z(), outPose.yaw(), outPose.pitch(), outPose.roll());
67  }
68 
70 
71 } // end TestCPose3DInterpolation
72 
74 {
75  FILE* f = mrpt::system::os::fopen("out2", "wt");
76 
77  CVectorDouble x, y;
78  double t;
79  x.resize(4);
80  y.resize(4);
81 
82  // x[0] = 0.0; x[1] = 1.0; x[2] = 2.0; x[3] = 4.0;
83  // y[0] = 0.0; y[1] = 1.0; y[2] = 1.8; y[3] = 1.6;
84 
85  x[0] = -1.5;
86  x[1] = -0.5;
87  x[2] = 0.5;
88  x[3] = 1.5;
89  y[0] = 3.14;
90  y[1] = -3.10;
91  y[2] = -3.05;
92  y[3] = 3.10;
93 
94  CVectorDouble ts, ys_interp;
95 
96  for (t = x[1]; t <= x[2]; t += 0.01)
97  {
98  double w = mrpt::math::spline(t, x, y); // wrap no
99  // double w = mrpt::math::spline(t, x, y, true); // wrap yes
100  ts.push_back(t);
101  ys_interp.push_back(w);
102  mrpt::system::os::fprintf(f, "%f %f\n", t, w);
103  }
104 
106  cout << "Done" << endl;
107 
108 #if MRPT_HAS_WXWIDGETS
109  CDisplayWindowPlots figure("Interpolation results");
110  figure.plot(x, y, "r.4", "true points");
111  figure.plot(ts, ys_interp, "b", "interp");
112 
113  figure.axis_equal();
114  figure.axis_fit();
115 
116  figure.waitForKey();
117 #endif
118 }
119 
121 {
122  const size_t N = 15;
123  CVectorDouble data_x, data_y(N);
124 
125  // Create random data:
126  mrpt::math::linspace(-20.0, 20.0, N, data_x);
127  getRandomGenerator().drawGaussian1DVector(data_y, 2.0, 1.0);
128 
129  // Create interpolator
131 
132  // Generate sequence of where to interpolate:
133  CVectorDouble xs;
134  mrpt::math::linspace(-20.0, 20.0, 500, xs);
135 
136  CVectorDouble ys;
137  bool valid = interp.queryVector(xs, ys);
138  ASSERT_(valid);
139 
140 #if MRPT_HAS_WXWIDGETS
141  CDisplayWindowPlots figure("Interpolation results");
142  figure.plot(data_x, data_y, "r.6", "true points");
143  figure.plot(xs, ys, "b", "interp");
144 
145  figure.axis_equal();
146  figure.axis_fit();
147 
148  figure.waitForKey();
149 #endif
150 }
151 
152 int main(int argc, char** argv)
153 {
154  try
155  {
157  // TestSplineInterpolation();
158  // TestCPose3DInterpolation();
159 
160  return 0;
161  }
162  catch (std::exception& e)
163  {
164  std::cout << "MRPT exception caught: " << e.what() << std::endl;
165  return -1;
166  }
167  catch (...)
168  {
169  printf("Another exception!!");
170  return -1;
171  }
172 }
os.h
mrpt::math::CSplineInterpolator1D
A (persistent) sequence of (x,y) coordinates, allowing queries of intermediate points through spline ...
Definition: CSplineInterpolator1D.h:26
mrpt::system::os::fclose
int void fclose(FILE *f)
An OS-independent version of fclose.
Definition: os.cpp:273
t
GLdouble GLdouble t
Definition: glext.h:3689
mrpt::math::dynamic_vector
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction.
Definition: eigen_frwds.h:44
mrpt::math::spline
NUMTYPE spline(const NUMTYPE t, const VECTORLIKE &x, const VECTORLIKE &y, bool wrap2pi=false)
Interpolates the value of a function in a point "t" given 4 SORTED points where "t" is between the tw...
Definition: interp_fit.hpp:36
interp_fit.hpp
mrpt::random::CRandomGenerator::drawGaussian1DVector
void drawGaussian1DVector(VEC &v, const double mean=0, const double std=1)
Fills the given vector with independent, 1D-normally distributed samples.
Definition: RandomGenerators.h:207
mrpt::system::now
mrpt::system::TTimeStamp now()
A shortcut for system::getCurrentTime.
Definition: datetime.h:75
w
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:4178
mrpt::poses::CPoseInterpolatorBase::interpolate
pose_t & interpolate(mrpt::system::TTimeStamp t, pose_t &out_interp, bool &out_valid_interp) const
Returns the pose at a given time, or interpolates using splines if there is not an exact match.
Definition: CPoseInterpolatorBase.hpp:59
interp
GLuint interp
Definition: glext.h:7133
ASSERT_
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
p
GLfloat GLfloat p
Definition: glext.h:6305
CPose3DInterpolator.h
TestSplineInterpolation
void TestSplineInterpolation()
Definition: vision_stereo_rectify/test.cpp:73
mrpt::poses::CPose3DInterpolator
This class stores a time-stamped trajectory in SE(3) (CPose3D poses).
Definition: CPose3DInterpolator.h:49
random.h
mrpt::system::TTimeStamp
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
Definition: datetime.h:31
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::poses::CPoseInterpolatorBase::insert
void insert(mrpt::system::TTimeStamp t, const pose_t &p)
Inserts a new pose in the sequence.
Definition: CPoseInterpolatorBase.hpp:41
mrpt::math::linspace
void linspace(T first, T last, size_t count, VECTOR &out_vector)
Generates an equidistant sequence of numbers given the first one, the last one and the desired number...
Definition: math/include/mrpt/math/utils.h:82
mrpt::poses::CPose3D
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
CSplineInterpolator1D.h
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
utils.h
mrpt::gui::CDisplayWindowPlots
Create a GUI window and display plots with MATLAB-like interfaces and commands.
Definition: CDisplayWindowPlots.h:31
CPose3D.h
TestSplineInterpolationVector
void TestSplineInterpolationVector()
Definition: vision_stereo_rectify/test.cpp:120
mrpt::system::os::fprintf
int fprintf(FILE *fil, const char *format,...) noexcept MRPT_printf_format_check(2
An OS-independent version of fprintf.
Definition: os.cpp:406
mrpt::random::getRandomGenerator
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Definition: RandomGenerator.cpp:19
mrpt::poses::CPoseInterpolatorBase::setMaxTimeInterpolation
void setMaxTimeInterpolation(double time)
Set value of the maximum time to consider interpolation.
Definition: CPoseInterpolatorBase.hpp:212
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::system::os::fopen
FILE * fopen(const char *fileName, const char *mode) noexcept
An OS-independent version of fopen.
Definition: os.cpp:255
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
CDisplayWindowPlots.h
TestCPose3DInterpolation
void TestCPose3DInterpolation()
Definition: vision_stereo_rectify/test.cpp:29
y
GLenum GLint GLint y
Definition: glext.h:3538
x
GLenum GLint x
Definition: glext.h:3538
datetime.h



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST