MRPT  1.9.9
test.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
11 #include <mrpt/random.h>
12 
13 #include <mrpt/opengl.h>
14 #include <iostream>
15 
16 using namespace std;
17 using namespace mrpt;
18 using namespace mrpt::gui;
19 using namespace mrpt::opengl;
20 using namespace mrpt::math;
21 
22 // ------------------------------------------------------
23 // TestOpenGLObjects
24 // ------------------------------------------------------
25 void TestOpenGLObjects()
26 {
28 
29  CDisplayWindow3D win("Demo of MRPT's OpenGL objects", 640, 480);
30 
31  COpenGLScene::Ptr& theScene = win.get3DSceneAndLock();
32 
33  // Lights:
34  // theScene->getViewport()->setNumberOfLights(1);
35  // mrpt::opengl::CLight & light0 = theScene->getViewport()->getLight(0);
36  // light0.light_ID = 0;
37  // light0.setPosition(1,1,0,0);
38 
39  // Objects:
40  double off_x = 0;
41  const double off_y_label = 20;
42  const double STEP_X = 25;
43 
44  // XY Grid
45  /**
46  * Define each one of the objects in its own scope and just attach it to the
47  * scene by using insert(obj) method call.
48  */
49  {
50  // using mrpt smart pointers so that obj survives outside this scope.
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);
56 
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);
63 
64  opengl::CText::Ptr gl_txt = opengl::CText::Create("CGridPlaneXY");
65  gl_txt->setLocation(off_x, off_y_label, 0);
66  theScene->insert(gl_txt);
67  }
68  off_x += STEP_X;
69 
70  // XZ Grid
71  {
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);
77 
78  opengl::CText::Ptr gl_txt = opengl::CText::Create("CGridPlaneXZ");
79  gl_txt->setLocation(off_x, off_y_label, 0);
80  theScene->insert(gl_txt);
81  }
82  off_x += STEP_X;
83 
84  // Arrow
85  {
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);
91 
92  opengl::CText::Ptr gl_txt = opengl::CText::Create("CArrow");
93  gl_txt->setLocation(off_x, off_y_label, 0);
94  theScene->insert(gl_txt);
95  }
96  off_x += STEP_X;
97 
98  // Axis
99  {
101  opengl::CAxis::Create(-6, -6, -6, 6, 6, 6, 2, 2, true);
102  obj->setLocation(off_x, 0, 0);
103  theScene->insert(obj);
104 
105  opengl::CText::Ptr gl_txt = opengl::CText::Create("CAxis");
106  gl_txt->setLocation(off_x, off_y_label, 0);
107  theScene->insert(gl_txt);
108  }
109  off_x += STEP_X;
110 
111  // Box
112  {
113  opengl::CBox::Ptr obj = opengl::CBox::Create(
114  TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), true, 3.0);
115  obj->setLocation(off_x, 0, 0);
116  theScene->insert(obj);
117 
118  opengl::CBox::Ptr obj2 =
119  opengl::CBox::Create(TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), false);
120  obj2->setLocation(off_x, 4, 0);
121  theScene->insert(obj2);
122 
123  opengl::CBox::Ptr obj3 =
124  opengl::CBox::Create(TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), false);
125  obj3->enableBoxBorder(true);
126  obj3->setLineWidth(3);
127  obj3->setLocation(off_x, 8, 0);
128  theScene->insert(obj3);
129 
130  opengl::CText::Ptr gl_txt = opengl::CText::Create("CBox");
131  gl_txt->setLocation(off_x, off_y_label, 0);
132  theScene->insert(gl_txt);
133  }
134  off_x += STEP_X;
135 
136  // Frustum
137  {
139  opengl::CFrustum::Create(1, 5, 60, 45, 1.5f, true, false);
140  obj->setLocation(off_x, 0, 0);
141  theScene->insert(obj);
142 
143  opengl::CFrustum::Ptr obj2 =
144  opengl::CFrustum::Create(1, 5, 60, 45, 2.5f, true, true);
145  obj2->setLocation(off_x, 6, 0);
146  theScene->insert(obj2);
147 
148  opengl::CText::Ptr gl_txt = opengl::CText::Create("CFrustum");
149  gl_txt->setLocation(off_x, off_y_label, 0);
150  theScene->insert(gl_txt);
151  }
152  off_x += STEP_X;
153 
154  // Cylinder
155  {
156  opengl::CCylinder::Ptr obj = opengl::CCylinder::Create(2, 2, 4, 20, 10);
157  obj->setLocation(off_x, 0, 0);
158  obj->setColor(0, 0, 0.8);
159  theScene->insert(obj);
160 
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);
166 
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);
172 
173  opengl::CText::Ptr gl_txt = opengl::CText::Create("CCylinder");
174  gl_txt->setLocation(off_x, off_y_label, 0);
175  theScene->insert(gl_txt);
176  }
177  off_x += STEP_X;
178 
179  // CDisk
180  {
181  {
182  opengl::CDisk::Ptr obj = opengl::CDisk::Create(2.0f, 1.8f, 50);
183  obj->setLocation(off_x, 0, 0);
184  obj->setColor(0.8, 0, 0);
185  theScene->insert(obj);
186  }
187 
188  {
189  opengl::CDisk::Ptr obj = opengl::CDisk::Create(2.0f, 0, 50);
190  obj->setLocation(off_x, 5, 0);
191  obj->setColor(0.8, 0, 0);
192  theScene->insert(obj);
193  }
194 
195  opengl::CText::Ptr gl_txt = opengl::CText::Create("CDisk");
196  gl_txt->setLocation(off_x, off_y_label, 0);
197  theScene->insert(gl_txt);
198  }
199  off_x += STEP_X;
200 
201  // CEllipsoid
202  {
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};
206  mrpt::math::CMatrixDouble22 cov2d(cov2d_dat);
207  mrpt::math::CMatrixDouble33 cov3d(cov3d_dat);
208 
209  {
210  opengl::CEllipsoid::Ptr obj = opengl::CEllipsoid::Create();
211  obj->setCovMatrix(cov2d);
212  obj->setLocation(off_x, 6, 0);
213  obj->setQuantiles(2.0);
214  theScene->insert(obj);
215  }
216  {
217  opengl::CEllipsoid::Ptr obj = opengl::CEllipsoid::Create();
218  obj->setCovMatrix(cov3d);
219  obj->setQuantiles(2.0);
220  obj->enableDrawSolid3D(false);
221  obj->setLocation(off_x, 0, 0);
222  theScene->insert(obj);
223  }
224  {
225  opengl::CEllipsoid::Ptr obj = opengl::CEllipsoid::Create();
226  obj->setCovMatrix(cov3d);
227  obj->setQuantiles(2.0);
228  obj->enableDrawSolid3D(true);
229  obj->setLocation(off_x, -6, 0);
230  theScene->insert(obj);
231  }
232 
233  opengl::CText::Ptr gl_txt = opengl::CText::Create("CEllipsoid");
234  gl_txt->setLocation(off_x, off_y_label, 0);
235  theScene->insert(gl_txt);
236  }
237  off_x += STEP_X;
238 
239  // CEllipsoidRangeBearing2D
240  { // (range,bearing) -> (x,y)
241  const double cov_params_dat[] = {0.2, 0, 0, 0.1};
242  const double mean_params_dat[] = {3.0, 0.5};
243  mrpt::math::CMatrixFixed<double, 2, 2> cov_params(cov_params_dat);
244  mrpt::math::CMatrixFixed<double, 2, 1> mean_params(mean_params_dat);
245 
246  {
248  opengl::CEllipsoidRangeBearing2D::Create();
249  obj->setCovMatrixAndMean(cov_params, mean_params);
250  obj->setLocation(off_x, 6, 0);
251  obj->setQuantiles(2.0f);
252  // obj->setNumberOfSegments(50);
253  theScene->insert(obj);
254 
255  opengl::CSetOfObjects::Ptr obj_corner =
257  obj_corner->setLocation(off_x, 6, 0);
258  theScene->insert(obj_corner);
259  }
260  }
261  { // (range,bearing) -> (x,y)
262  const double cov_params_dat[] = {0.2, 0.09, 0.09, 0.1};
263  const double mean_params_dat[] = {5.0, -0.5};
264  mrpt::math::CMatrixFixed<double, 2, 2> cov_params(cov_params_dat);
265  mrpt::math::CMatrixFixed<double, 2, 1> mean_params(mean_params_dat);
266 
267  {
269  opengl::CEllipsoidRangeBearing2D::Create();
270  obj->setCovMatrixAndMean(cov_params, mean_params);
271  obj->setLocation(off_x, 0, 0);
272  obj->setQuantiles(2.0f);
273  // obj->setNumberOfSegments(50);
274  theScene->insert(obj);
275 
276  opengl::CSetOfObjects::Ptr obj_corner =
278  obj_corner->setLocation(off_x, 0, 0);
279  theScene->insert(obj_corner);
280  }
281 
282  opengl::CText::Ptr gl_txt =
283  opengl::CText::Create("CEllipsoidRangeBearing2D");
284  gl_txt->setLocation(off_x, off_y_label, 0);
285  theScene->insert(gl_txt);
286  }
287  off_x += STEP_X;
288 
289  // CEllipsoidInverseDepth2D
290  { // (inv_range,yaw) -> (x,y)
291  // Formula from our book (ch8) for confidence intervals of 3sigmas:
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);
296 
297  const double cov_params_dat[] = {square(rho_std), 0, 0,
298  square(DEG2RAD(2))};
299  const double mean_params_dat[] = {rho_mean, DEG2RAD(70)};
300  mrpt::math::CMatrixFixed<double, 2, 2> cov_params(cov_params_dat);
301  mrpt::math::CMatrixFixed<double, 2, 1> mean_params(mean_params_dat);
302 
303  {
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);
311 
312  opengl::CSetOfObjects::Ptr obj_corner =
314  obj_corner->setLocation(off_x, 6, 0);
315  theScene->insert(obj_corner);
316  }
317 
318  opengl::CText::Ptr gl_txt =
319  opengl::CText::Create("CEllipsoidInverseDepth2D");
320  gl_txt->setLocation(off_x, off_y_label, 0);
321  theScene->insert(gl_txt);
322  }
323  off_x += STEP_X;
324 
325  // CEllipsoidInverseDepth3D
326  { // (inv_range,yaw,pitch) -> (x,y,z)
327  // Formula from our book (ch8) for confidence intervals of 3sigmas:
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);
332 
333  const double cov_params_dat[] = {square(rho_std), 0, 0, 0,
334  square(DEG2RAD(2)), 0, 0, 0,
335  square(DEG2RAD(2))};
336  const double mean_params_dat[] = {rho_mean, DEG2RAD(30), DEG2RAD(-45)};
337  mrpt::math::CMatrixFixed<double, 3, 3> cov_params(cov_params_dat);
338  mrpt::math::CMatrixFixed<double, 3, 1> mean_params(mean_params_dat);
339 
340  {
342  opengl::CEllipsoidInverseDepth3D::Create();
343  obj->setCovMatrixAndMean(cov_params, mean_params);
344  obj->setLocation(off_x, 0, 0);
345  obj->setQuantiles(3.f);
346  // obj->setNumberOfSegments(50);
347  theScene->insert(obj);
348 
349  opengl::CSetOfObjects::Ptr obj_corner =
351  obj_corner->setLocation(off_x, 0, 0);
352  theScene->insert(obj_corner);
353  }
354 
355  opengl::CText::Ptr gl_txt =
356  opengl::CText::Create("CEllipsoidInverseDepth3D");
357  gl_txt->setLocation(off_x, off_y_label, 0);
358  theScene->insert(gl_txt);
359  }
360  off_x += STEP_X;
361 
362  // CMesh
363  {
364  opengl::CMesh::Ptr obj = opengl::CMesh::Create();
365  obj->setLocation(off_x, 0, 0);
366 
367  mrpt::math::CMatrixFloat Zs(40, 40); // Height
368  for (size_t i = 0; i < Zs.rows(); i++)
369  for (size_t j = 0; j < Zs.cols(); j++)
370  {
371  double x = i * 0.25;
372  double y = j * 0.25;
373  Zs(i, j) = 4 * cos((x + y) * 0.6) +
374  sin((x - 0.5) * (y + 1.2) * 0.3) * 3;
375  }
376 
377  obj->setGridLimits(-10, 10, -10, 10);
378  obj->setZ(Zs);
379  // obj->enableWireFrame(true);
380  obj->enableColorFromZ(true, mrpt::img::cmJET);
381  theScene->insert(obj);
382 
383  opengl::CText::Ptr gl_txt = opengl::CText::Create("CMesh");
384  gl_txt->setLocation(off_x, off_y_label, 0);
385  theScene->insert(gl_txt);
386  }
387  off_x += STEP_X;
388 
389  // CMesh3D
390  {
391  opengl::CMesh3D::Ptr obj = opengl::CMesh3D::Create();
392  obj->enableShowEdges(false);
393  obj->enableShowFaces(true);
394  obj->enableShowVertices(false);
395  obj->setLocation(off_x, 0, 0);
396 
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];
403 
404  // Assign vertices to faces and set them to be Quads
405  unsigned int first_ind = 0;
406  for (unsigned int u = 0; u < cols; u++)
407  {
408  for (unsigned int v = 0; v < rows; v++)
409  {
410  const unsigned int face_ind = v + u * rows;
411  vert_per_face[face_ind] = 4;
412 
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;
417  first_ind++;
418  }
419 
420  first_ind++;
421  }
422 
423  // Create vert coords
424  for (unsigned int u = 0; u <= cols; u++)
425  for (unsigned int v = 0; v <= rows; v++)
426  {
427  const unsigned int vert_ind = v + u * (rows + 1);
428 
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);
437  }
438 
439  obj->loadMesh(
440  num_verts, num_faces, vert_per_face, face_verts, vert_coords);
441  theScene->insert(obj);
442 
443  opengl::CText::Ptr gl_txt = opengl::CText::Create("CMesh3D");
444  gl_txt->setLocation(off_x, off_y_label, 0);
445  theScene->insert(gl_txt);
446  }
447  off_x += STEP_X;
448 
449  // CPointCloud
450  {
451  opengl::CPointCloud::Ptr obj = opengl::CPointCloud::Create();
452  obj->setLocation(off_x, 0, 0);
453  theScene->insert(obj);
454 
455  obj->setPointSize(3.0);
456  obj->enablePointSmooth();
457  obj->enableColorFromY();
458 
459  for (int i = 0; i < 100000; i++)
460  obj->insertPoint(
464 
465  opengl::CText::Ptr gl_txt = opengl::CText::Create("CPointCloud");
466  gl_txt->setLocation(off_x, off_y_label, 0);
467  theScene->insert(gl_txt);
468  }
469  off_x += STEP_X;
470 
471  // CPointCloudColoured
472  {
474  opengl::CPointCloudColoured::Create();
475  obj->setLocation(off_x, 0, 0);
476  theScene->insert(obj);
477 
478  obj->setPointSize(3.0);
479  obj->enablePointSmooth();
480 
481  for (int i = 0; i < 200; i++)
482  obj->push_back(
489 
490  opengl::CText::Ptr gl_txt =
491  opengl::CText::Create("CPointCloudColoured");
492  gl_txt->setLocation(off_x, off_y_label, 0);
493  theScene->insert(gl_txt);
494  }
495  off_x += STEP_X;
496 
497  // CPolyhedron
498  {
499  {
501  opengl::CPolyhedron::CreateCuboctahedron(1.0);
502  obj->setLocation(off_x, 0, 0);
503  theScene->insert(obj);
504  }
505  {
507  opengl::CPolyhedron::CreateDodecahedron(1.0);
508  obj->setLocation(off_x, -5, 0);
509  theScene->insert(obj);
510  }
511  {
513  opengl::CPolyhedron::CreateIcosahedron(1.0);
514  obj->setLocation(off_x, 5, 0);
515  theScene->insert(obj);
516  }
517 
518  opengl::CText::Ptr gl_txt = opengl::CText::Create("CPolyhedron");
519  gl_txt->setLocation(off_x, off_y_label, 0);
520  theScene->insert(gl_txt);
521  }
522  off_x += STEP_X;
523 
524  // CSphere
525  {
526  {
527  opengl::CSphere::Ptr obj = opengl::CSphere::Create(3.0);
528  obj->setLocation(off_x, 0, 0);
529  theScene->insert(obj);
530  }
531 
532  opengl::CText::Ptr gl_txt = opengl::CText::Create("CSphere");
533  gl_txt->setLocation(off_x, off_y_label, 0);
534  theScene->insert(gl_txt);
535  }
536  off_x += STEP_X;
537 
538 #if 1
539  // CText
540  {
541  {
542  opengl::CText::Ptr obj = opengl::CText::Create(
543  "This is a CText example! My size is invariant to "
544  "eye-distance");
545  obj->setLocation(off_x, 0, 0);
546  theScene->insert(obj);
547  }
548 
549  opengl::CText::Ptr gl_txt = opengl::CText::Create("CText");
550  gl_txt->setLocation(off_x, off_y_label, 0);
551  theScene->insert(gl_txt);
552  }
553  off_x += STEP_X;
554 
555  // CText3D
556  {
557  {
559  opengl::CText3D::Create("I'm a cool CText3D!");
560  obj->setLocation(off_x, 0, 0);
561  theScene->insert(obj);
562  }
563 
564  opengl::CText::Ptr gl_txt = opengl::CText::Create("CText3D");
565  gl_txt->setLocation(off_x, off_y_label, 0);
566  theScene->insert(gl_txt);
567  }
568  off_x += STEP_X;
569 
570  // CColorMap
571  {
572  {
573  opengl::CColorBar::Ptr obj = opengl::CColorBar::Create(
574  mrpt::img::cmHOT, 0.2, 1.0, 0.0, 1.0, -50.0, 100.0,
575  "%7.02f m/s");
576  obj->setLocation(off_x, 0, 0);
577  theScene->insert(obj);
578  }
579 
580  opengl::CText::Ptr gl_txt = opengl::CText::Create("CColorBar");
581  gl_txt->setLocation(off_x, off_y_label, 0);
582  theScene->insert(gl_txt);
583  }
584  off_x += STEP_X;
585 
586  // CSetOfLines
587  {
588  {
589  opengl::CSetOfLines::Ptr obj = opengl::CSetOfLines::Create();
590  obj->setLocation(off_x, 0, 0);
591 
592  for (int i = 0; i < 15; i++)
593  obj->appendLine(
600 
601  theScene->insert(obj);
602  }
603 
604  opengl::CText::Ptr gl_txt = opengl::CText::Create("CSetOfLines");
605  gl_txt->setLocation(off_x, off_y_label, 0);
606  theScene->insert(gl_txt);
607  }
608  off_x += STEP_X;
609 
610  // CSimpleLine
611  {
612  {
613  opengl::CSimpleLine::Ptr obj = opengl::CSimpleLine::Create();
614  obj->setLocation(off_x, 0, 0);
615 
616  obj->setLineCoords(
617  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
618  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
619  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
620  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
621  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
622  mrpt::random::getRandomGenerator().drawUniform(-5, 5));
623 
624  theScene->insert(obj);
625  }
626 
627  opengl::CText::Ptr gl_txt = opengl::CText::Create("CSimpleLine");
628  gl_txt->setLocation(off_x, off_y_label, 0);
629  theScene->insert(gl_txt);
630  }
631  off_x += STEP_X;
632 
633  // CVectorField2D
634  {
635  {
636  opengl::CVectorField2D::Ptr obj = opengl::CVectorField2D::Create();
637  obj->setLocation(off_x, 0, 0);
638 
639  CMatrixFloat x(16, 16), y(16, 16);
640  for (unsigned int i = 0; i < x.rows(); i++)
641  for (unsigned int j = 0; j < x.cols(); j++)
642  {
643  x(i, j) = sin(0.3 * i);
644  y(i, j) = cos(0.3 * i);
645  }
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);
654  }
655 
656  opengl::CText::Ptr gl_txt = opengl::CText::Create("CVectorField2D");
657  gl_txt->setLocation(off_x, off_y_label, 0);
658  theScene->insert(gl_txt);
659  }
660  off_x += STEP_X;
661 
662  // CVectorField3D
663  {
664  {
665  const unsigned int num = 20;
666  const float scale = 0.8 * STEP_X / num;
667  opengl::CVectorField3D::Ptr obj = opengl::CVectorField3D::Create();
668  obj->setLocation(off_x, -0.5 * scale * num, 0); //
669 
670  CMatrixFloat x(num, num), y(num, num), z(num, num);
671  CMatrixFloat vx(num, num), vy(num, num), vz(num, num);
672  for (unsigned int i = 0; i < x.rows(); i++)
673  for (unsigned int j = 0; j < x.cols(); j++)
674  {
675  x(i, j) = (i - 0.5 * num) * scale;
676  y(i, j) = j * scale;
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;
681  }
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);
692  }
693 
694  opengl::CText::Ptr gl_txt = opengl::CText::Create("CVectorField3D");
695  gl_txt->setLocation(off_x, off_y_label, 0);
696  theScene->insert(gl_txt);
697  }
698  off_x += STEP_X;
699 
700  // stock_objects::BumblebeeCamera
701  {
702  {
705  obj->setLocation(off_x, 0, 0);
706  theScene->insert(obj);
707  }
708 
709  opengl::CText::Ptr gl_txt =
710  opengl::CText::Create("stock_objects::BumblebeeCamera()");
711  gl_txt->setLocation(off_x, off_y_label, 0);
712  theScene->insert(gl_txt);
713  }
714  off_x += STEP_X;
715 
716  // stock_objects::CornerXYSimple
717  {
718  {
721  obj->setLocation(off_x, 0, 0);
722  theScene->insert(obj);
723  }
724 
725  opengl::CText::Ptr gl_txt =
726  opengl::CText::Create("stock_objects::CornerXYSimple()");
727  gl_txt->setLocation(off_x, off_y_label, 0);
728  theScene->insert(gl_txt);
729  }
730  off_x += STEP_X;
731 
732  // stock_objects::CornerXYZSimple
733  {
734  {
737  obj->setLocation(off_x, 0, 0);
738  theScene->insert(obj);
739  }
740 
741  opengl::CText::Ptr gl_txt =
742  opengl::CText::Create("stock_objects::CornerXYZSimple()");
743  gl_txt->setLocation(off_x, off_y_label, 0);
744  theScene->insert(gl_txt);
745  }
746  off_x += STEP_X;
747 
748  // stock_objects::CornerXYZ
749  {
750  {
752  obj->setLocation(off_x, 0, 0);
753  theScene->insert(obj);
754  }
755 
756  opengl::CText::Ptr gl_txt =
757  opengl::CText::Create("stock_objects::CornerXYZ()");
758  gl_txt->setLocation(off_x, off_y_label, 0);
759  theScene->insert(gl_txt);
760  }
761  off_x += STEP_X;
762 
763  // stock_objects::RobotPioneer
764  {
765  {
768  obj->setLocation(off_x, 0, 0);
769  theScene->insert(obj);
770  }
771 
772  opengl::CText::Ptr gl_txt =
773  opengl::CText::Create("stock_objects::RobotPioneer()");
774  gl_txt->setLocation(off_x, off_y_label, 0);
775  theScene->insert(gl_txt);
776  }
777  off_x += STEP_X;
778 
779  // stock_objects::Hokuyo_URG
780  {
781  {
784  obj->setLocation(off_x, 0, 0);
785  theScene->insert(obj);
786  }
787 
788  opengl::CText::Ptr gl_txt =
789  opengl::CText::Create("stock_objects::Hokuyo_URG()");
790  gl_txt->setLocation(off_x, off_y_label, 0);
791  theScene->insert(gl_txt);
792  }
793  off_x += STEP_X;
794 
795  // stock_objects::Hokuyo_UTM
796  {
797  {
800  obj->setLocation(off_x, 0, 0);
801  theScene->insert(obj);
802  }
803 
804  opengl::CText::Ptr gl_txt =
805  opengl::CText::Create("stock_objects::Hokuyo_UTM()");
806  gl_txt->setLocation(off_x, off_y_label, 0);
807  theScene->insert(gl_txt);
808  }
809  off_x += STEP_X;
810 
811  // stock_objects::Househam_Sprayer
812  {
813  {
816  obj->setLocation(off_x, 0, 0);
817  theScene->insert(obj);
818  }
819 
820  opengl::CText::Ptr gl_txt =
821  opengl::CText::Create("stock_objects::Househam_Sprayer()");
822  gl_txt->setLocation(off_x, off_y_label, 0);
823  theScene->insert(gl_txt);
824  }
825  off_x += STEP_X;
826 
827  // stock_objects::RobotRhodon
828  {
829  {
832  obj->setLocation(off_x, 0, 0);
833  theScene->insert(obj);
834  }
835 
836  opengl::CText::Ptr gl_txt =
837  opengl::CText::Create("stock_objects::RobotRhodon()");
838  gl_txt->setLocation(off_x, off_y_label, 0);
839  theScene->insert(gl_txt);
840  }
841  off_x += STEP_X;
842 
843 #endif
844 
845  win.setCameraZoom(150);
846 
847  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
848  win.unlockAccess3DScene();
849  win.repaint();
850 
851  cout << "Close the window to end.\n";
852  while (win.isOpen())
853  {
854  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
855  std::this_thread::sleep_for(2ms);
856  win.repaint();
857  }
858 }
859 
860 // ------------------------------------------------------
861 // MAIN
862 // ------------------------------------------------------
863 int main()
864 {
865  try
866  {
868 
869  return 0;
870  }
871  catch (const std::exception& e)
872  {
873  std::cerr << "MRPT error: " << mrpt::exception_to_str(e) << std::endl;
874  return -1;
875  }
876  catch (...)
877  {
878  printf("Untyped exception!!");
879  return -1;
880  }
881 }
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.
Definition: CMatrixFixed.h:33
GLdouble GLdouble z
Definition: glext.h:3879
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
Definition: glext.h:6604
size_t OCTREE_RENDER_MAX_POINTS_PER_NODE()
Default value = 1e5.
Definition: CPointCloud.cpp:39
CSetOfObjects::Ptr RobotRhodon()
Returns a representation of Rhodon.
CSetOfObjects::Ptr Househam_Sprayer()
Returns a simple 3D model of a househam sprayer.
STL namespace.
GLsizei GLsizei GLuint * obj
Definition: glext.h:4085
GLuint GLuint num
Definition: glext.h:7397
T square(const T x)
Inline function for the square of a number.
This base provides a set of functions for maths stuff.
[New in MRPT 1.5.0]
Definition: color_maps.h:35
mrpt::gui::CDisplayWindow3D::Ptr win
CSetOfObjects::Ptr RobotPioneer()
Returns a representation of a Pioneer II mobile base.
const GLdouble * v
Definition: glext.h:3684
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.
Definition: CGlCanvasBase.h:15
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...
Definition: exceptions.cpp:59
GLenum GLint GLint y
Definition: glext.h:3542
GLenum GLsizei GLenum format
Definition: glext.h:3535
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
GLenum GLint x
Definition: glext.h:3542
Lightweight 3D point.
Definition: TPoint3D.h:90
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.
void TestOpenGLObjects()
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.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019