MRPT  2.0.4
StockObjects.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-2020, 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 
10 #include "opengl-precomp.h" // Precompiled header
11 
13 #include <mrpt/opengl/CArrow.h>
14 #include <mrpt/opengl/CBox.h>
15 #include <mrpt/opengl/CCylinder.h>
21 
22 using namespace mrpt::opengl;
23 using namespace mrpt::poses;
24 using namespace mrpt::math;
25 using namespace std;
26 
27 /*---------------------------------------------------------------
28  RobotPioneer
29  ---------------------------------------------------------------*/
31 {
32  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
33 
34  ret->setName("theRobot");
35 
36  CSetOfTriangles::Ptr obj = std::make_shared<CSetOfTriangles>();
37  obj->setLocalRepresentativePoint({0.0f, 0.0f, 0.15f});
38 
39  // Add triangles:
41 
42  t.r(0) = t.r(1) = t.r(2) = 255;
43  t.g(0) = t.g(1) = t.g(2) = 0;
44  t.b(0) = t.b(1) = t.b(2) = 0;
45  t.a(0) = t.a(1) = t.a(2) = 255;
46 
47  t.vertex(0) = {0.10f, -0.10f, 0.20f};
48  t.vertex(1) = {-0.20f, 0.10f, 0.25f};
49  t.vertex(2) = {-0.20f, -0.10f, 0.25f};
50  t.computeNormals();
51  obj->insertTriangle(t); // 0
52  t.vertex(0) = {0.10f, -0.10f, 0.20f};
53  t.vertex(1) = {0.10f, 0.10f, 0.20f};
54  t.vertex(2) = {-0.20f, 0.10f, 0.25f};
55  t.computeNormals();
56  obj->insertTriangle(t); // 1
57 
58  t.vertex(0) = {0.10f, -0.10f, 0.05f};
59  t.vertex(1) = {0.10f, 0.10f, 0.20f};
60  t.vertex(2) = {0.10f, -0.10f, 0.20f};
61  t.computeNormals();
62  obj->insertTriangle(t); // 2
63  t.vertex(0) = {0.10f, -0.10f, 0.05f};
64  t.vertex(1) = {0.10f, 0.10f, 0.05f};
65  t.vertex(2) = {0.10f, 0.10f, 0.20f};
66  t.computeNormals();
67  obj->insertTriangle(t); // 3
68 
69  t.vertex(0) = {-0.20f, -0.10f, 0.05f};
70  t.vertex(1) = {-0.20f, -0.10f, 0.25f};
71  t.vertex(2) = {-0.20f, 0.10f, 0.25f};
72  t.computeNormals();
73  obj->insertTriangle(t); // 2b
74  t.vertex(0) = {-0.20f, -0.10f, 0.05f};
75  t.vertex(1) = {-0.20f, 0.10f, 0.25f};
76  t.vertex(2) = {-0.20f, 0.10f, 0.05f};
77  t.computeNormals();
78  obj->insertTriangle(t); // 3b
79 
80  t.vertex(0) = {0.10f, -0.10f, 0.20f};
81  t.vertex(1) = {-0.20f, -0.10f, 0.25f};
82  t.vertex(2) = {-0.20f, -0.10f, 0.05f};
83  t.computeNormals();
84  obj->insertTriangle(t); // 4
85 
86  t.vertex(0) = {0.10f, -0.10f, 0.20f};
87  t.vertex(1) = {-0.20f, -0.10f, 0.05f};
88  t.vertex(2) = {0.10f, -0.10f, 0.05f};
89  t.computeNormals();
90  obj->insertTriangle(t); // 5
91 
92  t.vertex(0) = {0.10f, 0.10f, 0.20f};
93  t.vertex(1) = {-0.20f, 0.10f, 0.05f};
94  t.vertex(2) = {-0.20f, 0.10f, 0.25f};
95  t.computeNormals();
96  obj->insertTriangle(t); // 6
97 
98  t.vertex(0) = {0.10f, 0.10f, 0.20f};
99  t.vertex(1) = {0.10f, 0.10f, 0.05f};
100  t.vertex(2) = {-0.20f, 0.10f, 0.05f};
101  t.computeNormals();
102  obj->insertTriangle(t); // 7
103 
104  t.setColor(mrpt::img::TColorf(0.05f, 0.05f, 0.05f, 1));
105 
106  t.vertex(0) = {0.00f, 0.11f, 0.00f};
107  t.vertex(1) = {0.00f, 0.11f, 0.10f};
108  t.vertex(2) = {0.05f, 0.11f, 0.05f};
109  t.computeNormals();
110  obj->insertTriangle(t); // 8
111  t.vertex(0) = {0.00f, 0.11f, 0.00f};
112  t.vertex(1) = {0.00f, 0.11f, 0.10f};
113  t.vertex(2) = {-0.05f, 0.11f, 0.05f};
114  t.computeNormals();
115  obj->insertTriangle(t); // 9
116 
117  t.vertex(0) = {0.00f, -0.11f, 0.00f};
118  t.vertex(1) = {0.00f, -0.11f, 0.10f};
119  t.vertex(2) = {0.05f, -0.11f, 0.05f};
120  t.computeNormals();
121  obj->insertTriangle(t); // 10
122  t.vertex(0) = {0.00f, -0.11f, 0.00f};
123  t.vertex(1) = {0.00f, -0.11f, 0.10f};
124  t.vertex(2) = {-0.05f, -0.11f, 0.05f};
125  t.computeNormals();
126  obj->insertTriangle(t); // 11
127 
128  ret->insert(obj);
129 
130  return ret;
131 }
132 
133 /*---------------------------------------------------------------
134  CornerXYZ
135  ---------------------------------------------------------------*/
137 {
138  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
139 
141  0, 0, 0, scale, 0, 0, 0.25f * scale, 0.02f * scale, 0.05f * scale);
142 
143  obj->setColor(1, 0, 0);
144  ret->insert(obj);
145 
146  obj = CArrow::Create(
147  0, 0, 0, 0, scale, 0, 0.25f * scale, 0.02f * scale, 0.05f * scale);
148  obj->setColor(0, 1, 0);
149 
150  ret->insert(obj);
151 
152  obj = CArrow::Create(
153  0, 0, 0, 0, 0, scale, 0.25f * scale, 0.02f * scale, 0.05f * scale);
154  obj->setColor(0, 0, 1);
155 
156  ret->insert(obj);
157 
158  return ret;
159 }
160 
161 /*---------------------------------------------------------------
162  RobotRhodon
163  ---------------------------------------------------------------*/
165 {
166  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
167  float height = 0;
168 
169  vector<TPoint2D> level1;
170  level1.emplace_back(0.31, 0);
171  level1.emplace_back(0.22, 0.24);
172  level1.emplace_back(-0.22, 0.24);
173  level1.emplace_back(-0.31, 0);
174  level1.emplace_back(-0.22, -0.24);
175  level1.emplace_back(0.22, -0.24);
176 
177  CPolyhedron::Ptr obj1 =
179  obj1->setLocation(0, 0, height);
180  height += 0.38f;
181  obj1->setColor(0.6f, 0.6f, 0.6f);
182  ret->insert(obj1);
183 
184  vector<TPoint2D> level2;
185  level2.emplace_back(0.16, 0.21);
186  level2.emplace_back(-0.16, 0.21);
187  level2.emplace_back(-0.16, -0.21);
188  level2.emplace_back(0.16, -0.21);
189 
190  CPolyhedron::Ptr obj2 =
192  obj2->setLocation(0, 0, height);
193  height += 0.35f;
194  obj2->setColor(0.2f, 0.2f, 0.2f);
195  ret->insert(obj2);
196 
197  vector<TPoint2D> level3;
198  level3.emplace_back(-0.12, 0.12);
199  level3.emplace_back(-0.16, 0.12);
200  level3.emplace_back(-0.16, -0.12);
201  level3.emplace_back(-0.12, -0.12);
202 
204  obj3->setLocation(0, 0, height);
205  // height+=1;
206  obj3->setColor(0.6f, 0.6f, 0.6f);
207  ret->insert(obj3);
208 
210  std::make_shared<opengl::CCylinder>(0.05f, 0.05f, 0.4f, 20);
211  obj4->setLocation(0, 0, 0.73);
212  obj4->setColor(0.0f, 0.0f, 0.9f);
213  ret->insert(obj4);
214 
216  std::make_shared<opengl::CCylinder>(0.05f, 0.05f, 0.4f, 20);
217  obj5->setPose(CPose3D(0.32, 0, 0.89, 0, -1, 0));
218  obj5->setColor(0.0f, 0.0f, 0.9f);
219  ret->insert(obj5);
220 
221  return ret;
222 }
223 
224 /*---------------------------------------------------------------
225  RobotGiraff
226  ---------------------------------------------------------------*/
228 {
229  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
230  float height = 0;
231 
232  // Base
233  vector<TPoint2D> level1;
234  level1.emplace_back(0.31, 0);
235  level1.emplace_back(0.22, 0.24);
236  level1.emplace_back(-0.22, 0.24);
237  level1.emplace_back(-0.31, 0);
238  level1.emplace_back(-0.22, -0.24);
239  level1.emplace_back(0.22, -0.24);
240 
241  CPolyhedron::Ptr obj1 =
243  obj1->setLocation(0, 0, height);
244  height += 0.23f;
245  obj1->setColor(1.0f, 0.6f, 0.0f);
246  ret->insert(obj1);
247 
248  // Electronic's cage
249  vector<TPoint2D> level2;
250  level2.emplace_back(0.13, 0.1);
251  level2.emplace_back(-0.13, 0.1);
252  level2.emplace_back(-0.13, -0.1);
253  level2.emplace_back(0.13, -0.1);
254 
255  CPolyhedron::Ptr obj2 =
257  obj2->setLocation(0, 0, height);
258  height += 0.45f;
259  obj2->setColor(1.0f, 0.6f, 0.2f);
260  ret->insert(obj2);
261 
262  // Neck
263  vector<TPoint2D> level3;
264  level3.emplace_back(0.03, 0.03);
265  level3.emplace_back(-0.03, 0.03);
266  level3.emplace_back(-0.03, -0.03);
267  level3.emplace_back(0.03, -0.03);
268 
269  CPolyhedron::Ptr obj3 =
271  obj3->setLocation(0, 0, height);
272  height += 0.55f;
273  obj3->setColor(0.6f, 0.6f, 0.6f);
274  ret->insert(obj3);
275 
276  // Screen
277  vector<TPoint2D> level4;
278  level4.emplace_back(0.03, 0.11);
279  level4.emplace_back(-0.03, 0.11);
280  level4.emplace_back(-0.03, -0.11);
281  level4.emplace_back(0.03, -0.11);
282 
284  obj4->setLocation(0, 0, height);
285  obj4->setColor(1.0f, 0.6f, 0.0f);
286  ret->insert(obj4);
287 
288  return ret;
289 }
290 
292 {
293  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
294  CPose3D rotation;
295 
296  CArrow::Ptr obj = CArrow::Create(0, 0, 0, 1.0, 0, 0, 0.25f, 0.02f, 0.05f);
297 
298  obj->setColor(1, 0, 0);
299 
300  ret->insert(obj);
301 
302  obj = CArrow::Create(0, 0, 0, 0, 1.0, 0, 0.25f, 0.02f, 0.05f);
303  obj->setColor(0, 1, 0);
304 
305  ret->insert(obj);
306 
307  obj = CArrow::Create(0, 0, -1.0, 0, 0, 0, 0.25f, 0.02f, 0.05f);
308  obj->setColor(0, 0, 1);
309 
310  ret->insert(obj);
311 
312  return ret;
313 }
314 
315 /*---------------------------------------------------------------
316  BumblebeeCamera
317  ---------------------------------------------------------------*/
319 {
320  CSetOfObjects::Ptr camera = std::make_shared<opengl::CSetOfObjects>();
321 
323  -0.02, 0.14, -0.02, 0.02, 0, -0.04);
324  rect->setColor(1.0f, 0.8f, 0.0f);
325 
326  camera->insert(rect);
327 
328  CCylinder::Ptr lCam =
329  std::make_shared<opengl::CCylinder>(0.01f, 0.01f, 0.003f, 10);
330  lCam->setColor(1, 0, 0);
331 
332  CCylinder::Ptr rCam =
333  std::make_shared<opengl::CCylinder>(0.01f, 0.01f, 0.003f, 10);
334  rCam->setPose(CPose3D(0.12, 0, 0));
335  rCam->setColor(0, 0, 0);
336 
337  camera->insert(lCam);
338  camera->insert(rCam);
339 
340  return camera;
341 }
342 
344 {
345  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
346 
347  // Using OpenGL shaders, it's more complicated to set line widths.
348  // So, let's use cylinders of a diameter proportional to "scale":
349  const float R = scale * 0.01f;
350  const int nSlices = 6;
351 
352  { // X:
353  auto lin = CCylinder::Create(R, R, scale, nSlices);
354  lin->setColor(1, 0, 0);
355  lin->setPose(mrpt::poses::CPose3D::FromString("[0 0 0 0 90 0]"));
356  ret->insert(lin);
357  }
358  { // Y:
359  auto lin = CCylinder::Create(R, R, scale, nSlices);
360  lin->setColor(0, 1, 0);
361  lin->setPose(mrpt::poses::CPose3D::FromString("[0 0 0 0 0 -90]"));
362  ret->insert(lin);
363  }
364  { // Z:
365  auto lin = CCylinder::Create(R, R, scale, nSlices);
366  lin->setColor(0, 0, 1);
367  ret->insert(lin);
368  }
369  return ret;
370 }
371 
373 {
374  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
375 
376  // Using OpenGL shaders, it's more complicated to set line widths.
377  // So, let's use cylinders of a diameter proportional to "scale":
378  const float R = scale * 0.01f;
379  const int nSlices = 6;
380 
381  { // X:
382  auto lin = CCylinder::Create(R, R, scale, nSlices);
383  lin->setColor(1, 0, 0);
384  lin->setPose(mrpt::poses::CPose3D::FromString("[0 0 0 0 90 0]"));
385  ret->insert(lin);
386  }
387  { // Y:
388  auto lin = CCylinder::Create(R, R, scale, nSlices);
389  lin->setColor(0, 1, 0);
390  lin->setPose(mrpt::poses::CPose3D::FromString("[0 0 0 0 0 -90]"));
391  ret->insert(lin);
392  }
393  return ret;
394 }
395 
397 {
398  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
399 
400  {
401  CBox::Ptr base = std::make_shared<CBox>(
402  TPoint3D(-0.025, -0.025, -0.0575), TPoint3D(0.025, 0.025, -0.0185));
403  base->setColor(0.7f, 0.7f, 0.7f);
404  ret->insert(base);
405  }
406  {
407  CCylinder::Ptr cyl1 = std::make_shared<CCylinder>(0.02f, 0.02f, 0.01f);
408  cyl1->setColor(0, 0, 0);
409  cyl1->setLocation(0, 0, -0.014);
410  ret->insert(cyl1);
411  }
412  {
413  CCylinder::Ptr cyl2 =
414  std::make_shared<CCylinder>(0.02f, 0.0175f, 0.01f);
415  cyl2->setColor(0, 0, 0);
416  cyl2->setLocation(0, 0, -0.004);
417  ret->insert(cyl2);
418  }
419  {
420  CCylinder::Ptr cyl3 =
421  std::make_shared<CCylinder>(0.0175f, 0.0175f, 0.01f);
422  cyl3->setColor(0, 0, 0);
423  cyl3->setLocation(0, 0, 0.004);
424  ret->insert(cyl3);
425  }
426 
427  return ret;
428 }
429 
431 {
432  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
433 
434  {
435  CBox::Ptr base = std::make_shared<CBox>(
436  TPoint3D(-0.03, -0.03, -0.055), TPoint3D(0.03, 0.03, -0.014));
437  base->setColor(0, 0, 0);
438  ret->insert(base);
439  }
440  {
441  CCylinder::Ptr cyl1 =
442  std::make_shared<CCylinder>(0.028f, 0.024f, 0.028f);
443  cyl1->setColor(0, 0, 0);
444  cyl1->setPose(CPose3D(0, 0, -0.014));
445  ret->insert(cyl1);
446  }
447  {
448  CCylinder::Ptr cyl2 =
449  std::make_shared<CCylinder>(0.028f, 0.028f, 0.01f);
450  cyl2->setColor(1.0f, 69.0f / 255.0f, 0);
451  cyl2->setLocation(0, 0, 0.014);
452  ret->insert(cyl2);
453  }
454  {
455  CCylinder::Ptr cyl3 =
456  std::make_shared<CCylinder>(0.028f, 0.028f, 0.01f);
457  cyl3->setColor(0, 0, 0);
458  cyl3->setLocation(0, 0, 0.024);
459  ret->insert(cyl3);
460  }
461 
462  return ret;
463 }
464 
466 {
467  CSetOfObjects::Ptr ret = std::make_shared<CSetOfObjects>();
468 
469  {
470  CBox::Ptr cabin = std::make_shared<CBox>(
471  TPoint3D(0.878, 0.723, -0.12), TPoint3D(-0.258, -0.723, -1.690));
472  cabin->setColor(0.7f, 0.7f, 0.7f);
473  ret->insert(cabin);
474  }
475  {
476  CBox::Ptr back = std::make_shared<CBox>(
477  TPoint3D(-0.258, 0.723, -0.72), TPoint3D(-5.938, -0.723, -1.690));
478  back->setColor(1, 1, 1);
479  ret->insert(back);
480  }
481  {
482  CBox::Ptr boomAxis = std::make_shared<CBox>(
483  TPoint3D(-5.938, 0.723, -1.0), TPoint3D(-6.189, -0.723, -1.690));
484  boomAxis->setColor(0, 0, 0);
485  ret->insert(boomAxis);
486  }
487  {
488  CBox::Ptr boom1 = std::make_shared<CBox>(
489  TPoint3D(-5.938, 0.723, -1.0), TPoint3D(-6.189, 11.277, -1.620));
490  boom1->setColor(0, 1, 0);
491  ret->insert(boom1);
492  }
493  {
494  CBox::Ptr boom2 = std::make_shared<CBox>(
495  TPoint3D(-5.938, -0.723, -1.0), TPoint3D(-6.189, -11.277, -1.620));
496  boom2->setColor(0, 1, 0);
497  ret->insert(boom2);
498  }
499  {
500  CCylinder::Ptr cyl1 =
501  std::make_shared<CCylinder>(0.716f, 0.716f, 0.387f, 30);
502  cyl1->setColor(0, 0, 0);
503  cyl1->setPose(CPose3D(-0.710, 0.923, -2.480, 0, 0, 90.0_deg));
504  ret->insert(cyl1);
505  }
506  {
507  CCylinder::Ptr cyl2 =
508  std::make_shared<CCylinder>(0.716f, 0.716f, 0.387f, 30);
509  cyl2->setColor(0, 0, 0);
510  cyl2->setPose(CPose3D(-3.937, 0.923, -2.480, 0, 0, 90.0_deg));
511  ret->insert(cyl2);
512  }
513  {
514  CCylinder::Ptr cyl1 =
515  std::make_shared<CCylinder>(0.716f, 0.716f, 0.387f, 30);
516  cyl1->setColor(0, 0, 0);
517  cyl1->setPose(CPose3D(-0.710, -0.423, -2.480, 0, 0, 90.0_deg));
518  ret->insert(cyl1);
519  }
520  {
521  CCylinder::Ptr cyl2 =
522  std::make_shared<CCylinder>(0.716f, 0.716f, 0.387f, 30);
523  cyl2->setColor(0, 0, 0);
524  cyl2->setPose(CPose3D(-3.937, -0.423, -2.480, 0, 0, 90.0_deg));
525  ret->insert(cyl2);
526  }
527  return ret;
528 }
CSetOfObjects::Ptr Hokuyo_UTM()
Returns a simple 3D model of a Hokuyo UTM scanner.
mrpt::math::TPoint3Df & vertex(size_t i)
Definition: TTriangle.h:109
const uint8_t & b(size_t i) const
Definition: TTriangle.h:95
static Ptr Create(Args &&... args)
Definition: CCylinder.h:31
static CPose3D FromString(const std::string &s)
Definition: CPose3D.h:644
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).
const uint8_t & r(size_t i) const
Definition: TTriangle.h:93
CSetOfObjects::Ptr RobotGiraff()
Returns a representation of RobotGiraff.
A triangle (float coordinates) with RGBA colors (u8) and UV (texture coordinates) for each vertex...
Definition: TTriangle.h:35
CSetOfObjects::Ptr RobotRhodon()
Returns a representation of Rhodon.
const uint8_t & g(size_t i) const
Definition: TTriangle.h:94
CSetOfObjects::Ptr Househam_Sprayer()
Returns a simple 3D model of a househam sprayer.
STL namespace.
static CPolyhedron::Ptr CreateCubicPrism(double x1, double x2, double y1, double y2, double z1, double z2)
Creates a cubic prism, given the coordinates of two opposite vertices.
const uint8_t & a(size_t i) const
Definition: TTriangle.h:96
This base provides a set of functions for maths stuff.
static Ptr Create(Args &&... args)
Definition: CArrow.h:30
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
CSetOfObjects::Ptr RobotPioneer()
Returns a representation of a Pioneer II mobile base.
void setColor(const mrpt::img::TColor &c)
Sets the color of all vertices.
Definition: TTriangle.h:116
const float R
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:85
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...
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:13
CSetOfObjects::Ptr CornerXYZEye()
Returns three arrows representing a X,Y,Z 3D corner.
void computeNormals()
Compute the three normals from the cross-product of "v01 x v02".
Definition: TTriangle.cpp:21
CSetOfObjects::Ptr BumblebeeCamera()
Returns a simple 3D model of a PointGrey Bumblebee stereo camera.
static CPolyhedron::Ptr CreateCustomPrism(const std::vector< mrpt::math::TPoint2D > &baseVertices, double height)
Creates a custom prism with vertical edges, given any base which will lie on the XY plane...
CSetOfObjects::Ptr Hokuyo_URG()
Returns a simple 3D model of a Hokuyo URG scanner.



Page generated by Doxygen 1.8.14 for MRPT 2.0.4 Git: 33de1d0ad Sat Jun 20 11:02:42 2020 +0200 at sáb jun 20 17:35:17 CEST 2020