Gazebo Rendering

API Reference

9.3.0
BaseLidarVisual.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 Open Source Robotics Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16*/
17#ifndef GZ_RENDERING_BASELIDARVISUAL_HH_
18#define GZ_RENDERING_BASELIDARVISUAL_HH_
19
20#include <vector>
21
22#include <gz/common/Console.hh>
23
27#include "gz/rendering/Scene.hh"
28
29namespace gz
30{
31 namespace rendering
32 {
33 inline namespace GZ_RENDERING_VERSION_NAMESPACE {
35 template <class T>
37 public virtual LidarVisual,
38 public virtual T
39 {
40 // Documentation inherited
41 protected: BaseLidarVisual();
42
43 // Documentation inherited
44 public: virtual ~BaseLidarVisual();
45
46 // Documentation inherited
47 public: virtual void PreRender() override;
48
49 // Documentation inherited
50 public: virtual void Destroy() override;
51
52 // Documentation inherited
53 public: virtual void ClearPoints() override;
54
55 // Documentation inherited
56 public: virtual void SetPoints(
57 const std::vector<double> &_points) override;
58
59 // Documentation inherited
60 public: virtual void SetPoints(const std::vector<double> &_points,
61 const std::vector<gz::math::Color> &_colors)
62 override;
63
64 // Documentation inherited
65 public: virtual void Update() override;
66
67 // Documentation inherited
68 public: virtual void Init() override;
69
70 // Documentation inherited
71 public: virtual void SetMinVerticalAngle(
72 double _minVerticalAngle) override;
73
74 // Documentation inherited
75 public: virtual double MinVerticalAngle() const override;
76
77 // Documentation inherited
78 public: virtual void SetMaxVerticalAngle(
79 double _maxVerticalAngle) override;
80
81 // Documentation inherited
82 public: virtual double MaxVerticalAngle() const override;
83
84 // Documentation inherited
85 public: virtual void SetMinHorizontalAngle(
86 double _minHorizontalAngle) override;
87
88 // Documentation inherited
89 public: virtual double MinHorizontalAngle() const override;
90
91 // Documentation inherited
92 public: virtual void SetMaxHorizontalAngle(
93 double _maxHorizontalAngle) override;
94
95 // Documentation inherited
96 public: virtual double MaxHorizontalAngle() const override;
97
98 // Documentation inherited
99 public: virtual void SetVerticalRayCount(
100 unsigned int _verticalRayCount) override;
101
102 // Documentation inherited
103 public: virtual unsigned int VerticalRayCount() const override;
104
105 // Documentation inherited
106 public: virtual void SetHorizontalRayCount(
107 unsigned int _horizontalRayCount) override;
108
109 // Documentation inherited
110 public: virtual unsigned int HorizontalRayCount() const override;
111
112 // Documentation inherited
113 public: virtual void SetMinRange(double _minRange) override;
114
115 // Documentation inherited
116 public: virtual double MinRange() const override;
117
118 // Documentation inherited
119 public: virtual void SetMaxRange(double _maxRange) override;
120
121 // Documentation inherited
122 public: virtual double MaxRange() const override;
123
124 // Documentation inherited
125 public: virtual void SetOffset(
126 const gz::math::Pose3d _offset) override;
127
128 // Documentation inherited
129 public: virtual gz::math::Pose3d Offset() const override;
130
131 // Documentation inherited
132 public: virtual unsigned int PointCount() const override;
133
134 // Documentation inherited
135 public: virtual std::vector<double> Points() const override;
136
137 // Documentation inherited
138 public: virtual void SetType(const LidarVisualType _type) override;
139
140 // Documentation inherited
141 public: virtual LidarVisualType Type() const override;
142
143 // Documentation inherited
144 public: virtual void SetSize(double _size) override;
145
146 // Documentation inherited
147 public: virtual double Size() const override;
148
150 public: virtual void CreateMaterials();
151
152 // Documentation inherited
153 public: virtual void SetDisplayNonHitting(bool _display) override;
154
155 // Documentation inherited
156 public: virtual bool DisplayNonHitting() const override;
157
159 protected: double minVerticalAngle = 0;
160
162 protected: double maxVerticalAngle = 0;
163
165 protected: unsigned int verticalCount = 1u;
166
168 protected: double verticalAngleStep = 0;
169
171 protected: double minHorizontalAngle = 0;
172
174 protected: double maxHorizontalAngle = 0;
175
177 protected: unsigned int horizontalCount = 1u;
178
180 protected: double horizontalAngleStep = 0;
181
183 protected: double minRange = 0;
184
186 protected: double maxRange = 0;
187
189 protected: bool displayNonHitting = true;
190
193
195 protected: LidarVisualType lidarVisualType =
196 LidarVisualType::LVT_TRIANGLE_STRIPS;
197
199 protected: double size = 1.0;
200 };
201
203 // BaseLidarVisual
205 template <class T>
209
211 template <class T>
215
217 template <class T>
219 {
220 T::PreRender();
221 }
222
224 template <class T>
226 {
227 T::Destroy();
228 }
229
231 template <class T>
233 {
234 // no op
235 }
236
238 template <class T>
240 {
241 return 0u;
242 }
243
245 template <class T>
251
253 template <class T>
255 {
256 // no op
257 }
258
260 template <class T>
262 {
263 // no op
264 }
265
267 template <class T>
270 {
271 // no op
272 }
273
275 template <class T>
277 {
278 T::Init();
279 this->CreateMaterials();
280 }
281
283 template <class T>
285 double _minVerticalAngle)
286 {
287 this->minVerticalAngle = _minVerticalAngle;
288 }
289
291 template <class T>
293 {
294 return this->minVerticalAngle;
295 }
296
298 template <class T>
300 double _maxVerticalAngle)
301 {
302 this->maxVerticalAngle = _maxVerticalAngle;
303 }
304
306 template <class T>
308 {
309 return this->maxVerticalAngle;
310 }
311
313 template <class T>
315 unsigned int _verticalRayCount)
316 {
317 if (_verticalRayCount == 0)
318 {
319 gzwarn << "Cannot have zero vertical rays. Setting value to 1."
320 << std::endl;
321 this->verticalCount = 1;
322 }
323 else
324 {
325 this->verticalCount = _verticalRayCount;
326 }
327 }
328
330 template <class T>
332 {
333 return this->verticalCount;
334 }
335
337 template <class T>
339 double _minHorizontalAngle)
340 {
341 this->minHorizontalAngle = _minHorizontalAngle;
342 }
343
345 template <class T>
347 {
348 return this->minHorizontalAngle;
349 }
350
352 template <class T>
354 double _maxHorizontalAngle)
355 {
356 this->maxHorizontalAngle = _maxHorizontalAngle;
357 }
358
360 template <class T>
362 {
363 return this->maxHorizontalAngle;
364 }
365
367 template <class T>
369 unsigned int _horizontalRayCount)
370 {
371 if (_horizontalRayCount == 0)
372 {
373 gzwarn << "Cannot have zero horizontal rays. Setting value to 1."
374 << std::endl;
375 this->horizontalCount = 1u;
376 }
377 else
378 {
379 this->horizontalCount = _horizontalRayCount;
380 }
381 }
382
384 template <class T>
386 {
387 return this->horizontalCount;
388 }
389
391 template <class T>
392 void BaseLidarVisual<T>::SetMinRange(double _minRange)
393 {
394 this->minRange = _minRange;
395 }
396
398 template <class T>
400 {
401 return this->minRange;
402 }
403
405 template <class T>
406 void BaseLidarVisual<T>::SetMaxRange(double _maxRange)
407 {
408 this->maxRange = _maxRange;
409 }
410
412 template <class T>
414 {
415 return this->maxRange;
416 }
417
419 template <class T>
421 {
422 this->offset = _offset;
423 }
424
426 template <class T>
428 {
429 return this->offset;
430 }
431
433 template <class T>
435 {
436 this->lidarVisualType = _type;
437 }
438
440 template <class T>
442 {
443 return this->lidarVisualType;
444 }
445
447 template <class T>
449 {
450 this->size = _size;
451 }
452
454 template <class T>
456 {
457 return this->size;
458 }
459
461 template <class T>
463 {
464 this->displayNonHitting = _display;
465 }
466
468 template <class T>
470 {
471 return this->displayNonHitting;
472 }
473
475 template <class T>
477 {
478 MaterialPtr mtl;
479
480 if (!this->Scene()->MaterialRegistered("Lidar/BlueStrips"))
481 {
482 mtl = this->Scene()->CreateMaterial("Lidar/BlueStrips");
483 mtl->SetAmbient(0.0, 0.0, 1.0);
484 mtl->SetDiffuse(0.0, 0.0, 1.0);
485 mtl->SetEmissive(0.0, 0.0, 1.0);
486 mtl->SetTransparency(0.4);
487 mtl->SetCastShadows(false);
488 mtl->SetReceiveShadows(false);
489 mtl->SetLightingEnabled(false);
490 mtl->SetMetalness(0.0f);
491 mtl->SetReflectivity(0.0);
492 }
493
494 if (!this->Scene()->MaterialRegistered("Lidar/LightBlueStrips"))
495 {
496 mtl = this->Scene()->CreateMaterial("Lidar/LightBlueStrips");
497 mtl->SetAmbient(0.0, 0.0, 1.0);
498 mtl->SetDiffuse(0.0, 0.0, 1.0);
499 mtl->SetEmissive(0.0, 0.0, 1.0);
500 mtl->SetTransparency(0.8);
501 mtl->SetCastShadows(false);
502 mtl->SetReceiveShadows(false);
503 mtl->SetLightingEnabled(false);
504 mtl->SetMetalness(0.0f);
505 mtl->SetReflectivity(0.0);
506 }
507
508 if (!this->Scene()->MaterialRegistered("Lidar/TransBlack"))
509 {
510 mtl = this->Scene()->CreateMaterial("Lidar/TransBlack");
511 mtl->SetAmbient(0.0, 0.0, 0.0);
512 mtl->SetDiffuse(0.0, 0.0, 0.0);
513 mtl->SetEmissive(0.0, 0.0, 0.0);
514 mtl->SetTransparency(0.4);
515 mtl->SetCastShadows(false);
516 mtl->SetReceiveShadows(false);
517 mtl->SetLightingEnabled(false);
518 mtl->SetMetalness(0.5f);
519 mtl->SetReflectivity(0.2);
520 }
521
522 if (!this->Scene()->MaterialRegistered("Lidar/BlueRay"))
523 {
524 mtl = this->Scene()->CreateMaterial("Lidar/BlueRay");
525 mtl->SetAmbient(0.0, 0.0, 1.0);
526 mtl->SetDiffuse(0.0, 0.0, 1.0);
527 mtl->SetEmissive(0.0, 0.0, 1.0);
528 mtl->SetSpecular(0.0, 0.0, 1.0);
529 mtl->SetTransparency(0.0);
530 mtl->SetCastShadows(false);
531 mtl->SetReceiveShadows(false);
532 mtl->SetLightingEnabled(false);
533 mtl->SetMetalness(0.1f);
534 mtl->SetReflectivity(0.2);
535 }
536 return;
537 }
538 }
539 }
540}
541#endif