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 
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  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);
56 
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);
63 
64  opengl::CText::Ptr gl_txt =
65  mrpt::make_aligned_shared<opengl::CText>("CGridPlaneXY");
66  gl_txt->setLocation(off_x, off_y_label, 0);
67  theScene->insert(gl_txt);
68  }
69  off_x += STEP_X;
70 
71  // XZ Grid
72  {
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);
78 
79  opengl::CText::Ptr gl_txt =
80  mrpt::make_aligned_shared<opengl::CText>("CGridPlaneXZ");
81  gl_txt->setLocation(off_x, off_y_label, 0);
82  theScene->insert(gl_txt);
83  }
84  off_x += STEP_X;
85 
86  // Arrow
87  {
88  opengl::CArrow::Ptr obj = mrpt::make_aligned_shared<opengl::CArrow>(
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);
93 
94  opengl::CText::Ptr gl_txt =
95  mrpt::make_aligned_shared<opengl::CText>("CArrow");
96  gl_txt->setLocation(off_x, off_y_label, 0);
97  theScene->insert(gl_txt);
98  }
99  off_x += STEP_X;
100 
101  // Axis
102  {
103  opengl::CAxis::Ptr obj = mrpt::make_aligned_shared<opengl::CAxis>(
104  -6, -6, -6, 6, 6, 6, 2, 2, true);
105  obj->setLocation(off_x, 0, 0);
106  theScene->insert(obj);
107 
108  opengl::CText::Ptr gl_txt =
109  mrpt::make_aligned_shared<opengl::CText>("CAxis");
110  gl_txt->setLocation(off_x, off_y_label, 0);
111  theScene->insert(gl_txt);
112  }
113  off_x += STEP_X;
114 
115  // Box
116  {
117  opengl::CBox::Ptr obj = mrpt::make_aligned_shared<opengl::CBox>(
118  TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), true, 3.0);
119  obj->setLocation(off_x, 0, 0);
120  theScene->insert(obj);
121 
122  opengl::CBox::Ptr obj2 = mrpt::make_aligned_shared<opengl::CBox>(
123  TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), false);
124  obj2->setLocation(off_x, 4, 0);
125  theScene->insert(obj2);
126 
127  opengl::CBox::Ptr obj3 = mrpt::make_aligned_shared<opengl::CBox>(
128  TPoint3D(0, 0, 0), TPoint3D(1, 1, 1), false);
129  obj3->enableBoxBorder(true);
130  obj3->setLineWidth(3);
131  obj3->setLocation(off_x, 8, 0);
132  theScene->insert(obj3);
133 
134  opengl::CText::Ptr gl_txt =
135  mrpt::make_aligned_shared<opengl::CText>("CBox");
136  gl_txt->setLocation(off_x, off_y_label, 0);
137  theScene->insert(gl_txt);
138  }
139  off_x += STEP_X;
140 
141  // Frustum
142  {
143  opengl::CFrustum::Ptr obj = mrpt::make_aligned_shared<opengl::CFrustum>(
144  1, 5, 60, 45, 1.5f, true, false);
145  obj->setLocation(off_x, 0, 0);
146  theScene->insert(obj);
147 
148  opengl::CFrustum::Ptr obj2 =
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);
153 
154  opengl::CText::Ptr gl_txt =
155  mrpt::make_aligned_shared<opengl::CText>("CFrustum");
156  gl_txt->setLocation(off_x, off_y_label, 0);
157  theScene->insert(gl_txt);
158  }
159  off_x += STEP_X;
160 
161  // Cylinder
162  {
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);
168 
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);
174 
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);
180 
181  opengl::CText::Ptr gl_txt =
182  mrpt::make_aligned_shared<opengl::CText>("CCylinder");
183  gl_txt->setLocation(off_x, off_y_label, 0);
184  theScene->insert(gl_txt);
185  }
186  off_x += STEP_X;
187 
188  // CDisk
189  {
190  {
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);
196  }
197 
198  {
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);
204  }
205 
206  opengl::CText::Ptr gl_txt =
207  mrpt::make_aligned_shared<opengl::CText>("CDisk");
208  gl_txt->setLocation(off_x, off_y_label, 0);
209  theScene->insert(gl_txt);
210  }
211  off_x += STEP_X;
212 
213  // CEllipsoid
214  {
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};
218  mrpt::math::CMatrixDouble22 cov2d(cov2d_dat);
219  mrpt::math::CMatrixDouble33 cov3d(cov3d_dat);
220 
221  {
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);
228  }
229  {
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);
237  }
238  {
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);
246  }
247 
248  opengl::CText::Ptr gl_txt =
249  mrpt::make_aligned_shared<opengl::CText>("CEllipsoid");
250  gl_txt->setLocation(off_x, off_y_label, 0);
251  theScene->insert(gl_txt);
252  }
253  off_x += STEP_X;
254 
255  // CEllipsoidRangeBearing2D
256  { // (range,bearing) -> (x,y)
257  const double cov_params_dat[] = {0.2, 0, 0, 0.1};
258  const double mean_params_dat[] = {3.0, 0.5};
260  cov_params_dat);
262  mean_params_dat);
263 
264  {
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);
270  // obj->setNumberOfSegments(50);
271  theScene->insert(obj);
272 
273  opengl::CSetOfObjects::Ptr obj_corner =
275  obj_corner->setLocation(off_x, 6, 0);
276  theScene->insert(obj_corner);
277  }
278  }
279  { // (range,bearing) -> (x,y)
280  const double cov_params_dat[] = {0.2, 0.09, 0.09, 0.1};
281  const double mean_params_dat[] = {5.0, -0.5};
283  cov_params_dat);
285  mean_params_dat);
286 
287  {
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);
293  // obj->setNumberOfSegments(50);
294  theScene->insert(obj);
295 
296  opengl::CSetOfObjects::Ptr obj_corner =
298  obj_corner->setLocation(off_x, 0, 0);
299  theScene->insert(obj_corner);
300  }
301 
302  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
303  "CEllipsoidRangeBearing2D");
304  gl_txt->setLocation(off_x, off_y_label, 0);
305  theScene->insert(gl_txt);
306  }
307  off_x += STEP_X;
308 
309  // CEllipsoidInverseDepth2D
310  { // (inv_range,yaw) -> (x,y)
311  // Formula from our book (ch8) for confidence intervals of 3sigmas:
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);
316 
317  const double cov_params_dat[] = {square(rho_std), 0, 0,
318  square(DEG2RAD(2))};
319  const double mean_params_dat[] = {rho_mean, DEG2RAD(70)};
321  cov_params_dat);
323  mean_params_dat);
324 
325  {
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);
333 
334  opengl::CSetOfObjects::Ptr obj_corner =
336  obj_corner->setLocation(off_x, 6, 0);
337  theScene->insert(obj_corner);
338  }
339 
340  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
341  "CEllipsoidInverseDepth2D");
342  gl_txt->setLocation(off_x, off_y_label, 0);
343  theScene->insert(gl_txt);
344  }
345  off_x += STEP_X;
346 
347  // CEllipsoidInverseDepth3D
348  { // (inv_range,yaw,pitch) -> (x,y,z)
349  // Formula from our book (ch8) for confidence intervals of 3sigmas:
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);
354 
355  const double cov_params_dat[] = {square(rho_std), 0, 0, 0,
356  square(DEG2RAD(2)), 0, 0, 0,
357  square(DEG2RAD(2))};
358  const double mean_params_dat[] = {rho_mean, DEG2RAD(30), DEG2RAD(-45)};
360  cov_params_dat);
362  mean_params_dat);
363 
364  {
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);
370  // obj->setNumberOfSegments(50);
371  theScene->insert(obj);
372 
373  opengl::CSetOfObjects::Ptr obj_corner =
375  obj_corner->setLocation(off_x, 0, 0);
376  theScene->insert(obj_corner);
377  }
378 
379  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
380  "CEllipsoidInverseDepth3D");
381  gl_txt->setLocation(off_x, off_y_label, 0);
382  theScene->insert(gl_txt);
383  }
384  off_x += STEP_X;
385 
386  // CMesh
387  {
388  opengl::CMesh::Ptr obj = mrpt::make_aligned_shared<opengl::CMesh>();
389  obj->setLocation(off_x, 0, 0);
390 
391  mrpt::math::CMatrixFloat Zs(40, 40); // Height
392  // mrpt::math::CMatrixFloat Us,Vs; // Texture
393  // Us.resize(Zs.size());
394  // Vs.resize(Zs.size());
395 
396  for (size_t i = 0; i < Zs.rows(); i++)
397  for (size_t j = 0; j < Zs.cols(); j++)
398  {
399  double x = i * 0.25;
400  double y = j * 0.25;
401  Zs(i, j) = 4 * cos((x + y) * 0.6) +
402  sin((x - 0.5) * (y + 1.2) * 0.3) * 3;
403  }
404 
405  obj->setGridLimits(-10, 10, -10, 10);
406  obj->setZ(Zs);
407  // obj->enableWireFrame(true);
408  obj->enableColorFromZ(true, mrpt::img::cmJET);
409  theScene->insert(obj);
410 
411  opengl::CText::Ptr gl_txt =
412  mrpt::make_aligned_shared<opengl::CText>("CMesh");
413  gl_txt->setLocation(off_x, off_y_label, 0);
414  theScene->insert(gl_txt);
415  }
416  off_x += STEP_X;
417 
418  // CMesh3D
419  {
420  opengl::CMesh3D::Ptr obj = mrpt::make_aligned_shared<opengl::CMesh3D>();
421  obj->enableShowEdges(false);
422  obj->enableShowFaces(true);
423  obj->enableShowVertices(false);
424  obj->setLocation(off_x, 0, 0);
425 
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];
432 
433  // Assign vertices to faces and set them to be Quads
434  unsigned int first_ind = 0;
435  for (unsigned int u = 0; u < cols; u++)
436  {
437  for (unsigned int v = 0; v < rows; v++)
438  {
439  const unsigned int face_ind = v + u * rows;
440  vert_per_face[face_ind] = 4;
441 
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;
446  first_ind++;
447  }
448 
449  first_ind++;
450  }
451 
452  // Create vert coords
453  for (unsigned int u = 0; u <= cols; u++)
454  for (unsigned int v = 0; v <= rows; v++)
455  {
456  const unsigned int vert_ind = v + u * (rows + 1);
457 
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);
466  }
467 
468  obj->loadMesh(
469  num_verts, num_faces, vert_per_face, face_verts, vert_coords);
470  theScene->insert(obj);
471 
472  opengl::CText::Ptr gl_txt =
473  mrpt::make_aligned_shared<opengl::CText>("CMesh3D");
474  gl_txt->setLocation(off_x, off_y_label, 0);
475  theScene->insert(gl_txt);
476  }
477  off_x += STEP_X;
478 
479  // CPointCloud
480  {
482  mrpt::make_aligned_shared<opengl::CPointCloud>();
483  obj->setLocation(off_x, 0, 0);
484  theScene->insert(obj);
485 
486  obj->setPointSize(3.0);
487  obj->enablePointSmooth();
488  obj->enableColorFromY();
489 
490  for (int i = 0; i < 100000; i++)
491  obj->insertPoint(
495 
496  opengl::CText::Ptr gl_txt =
497  mrpt::make_aligned_shared<opengl::CText>("CPointCloud");
498  gl_txt->setLocation(off_x, off_y_label, 0);
499  theScene->insert(gl_txt);
500  }
501  off_x += STEP_X;
502 
503  // CPointCloudColoured
504  {
506  mrpt::make_aligned_shared<opengl::CPointCloudColoured>();
507  obj->setLocation(off_x, 0, 0);
508  theScene->insert(obj);
509 
510  obj->setPointSize(3.0);
511  obj->enablePointSmooth();
512 
513  for (int i = 0; i < 200; i++)
514  obj->push_back(
521 
522  opengl::CText::Ptr gl_txt =
523  mrpt::make_aligned_shared<opengl::CText>("CPointCloudColoured");
524  gl_txt->setLocation(off_x, off_y_label, 0);
525  theScene->insert(gl_txt);
526  }
527  off_x += STEP_X;
528 
529  // CPolyhedron
530  {
531  {
533  opengl::CPolyhedron::CreateCuboctahedron(1.0);
534  obj->setLocation(off_x, 0, 0);
535  theScene->insert(obj);
536  }
537  {
539  opengl::CPolyhedron::CreateDodecahedron(1.0);
540  obj->setLocation(off_x, -5, 0);
541  theScene->insert(obj);
542  }
543  {
545  opengl::CPolyhedron::CreateIcosahedron(1.0);
546  obj->setLocation(off_x, 5, 0);
547  theScene->insert(obj);
548  }
549 
550  opengl::CText::Ptr gl_txt =
551  mrpt::make_aligned_shared<opengl::CText>("CPolyhedron");
552  gl_txt->setLocation(off_x, off_y_label, 0);
553  theScene->insert(gl_txt);
554  }
555  off_x += STEP_X;
556 
557  // CSphere
558  {
559  {
561  mrpt::make_aligned_shared<opengl::CSphere>(3.0);
562  obj->setLocation(off_x, 0, 0);
563  theScene->insert(obj);
564  }
565 
566  opengl::CText::Ptr gl_txt =
567  mrpt::make_aligned_shared<opengl::CText>("CSphere");
568  gl_txt->setLocation(off_x, off_y_label, 0);
569  theScene->insert(gl_txt);
570  }
571  off_x += STEP_X;
572 
573 #if 1
574  // CText
575  {
576  {
577  opengl::CText::Ptr obj = mrpt::make_aligned_shared<opengl::CText>(
578  "This is a CText example! My size is invariant to "
579  "eye-distance");
580  obj->setLocation(off_x, 0, 0);
581  theScene->insert(obj);
582  }
583 
584  opengl::CText::Ptr gl_txt =
585  mrpt::make_aligned_shared<opengl::CText>("CText");
586  gl_txt->setLocation(off_x, off_y_label, 0);
587  theScene->insert(gl_txt);
588  }
589  off_x += STEP_X;
590 
591  // CText3D
592  {
593  {
595  mrpt::make_aligned_shared<opengl::CText3D>(
596  "I'm a cool CText3D!");
597  obj->setLocation(off_x, 0, 0);
598  theScene->insert(obj);
599  }
600 
601  opengl::CText::Ptr gl_txt =
602  mrpt::make_aligned_shared<opengl::CText>("CText3D");
603  gl_txt->setLocation(off_x, off_y_label, 0);
604  theScene->insert(gl_txt);
605  }
606  off_x += STEP_X;
607 
608  // CColorMap
609  {
610  {
612  mrpt::make_aligned_shared<opengl::CColorBar>(
613  mrpt::img::cmHOT, 0.2, 1.0, 0.0, 1.0, -50.0, 100.0,
614  "%7.02f m/s");
615  obj->setLocation(off_x, 0, 0);
616  theScene->insert(obj);
617  }
618 
619  opengl::CText::Ptr gl_txt =
620  mrpt::make_aligned_shared<opengl::CText>("CColorBar");
621  gl_txt->setLocation(off_x, off_y_label, 0);
622  theScene->insert(gl_txt);
623  }
624  off_x += STEP_X;
625 
626  // CSetOfLines
627  {
628  {
630  mrpt::make_aligned_shared<opengl::CSetOfLines>();
631  obj->setLocation(off_x, 0, 0);
632 
633  for (int i = 0; i < 15; i++)
634  obj->appendLine(
641 
642  theScene->insert(obj);
643  }
644 
645  opengl::CText::Ptr gl_txt =
646  mrpt::make_aligned_shared<opengl::CText>("CSetOfLines");
647  gl_txt->setLocation(off_x, off_y_label, 0);
648  theScene->insert(gl_txt);
649  }
650  off_x += STEP_X;
651 
652  // CSimpleLine
653  {
654  {
656  mrpt::make_aligned_shared<opengl::CSimpleLine>();
657  obj->setLocation(off_x, 0, 0);
658 
659  obj->setLineCoords(
660  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
661  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
662  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
663  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
664  mrpt::random::getRandomGenerator().drawUniform(-5, 5),
665  mrpt::random::getRandomGenerator().drawUniform(-5, 5));
666 
667  theScene->insert(obj);
668  }
669 
670  opengl::CText::Ptr gl_txt =
671  mrpt::make_aligned_shared<opengl::CText>("CSimpleLine");
672  gl_txt->setLocation(off_x, off_y_label, 0);
673  theScene->insert(gl_txt);
674  }
675  off_x += STEP_X;
676 
677  // CVectorField2D
678  {
679  {
681  mrpt::make_aligned_shared<opengl::CVectorField2D>();
682  obj->setLocation(off_x, 0, 0);
683 
684  CMatrixFloat x(16, 16), y(16, 16);
685  for (unsigned int i = 0; i < x.rows(); i++)
686  for (unsigned int j = 0; j < x.cols(); j++)
687  {
688  x(i, j) = sin(0.3 * i);
689  y(i, j) = cos(0.3 * i);
690  }
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);
699  }
700 
701  opengl::CText::Ptr gl_txt =
702  mrpt::make_aligned_shared<opengl::CText>("CVectorField2D");
703  gl_txt->setLocation(off_x, off_y_label, 0);
704  theScene->insert(gl_txt);
705  }
706  off_x += STEP_X;
707 
708  // CVectorField3D
709  {
710  {
711  const unsigned int num = 20;
712  const float scale = 0.8 * STEP_X / num;
714  mrpt::make_aligned_shared<opengl::CVectorField3D>();
715  obj->setLocation(off_x, -0.5 * scale * num, 0); //
716 
717  CMatrixFloat x(num, num), y(num, num), z(num, num);
718  CMatrixFloat vx(num, num), vy(num, num), vz(num, num);
719  for (unsigned int i = 0; i < x.rows(); i++)
720  for (unsigned int j = 0; j < x.cols(); j++)
721  {
722  x(i, j) = (i - 0.5 * num) * scale;
723  y(i, j) = j * scale;
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;
728  }
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);
739  }
740 
741  opengl::CText::Ptr gl_txt =
742  mrpt::make_aligned_shared<opengl::CText>("CVectorField3D");
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::BumblebeeCamera
749  {
750  {
753  obj->setLocation(off_x, 0, 0);
754  theScene->insert(obj);
755  }
756 
757  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
758  "stock_objects::BumblebeeCamera()");
759  gl_txt->setLocation(off_x, off_y_label, 0);
760  theScene->insert(gl_txt);
761  }
762  off_x += STEP_X;
763 
764  // stock_objects::CornerXYSimple
765  {
766  {
769  obj->setLocation(off_x, 0, 0);
770  theScene->insert(obj);
771  }
772 
773  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
774  "stock_objects::CornerXYSimple()");
775  gl_txt->setLocation(off_x, off_y_label, 0);
776  theScene->insert(gl_txt);
777  }
778  off_x += STEP_X;
779 
780  // stock_objects::CornerXYZSimple
781  {
782  {
785  obj->setLocation(off_x, 0, 0);
786  theScene->insert(obj);
787  }
788 
789  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
790  "stock_objects::CornerXYZSimple()");
791  gl_txt->setLocation(off_x, off_y_label, 0);
792  theScene->insert(gl_txt);
793  }
794  off_x += STEP_X;
795 
796  // stock_objects::CornerXYZ
797  {
798  {
800  obj->setLocation(off_x, 0, 0);
801  theScene->insert(obj);
802  }
803 
804  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
805  "stock_objects::CornerXYZ()");
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::RobotPioneer
812  {
813  {
816  obj->setLocation(off_x, 0, 0);
817  theScene->insert(obj);
818  }
819 
820  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
821  "stock_objects::RobotPioneer()");
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::Hokuyo_URG
828  {
829  {
832  obj->setLocation(off_x, 0, 0);
833  theScene->insert(obj);
834  }
835 
836  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
837  "stock_objects::Hokuyo_URG()");
838  gl_txt->setLocation(off_x, off_y_label, 0);
839  theScene->insert(gl_txt);
840  }
841  off_x += STEP_X;
842 
843  // stock_objects::Hokuyo_UTM
844  {
845  {
848  obj->setLocation(off_x, 0, 0);
849  theScene->insert(obj);
850  }
851 
852  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
853  "stock_objects::Hokuyo_UTM()");
854  gl_txt->setLocation(off_x, off_y_label, 0);
855  theScene->insert(gl_txt);
856  }
857  off_x += STEP_X;
858 
859  // stock_objects::Househam_Sprayer
860  {
861  {
864  obj->setLocation(off_x, 0, 0);
865  theScene->insert(obj);
866  }
867 
868  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
869  "stock_objects::Househam_Sprayer()");
870  gl_txt->setLocation(off_x, off_y_label, 0);
871  theScene->insert(gl_txt);
872  }
873  off_x += STEP_X;
874 
875  // stock_objects::RobotRhodon
876  {
877  {
880  obj->setLocation(off_x, 0, 0);
881  theScene->insert(obj);
882  }
883 
884  opengl::CText::Ptr gl_txt = mrpt::make_aligned_shared<opengl::CText>(
885  "stock_objects::RobotRhodon()");
886  gl_txt->setLocation(off_x, off_y_label, 0);
887  theScene->insert(gl_txt);
888  }
889  off_x += STEP_X;
890 
891 #endif
892 
893  win.setCameraZoom(150);
894 
895  // IMPORTANT!!! IF NOT UNLOCKED, THE WINDOW WILL NOT BE UPDATED!
896  win.unlockAccess3DScene();
897  win.repaint();
898 
899  cout << "Close the window to end.\n";
900  while (win.isOpen())
901  {
902  win.addTextMessage(5, 5, format("%.02fFPS", win.getRenderingFPS()));
903  std::this_thread::sleep_for(2ms);
904  win.repaint();
905  }
906 }
907 
908 // ------------------------------------------------------
909 // MAIN
910 // ------------------------------------------------------
911 int main()
912 {
913  try
914  {
916 
917  return 0;
918  }
919  catch (std::exception& e)
920  {
921  std::cout << "MRPT exception caught: " << e.what() << std::endl;
922  return -1;
923  }
924  catch (...)
925  {
926  printf("Untyped exception!!");
927  return -1;
928  }
929 }
DEG2RAD
#define DEG2RAD
Definition: core/include/mrpt/core/bits_math.h:59
mrpt::opengl::CGridPlaneXY::Ptr
std::shared_ptr< CGridPlaneXY > Ptr
Definition: CGridPlaneXY.h:34
mrpt::opengl::CSetOfLines::Ptr
std::shared_ptr< CSetOfLines > Ptr
Definition: CSetOfLines.h:35
mrpt::opengl::CColorBar::Ptr
std::shared_ptr< CColorBar > Ptr
Definition: CColorBar.h:38
format
GLenum GLsizei GLenum format
Definition: glext.h:3531
mrpt::opengl::CVectorField3D::Ptr
std::shared_ptr< CVectorField3D > Ptr
Definition: CVectorField3D.h:43
mrpt::global_settings::OCTREE_RENDER_MAX_POINTS_PER_NODE
size_t OCTREE_RENDER_MAX_POINTS_PER_NODE()
Default value = 1e5.
Definition: CPointCloud.cpp:38
mrpt::opengl::CSphere::Ptr
std::shared_ptr< CSphere > Ptr
Definition: CSphere.h:33
mrpt::opengl::CSimpleLine::Ptr
std::shared_ptr< CSimpleLine > Ptr
Definition: CSimpleLine.h:24
mrpt::opengl::CArrow::Ptr
std::shared_ptr< CArrow > Ptr
Definition: CArrow.h:33
mrpt::img::cmHOT
@ cmHOT
[New in MRPT 1.5.0]
Definition: color_maps.h:37
obj
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
mrpt::opengl::CCylinder::Ptr
std::shared_ptr< CCylinder > Ptr
Definition: CCylinder.h:34
mrpt::opengl::CGridPlaneXZ::Ptr
std::shared_ptr< CGridPlaneXZ > Ptr
Definition: CGridPlaneXZ.h:34
mrpt::opengl::CEllipsoidRangeBearing2D::Ptr
std::shared_ptr< CEllipsoidRangeBearing2D > Ptr
Definition: CEllipsoidRangeBearing2D.h:46
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::opengl::stock_objects::CornerXYZSimple
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...
Definition: StockObjects.cpp:419
mrpt::square
T square(const T x)
Inline function for the square of a number.
Definition: core/include/mrpt/core/bits_math.h:18
mrpt::opengl::CPointCloudColoured::Ptr
std::shared_ptr< CPointCloudColoured > Ptr
Definition: CPointCloudColoured.h:49
mrpt::opengl::CPointCloud::Ptr
std::shared_ptr< CPointCloud > Ptr
Definition: CPointCloud.h:50
CDisplayWindow3D.h
mrpt::opengl::CFrustum::Ptr
std::shared_ptr< CFrustum > Ptr
Definition: CFrustum.h:56
mrpt::opengl::CEllipsoidInverseDepth2D::Ptr
std::shared_ptr< CEllipsoidInverseDepth2D > Ptr
Definition: CEllipsoidInverseDepth2D.h:49
random.h
mrpt::opengl::CBox::Ptr
std::shared_ptr< CBox > Ptr
Definition: CBox.h:44
mrpt::math::CMatrixTemplateNumeric
A matrix of dynamic size.
Definition: CMatrixTemplateNumeric.h:37
v
const GLdouble * v
Definition: glext.h:3678
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::opengl::CVectorField2D::Ptr
std::shared_ptr< CVectorField2D > Ptr
Definition: CVectorField2D.h:38
M_PI
#define M_PI
Definition: core/include/mrpt/core/bits_math.h:38
mrpt::random::CRandomGenerator::drawUniform
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm,...
Definition: RandomGenerators.h:111
mrpt::opengl::CPolyhedron::Ptr
std::shared_ptr< CPolyhedron > Ptr
Definition: CPolyhedron.h:46
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::opengl::CSetOfObjects::Ptr
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:30
mrpt::opengl::CAxis::Ptr
std::shared_ptr< CAxis > Ptr
Definition: CAxis.h:33
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::math::CMatrixFixedNumeric
A numeric matrix of compile-time fixed size.
Definition: CMatrixFixedNumeric.h:40
mrpt::math::TPoint3D
Lightweight 3D point.
Definition: lightweight_geom_data.h:378
scale
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:6503
mrpt::opengl::stock_objects::RobotPioneer
CSetOfObjects::Ptr RobotPioneer()
Returns a representation of a Pioneer II mobile base.
Definition: StockObjects.cpp:30
mrpt::opengl::CText3D::Ptr
std::shared_ptr< CText3D > Ptr
Definition: CText3D.h:47
mrpt::opengl::stock_objects::BumblebeeCamera
CSetOfObjects::Ptr BumblebeeCamera()
Returns a simple 3D model of a PointGrey Bumblebee stereo camera.
Definition: StockObjects.cpp:393
mrpt::opengl::stock_objects::CornerXYZ
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
Definition: StockObjects.cpp:209
mrpt::random::getRandomGenerator
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Definition: RandomGenerator.cpp:19
opengl.h
mrpt::opengl::CMesh3D::Ptr
std::shared_ptr< CMesh3D > Ptr
Definition: CMesh3D.h:40
mrpt::opengl::CDisk::Ptr
std::shared_ptr< CDisk > Ptr
Definition: CDisk.h:35
mrpt::opengl::stock_objects::Hokuyo_UTM
CSetOfObjects::Ptr Hokuyo_UTM()
Returns a simple 3D model of a Hokuyo UTM scanner.
Definition: StockObjects.cpp:503
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::opengl::stock_objects::CornerXYSimple
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).
Definition: StockObjects.cpp:447
z
GLdouble GLdouble z
Definition: glext.h:3872
mrpt::img::cmJET
@ cmJET
Definition: color_maps.h:35
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
mrpt::opengl::stock_objects::RobotRhodon
CSetOfObjects::Ptr RobotRhodon()
Returns a representation of Rhodon.
Definition: StockObjects.cpp:238
mrpt::opengl::CEllipsoid::Ptr
std::shared_ptr< CEllipsoid > Ptr
Definition: CEllipsoid.h:49
mrpt::opengl::stock_objects::Hokuyo_URG
CSetOfObjects::Ptr Hokuyo_URG()
Returns a simple 3D model of a Hokuyo URG scanner.
Definition: StockObjects.cpp:468
mrpt::opengl::CEllipsoidInverseDepth3D::Ptr
std::shared_ptr< CEllipsoidInverseDepth3D > Ptr
Definition: CEllipsoidInverseDepth3D.h:52
TestOpenGLObjects
void TestOpenGLObjects()
Definition: vision_stereo_rectify/test.cpp:25
mrpt::opengl::CMesh::Ptr
std::shared_ptr< CMesh > Ptr
Definition: CMesh.h:41
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
y
GLenum GLint GLint y
Definition: glext.h:3538
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
x
GLenum GLint x
Definition: glext.h:3538
mrpt::opengl::CText::Ptr
std::shared_ptr< CText > Ptr
Definition: CText.h:40
num
GLuint GLuint num
Definition: glext.h:7278
mrpt::opengl::stock_objects::Househam_Sprayer
CSetOfObjects::Ptr Househam_Sprayer()
Returns a simple 3D model of a househam sprayer.
Definition: StockObjects.cpp:538



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