41 const double off_y_label = 20;
42 const double STEP_X = 25;
52 mrpt::make_aligned_shared<opengl::CGridPlaneXY>(-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 mrpt::make_aligned_shared<opengl::CGridPlaneXY>(-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 mrpt::make_aligned_shared<opengl::CText>(
"CGridPlaneXY");
66 gl_txt->setLocation(off_x, off_y_label, 0);
67 theScene->insert(gl_txt);
74 mrpt::make_aligned_shared<opengl::CGridPlaneXZ>(-7, 7, -7, 7, 0, 1);
75 obj->setColor(0.7, 0.7, 0.7);
76 obj->setLocation(off_x, 0, 0);
77 theScene->insert(
obj);
80 mrpt::make_aligned_shared<opengl::CText>(
"CGridPlaneXZ");
81 gl_txt->setLocation(off_x, off_y_label, 0);
82 theScene->insert(gl_txt);
89 0, 0, 0, 3, 0, 0, 0.2f, 0.1f, 0.2f, 0, 0, 0);
90 obj->setLocation(off_x, 0, 0);
91 obj->setColor(1, 0, 0);
92 theScene->insert(
obj);
95 mrpt::make_aligned_shared<opengl::CText>(
"CArrow");
96 gl_txt->setLocation(off_x, off_y_label, 0);
97 theScene->insert(gl_txt);
104 -6, -6, -6, 6, 6, 6, 2, 2,
true);
105 obj->setLocation(off_x, 0, 0);
106 theScene->insert(
obj);
109 mrpt::make_aligned_shared<opengl::CText>(
"CAxis");
110 gl_txt->setLocation(off_x, off_y_label, 0);
111 theScene->insert(gl_txt);
119 obj->setLocation(off_x, 0, 0);
120 theScene->insert(
obj);
124 obj2->setLocation(off_x, 4, 0);
125 theScene->insert(obj2);
129 obj3->enableBoxBorder(
true);
130 obj3->setLineWidth(3);
131 obj3->setLocation(off_x, 8, 0);
132 theScene->insert(obj3);
135 mrpt::make_aligned_shared<opengl::CText>(
"CBox");
136 gl_txt->setLocation(off_x, off_y_label, 0);
137 theScene->insert(gl_txt);
144 1, 5, 60, 45, 1.5f,
true,
false);
145 obj->setLocation(off_x, 0, 0);
146 theScene->insert(
obj);
149 mrpt::make_aligned_shared<opengl::CFrustum>(
150 1, 5, 60, 45, 2.5f,
true,
true);
151 obj2->setLocation(off_x, 6, 0);
152 theScene->insert(obj2);
155 mrpt::make_aligned_shared<opengl::CText>(
"CFrustum");
156 gl_txt->setLocation(off_x, off_y_label, 0);
157 theScene->insert(gl_txt);
164 mrpt::make_aligned_shared<opengl::CCylinder>(2, 2, 4, 20, 10);
165 obj->setLocation(off_x, 0, 0);
166 obj->setColor(0, 0, 0.8);
167 theScene->insert(
obj);
170 mrpt::make_aligned_shared<opengl::CCylinder>(2, 1, 4, 20, 10);
171 obj2->setLocation(off_x, 6, 0);
172 obj2->setColor(0, 0, 0.8);
173 theScene->insert(obj2);
176 mrpt::make_aligned_shared<opengl::CCylinder>(2, 0, 4, 20, 10);
177 obj3->setLocation(off_x, -6, 0);
178 obj3->setColor(0, 0, 0.8);
179 theScene->insert(obj3);
182 mrpt::make_aligned_shared<opengl::CText>(
"CCylinder");
183 gl_txt->setLocation(off_x, off_y_label, 0);
184 theScene->insert(gl_txt);
192 mrpt::make_aligned_shared<opengl::CDisk>(2.0f, 1.8f, 50);
193 obj->setLocation(off_x, 0, 0);
194 obj->setColor(0.8, 0, 0);
195 theScene->insert(
obj);
200 mrpt::make_aligned_shared<opengl::CDisk>(2.0f, 0, 50);
201 obj->setLocation(off_x, 5, 0);
202 obj->setColor(0.8, 0, 0);
203 theScene->insert(
obj);
207 mrpt::make_aligned_shared<opengl::CText>(
"CDisk");
208 gl_txt->setLocation(off_x, off_y_label, 0);
209 theScene->insert(gl_txt);
215 const double cov3d_dat[] = {0.9, 0.7, -0.4, 0.7, 1.6,
216 -0.6, -0.4, -0.6, 1.5};
217 const double cov2d_dat[] = {0.9, 0.7, 0.7, 1.6};
223 mrpt::make_aligned_shared<opengl::CEllipsoid>();
224 obj->setCovMatrix(cov2d);
225 obj->setLocation(off_x, 6, 0);
226 obj->setQuantiles(2.0);
227 theScene->insert(
obj);
231 mrpt::make_aligned_shared<opengl::CEllipsoid>();
232 obj->setCovMatrix(cov3d);
233 obj->setQuantiles(2.0);
234 obj->enableDrawSolid3D(
false);
235 obj->setLocation(off_x, 0, 0);
236 theScene->insert(
obj);
240 mrpt::make_aligned_shared<opengl::CEllipsoid>();
241 obj->setCovMatrix(cov3d);
242 obj->setQuantiles(2.0);
243 obj->enableDrawSolid3D(
true);
244 obj->setLocation(off_x, -6, 0);
245 theScene->insert(
obj);
249 mrpt::make_aligned_shared<opengl::CText>(
"CEllipsoid");
250 gl_txt->setLocation(off_x, off_y_label, 0);
251 theScene->insert(gl_txt);
257 const double cov_params_dat[] = {0.2, 0, 0, 0.1};
258 const double mean_params_dat[] = {3.0, 0.5};
266 mrpt::make_aligned_shared<opengl::CEllipsoidRangeBearing2D>();
267 obj->setCovMatrixAndMean(cov_params, mean_params);
268 obj->setLocation(off_x, 6, 0);
269 obj->setQuantiles(2.0f);
271 theScene->insert(
obj);
275 obj_corner->setLocation(off_x, 6, 0);
276 theScene->insert(obj_corner);
280 const double cov_params_dat[] = {0.2, 0.09, 0.09, 0.1};
281 const double mean_params_dat[] = {5.0, -0.5};
289 mrpt::make_aligned_shared<opengl::CEllipsoidRangeBearing2D>();
290 obj->setCovMatrixAndMean(cov_params, mean_params);
291 obj->setLocation(off_x, 0, 0);
292 obj->setQuantiles(2.0f);
294 theScene->insert(
obj);
298 obj_corner->setLocation(off_x, 0, 0);
299 theScene->insert(obj_corner);
303 "CEllipsoidRangeBearing2D");
304 gl_txt->setLocation(off_x, off_y_label, 0);
305 theScene->insert(gl_txt);
312 const double max_dist = 1e4;
313 const double min_dist = 1;
314 const double rho_mean = 0.5 * (1. / min_dist + 1. / max_dist);
315 const double rho_std = (1. / 6.) * (1. / min_dist - 1. / max_dist);
317 const double cov_params_dat[] = {
square(rho_std), 0, 0,
319 const double mean_params_dat[] = {rho_mean,
DEG2RAD(70)};
327 mrpt::make_aligned_shared<opengl::CEllipsoidInverseDepth2D>();
328 obj->setCovMatrixAndMean(cov_params, mean_params);
329 obj->setLocation(off_x, 6, 0);
330 obj->setQuantiles(3.f);
331 obj->setNumberOfSegments(100);
332 theScene->insert(
obj);
336 obj_corner->setLocation(off_x, 6, 0);
337 theScene->insert(obj_corner);
341 "CEllipsoidInverseDepth2D");
342 gl_txt->setLocation(off_x, off_y_label, 0);
343 theScene->insert(gl_txt);
350 const double max_dist = 1e2;
351 const double min_dist = 1;
352 const double rho_mean = 0.5 * (1. / min_dist + 1. / max_dist);
353 const double rho_std = (1. / 6.) * (1. / min_dist - 1. / max_dist);
355 const double cov_params_dat[] = {
square(rho_std), 0, 0, 0,
358 const double mean_params_dat[] = {rho_mean,
DEG2RAD(30),
DEG2RAD(-45)};
366 mrpt::make_aligned_shared<opengl::CEllipsoidInverseDepth3D>();
367 obj->setCovMatrixAndMean(cov_params, mean_params);
368 obj->setLocation(off_x, 0, 0);
369 obj->setQuantiles(3.f);
371 theScene->insert(
obj);
375 obj_corner->setLocation(off_x, 0, 0);
376 theScene->insert(obj_corner);
380 "CEllipsoidInverseDepth3D");
381 gl_txt->setLocation(off_x, off_y_label, 0);
382 theScene->insert(gl_txt);
389 obj->setLocation(off_x, 0, 0);
396 for (
size_t i = 0; i < Zs.rows(); i++)
397 for (
size_t j = 0; j < Zs.cols(); j++)
401 Zs(i, j) = 4 * cos((
x +
y) * 0.6) +
402 sin((
x - 0.5) * (
y + 1.2) * 0.3) * 3;
405 obj->setGridLimits(-10, 10, -10, 10);
409 theScene->insert(
obj);
412 mrpt::make_aligned_shared<opengl::CText>(
"CMesh");
413 gl_txt->setLocation(off_x, off_y_label, 0);
414 theScene->insert(gl_txt);
421 obj->enableShowEdges(
false);
422 obj->enableShowFaces(
true);
423 obj->enableShowVertices(
false);
424 obj->setLocation(off_x, 0, 0);
426 const unsigned int rows = 200, cols = 200;
427 const unsigned int num_verts = (rows + 1) * (cols + 1);
428 const unsigned int num_faces = rows * cols;
429 int* vert_per_face =
new int[num_faces];
430 int* face_verts =
new int[4 * num_faces];
431 float* vert_coords =
new float[3 * num_verts];
434 unsigned int first_ind = 0;
435 for (
unsigned int u = 0; u < cols; u++)
437 for (
unsigned int v = 0;
v < rows;
v++)
439 const unsigned int face_ind =
v + u * rows;
440 vert_per_face[face_ind] = 4;
442 face_verts[4 * face_ind] = first_ind;
443 face_verts[4 * face_ind + 1] = first_ind + 1;
444 face_verts[4 * face_ind + 2] = first_ind + rows + 2;
445 face_verts[4 * face_ind + 3] = first_ind + rows + 1;
453 for (
unsigned int u = 0; u <= cols; u++)
454 for (
unsigned int v = 0;
v <= rows;
v++)
456 const unsigned int vert_ind =
v + u * (rows + 1);
458 vert_coords[3 * vert_ind] = (2.f - 0.01f * u) *
459 (2.f + cos(0.01f *
M_PI *
v)) *
460 cos(0.01f *
M_PI * u);
461 vert_coords[3 * vert_ind + 1] = (2.f - 0.01f * u) *
462 (2.f + cos(0.01f *
M_PI *
v)) *
463 sin(0.01f *
M_PI * u);
464 vert_coords[3 * vert_ind + 2] =
465 3.f * 0.01f * u + (2.f - 0.01f * u) * sin(0.01f *
M_PI *
v);
469 num_verts, num_faces, vert_per_face, face_verts, vert_coords);
470 theScene->insert(
obj);
473 mrpt::make_aligned_shared<opengl::CText>(
"CMesh3D");
474 gl_txt->setLocation(off_x, off_y_label, 0);
475 theScene->insert(gl_txt);
482 mrpt::make_aligned_shared<opengl::CPointCloud>();
483 obj->setLocation(off_x, 0, 0);
484 theScene->insert(
obj);
486 obj->setPointSize(3.0);
487 obj->enablePointSmooth();
488 obj->enableColorFromY();
490 for (
int i = 0; i < 100000; i++)
497 mrpt::make_aligned_shared<opengl::CText>(
"CPointCloud");
498 gl_txt->setLocation(off_x, off_y_label, 0);
499 theScene->insert(gl_txt);
506 mrpt::make_aligned_shared<opengl::CPointCloudColoured>();
507 obj->setLocation(off_x, 0, 0);
508 theScene->insert(
obj);
510 obj->setPointSize(3.0);
511 obj->enablePointSmooth();
513 for (
int i = 0; i < 200; i++)
523 mrpt::make_aligned_shared<opengl::CText>(
"CPointCloudColoured");
524 gl_txt->setLocation(off_x, off_y_label, 0);
525 theScene->insert(gl_txt);
533 opengl::CPolyhedron::CreateCuboctahedron(1.0);
534 obj->setLocation(off_x, 0, 0);
535 theScene->insert(
obj);
539 opengl::CPolyhedron::CreateDodecahedron(1.0);
540 obj->setLocation(off_x, -5, 0);
541 theScene->insert(
obj);
545 opengl::CPolyhedron::CreateIcosahedron(1.0);
546 obj->setLocation(off_x, 5, 0);
547 theScene->insert(
obj);
551 mrpt::make_aligned_shared<opengl::CText>(
"CPolyhedron");
552 gl_txt->setLocation(off_x, off_y_label, 0);
553 theScene->insert(gl_txt);
561 mrpt::make_aligned_shared<opengl::CSphere>(3.0);
562 obj->setLocation(off_x, 0, 0);
563 theScene->insert(
obj);
567 mrpt::make_aligned_shared<opengl::CText>(
"CSphere");
568 gl_txt->setLocation(off_x, off_y_label, 0);
569 theScene->insert(gl_txt);
578 "This is a CText example! My size is invariant to "
580 obj->setLocation(off_x, 0, 0);
581 theScene->insert(
obj);
585 mrpt::make_aligned_shared<opengl::CText>(
"CText");
586 gl_txt->setLocation(off_x, off_y_label, 0);
587 theScene->insert(gl_txt);
595 mrpt::make_aligned_shared<opengl::CText3D>(
596 "I'm a cool CText3D!");
597 obj->setLocation(off_x, 0, 0);
598 theScene->insert(
obj);
602 mrpt::make_aligned_shared<opengl::CText>(
"CText3D");
603 gl_txt->setLocation(off_x, off_y_label, 0);
604 theScene->insert(gl_txt);
612 mrpt::make_aligned_shared<opengl::CColorBar>(
615 obj->setLocation(off_x, 0, 0);
616 theScene->insert(
obj);
620 mrpt::make_aligned_shared<opengl::CText>(
"CColorBar");
621 gl_txt->setLocation(off_x, off_y_label, 0);
622 theScene->insert(gl_txt);
630 mrpt::make_aligned_shared<opengl::CSetOfLines>();
631 obj->setLocation(off_x, 0, 0);
633 for (
int i = 0; i < 15; i++)
642 theScene->insert(
obj);
646 mrpt::make_aligned_shared<opengl::CText>(
"CSetOfLines");
647 gl_txt->setLocation(off_x, off_y_label, 0);
648 theScene->insert(gl_txt);
656 mrpt::make_aligned_shared<opengl::CSimpleLine>();
657 obj->setLocation(off_x, 0, 0);
667 theScene->insert(
obj);
671 mrpt::make_aligned_shared<opengl::CText>(
"CSimpleLine");
672 gl_txt->setLocation(off_x, off_y_label, 0);
673 theScene->insert(gl_txt);
681 mrpt::make_aligned_shared<opengl::CVectorField2D>();
682 obj->setLocation(off_x, 0, 0);
685 for (
unsigned int i = 0; i <
x.rows(); i++)
686 for (
unsigned int j = 0; j <
x.cols(); j++)
688 x(i, j) = sin(0.3 * i);
689 y(i, j) = cos(0.3 * i);
691 obj->setVectorField(
x,
y);
692 obj->setPointColor(1, 0.3f, 0);
693 obj->setVectorFieldColor(0, 0, 1);
694 obj->setPointSize(3.0);
695 obj->setLineWidth(2.0);
696 obj->setGridCenterAndCellSize(0, 0, 1.2f, 1.2f);
697 obj->adjustVectorFieldToGrid();
698 theScene->insert(
obj);
702 mrpt::make_aligned_shared<opengl::CText>(
"CVectorField2D");
703 gl_txt->setLocation(off_x, off_y_label, 0);
704 theScene->insert(gl_txt);
711 const unsigned int num = 20;
712 const float scale = 0.8 * STEP_X /
num;
714 mrpt::make_aligned_shared<opengl::CVectorField3D>();
719 for (
unsigned int i = 0; i <
x.rows(); i++)
720 for (
unsigned int j = 0; j <
x.cols(); j++)
724 z(i, j) = 3 * sin(0.3 * i) * cos(0.3 * j);
725 vx(i, j) = 0.4 * sin(0.3 * i);
726 vy(i, j) = 0.8 * cos(0.3 * i);
727 vz(i, j) = 0.01 * i * j;
729 obj->setPointCoordinates(
x,
y,
z);
730 obj->setVectorField(vx, vy, vz);
731 obj->setPointColor(1, 0.3f, 0);
732 obj->setVectorFieldColor(0, 0, 1);
733 obj->setPointSize(3.0);
734 obj->setLineWidth(2.0);
735 obj->enableColorFromModule();
736 obj->setMaxSpeedForColor(3.0);
737 obj->setMotionFieldColormap(0, 0, 1, 1, 0, 0);
738 theScene->insert(
obj);
742 mrpt::make_aligned_shared<opengl::CText>(
"CVectorField3D");
743 gl_txt->setLocation(off_x, off_y_label, 0);
744 theScene->insert(gl_txt);
753 obj->setLocation(off_x, 0, 0);
754 theScene->insert(
obj);
758 "stock_objects::BumblebeeCamera()");
759 gl_txt->setLocation(off_x, off_y_label, 0);
760 theScene->insert(gl_txt);
769 obj->setLocation(off_x, 0, 0);
770 theScene->insert(
obj);
774 "stock_objects::CornerXYSimple()");
775 gl_txt->setLocation(off_x, off_y_label, 0);
776 theScene->insert(gl_txt);
785 obj->setLocation(off_x, 0, 0);
786 theScene->insert(
obj);
790 "stock_objects::CornerXYZSimple()");
791 gl_txt->setLocation(off_x, off_y_label, 0);
792 theScene->insert(gl_txt);
800 obj->setLocation(off_x, 0, 0);
801 theScene->insert(
obj);
805 "stock_objects::CornerXYZ()");
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 "stock_objects::RobotPioneer()");
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 "stock_objects::Hokuyo_URG()");
838 gl_txt->setLocation(off_x, off_y_label, 0);
839 theScene->insert(gl_txt);
848 obj->setLocation(off_x, 0, 0);
849 theScene->insert(
obj);
853 "stock_objects::Hokuyo_UTM()");
854 gl_txt->setLocation(off_x, off_y_label, 0);
855 theScene->insert(gl_txt);
864 obj->setLocation(off_x, 0, 0);
865 theScene->insert(
obj);
869 "stock_objects::Househam_Sprayer()");
870 gl_txt->setLocation(off_x, off_y_label, 0);
871 theScene->insert(gl_txt);
880 obj->setLocation(off_x, 0, 0);
881 theScene->insert(
obj);
885 "stock_objects::RobotRhodon()");
886 gl_txt->setLocation(off_x, off_y_label, 0);
887 theScene->insert(gl_txt);
893 win.setCameraZoom(150);
896 win.unlockAccess3DScene();
899 cout <<
"Close the window to end.\n";
902 win.addTextMessage(5, 5,
format(
"%.02fFPS",
win.getRenderingFPS()));
903 std::this_thread::sleep_for(2ms);
919 catch (std::exception& e)
921 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
926 printf(
"Untyped exception!!");