VolumeParticleEmitter3.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_EMITTER3_HPP
12 #define CUBBYFLOW_VOLUME_PARTICLE_EMITTER3_HPP
13 
17 
18 #include <random>
19 
20 namespace CubbyFlow
21 {
28 {
29  public:
30  class Builder;
31 
52  ImplicitSurface3Ptr implicitSurface, BoundingBox3D maxRegion,
53  double spacing, const Vector3D& initialVel = Vector3D(),
54  const Vector3D& linearVel = Vector3D(),
55  const Vector3D& angularVel = Vector3D(),
56  size_t maxNumberOfParticles = std::numeric_limits<size_t>::max(),
57  double jitter = 0.0, bool isOneShot = true,
58  bool allowOverlapping = false, uint32_t seed = 0);
59 
68  void SetPointGenerator(const PointGenerator3Ptr& newPointsGen);
69 
71  [[nodiscard]] const ImplicitSurface3Ptr& GetSurface() const;
72 
74  void SetSurface(const ImplicitSurface3Ptr& newSurface);
75 
77  [[nodiscard]] const BoundingBox3D& GetMaxRegion() const;
78 
80  void SetMaxRegion(const BoundingBox3D& newMaxRegion);
81 
83  [[nodiscard]] double GetJitter() const;
84 
86  void SetJitter(double newJitter);
87 
89  [[nodiscard]] bool GetIsOneShot() const;
90 
100  void SetIsOneShot(bool newValue);
101 
103  [[nodiscard]] bool GetAllowOverlapping() const;
104 
114  void SetAllowOverlapping(bool newValue);
115 
117  [[nodiscard]] size_t GetMaxNumberOfParticles() const;
118 
120  void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles);
121 
123  [[nodiscard]] double GetSpacing() const;
124 
126  void SetSpacing(double newSpacing);
127 
129  [[nodiscard]] Vector3D GetInitialVelocity() const;
130 
132  void SetInitialVelocity(const Vector3D& newInitialVel);
133 
135  [[nodiscard]] Vector3D GetLinearVelocity() const;
136 
138  void SetLinearVelocity(const Vector3D& newLinearVel);
139 
141  [[nodiscard]] Vector3D GetAngularVelocity() const;
142 
144  void SetAngularVelocity(const Vector3D& newAngularVel);
145 
147  [[nodiscard]] static Builder GetBuilder();
148 
149  private:
156  void OnUpdate(double currentTimeInSeconds,
157  double timeIntervalInSeconds) override;
158 
159  void Emit(const ParticleSystemData3Ptr& particles,
160  Array1<Vector3D>* newPositions, Array1<Vector3D>* newVelocities);
161 
162  [[nodiscard]] double Random();
163 
164  [[nodiscard]] Vector3D VelocityAt(const Vector3D& point) const;
165 
166  std::mt19937 m_rng;
167 
168  ImplicitSurface3Ptr m_implicitSurface;
169  BoundingBox3D m_maxRegion;
170  double m_spacing;
171  Vector3D m_initialVel;
172  Vector3D m_linearVel;
173  Vector3D m_angularVel;
174  PointGenerator3Ptr m_pointsGen;
175 
176  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
177  size_t m_numberOfEmittedParticles = 0;
178 
179  double m_jitter = 0.0;
180  bool m_isOneShot = true;
181  bool m_allowOverlapping = false;
182 };
183 
185 using VolumeParticleEmitter3Ptr = std::shared_ptr<VolumeParticleEmitter3>;
186 
191 {
192  public:
194  [[nodiscard]] Builder& WithImplicitSurface(
195  const ImplicitSurface3Ptr& implicitSurface);
196 
198  [[nodiscard]] Builder& WithSurface(const Surface3Ptr& surface);
199 
201  [[nodiscard]] Builder& WithMaxRegion(const BoundingBox3D& maxRegion);
202 
204  [[nodiscard]] Builder& WithSpacing(double spacing);
205 
207  [[nodiscard]] Builder& WithInitialVelocity(const Vector3D& initialVel);
208 
210  [[nodiscard]] Builder& WithLinearVelocity(const Vector3D& linearVel);
211 
213  [[nodiscard]] Builder& WithAngularVelocity(const Vector3D& angularVel);
214 
216  [[nodiscard]] Builder& WithMaxNumberOfParticles(
217  size_t maxNumberOfParticles);
218 
220  [[nodiscard]] Builder& WithJitter(double jitter);
221 
223  [[nodiscard]] Builder& WithIsOneShot(bool isOneShot);
224 
226  [[nodiscard]] Builder& WithAllowOverlapping(bool allowOverlapping);
227 
229  [[nodiscard]] Builder& WithRandomSeed(uint32_t seed);
230 
232  [[nodiscard]] VolumeParticleEmitter3 Build() const;
233 
235  [[nodiscard]] VolumeParticleEmitter3Ptr MakeShared() const;
236 
237  private:
238  ImplicitSurface3Ptr m_implicitSurface;
239  BoundingBox3D m_maxRegion;
240  double m_spacing = 0.1;
241  Vector3D m_initialVel;
242  Vector3D m_linearVel;
243  Vector3D m_angularVel;
244  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
245  double m_jitter = 0.0;
246  uint32_t m_seed = 0;
247  bool m_isBoundSet = false;
248  bool m_isOneShot = true;
249  bool m_allowOverlapping = false;
250 };
251 } // namespace CubbyFlow
252 
253 #endif
static Builder GetBuilder()
Returns builder fox VolumeParticleEmitter3.
std::shared_ptr< PointGenerator3 > PointGenerator3Ptr
Shared pointer for the PointGenerator3 type.
Definition: PointGenerator3.hpp:71
Abstract base class for 3-D particle emitter.
Definition: ParticleEmitter3.hpp:21
void SetAllowOverlapping(bool newValue)
Sets the flag to true if particles can overlap each other.
N-D axis-aligned bounding box class.
Definition: BoundingBox.hpp:46
std::shared_ptr< ImplicitSurface3 > ImplicitSurface3Ptr
Shared pointer type for the ImplicitSurface3.
Definition: ImplicitSurface.hpp:70
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition: ParticleSystemData.hpp:284
void SetInitialVelocity(const Vector3D &newInitialVel)
Returns the initial velocity of the particles.
void SetAngularVelocity(const Vector3D &newAngularVel)
Sets the linear velocity of the emitter.
const BoundingBox3D & GetMaxRegion() const
Returns max particle gen region.
const ImplicitSurface3Ptr & GetSurface() const
Returns source surface.
void SetJitter(double newJitter)
Sets jitter amount between 0 and 1.
void SetLinearVelocity(const Vector3D &newLinearVel)
Sets the linear velocity of the emitter.
void SetSurface(const ImplicitSurface3Ptr &newSurface)
Sets the source surface.
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
double GetJitter() const
Returns jitter amount.
VolumeParticleEmitter3(ImplicitSurface3Ptr implicitSurface, BoundingBox3D maxRegion, double spacing, const Vector3D &initialVel=Vector3D(), const Vector3D &linearVel=Vector3D(), const Vector3D &angularVel=Vector3D(), size_t maxNumberOfParticles=std::numeric_limits< size_t >::max(), double jitter=0.0, bool isOneShot=true, bool allowOverlapping=false, uint32_t seed=0)
Definition: Array-Impl.hpp:19
size_t GetMaxNumberOfParticles() const
Returns max number of particles to be emitted.
void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles)
Sets the max number of particles to be emitted.
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: Surface.hpp:147
void SetIsOneShot(bool newValue)
Sets the flag to true if particles are emitted just once.
bool GetAllowOverlapping() const
Returns true if particles can be overlapped.
Front-end to create VolumeParticleEmitter3 objects step by step.
Definition: VolumeParticleEmitter3.hpp:190
Vector3D GetInitialVelocity() const
Sets the initial velocity of the particles.
double GetSpacing() const
Returns the spacing between particles.
void SetPointGenerator(const PointGenerator3Ptr &newPointsGen)
Sets the point generator.
Vector3D GetLinearVelocity() const
Returns the linear velocity of the emitter.
std::shared_ptr< VolumeParticleEmitter3 > VolumeParticleEmitter3Ptr
Shared pointer for the VolumeParticleEmitter3 type.
Definition: VolumeParticleEmitter3.hpp:185
void SetMaxRegion(const BoundingBox3D &newMaxRegion)
Sets the max particle gen region.
3-D volumetric particle emitter.
Definition: VolumeParticleEmitter3.hpp:27
Vector3< double > Vector3D
Definition: Matrix.hpp:787
void SetSpacing(double newSpacing)
Sets the spacing between particles.
bool GetIsOneShot() const
Returns true if particles should be emitted just once.
Vector3D GetAngularVelocity() const
Returns the angular velocity of the emitter.