41 const double off_y_label = 20;
42 const double STEP_X = 25;
52 opengl::CGridPlaneXY::Create(-7, 7, -7, 7, 0, 1);
53 obj->setColor(0.7, 0.7, 0.7);
54 obj->setLocation(off_x, 0, 0);
55 theScene->insert(
obj);
58 opengl::CGridPlaneXY::Create(-7, 7, -7, 7, 0, 1);
59 obj2->setColor(0.7, 0.7, 0.7, 0.99);
60 obj2->setLocation(off_x, 15, 0);
61 obj2->enableAntiAliasing();
62 theScene->insert(obj2);
65 gl_txt->setLocation(off_x, off_y_label, 0);
66 theScene->insert(gl_txt);
73 opengl::CGridPlaneXZ::Create(-7, 7, -7, 7, 0, 1);
74 obj->setColor(0.7, 0.7, 0.7);
75 obj->setLocation(off_x, 0, 0);
76 theScene->insert(
obj);
79 gl_txt->setLocation(off_x, off_y_label, 0);
80 theScene->insert(gl_txt);
87 opengl::CArrow::Create(0, 0, 0, 3, 0, 0, 0.2f, 0.1f, 0.2f, 0, 0, 0);
88 obj->setLocation(off_x, 0, 0);
89 obj->setColor(1, 0, 0);
90 theScene->insert(
obj);
93 gl_txt->setLocation(off_x, off_y_label, 0);
94 theScene->insert(gl_txt);
101 opengl::CAxis::Create(-6, -6, -6, 6, 6, 6, 2, 2,
true);
102 obj->setLocation(off_x, 0, 0);
103 theScene->insert(
obj);
106 gl_txt->setLocation(off_x, off_y_label, 0);
107 theScene->insert(gl_txt);
115 obj->setLocation(off_x, 0, 0);
116 theScene->insert(
obj);
120 obj2->setLocation(off_x, 4, 0);
121 theScene->insert(obj2);
125 obj3->enableBoxBorder(
true);
126 obj3->setLineWidth(3);
127 obj3->setLocation(off_x, 8, 0);
128 theScene->insert(obj3);
131 gl_txt->setLocation(off_x, off_y_label, 0);
132 theScene->insert(gl_txt);
139 opengl::CFrustum::Create(1, 5, 60, 45, 1.5f,
true,
false);
140 obj->setLocation(off_x, 0, 0);
141 theScene->insert(
obj);
144 opengl::CFrustum::Create(1, 5, 60, 45, 2.5f,
true,
true);
145 obj2->setLocation(off_x, 6, 0);
146 theScene->insert(obj2);
149 gl_txt->setLocation(off_x, off_y_label, 0);
150 theScene->insert(gl_txt);
157 obj->setLocation(off_x, 0, 0);
158 obj->setColor(0, 0, 0.8);
159 theScene->insert(
obj);
162 opengl::CCylinder::Create(2, 1, 4, 20, 10);
163 obj2->setLocation(off_x, 6, 0);
164 obj2->setColor(0, 0, 0.8);
165 theScene->insert(obj2);
168 opengl::CCylinder::Create(2, 0, 4, 20, 10);
169 obj3->setLocation(off_x, -6, 0);
170 obj3->setColor(0, 0, 0.8);
171 theScene->insert(obj3);
174 gl_txt->setLocation(off_x, off_y_label, 0);
175 theScene->insert(gl_txt);
183 obj->setLocation(off_x, 0, 0);
184 obj->setColor(0.8, 0, 0);
185 theScene->insert(
obj);
190 obj->setLocation(off_x, 5, 0);
191 obj->setColor(0.8, 0, 0);
192 theScene->insert(
obj);
196 gl_txt->setLocation(off_x, off_y_label, 0);
197 theScene->insert(gl_txt);
203 const double cov3d_dat[] = {0.9, 0.7, -0.4, 0.7, 1.6,
204 -0.6, -0.4, -0.6, 1.5};
205 const double cov2d_dat[] = {0.9, 0.7, 0.7, 1.6};
211 obj->setCovMatrix(cov2d);
212 obj->setLocation(off_x, 6, 0);
213 obj->setQuantiles(2.0);
214 theScene->insert(
obj);
218 obj->setCovMatrix(cov3d);
219 obj->setQuantiles(2.0);
220 obj->enableDrawSolid3D(
false);
221 obj->setLocation(off_x, 0, 0);
222 theScene->insert(
obj);
226 obj->setCovMatrix(cov3d);
227 obj->setQuantiles(2.0);
228 obj->enableDrawSolid3D(
true);
229 obj->setLocation(off_x, -6, 0);
230 theScene->insert(
obj);
234 gl_txt->setLocation(off_x, off_y_label, 0);
235 theScene->insert(gl_txt);
241 const double cov_params_dat[] = {0.2, 0, 0, 0.1};
242 const double mean_params_dat[] = {3.0, 0.5};
248 opengl::CEllipsoidRangeBearing2D::Create();
249 obj->setCovMatrixAndMean(cov_params, mean_params);
250 obj->setLocation(off_x, 6, 0);
251 obj->setQuantiles(2.0f);
253 theScene->insert(
obj);
257 obj_corner->setLocation(off_x, 6, 0);
258 theScene->insert(obj_corner);
262 const double cov_params_dat[] = {0.2, 0.09, 0.09, 0.1};
263 const double mean_params_dat[] = {5.0, -0.5};
269 opengl::CEllipsoidRangeBearing2D::Create();
270 obj->setCovMatrixAndMean(cov_params, mean_params);
271 obj->setLocation(off_x, 0, 0);
272 obj->setQuantiles(2.0f);
274 theScene->insert(
obj);
278 obj_corner->setLocation(off_x, 0, 0);
279 theScene->insert(obj_corner);
283 opengl::CText::Create(
"CEllipsoidRangeBearing2D");
284 gl_txt->setLocation(off_x, off_y_label, 0);
285 theScene->insert(gl_txt);
292 const double max_dist = 1e4;
293 const double min_dist = 1;
294 const double rho_mean = 0.5 * (1. / min_dist + 1. / max_dist);
295 const double rho_std = (1. / 6.) * (1. / min_dist - 1. / max_dist);
297 const double cov_params_dat[] = {
square(rho_std), 0, 0,
299 const double mean_params_dat[] = {rho_mean,
DEG2RAD(70)};
305 opengl::CEllipsoidInverseDepth2D::Create();
306 obj->setCovMatrixAndMean(cov_params, mean_params);
307 obj->setLocation(off_x, 6, 0);
308 obj->setQuantiles(3.f);
309 obj->setNumberOfSegments(100);
310 theScene->insert(
obj);
314 obj_corner->setLocation(off_x, 6, 0);
315 theScene->insert(obj_corner);
319 opengl::CText::Create(
"CEllipsoidInverseDepth2D");
320 gl_txt->setLocation(off_x, off_y_label, 0);
321 theScene->insert(gl_txt);
328 const double max_dist = 1e2;
329 const double min_dist = 1;
330 const double rho_mean = 0.5 * (1. / min_dist + 1. / max_dist);
331 const double rho_std = (1. / 6.) * (1. / min_dist - 1. / max_dist);
333 const double cov_params_dat[] = {
square(rho_std), 0, 0, 0,
336 const double mean_params_dat[] = {rho_mean,
DEG2RAD(30),
DEG2RAD(-45)};
342 opengl::CEllipsoidInverseDepth3D::Create();
343 obj->setCovMatrixAndMean(cov_params, mean_params);
344 obj->setLocation(off_x, 0, 0);
345 obj->setQuantiles(3.f);
347 theScene->insert(
obj);
351 obj_corner->setLocation(off_x, 0, 0);
352 theScene->insert(obj_corner);
356 opengl::CText::Create(
"CEllipsoidInverseDepth3D");
357 gl_txt->setLocation(off_x, off_y_label, 0);
358 theScene->insert(gl_txt);
365 obj->setLocation(off_x, 0, 0);
368 for (
size_t i = 0; i < Zs.rows(); i++)
369 for (
size_t j = 0; j < Zs.cols(); j++)
373 Zs(i, j) = 4 * cos((
x +
y) * 0.6) +
374 sin((
x - 0.5) * (
y + 1.2) * 0.3) * 3;
377 obj->setGridLimits(-10, 10, -10, 10);
381 theScene->insert(
obj);
384 gl_txt->setLocation(off_x, off_y_label, 0);
385 theScene->insert(gl_txt);
392 obj->enableShowEdges(
false);
393 obj->enableShowFaces(
true);
394 obj->enableShowVertices(
false);
395 obj->setLocation(off_x, 0, 0);
397 const unsigned int rows = 200, cols = 200;
398 const unsigned int num_verts = (rows + 1) * (cols + 1);
399 const unsigned int num_faces = rows * cols;
400 int* vert_per_face =
new int[num_faces];
401 int* face_verts =
new int[4 * num_faces];
402 float* vert_coords =
new float[3 * num_verts];
405 unsigned int first_ind = 0;
406 for (
unsigned int u = 0; u < cols; u++)
408 for (
unsigned int v = 0;
v < rows;
v++)
410 const unsigned int face_ind =
v + u * rows;
411 vert_per_face[face_ind] = 4;
413 face_verts[4 * face_ind] = first_ind;
414 face_verts[4 * face_ind + 1] = first_ind + 1;
415 face_verts[4 * face_ind + 2] = first_ind + rows + 2;
416 face_verts[4 * face_ind + 3] = first_ind + rows + 1;
424 for (
unsigned int u = 0; u <= cols; u++)
425 for (
unsigned int v = 0;
v <= rows;
v++)
427 const unsigned int vert_ind =
v + u * (rows + 1);
429 vert_coords[3 * vert_ind] = (2.f - 0.01f * u) *
430 (2.f + cos(0.01f *
M_PI *
v)) *
431 cos(0.01f *
M_PI * u);
432 vert_coords[3 * vert_ind + 1] = (2.f - 0.01f * u) *
433 (2.f + cos(0.01f *
M_PI *
v)) *
434 sin(0.01f *
M_PI * u);
435 vert_coords[3 * vert_ind + 2] =
436 3.f * 0.01f * u + (2.f - 0.01f * u) * sin(0.01f *
M_PI *
v);
440 num_verts, num_faces, vert_per_face, face_verts, vert_coords);
441 theScene->insert(
obj);
444 gl_txt->setLocation(off_x, off_y_label, 0);
445 theScene->insert(gl_txt);
452 obj->setLocation(off_x, 0, 0);
453 theScene->insert(
obj);
455 obj->setPointSize(3.0);
456 obj->enablePointSmooth();
457 obj->enableColorFromY();
459 for (
int i = 0; i < 100000; i++)
466 gl_txt->setLocation(off_x, off_y_label, 0);
467 theScene->insert(gl_txt);
474 opengl::CPointCloudColoured::Create();
475 obj->setLocation(off_x, 0, 0);
476 theScene->insert(
obj);
478 obj->setPointSize(3.0);
479 obj->enablePointSmooth();
481 for (
int i = 0; i < 200; i++)
491 opengl::CText::Create(
"CPointCloudColoured");
492 gl_txt->setLocation(off_x, off_y_label, 0);
493 theScene->insert(gl_txt);
501 opengl::CPolyhedron::CreateCuboctahedron(1.0);
502 obj->setLocation(off_x, 0, 0);
503 theScene->insert(
obj);
507 opengl::CPolyhedron::CreateDodecahedron(1.0);
508 obj->setLocation(off_x, -5, 0);
509 theScene->insert(
obj);
513 opengl::CPolyhedron::CreateIcosahedron(1.0);
514 obj->setLocation(off_x, 5, 0);
515 theScene->insert(
obj);
519 gl_txt->setLocation(off_x, off_y_label, 0);
520 theScene->insert(gl_txt);
528 obj->setLocation(off_x, 0, 0);
529 theScene->insert(
obj);
533 gl_txt->setLocation(off_x, off_y_label, 0);
534 theScene->insert(gl_txt);
543 "This is a CText example! My size is invariant to " 545 obj->setLocation(off_x, 0, 0);
546 theScene->insert(
obj);
550 gl_txt->setLocation(off_x, off_y_label, 0);
551 theScene->insert(gl_txt);
559 opengl::CText3D::Create(
"I'm a cool CText3D!");
560 obj->setLocation(off_x, 0, 0);
561 theScene->insert(
obj);
565 gl_txt->setLocation(off_x, off_y_label, 0);
566 theScene->insert(gl_txt);
576 obj->setLocation(off_x, 0, 0);
577 theScene->insert(
obj);
581 gl_txt->setLocation(off_x, off_y_label, 0);
582 theScene->insert(gl_txt);
590 obj->setLocation(off_x, 0, 0);
592 for (
int i = 0; i < 15; i++)
601 theScene->insert(
obj);
605 gl_txt->setLocation(off_x, off_y_label, 0);
606 theScene->insert(gl_txt);
614 obj->setLocation(off_x, 0, 0);
624 theScene->insert(
obj);
628 gl_txt->setLocation(off_x, off_y_label, 0);
629 theScene->insert(gl_txt);
637 obj->setLocation(off_x, 0, 0);
640 for (
unsigned int i = 0; i <
x.rows(); i++)
641 for (
unsigned int j = 0; j <
x.cols(); j++)
643 x(i, j) = sin(0.3 * i);
644 y(i, j) = cos(0.3 * i);
646 obj->setVectorField(
x,
y);
647 obj->setPointColor(1, 0.3f, 0);
648 obj->setVectorFieldColor(0, 0, 1);
649 obj->setPointSize(3.0);
650 obj->setLineWidth(2.0);
651 obj->setGridCenterAndCellSize(0, 0, 1.2f, 1.2f);
652 obj->adjustVectorFieldToGrid();
653 theScene->insert(
obj);
657 gl_txt->setLocation(off_x, off_y_label, 0);
658 theScene->insert(gl_txt);
665 const unsigned int num = 20;
666 const float scale = 0.8 * STEP_X /
num;
672 for (
unsigned int i = 0; i <
x.rows(); i++)
673 for (
unsigned int j = 0; j <
x.cols(); j++)
677 z(i, j) = 3 * sin(0.3 * i) * cos(0.3 * j);
678 vx(i, j) = 0.4 * sin(0.3 * i);
679 vy(i, j) = 0.8 * cos(0.3 * i);
680 vz(i, j) = 0.01 * i * j;
682 obj->setPointCoordinates(
x,
y,
z);
683 obj->setVectorField(vx, vy, vz);
684 obj->setPointColor(1, 0.3f, 0);
685 obj->setVectorFieldColor(0, 0, 1);
686 obj->setPointSize(3.0);
687 obj->setLineWidth(2.0);
688 obj->enableColorFromModule();
689 obj->setMaxSpeedForColor(3.0);
690 obj->setMotionFieldColormap(0, 0, 1, 1, 0, 0);
691 theScene->insert(
obj);
695 gl_txt->setLocation(off_x, off_y_label, 0);
696 theScene->insert(gl_txt);
705 obj->setLocation(off_x, 0, 0);
706 theScene->insert(
obj);
710 opengl::CText::Create(
"stock_objects::BumblebeeCamera()");
711 gl_txt->setLocation(off_x, off_y_label, 0);
712 theScene->insert(gl_txt);
721 obj->setLocation(off_x, 0, 0);
722 theScene->insert(
obj);
726 opengl::CText::Create(
"stock_objects::CornerXYSimple()");
727 gl_txt->setLocation(off_x, off_y_label, 0);
728 theScene->insert(gl_txt);
737 obj->setLocation(off_x, 0, 0);
738 theScene->insert(
obj);
742 opengl::CText::Create(
"stock_objects::CornerXYZSimple()");
743 gl_txt->setLocation(off_x, off_y_label, 0);
744 theScene->insert(gl_txt);
752 obj->setLocation(off_x, 0, 0);
753 theScene->insert(
obj);
757 opengl::CText::Create(
"stock_objects::CornerXYZ()");
758 gl_txt->setLocation(off_x, off_y_label, 0);
759 theScene->insert(gl_txt);
768 obj->setLocation(off_x, 0, 0);
769 theScene->insert(
obj);
773 opengl::CText::Create(
"stock_objects::RobotPioneer()");
774 gl_txt->setLocation(off_x, off_y_label, 0);
775 theScene->insert(gl_txt);
784 obj->setLocation(off_x, 0, 0);
785 theScene->insert(
obj);
789 opengl::CText::Create(
"stock_objects::Hokuyo_URG()");
790 gl_txt->setLocation(off_x, off_y_label, 0);
791 theScene->insert(gl_txt);
800 obj->setLocation(off_x, 0, 0);
801 theScene->insert(
obj);
805 opengl::CText::Create(
"stock_objects::Hokuyo_UTM()");
806 gl_txt->setLocation(off_x, off_y_label, 0);
807 theScene->insert(gl_txt);
816 obj->setLocation(off_x, 0, 0);
817 theScene->insert(
obj);
821 opengl::CText::Create(
"stock_objects::Househam_Sprayer()");
822 gl_txt->setLocation(off_x, off_y_label, 0);
823 theScene->insert(gl_txt);
832 obj->setLocation(off_x, 0, 0);
833 theScene->insert(
obj);
837 opengl::CText::Create(
"stock_objects::RobotRhodon()");
838 gl_txt->setLocation(off_x, off_y_label, 0);
839 theScene->insert(gl_txt);
845 win.setCameraZoom(150);
848 win.unlockAccess3DScene();
851 cout <<
"Close the window to end.\n";
854 win.addTextMessage(5, 5,
format(
"%.02fFPS",
win.getRenderingFPS()));
855 std::this_thread::sleep_for(2ms);
871 catch (
const std::exception& e)
878 printf(
"Untyped exception!!");
CSetOfObjects::Ptr Hokuyo_UTM()
Returns a simple 3D model of a Hokuyo UTM scanner.
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm, scaled to the selected range.
A compile-time fixed-size numeric matrix container.
CSetOfObjects::Ptr CornerXYSimple(float scale=1.0, float lineWidth=1.0)
Returns two arrows representing a X,Y 2D corner (just thick lines, fast to render).
GLenum GLenum GLenum GLenum GLenum scale
size_t OCTREE_RENDER_MAX_POINTS_PER_NODE()
Default value = 1e5.
CSetOfObjects::Ptr RobotRhodon()
Returns a representation of Rhodon.
CSetOfObjects::Ptr Househam_Sprayer()
Returns a simple 3D model of a househam sprayer.
GLsizei GLsizei GLuint * obj
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
mrpt::gui::CDisplayWindow3D::Ptr win
CSetOfObjects::Ptr RobotPioneer()
Returns a representation of a Pioneer II mobile base.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
CSetOfObjects::Ptr CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
Returns three arrows representing a X,Y,Z 3D corner (just thick lines instead of complex arrows for f...
The namespace for 3D scene representation and rendering.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
This template class provides the basic functionality for a general 2D any-size, resizable container o...
CSetOfObjects::Ptr BumblebeeCamera()
Returns a simple 3D model of a PointGrey Bumblebee stereo camera.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
CSetOfObjects::Ptr Hokuyo_URG()
Returns a simple 3D model of a Hokuyo URG scanner.