VolumeParticleEmitter2.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_HPP
12 #define CUBBYFLOW_VOLUME_PARTICLE_EMITTER2_HPP
13 
17 
18 #include <random>
19 
20 namespace CubbyFlow
21 {
28 {
29  public:
30  class Builder;
31 
52  ImplicitSurface2Ptr implicitSurface, BoundingBox2D maxRegion,
53  double spacing, const Vector2D& initialVel = Vector2D(),
54  const Vector2D& linearVel = Vector2D(), double angularVel = 0.0,
55  size_t maxNumberOfParticles = std::numeric_limits<size_t>::max(),
56  double jitter = 0.0, bool isOneShot = true,
57  bool allowOverlapping = false, uint32_t seed = 0);
58 
67  void SetPointGenerator(const PointGenerator2Ptr& newPointsGen);
68 
70  [[nodiscard]] const ImplicitSurface2Ptr& GetSurface() const;
71 
73  void SetSurface(const ImplicitSurface2Ptr& newSurface);
74 
76  [[nodiscard]] const BoundingBox2D& GetMaxRegion() const;
77 
79  void SetMaxRegion(const BoundingBox2D& newMaxRegion);
80 
82  [[nodiscard]] double GetJitter() const;
83 
85  void SetJitter(double newJitter);
86 
88  [[nodiscard]] bool GetIsOneShot() const;
89 
99  void SetIsOneShot(bool newValue);
100 
102  [[nodiscard]] bool GetAllowOverlapping() const;
103 
113  void SetAllowOverlapping(bool newValue);
114 
116  [[nodiscard]] size_t GetMaxNumberOfParticles() const;
117 
119  void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles);
120 
122  [[nodiscard]] double GetSpacing() const;
123 
125  void SetSpacing(double newSpacing);
126 
128  [[nodiscard]] Vector2D GetInitialVelocity() const;
129 
131  void SetInitialVelocity(const Vector2D& newInitialVel);
132 
134  [[nodiscard]] Vector2D GetLinearVelocity() const;
135 
137  void SetLinearVelocity(const Vector2D& newLinearVel);
138 
140  [[nodiscard]] double GetAngularVelocity() const;
141 
143  void SetAngularVelocity(double newAngularVel);
144 
146  [[nodiscard]] static Builder GetBuilder();
147 
148  private:
155  void OnUpdate(double currentTimeInSeconds,
156  double timeIntervalInSeconds) override;
157 
158  void Emit(const ParticleSystemData2Ptr& particles,
159  Array1<Vector2D>* newPositions, Array1<Vector2D>* newVelocities);
160 
161  [[nodiscard]] double Random();
162 
163  [[nodiscard]] Vector2D VelocityAt(const Vector2D& point) const;
164 
165  std::mt19937 m_rng;
166 
167  ImplicitSurface2Ptr m_implicitSurface;
168  BoundingBox2D m_maxRegion;
169  double m_spacing;
170  Vector2D m_initialVel;
171  Vector2D m_linearVel;
172  double m_angularVel = 0.0;
173  PointGenerator2Ptr m_pointsGen;
174 
175  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
176  size_t m_numberOfEmittedParticles = 0;
177 
178  double m_jitter = 0.0;
179  bool m_isOneShot = true;
180  bool m_allowOverlapping = false;
181 };
182 
184 using VolumeParticleEmitter2Ptr = std::shared_ptr<VolumeParticleEmitter2>;
185 
190 {
191  public:
193  [[nodiscard]] Builder& WithImplicitSurface(
194  const ImplicitSurface2Ptr& implicitSurface);
195 
197  [[nodiscard]] Builder& WithSurface(const Surface2Ptr& surface);
198 
200  [[nodiscard]] Builder& WithMaxRegion(const BoundingBox2D& maxRegion);
201 
203  [[nodiscard]] Builder& WithSpacing(double spacing);
204 
206  [[nodiscard]] Builder& WithInitialVelocity(const Vector2D& initialVel);
207 
209  [[nodiscard]] Builder& WithLinearVelocity(const Vector2D& linearVel);
210 
212  [[nodiscard]] Builder& WithAngularVelocity(double angularVel);
213 
215  [[nodiscard]] Builder& WithMaxNumberOfParticles(
216  size_t maxNumberOfParticles);
217 
219  [[nodiscard]] Builder& WithJitter(double jitter);
220 
222  [[nodiscard]] Builder& WithIsOneShot(bool isOneShot);
223 
225  [[nodiscard]] Builder& WithAllowOverlapping(bool allowOverlapping);
226 
228  [[nodiscard]] Builder& WithRandomSeed(uint32_t seed);
229 
231  [[nodiscard]] VolumeParticleEmitter2 Build() const;
232 
234  [[nodiscard]] VolumeParticleEmitter2Ptr MakeShared() const;
235 
236  private:
237  ImplicitSurface2Ptr m_implicitSurface;
238  BoundingBox2D m_maxRegion;
239  double m_spacing = 0.1;
240  Vector2D m_initialVel;
241  Vector2D m_linearVel;
242  double m_angularVel = 0.0;
243  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
244  double m_jitter = 0.0;
245  uint32_t m_seed = 0;
246  bool m_isBoundSet = false;
247  bool m_isOneShot = true;
248  bool m_allowOverlapping = false;
249 };
250 } // namespace CubbyFlow
251 
252 #endif
N-D axis-aligned bounding box class.
Definition: BoundingBox.hpp:46
void SetInitialVelocity(const Vector2D &newInitialVel)
Returns the initial velocity of the particles.
void SetLinearVelocity(const Vector2D &newLinearVel)
Sets the linear velocity of the emitter.
Vector2D GetLinearVelocity() const
Returns the linear velocity of the emitter.
void SetMaxRegion(const BoundingBox2D &newMaxRegion)
Sets the max particle generator region.
std::shared_ptr< VolumeParticleEmitter2 > VolumeParticleEmitter2Ptr
Shared pointer for the VolumeParticleEmitter2 type.
Definition: VolumeParticleEmitter2.hpp:184
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
double GetJitter() const
Returns jitter amount.
void SetPointGenerator(const PointGenerator2Ptr &newPointsGen)
Sets the point generator.
std::shared_ptr< ParticleSystemData2 > ParticleSystemData2Ptr
Shared pointer type of ParticleSystemData2.
Definition: ParticleSystemData.hpp:281
Definition: Matrix.hpp:27
Vector2D GetInitialVelocity() const
Sets the initial velocity of the particles.
Definition: pybind11Utils.hpp:20
const BoundingBox2D & GetMaxRegion() const
Returns max particle generator region.
void SetSpacing(double newSpacing)
Sets the spacing between particles.
Definition: Array-Impl.hpp:19
Vector2< double > Vector2D
Definition: Matrix.hpp:774
VolumeParticleEmitter2(ImplicitSurface2Ptr implicitSurface, BoundingBox2D maxRegion, double spacing, const Vector2D &initialVel=Vector2D(), const Vector2D &linearVel=Vector2D(), double angularVel=0.0, size_t maxNumberOfParticles=std::numeric_limits< size_t >::max(), double jitter=0.0, bool isOneShot=true, bool allowOverlapping=false, uint32_t seed=0)
void SetJitter(double newJitter)
Sets jitter amount between 0 and 1.
Front-end to create VolumeParticleEmitter2 objects step by step.
Definition: VolumeParticleEmitter2.hpp:189
2-D volumetric particle emitter.
Definition: VolumeParticleEmitter2.hpp:27
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition: ImplicitSurface.hpp:67
const ImplicitSurface2Ptr & GetSurface() const
Returns source surface.
double GetSpacing() const
Returns the spacing between particles.
void SetIsOneShot(bool newValue)
Sets the flag to true if particles are emitted just once.
void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles)
Sets the max number of particles to be emitted.
double GetAngularVelocity() const
Returns the angular velocity of the emitter.
static Builder GetBuilder()
Returns builder fox VolumeParticleEmitter2.
bool GetIsOneShot() const
Returns true if particles should be emitted just once.
void SetSurface(const ImplicitSurface2Ptr &newSurface)
Sets the source surface.
std::shared_ptr< PointGenerator2 > PointGenerator2Ptr
Shared pointer for the PointGenerator2 type.
Definition: PointGenerator2.hpp:71
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface.hpp:144
Abstract base class for 2-D particle emitter.
Definition: ParticleEmitter2.hpp:21
void SetAllowOverlapping(bool newValue)
Sets the flag to true if particles can overlap each other.
bool GetAllowOverlapping() const
Returns true if particles can be overlapped.
void SetAngularVelocity(double newAngularVel)
Sets the linear velocity of the emitter.