Gazebo Rendering

API Reference

6.6.3
gz/rendering/base/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 IGNITION_RENDERING_BASELIDARVISUAL_HH_
18 #define IGNITION_RENDERING_BASELIDARVISUAL_HH_
19 
20 #include <vector>
21 
26 
27 namespace ignition
28 {
29  namespace rendering
30  {
31  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
33  template <class T>
35  public virtual LidarVisual,
36  public virtual T
37  {
38  // Documentation inherited
39  protected: BaseLidarVisual();
40 
41  // Documentation inherited
42  public: virtual ~BaseLidarVisual();
43 
44  // Documentation inherited
45  public: virtual void PreRender() override;
46 
47  // Documentation inherited
48  public: virtual void Destroy() override;
49 
50  // Documentation inherited
51  public: virtual void ClearPoints() override;
52 
53  // Documentation inherited
54  public: virtual void SetPoints(
55  const std::vector<double> &_points) override;
56 
57  // Documentation inherited
58  public: virtual void SetPoints(const std::vector<double> &_points,
60  override;
61 
62  // Documentation inherited
63  public: virtual void Update() override;
64 
65  // Documentation inherited
66  public: virtual void Init() override;
67 
68  // Documentation inherited
69  public: virtual void SetMinVerticalAngle(
70  double _minVerticalAngle) override;
71 
72  // Documentation inherited
73  public: virtual double MinVerticalAngle() const override;
74 
75  // Documentation inherited
76  public: virtual void SetMaxVerticalAngle(
77  double _maxVerticalAngle) override;
78 
79  // Documentation inherited
80  public: virtual double MaxVerticalAngle() const override;
81 
82  // Documentation inherited
83  public: virtual void SetMinHorizontalAngle(
84  double _minHorizontalAngle) override;
85 
86  // Documentation inherited
87  public: virtual double MinHorizontalAngle() const override;
88 
89  // Documentation inherited
90  public: virtual void SetMaxHorizontalAngle(
91  double _maxHorizontalAngle) override;
92 
93  // Documentation inherited
94  public: virtual double MaxHorizontalAngle() const override;
95 
96  // Documentation inherited
97  public: virtual void SetVerticalRayCount(
98  unsigned int _verticalRayCount) override;
99 
100  // Documentation inherited
101  public: virtual unsigned int VerticalRayCount() const override;
102 
103  // Documentation inherited
104  public: virtual void SetHorizontalRayCount(
105  unsigned int _horizontalRayCount) override;
106 
107  // Documentation inherited
108  public: virtual unsigned int HorizontalRayCount() const override;
109 
110  // Documentation inherited
111  public: virtual void SetMinRange(double _minRange) override;
112 
113  // Documentation inherited
114  public: virtual double MinRange() const override;
115 
116  // Documentation inherited
117  public: virtual void SetMaxRange(double _maxRange) override;
118 
119  // Documentation inherited
120  public: virtual double MaxRange() const override;
121 
122  // Documentation inherited
123  public: virtual void SetOffset(
124  const ignition::math::Pose3d _offset) override;
125 
126  // Documentation inherited
127  public: virtual ignition::math::Pose3d Offset() const override;
128 
129  // Documentation inherited
130  public: virtual unsigned int PointCount() const override;
131 
132  // Documentation inherited
133  public: virtual std::vector<double> Points() const override;
134 
135  // Documentation inherited
136  public: virtual void SetType(const LidarVisualType _type) override;
137 
138  // Documentation inherited
139  public: virtual LidarVisualType Type() const override;
140 
141  // Documentation inherited
142  public: virtual void SetSize(double _size) override;
143 
144  // Documentation inherited
145  public: virtual double Size() const override;
146 
148  public: virtual void CreateMaterials();
149 
150  // Documentation inherited
151  public: virtual void SetDisplayNonHitting(bool _display) override;
152 
153  // Documentation inherited
154  public: virtual bool DisplayNonHitting() const override;
155 
157  protected: double minVerticalAngle = 0;
158 
160  protected: double maxVerticalAngle = 0;
161 
163  protected: unsigned int verticalCount = 1u;
164 
166  protected: double verticalAngleStep = 0;
167 
169  protected: double minHorizontalAngle = 0;
170 
172  protected: double maxHorizontalAngle = 0;
173 
175  protected: unsigned int horizontalCount = 1u;
176 
178  protected: double horizontalAngleStep = 0;
179 
181  protected: double minRange = 0;
182 
184  protected: double maxRange = 0;
185 
187  protected: bool displayNonHitting = true;
188 
191 
193  protected: LidarVisualType lidarVisualType =
195 
197  protected: double size = 1.0;
198  };
199 
201  // BaseLidarVisual
203  template <class T>
205  {
206  }
207 
209  template <class T>
211  {
212  }
213 
215  template <class T>
217  {
218  T::PreRender();
219  }
220 
222  template <class T>
224  {
225  T::Destroy();
226  }
227 
229  template <class T>
231  {
232  // no op
233  }
234 
236  template <class T>
237  unsigned int BaseLidarVisual<T>::PointCount() const
238  {
239  return 0u;
240  }
241 
243  template <class T>
245  {
247  return d;
248  }
249 
251  template <class T>
253  {
254  // no op
255  }
256 
258  template <class T>
260  {
261  // no op
262  }
263 
265  template <class T>
268  {
269  // no op
270  }
271 
273  template <class T>
275  {
276  T::Init();
277  this->CreateMaterials();
278  }
279 
281  template <class T>
283  double _minVerticalAngle)
284  {
285  this->minVerticalAngle = _minVerticalAngle;
286  }
287 
289  template <class T>
291  {
292  return this->minVerticalAngle;
293  }
294 
296  template <class T>
298  double _maxVerticalAngle)
299  {
300  this->maxVerticalAngle = _maxVerticalAngle;
301  }
302 
304  template <class T>
306  {
307  return this->maxVerticalAngle;
308  }
309 
311  template <class T>
313  unsigned int _verticalRayCount)
314  {
315  if (_verticalRayCount == 0)
316  {
317  ignwarn << "Cannot have zero vertical rays. Setting value to 1."
318  << std::endl;
319  this->verticalCount = 1;
320  }
321  else
322  {
323  this->verticalCount = _verticalRayCount;
324  }
325  }
326 
328  template <class T>
330  {
331  return this->verticalCount;
332  }
333 
335  template <class T>
337  double _minHorizontalAngle)
338  {
339  this->minHorizontalAngle = _minHorizontalAngle;
340  }
341 
343  template <class T>
345  {
346  return this->minHorizontalAngle;
347  }
348 
350  template <class T>
352  double _maxHorizontalAngle)
353  {
354  this->maxHorizontalAngle = _maxHorizontalAngle;
355  }
356 
358  template <class T>
360  {
361  return this->maxHorizontalAngle;
362  }
363 
365  template <class T>
367  unsigned int _horizontalRayCount)
368  {
369  if (_horizontalRayCount == 0)
370  {
371  ignwarn << "Cannot have zero horizontal rays. Setting value to 1."
372  << std::endl;
373  this->horizontalCount = 1u;
374  }
375  else
376  {
377  this->horizontalCount = _horizontalRayCount;
378  }
379  }
380 
382  template <class T>
384  {
385  return this->horizontalCount;
386  }
387 
389  template <class T>
390  void BaseLidarVisual<T>::SetMinRange(double _minRange)
391  {
392  this->minRange = _minRange;
393  }
394 
396  template <class T>
398  {
399  return this->minRange;
400  }
401 
403  template <class T>
404  void BaseLidarVisual<T>::SetMaxRange(double _maxRange)
405  {
406  this->maxRange = _maxRange;
407  }
408 
410  template <class T>
412  {
413  return this->maxRange;
414  }
415 
417  template <class T>
419  {
420  this->offset = _offset;
421  }
422 
424  template <class T>
426  {
427  return this->offset;
428  }
429 
431  template <class T>
433  {
434  this->lidarVisualType = _type;
435  }
436 
438  template <class T>
440  {
441  return this->lidarVisualType;
442  }
443 
445  template <class T>
446  void BaseLidarVisual<T>::SetSize(double _size)
447  {
448  this->size = _size;
449  }
450 
452  template <class T>
454  {
455  return this->size;
456  }
457 
459  template <class T>
461  {
462  this->displayNonHitting = _display;
463  }
464 
466  template <class T>
468  {
469  return this->displayNonHitting;
470  }
471 
473  template <class T>
475  {
476  MaterialPtr mtl;
477 
478  if (!this->Scene()->MaterialRegistered("Lidar/BlueStrips"))
479  {
480  mtl = this->Scene()->CreateMaterial("Lidar/BlueStrips");
481  mtl->SetAmbient(0.0, 0.0, 1.0);
482  mtl->SetDiffuse(0.0, 0.0, 1.0);
483  mtl->SetEmissive(0.0, 0.0, 1.0);
484  mtl->SetTransparency(0.4);
485  mtl->SetCastShadows(false);
486  mtl->SetReceiveShadows(false);
487  mtl->SetLightingEnabled(false);
488  mtl->SetMetalness(0.0f);
489  mtl->SetReflectivity(0.0);
490  }
491 
492  if (!this->Scene()->MaterialRegistered("Lidar/LightBlueStrips"))
493  {
494  mtl = this->Scene()->CreateMaterial("Lidar/LightBlueStrips");
495  mtl->SetAmbient(0.0, 0.0, 1.0);
496  mtl->SetDiffuse(0.0, 0.0, 1.0);
497  mtl->SetEmissive(0.0, 0.0, 1.0);
498  mtl->SetTransparency(0.8);
499  mtl->SetCastShadows(false);
500  mtl->SetReceiveShadows(false);
501  mtl->SetLightingEnabled(false);
502  mtl->SetMetalness(0.0f);
503  mtl->SetReflectivity(0.0);
504  }
505 
506  if (!this->Scene()->MaterialRegistered("Lidar/TransBlack"))
507  {
508  mtl = this->Scene()->CreateMaterial("Lidar/TransBlack");
509  mtl->SetAmbient(0.0, 0.0, 0.0);
510  mtl->SetDiffuse(0.0, 0.0, 0.0);
511  mtl->SetEmissive(0.0, 0.0, 0.0);
512  mtl->SetTransparency(0.4);
513  mtl->SetCastShadows(false);
514  mtl->SetReceiveShadows(false);
515  mtl->SetLightingEnabled(false);
516  mtl->SetMetalness(0.5f);
517  mtl->SetReflectivity(0.2);
518  }
519 
520  if (!this->Scene()->MaterialRegistered("Lidar/BlueRay"))
521  {
522  mtl = this->Scene()->CreateMaterial("Lidar/BlueRay");
523  mtl->SetAmbient(0.0, 0.0, 1.0);
524  mtl->SetDiffuse(0.0, 0.0, 1.0);
525  mtl->SetEmissive(0.0, 0.0, 1.0);
526  mtl->SetSpecular(0.0, 0.0, 1.0);
527  mtl->SetTransparency(0.0);
528  mtl->SetCastShadows(false);
529  mtl->SetReceiveShadows(false);
530  mtl->SetLightingEnabled(false);
531  mtl->SetMetalness(0.1f);
532  mtl->SetReflectivity(0.2);
533  }
534  return;
535  }
536  }
537  }
538 }
539 #endif
virtual MaterialPtr CreateMaterial(const std::string &_name="")=0
Create new material with the given name. Created material will have default properties.
virtual double Size() const override
Get size of the lidar visualization.
Definition: gz/rendering/base/BaseLidarVisual.hh:453
virtual unsigned int VerticalRayCount() const override
Get number of vertical rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:329
A LidarVisual geometry class. The visual appearance is based on the type specified.
Definition: gz/rendering/LidarVisual.hh:55
STL class.
@ LVT_TRIANGLE_STRIPS
Triangle strips visual.
Definition: gz/rendering/LidarVisual.hh:49
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: gz/rendering/base/BaseLidarVisual.hh:216
BaseLidarVisual()
Definition: gz/rendering/base/BaseLidarVisual.hh:204
virtual double MinVerticalAngle() const override
Get minimum vertical angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:290
virtual unsigned int PointCount() const override
Get number of points in laser data.
Definition: gz/rendering/base/BaseLidarVisual.hh:237
virtual ignition::math::Pose3d Offset() const override
Get offset of visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:425
virtual void SetOffset(const ignition::math::Pose3d _offset) override
Set offset of visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:418
virtual unsigned int HorizontalRayCount() const override
Get number of horizontal rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:383
virtual double MinRange() const override
Get minimum range of lidar rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:397
virtual void SetHorizontalRayCount(unsigned int _horizontalRayCount) override
Set number of horizontal rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:366
double verticalAngleStep
Angle between two vertical rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:166
virtual void SetSize(double _size) override
Set size of the lidar visualization, e.g. size of rasterized lidar points in pixels.
Definition: gz/rendering/base/BaseLidarVisual.hh:446
virtual double MaxVerticalAngle() const override
Get minimum vertical angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:305
Base implementation of a Lidar Visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:34
virtual void CreateMaterials()
Create predefined materials for lidar visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:474
Manages a single scene-graph. This class updates scene-wide properties and holds the root scene node....
Definition: gz/rendering/Scene.hh:49
virtual LidarVisualType Type() const override
Get the type for lidar visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:439
virtual void Update() override
Update the Visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:252
virtual void Destroy() override
Destroy any resources associated with this object. Invoking any other functions after destroying an o...
Definition: gz/rendering/base/BaseLidarVisual.hh:223
double size
Size of lidar visualisation.
Definition: gz/rendering/base/BaseLidarVisual.hh:197
virtual double MinHorizontalAngle() const override
Get minimum horizontal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:344
LidarVisualType
Enum for LidarVisual types.
Definition: gz/rendering/LidarVisual.hh:37
virtual void ClearPoints() override
Clear the points of the lidar visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:230
virtual void SetPoints(const std::vector< double > &_points) override
Set lidar points to be visualised.
Definition: gz/rendering/base/BaseLidarVisual.hh:259
LidarVisualType lidarVisualType
Type of lidar visualisation.
Definition: gz/rendering/base/BaseLidarVisual.hh:193
virtual std::vector< double > Points() const override
Get the points in laser data.
Definition: gz/rendering/base/BaseLidarVisual.hh:244
#define ignwarn
unsigned int horizontalCount
Horizontal laser count.
Definition: gz/rendering/base/BaseLidarVisual.hh:175
virtual void SetMinHorizontalAngle(double _minHorizontalAngle) override
Set minimum horizontal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:336
virtual void SetMaxRange(double _maxRange) override
Set maximum range of lidar rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:404
virtual ~BaseLidarVisual()
Definition: gz/rendering/base/BaseLidarVisual.hh:210
virtual void Init() override
Definition: gz/rendering/base/BaseLidarVisual.hh:274
unsigned int verticalCount
Vertical laser count.
Definition: gz/rendering/base/BaseLidarVisual.hh:163
T endl(T... args)
virtual void SetMaxHorizontalAngle(double _maxHorizontalAngle) override
Set maximum horizontal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:351
double minVerticalAngle
Vertical minimal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:157
double maxVerticalAngle
Vertical maximum angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:160
virtual void SetMinRange(double _minRange) override
Set minimum range of lidar rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:390
virtual void SetMinVerticalAngle(double _minVerticalAngle) override
Set minimum vertical angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:282
virtual void SetDisplayNonHitting(bool _display) override
Set if non-hitting rays will be displayed (this does not work for TRIANGLE_STRIPS visual)
Definition: gz/rendering/base/BaseLidarVisual.hh:460
virtual double MaxHorizontalAngle() const override
Get maximum horizontal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:359
double maxRange
Maximum Range.
Definition: gz/rendering/base/BaseLidarVisual.hh:184
virtual void SetMaxVerticalAngle(double _maxVerticalAngle) override
Set maximum vertical angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:297
double horizontalAngleStep
Angle between two horizontal rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:178
virtual double MaxRange() const override
Get maximum range of lidar rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:411
double maxHorizontalAngle
Horizontal maximum angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:172
double minRange
Minimum Range.
Definition: gz/rendering/base/BaseLidarVisual.hh:181
virtual void SetVerticalRayCount(unsigned int _verticalRayCount) override
Set number of vertical rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:312
bool displayNonHitting
Option to display non-hitting rays.
Definition: gz/rendering/base/BaseLidarVisual.hh:187
static const Pose3< T > Zero
ignition::math::Pose3d offset
Offset of visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:190
virtual bool DisplayNonHitting() const override
Get if non-hitting rays will be displayed.
Definition: gz/rendering/base/BaseLidarVisual.hh:467
double minHorizontalAngle
Horizontal minimal angle.
Definition: gz/rendering/base/BaseLidarVisual.hh:169
virtual void SetType(const LidarVisualType _type) override
Set type for lidar visual.
Definition: gz/rendering/base/BaseLidarVisual.hh:432