Ignition Rendering

API Reference

5.1.0
BaseParticleEmitter.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 
18 #ifndef IGNITION_RENDERING_BASE_BASEPARTICLEEMITTER_HH_
19 #define IGNITION_RENDERING_BASE_BASEPARTICLEEMITTER_HH_
20 
21 #include <string>
25 
26 namespace ignition
27 {
28  namespace rendering
29  {
30  inline namespace IGNITION_RENDERING_VERSION_NAMESPACE {
31  //
32  /* \class BaseParticleEmitter BaseParticleEmitter.hh \
33  * ignition/rendering/base/BaseParticleEmitter.hh
34  */
36  template <class T>
38  public virtual ParticleEmitter,
39  public virtual T
40  {
42  protected: BaseParticleEmitter();
43 
45  public: virtual ~BaseParticleEmitter();
46 
47  // Documentation inherited
48  public: virtual void Init() override;
49 
50  // Documentation inherited
51  public: virtual void PreRender() override;
52 
54  public: virtual void Reset();
55 
56  // Documentation inherited.
57  public: virtual EmitterType Type() const override;
58 
59  // Documentation inherited.
60  public: virtual void SetType(const EmitterType _type) override;
61 
62  // Documentation inherited.
63  public: virtual ignition::math::Vector3d EmitterSize() const override;
64 
65  // Documentation inherited.
66  public: virtual void SetEmitterSize(
67  const ignition::math::Vector3d &_size) override;
68 
69  // Documentation inherited.
70  public: virtual double Rate() const override;
71 
72  // Documentation inherited.
73  public: virtual void SetRate(double _rate) override;
74 
75  // Documentation inherited.
76  public: virtual double Duration() const override;
77 
78  // Documentation inherited.
79  public: virtual void SetDuration(double _duration) override;
80 
81  // Documentation inherited.
82  public: virtual bool Emitting() const override;
83 
84  // Documentation inherited.
85  public: virtual void SetEmitting(bool _enable) override;
86 
87  // Documentation inherited.
88  public: virtual ignition::math::Vector3d ParticleSize() const override;
89 
90  // Documentation inherited.
91  public: virtual void SetParticleSize(
92  const ignition::math::Vector3d &_size) override;
93 
94  // Documentation inherited.
95  public: virtual double Lifetime() const override;
96 
97  // Documentation inherited.
98  public: virtual void SetLifetime(double _lifetime) override;
99 
100  // Documentation inherited.
101  public: virtual MaterialPtr Material() const override;
102 
103  // Documentation inherited.
104  public: virtual void SetMaterial(const MaterialPtr &_material) override;
105 
106  // Documentation inherited.
107  public: virtual double MinVelocity() const override;
108 
109  // Documentation inherited.
110  public: virtual double MaxVelocity() const override;
111 
112  // Documentation inherited.
113  public: virtual void SetVelocityRange(double _minVelocity,
114  double _maxVelocity) override;
115 
116  // Documentation inherited.
117  public: virtual ignition::math::Color ColorStart() const override;
118 
119  // Documentation inherited.
120  public: virtual ignition::math::Color ColorEnd() const override;
121 
122  // Documentation inherited.
123  public: virtual void SetColorRange(
124  const ignition::math::Color &_colorStart,
125  const ignition::math::Color &_colorEnd) override;
126 
127  // Documentation inherited.
128  public: virtual double ScaleRate() const override;
129 
130  // Documentation inherited.
131  public: virtual void SetScaleRate(double _scaleRate) override;
132 
133  // Documentation inherited.
134  public: virtual std::string ColorRangeImage() const override;
135 
136  // Documentation inherited.
137  public: virtual void SetColorRangeImage(
138  const std::string &_image) override;
139 
140  // Documentation inherited.
141  public: virtual float ParticleScatterRatio() const override;
142 
143  // Documentation inherited.
144  public: virtual void SetParticleScatterRatio(float _ratio) override;
145 
147  protected: EmitterType type = EM_POINT;
148 
150  protected: ignition::math::Vector3d emitterSize =
152 
154  protected: double rate = 10;
155 
157  protected: double duration = 0;
158 
160  protected: bool emitting = false;
161 
163  protected: ignition::math::Vector3d particleSize = {1, 1, 1};
164 
166  protected: double lifetime = 5;
167 
169  protected: MaterialPtr material = nullptr;
170 
172  protected: double minVelocity = 1;
173 
175  protected: double maxVelocity = 1;
176 
178  protected: ignition::math::Color colorStart =
180 
182  protected: ignition::math::Color colorEnd =
184 
186  protected: double scaleRate = 1;
187 
189  protected: std::string colorRangeImage = "";
190 
198  protected: float particleScatterRatio = 0.65f;
199 
201  private: friend class BaseScene;
202  };
203 
205  template <class T>
207  {
208  }
209 
211  template <class T>
213  {
214  }
215 
217  template <class T>
219  {
220  T::Init();
221  }
222 
224  template <class T>
226  {
227  }
228 
230  template <class T>
232  {
233  }
234 
236  template <class T>
238  {
239  return this->type;
240  }
241 
243  template <class T>
245  {
246  this->type = _type;
247  }
248 
250  template <class T>
252  {
253  return this->emitterSize;
254  }
255 
257  template <class T>
259  const ignition::math::Vector3d &_size)
260  {
261  this->emitterSize = _size;
262  }
263 
265  template <class T>
267  {
268  return this->rate;
269  }
270 
272  template <class T>
274  {
275  this->rate = _rate;
276  }
277 
279  template <class T>
281  {
282  return this->duration;
283  }
284 
286  template <class T>
287  void BaseParticleEmitter<T>::SetDuration(double _duration)
288  {
289  this->duration = _duration;
290  }
291 
293  template <class T>
295  {
296  return this->emitting;
297  }
298 
300  template <class T>
302  {
303  this->emitting = _enable;
304  }
305 
307  template <class T>
309  {
310  return this->particleSize;
311  }
312 
314  template <class T>
316  const ignition::math::Vector3d &_size)
317  {
318  this->particleSize = _size;
319  }
320 
322  template <class T>
324  {
325  return this->lifetime;
326  }
327 
329  template <class T>
330  void BaseParticleEmitter<T>::SetLifetime(double _lifetime)
331  {
332  this->lifetime = _lifetime;
333  }
334 
336  template <class T>
338  {
339  return this->material;
340  }
341 
343  template <class T>
345  {
346  this->material = _material;
347  }
348 
350  template <class T>
352  {
353  return this->minVelocity;
354  }
355 
357  template <class T>
359  {
360  return this->maxVelocity;
361  }
362 
364  template <class T>
366  double _maxVelocity)
367  {
368  this->minVelocity = _minVelocity;
369  this->maxVelocity = _maxVelocity;
370  }
371 
373  template <class T>
375  {
376  return this->colorStart;
377  }
378 
380  template <class T>
382  {
383  return this->colorEnd;
384  }
385 
387  template <class T>
389  const ignition::math::Color &_colorStart,
390  const ignition::math::Color &_colorEnd)
391  {
392  this->colorStart = _colorStart;
393  this->colorEnd = _colorEnd;
394  }
395 
397  template <class T>
399  {
400  return this->scaleRate;
401  }
402 
404  template <class T>
405  void BaseParticleEmitter<T>::SetScaleRate(double _scaleRate)
406  {
407  this->scaleRate = _scaleRate;
408  }
409 
411  template <class T>
413  {
414  return this->colorRangeImage;
415  }
416 
418  template <class T>
420  {
421  this->colorRangeImage = _image;
422  }
423 
425  template <class T>
427  {
428  return this->particleScatterRatio;
429  }
430 
432  template <class T>
434  {
435  if (_ratio > 0.0f)
436  this->particleScatterRatio = _ratio;
437  }
438  }
439  }
440 }
441 #endif
virtual double Rate() const override
Get how many particles per second should be emitted.
Definition: BaseParticleEmitter.hh:266
virtual ignition::math::Vector3d ParticleSize() const override
Get the particle dimensions (width, height, depth).
Definition: BaseParticleEmitter.hh:308
virtual void Reset()
Reset the particle emitter visual state.
Definition: BaseParticleEmitter.hh:225
EmitterType
Enum for emitter types.
Definition: ParticleEmitter.hh:36
virtual MaterialPtr Material() const override
Get the material which all particles in the emitter will use.
Definition: BaseParticleEmitter.hh:337
virtual float ParticleScatterRatio() const override
Get the particle scatter ratio.
Definition: BaseParticleEmitter.hh:426
virtual double MaxVelocity() const override
Get the maximum velocity each particle is emitted (m/s).
Definition: BaseParticleEmitter.hh:358
virtual void SetEmitting(bool _enable) override
This is used to turn on or off particle emission. Default value is false.
Definition: BaseParticleEmitter.hh:301
virtual void SetParticleScatterRatio(float _ratio) override
Set the particle scatter ratio.
Definition: BaseParticleEmitter.hh:433
virtual void SetDuration(double _duration) override
Set the number of seconds the emitter is active. A value of 0 means infinite duration. Default value is 0.
Definition: BaseParticleEmitter.hh:287
virtual void SetType(const EmitterType _type) override
Set the emitter type. Default value is EM_POINT.
Definition: BaseParticleEmitter.hh:244
virtual void SetEmitterSize(const ignition::math::Vector3d &_size) override
Set the size of the emitter where the particles are sampled. Default value is (1, 1...
Definition: BaseParticleEmitter.hh:258
virtual void SetColorRange(const ignition::math::Color &_colorStart, const ignition::math::Color &_colorEnd) override
Sets a color for all particle emitted. The actual color will be interpolated between these two colors...
Definition: BaseParticleEmitter.hh:388
STL class.
virtual double MinVelocity() const override
Get the minimum velocity each particle is emitted (m/s).
Definition: BaseParticleEmitter.hh:351
virtual ignition::math::Color ColorEnd() const override
Get the end color of the particles.
Definition: BaseParticleEmitter.hh:381
virtual void SetScaleRate(double _scaleRate) override
Set the amount by which to scale the particles in both x and y direction per second.
Definition: BaseParticleEmitter.hh:405
virtual std::string ColorRangeImage() const override
Get the path to the color image used as an affector.
Definition: BaseParticleEmitter.hh:412
virtual void SetRate(double _rate) override
Set how many particles per second should be emitted. Default value is 10.
Definition: BaseParticleEmitter.hh:273
virtual bool Emitting() const override
Is the particle emitter enabled?
Definition: BaseParticleEmitter.hh:294
virtual ignition::math::Vector3d EmitterSize() const override
Get the size of the emitter where the particles are sampled.
Definition: BaseParticleEmitter.hh:251
virtual void SetMaterial(const MaterialPtr &_material) override
Sets the material which all particles in the emitter will use.
Definition: BaseParticleEmitter.hh:344
virtual ~BaseParticleEmitter()
Destructor.
Definition: BaseParticleEmitter.hh:212
virtual ignition::math::Color ColorStart() const override
Get the starting color of the particles.
Definition: BaseParticleEmitter.hh:374
virtual void Init() override
Definition: BaseParticleEmitter.hh:218
BaseParticleEmitter()
Constructor.
Definition: BaseParticleEmitter.hh:206
Class to manage a particle emitter.
Definition: ParticleEmitter.hh:58
virtual void SetParticleSize(const ignition::math::Vector3d &_size) override
Set the particle dimensions (width, height, depth). Default value is {1, 1, 1}.
Definition: BaseParticleEmitter.hh:315
Definition: BaseScene.hh:37
static const Color White
virtual void SetLifetime(double _lifetime) override
Set the number of seconds each particle will ’live’ for before being destroyed. Default value is 5...
Definition: BaseParticleEmitter.hh:330
static const Vector3 One
virtual void SetColorRangeImage(const std::string &_image) override
Set the path to the color image used as an affector. This affector modifies the color of particles in...
Definition: BaseParticleEmitter.hh:419
virtual double Duration() const override
Get the number of seconds the emitter is active. A value of 0 means infinite duration.
Definition: BaseParticleEmitter.hh:280
virtual double ScaleRate() const override
Get the amount by which to scale the particles in both x and y direction per second. Default value is 1.
Definition: BaseParticleEmitter.hh:398
virtual void PreRender() override
Prepare this object and any of its children for rendering. This should be called for each object in a...
Definition: BaseParticleEmitter.hh:231
Represents a surface material of a Geometry.
Definition: Material.hh:47
virtual double Lifetime() const override
Get the number of seconds each particle will ’live’ for before being destroyed. ...
Definition: BaseParticleEmitter.hh:323
virtual void SetVelocityRange(double _minVelocity, double _maxVelocity) override
Set a velocity range and each particle is emitted with a random velocity within this range (m/s)...
Definition: BaseParticleEmitter.hh:365
virtual EmitterType Type() const override
Get the emitter type.
Definition: BaseParticleEmitter.hh:237
Point emitter.
Definition: ParticleEmitter.hh:39
A base implementation of the ParticleEmitter class.
Definition: BaseParticleEmitter.hh:37