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/datetime.h>
11 #include <mrpt/gui.h>
12 #include <mrpt/math/geometry.h>
13 #include <iostream>
14 
15 using namespace std;
16 using namespace mrpt;
17 using namespace mrpt::gui;
18 using namespace mrpt::math;
19 
20 const unsigned int NUMBER_OF_EDGES = 20;
21 const double MIN_RADIUS = 5;
22 const double MAX_RADIUS = 40;
23 
24 const double DIFF_RADIUS = MAX_RADIUS - MIN_RADIUS;
25 
26 inline double randomDouble(size_t precision = 1000)
27 {
28  return MIN_RADIUS +
29  DIFF_RADIUS * (static_cast<double>(rand() % precision) /
30  static_cast<double>(precision - 1));
31 }
32 
33 void display()
34 {
35  CDisplayWindowPlots win1("Unsplitted polygon", 400, 300);
36  win1.enableMousePanZoom(true);
37  TPolygon2D randomPoly(NUMBER_OF_EDGES);
38  for (size_t i = 0; i < NUMBER_OF_EDGES; i++)
39  {
40  double ang = 2 * M_PI * i / NUMBER_OF_EDGES;
41  double radius = randomDouble();
42  randomPoly[i].x = radius * cos(ang);
43  randomPoly[i].y = radius * sin(ang);
44  }
45  randomPoly.removeRedundantVertices();
46  std::vector<double> x, y;
47  randomPoly.getPlotData(x, y);
48  win1.plot(x, y, "b-5", "Polygon");
49  win1.axis_fit();
50  std::vector<TPolygon2D> convexPolys;
51  if (!splitInConvexComponents(randomPoly, convexPolys))
52  convexPolys.push_back(randomPoly);
53  CDisplayWindowPlots win2("Splitted polygon", 400, 300);
54  win2.enableMousePanZoom(true);
55  std::string plotName = "Polygon0";
56  for (std::vector<TPolygon2D>::const_iterator it = convexPolys.begin();
57  it != convexPolys.end(); ++it)
58  {
59  plotName[7]++;
60  it->getPlotData(x, y);
61  win2.plot(x, y, "r-3", plotName);
62  if (!it->isConvex()) cout << "FAIL.\n";
63  }
64  win2.axis_fit();
65  while (!mrpt::system::os::kbhit() && win1.isOpen() && win2.isOpen())
66  ;
67 }
68 
69 int main(int argc, char** argv)
70 {
71  srand(
74  display();
75  return 0;
76 }
mrpt::system::os::kbhit
bool kbhit() noexcept
An OS-independent version of kbhit, which returns true if a key has been pushed.
Definition: os.cpp:390
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
geometry.h
mrpt::system::extractDayTimeFromTimestamp
double extractDayTimeFromTimestamp(const mrpt::system::TTimeStamp t)
Returns the number of seconds ellapsed from midnight in the given timestamp.
Definition: datetime.cpp:291
MAX_RADIUS
const double MAX_RADIUS
Definition: vision_stereo_rectify/test.cpp:22
MIN_RADIUS
const double MIN_RADIUS
Definition: vision_stereo_rectify/test.cpp:21
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::getCurrentLocalTime
mrpt::system::TTimeStamp getCurrentLocalTime()
Returns the current (local) time.
Definition: datetime.cpp:174
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
M_PI
#define M_PI
Definition: core/include/mrpt/core/bits_math.h:38
NUMBER_OF_EDGES
const unsigned int NUMBER_OF_EDGES
Definition: vision_stereo_rectify/test.cpp:20
mrpt::math::TPolygon2D
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: lightweight_geom_data.h:1403
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::gui::CDisplayWindowPlots
Create a GUI window and display plots with MATLAB-like interfaces and commands.
Definition: CDisplayWindowPlots.h:31
display
void display()
Definition: vision_stereo_rectify/test.cpp:33
mrpt::math::splitInConvexComponents
bool splitInConvexComponents(const TPolygon2D &poly, std::vector< TPolygon2D > &components)
Splits a 2D polygon into convex components.
Definition: geometry.cpp:2397
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
gui.h
string
GLsizei const GLchar ** string
Definition: glext.h:4101
DIFF_RADIUS
const double DIFF_RADIUS
Definition: vision_stereo_rectify/test.cpp:24
randomDouble
double randomDouble(size_t precision=1000)
Definition: vision_stereo_rectify/test.cpp:26
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