Gazebo Rendering

API Reference

7.4.2
gz/rendering/base/BaseLightVisual.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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_BASE_BASELIGHTVISUAL_HH_
18 #define GZ_RENDERING_BASE_BASELIGHTVISUAL_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 {
32  //
34  template <class T>
36  public virtual LightVisual,
37  public virtual T
38  {
40  protected: BaseLightVisual();
41 
43  public: virtual ~BaseLightVisual();
44 
45  // Documentation inherited.
46  protected: virtual void Init() override;
47 
48  // Documentation inherited.
49  protected: virtual void PreRender() override;
50 
51  // Documentation inherited
52  public: virtual void SetType(LightVisualType _type) override;
53 
54  // Documentation inherited
55  public: virtual void SetInnerAngle(double _innerAngle) override;
56 
57  // Documentation inherited
58  public: virtual double InnerAngle() override;
59 
60  // Documentation inherited
61  public: virtual void SetOuterAngle(double _innerAngle) override;
62 
63  // Documentation inherited
64  public: virtual double OuterAngle() override;
65 
67  public: std::vector<gz::math::Vector3d> CreateVisualLines();
68 
69  // Documentation inherited
70  public: virtual LightVisualType Type() override;
71 
74 
76  protected: double innerAngle = 0;
77 
79  protected: double outerAngle = 0;
80 
82  protected: bool dirtyLightVisual = false;
83  };
84 
86  template <class T>
88  {
89  }
90 
92  template <class T>
94  {
95  }
96 
98  template <class T>
100  {
101  T::PreRender();
102  }
103 
105  template <class T>
107  {
108  T::Init();
109  }
110 
112  template <class T>
114  {
115  this->type = _type;
116  this->dirtyLightVisual = true;
117  }
118 
120  template <class T>
122  {
123  return this->type;
124  }
125 
127  template <class T>
128  void BaseLightVisual<T>::SetInnerAngle(double _innerAngle)
129  {
130  this->innerAngle = _innerAngle;
131  this->dirtyLightVisual = true;
132  }
133 
135  template <class T>
137  {
138  return this->innerAngle;
139  }
140 
142  template <class T>
143  void BaseLightVisual<T>::SetOuterAngle(double _outerAngle)
144  {
145  this->outerAngle = _outerAngle;
146  this->dirtyLightVisual = true;
147  }
148 
150  template <class T>
152  {
153  return this->outerAngle;
154  }
155 
156  template <class T>
159  {
161 
162  if (this->type == LightVisualType::LVT_DIRECTIONAL)
163  {
164  float s = 0.5;
165  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
166  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
167 
168  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
169  positions.emplace_back(gz::math::Vector3d(s, s, 0));
170 
171  positions.emplace_back(gz::math::Vector3d(s, s, 0));
172  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
173 
174  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
175  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
176 
177  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
178  positions.emplace_back(gz::math::Vector3d(0, 0, -s));
179  }
180  else if (this->type == LightVisualType::LVT_POINT)
181  {
182  float s = 0.1f;
183  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
184  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
185 
186  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
187  positions.emplace_back(gz::math::Vector3d(s, s, 0));
188 
189  positions.emplace_back(gz::math::Vector3d(s, s, 0));
190  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
191 
192  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
193  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
194 
195  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
196  positions.emplace_back(gz::math::Vector3d(0, 0, s));
197 
198  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
199  positions.emplace_back(gz::math::Vector3d(0, 0, s));
200 
201  positions.emplace_back(gz::math::Vector3d(s, s, 0));
202  positions.emplace_back(gz::math::Vector3d(0, 0, s));
203 
204  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
205  positions.emplace_back(gz::math::Vector3d(0, 0, s));
206 
207  positions.emplace_back(gz::math::Vector3d(-s, -s, 0));
208  positions.emplace_back(gz::math::Vector3d(0, 0, -s));
209 
210  positions.emplace_back(gz::math::Vector3d(-s, s, 0));
211  positions.emplace_back(gz::math::Vector3d(0, 0, -s));
212 
213  positions.emplace_back(gz::math::Vector3d(s, s, 0));
214  positions.emplace_back(gz::math::Vector3d(0, 0, -s));
215 
216  positions.emplace_back(gz::math::Vector3d(s, -s, 0));
217  positions.emplace_back(gz::math::Vector3d(0, 0, -s));
218  }
219  else if (this->type == LightVisualType::LVT_SPOT)
220  {
221  double angles[2];
222  double range = 0.2;
223  angles[0] = range * tan(outerAngle / 2.0);
224  angles[1] = range * tan(innerAngle / 2.0);
225 
226  unsigned int i = 0;
227  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
228  positions.emplace_back(
229  gz::math::Vector3d(angles[i], angles[i], -range));
230 
231  for (i = 0; i < 2; i++)
232  {
233  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
235  angles[i], angles[i], -range));
236 
237  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
239  -angles[i], -angles[i], -range));
240 
241  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
243  angles[i], -angles[i], -range));
244 
245  positions.emplace_back(gz::math::Vector3d(0, 0, 0));
247  -angles[i], angles[i], -range));
248 
250  angles[i], angles[i], -range));
252  -angles[i], angles[i], -range));
253 
255  -angles[i], angles[i], -range));
257  -angles[i], -angles[i], -range));
258 
260  -angles[i], -angles[i], -range));
262  angles[i], -angles[i], -range));
263 
265  angles[i], -angles[i], -range));
267  angles[i], angles[i], -range));
268  }
269  }
270  return positions;
271  }
272  }
273  }
274 }
275 #endif