Gazebo Rendering

API Reference

8.2.1
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 
25 #include "gz/rendering/Scene.hh"
26 
27 namespace gz
28 {
29  namespace rendering
30  {
31  inline namespace GZ_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,
59  const std::vector<gz::math::Color> &_colors)
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 gz::math::Pose3d _offset) override;
125 
126  // Documentation inherited
127  public: virtual gz::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  gzwarn << "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  gzwarn << "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