VolumeParticleEmitter3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VolumeParticleEmitter3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-D volumetric particle emitter.
6 > Created Time: 2017/06/20
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_VOLUME_PARTICLE_EMITTER3_H
10 #define CUBBYFLOW_VOLUME_PARTICLE_EMITTER3_H
11 
15 
16 #include <random>
17 
18 namespace CubbyFlow
19 {
26  {
27  public:
28  class Builder;
29 
48  const ImplicitSurface3Ptr& implicitSurface,
49  const BoundingBox3D& bounds,
50  double spacing,
51  const Vector3D& initialVel = Vector3D(),
52  size_t maxNumberOfParticles = std::numeric_limits<size_t>::max(),
53  double jitter = 0.0,
54  bool isOneShot = true,
55  bool allowOverlapping = false,
56  uint32_t seed = 0);
57 
66  void SetPointGenerator(const PointGenerator3Ptr& newPointsGen);
67 
69  double GetJitter() const;
70 
72  void SetJitter(double newJitter);
73 
75  bool GetIsOneShot() const;
76 
86  void SetIsOneShot(bool newValue);
87 
89  bool GetAllowOverlapping() const;
90 
100  void SetAllowOverlapping(bool newValue);
101 
103  size_t GetMaxNumberOfParticles() const;
104 
106  void SetMaxNumberOfParticles(size_t newMaxNumberOfParticles);
107 
109  double GetSpacing() const;
110 
112  void SetSpacing(double newSpacing);
113 
116 
118  void SetInitialVelocity(const Vector3D& newInitialVel);
119 
121  static Builder GetBuilder();
122 
123  private:
124  std::mt19937 m_rng;
125 
126  ImplicitSurface3Ptr m_implicitSurface;
127  BoundingBox3D m_bounds;
128  double m_spacing;
129  Vector3D m_initialVel;
130  PointGenerator3Ptr m_pointsGen;
131 
132  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
133  size_t m_numberOfEmittedParticles = 0;
134 
135  double m_jitter = 0.0;
136  bool m_isOneShot = true;
137  bool m_allowOverlapping = false;
138 
145  void OnUpdate(double currentTimeInSeconds, double timeIntervalInSeconds) override;
146 
147  void Emit(const ParticleSystemData3Ptr& particles,
148  Array1<Vector3D>* newPositions, Array1<Vector3D>* newVelocities);
149 
150  double Random();
151  };
152 
154  using VolumeParticleEmitter3Ptr = std::shared_ptr<VolumeParticleEmitter3>;
155 
160  {
161  public:
163  Builder& WithImplicitSurface(const ImplicitSurface3Ptr& implicitSurface);
164 
166  Builder& WithSurface(const Surface3Ptr& surface);
167 
169  Builder& WithMaxRegion(const BoundingBox3D& bounds);
170 
172  Builder& WithSpacing(double spacing);
173 
175  Builder& WithInitialVelocity(const Vector3D& initialVel);
176 
178  Builder& WithMaxNumberOfParticles(size_t maxNumberOfParticles);
179 
181  Builder& WithJitter(double jitter);
182 
184  Builder& WithIsOneShot(bool isOneShot);
185 
187  Builder& WithAllowOverlapping(bool allowOverlapping);
188 
190  Builder& WithRandomSeed(uint32_t seed);
191 
194 
197 
198  private:
199  ImplicitSurface3Ptr m_implicitSurface;
200  bool m_isBoundSet = false;
201  BoundingBox3D m_bounds;
202  double m_spacing = 0.1;
203  Vector3D m_initialVel{ 0, 0, 0 };
204  size_t m_maxNumberOfParticles = std::numeric_limits<size_t>::max();
205  double m_jitter = 0.0;
206  bool m_isOneShot = true;
207  bool m_allowOverlapping = false;
208  uint32_t m_seed = 0;
209  };
210 }
211 
212 #endif
3-D vector class.
Definition: Vector3.h:26
VolumeParticleEmitter3Ptr MakeShared() const
Builds shared pointer of VolumeParticleEmitter3 instance.
static Builder GetBuilder()
Returns builder fox VolumeParticleEmitter3.
Builder & WithImplicitSurface(const ImplicitSurface3Ptr &implicitSurface)
Returns builder with implicit surface defining volume shape.
std::shared_ptr< PointGenerator3 > PointGenerator3Ptr
Shared pointer for the PointGenerator3 type.
Definition: PointGenerator3.h:53
Abstract base class for 3-D particle emitter.
Definition: ParticleEmitter3.h:19
Builder & WithSpacing(double spacing)
Returns builder with spacing.
void SetAllowOverlapping(bool newValue)
Sets the flag to true if particles can overlap each other.
Builder & WithSurface(const Surface3Ptr &surface)
Returns builder with surface defining volume shape.
std::shared_ptr< ImplicitSurface3 > ImplicitSurface3Ptr
Shared pointer type for the ImplicitSurface3.
Definition: ImplicitSurface3.h:43
std::shared_ptr< ParticleSystemData3 > ParticleSystemData3Ptr
Shared pointer type of ParticleSystemData3.
Definition: ParticleSystemData3.h:250
void SetInitialVelocity(const Vector3D &newInitialVel)
Returns the initial velocity of the particles.
Builder & WithMaxRegion(const BoundingBox3D &bounds)
Returns builder with max region.
Builder & WithMaxNumberOfParticles(size_t maxNumberOfParticles)
Returns builder with max number of particles.
Builder & WithJitter(double jitter)
Returns builder with jitter amount.
void SetJitter(double newJitter)
Sets jitter amount between 0 and 1.
1-D array class.
Definition: Array1.h:29
Definition: pybind11Utils.h:24
double GetJitter() const
Returns jitter amount.
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: Surface3.h:100
3-D axis-aligned bounding box class.
Definition: BoundingBox3.h:44
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.
VolumeParticleEmitter3 Build() const
Builds VolumeParticleEmitter3.
Builder & WithAllowOverlapping(bool allowOverlapping)
Returns builder with overlapping flag.
Front-end to create VolumeParticleEmitter3 objects step by step.
Definition: VolumeParticleEmitter3.h:159
Vector3D GetInitialVelocity() const
Sets the initial velocity of the particles.
double GetSpacing() const
Returns the spacing between particles.
Builder & WithInitialVelocity(const Vector3D &initialVel)
Returns builder with initial velocity.
Builder & WithIsOneShot(bool isOneShot)
Returns builder with one-shot flag.
void SetPointGenerator(const PointGenerator3Ptr &newPointsGen)
Sets the point generator.
std::shared_ptr< VolumeParticleEmitter3 > VolumeParticleEmitter3Ptr
Shared pointer for the VolumeParticleEmitter3 type.
Definition: VolumeParticleEmitter3.h:154
Builder & WithRandomSeed(uint32_t seed)
Returns builder with random seed.
3-D volumetric particle emitter.
Definition: VolumeParticleEmitter3.h:25
VolumeParticleEmitter3(const ImplicitSurface3Ptr &implicitSurface, const BoundingBox3D &bounds, double spacing, const Vector3D &initialVel=Vector3D(), size_t maxNumberOfParticles=std::numeric_limits< size_t >::max(), double jitter=0.0, bool isOneShot=true, bool allowOverlapping=false, uint32_t seed=0)
Vector3< double > Vector3D
Double-type 3D vector.
Definition: Vector3.h:353
void SetSpacing(double newSpacing)
Sets the spacing between particles.
bool GetIsOneShot() const
Returns true if particles should be emitted just once.