VolumeGridEmitter2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VolumeGridEmitter2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 2-D grid-based volumetric emitter.
6 > Created Time: 2017/08/06
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_VOLUME_GRID_EMITTER2_H
10 #define CUBBYFLOW_VOLUME_GRID_EMITTER2_H
11 
13 #include <Core/Grid/ScalarGrid2.h>
14 #include <Core/Grid/VectorGrid2.h>
16 #include <Core/Vector/Vector2.h>
17 
18 #include <memory>
19 
20 namespace CubbyFlow
21 {
25  class VolumeGridEmitter2 final : public GridEmitter2
26  {
27  public:
28  class Builder;
29 
31  using ScalarMapper = std::function<double(double, const Vector2D&, double)>;
32 
34  using VectorMapper = std::function<Vector2D(double, const Vector2D&, const Vector2D&)>;
35 
37  explicit VolumeGridEmitter2(const ImplicitSurface2Ptr& sourceRegion, bool isOneShot = true);
38 
40  virtual ~VolumeGridEmitter2();
41 
43  void AddSignedDistanceTarget(const ScalarGrid2Ptr& scalarGridTarget);
44 
52  void AddStepFunctionTarget(const ScalarGrid2Ptr& scalarGridTarget, double minValue, double maxValue);
53 
68  void AddTarget(const ScalarGrid2Ptr& scalarGridTarget, const ScalarMapper& customMapper);
69 
84  void AddTarget(const VectorGrid2Ptr& vectorGridTarget, const VectorMapper& customMapper);
85 
87  const ImplicitSurface2Ptr& GetSourceRegion() const;
88 
90  bool GetIsOneShot() const;
91 
93  static Builder GetBuilder();
94 
95  private:
96  using ScalarTarget = std::tuple<ScalarGrid2Ptr, ScalarMapper>;
97  using VectorTarget = std::tuple<VectorGrid2Ptr, VectorMapper>;
98 
99  ImplicitSurface2Ptr m_sourceRegion;
100  bool m_isOneShot = true;
101  bool m_hasEmitted = false;
102  std::vector<ScalarTarget> m_customScalarTargets;
103  std::vector<VectorTarget> m_customVectorTargets;
104 
105  void OnUpdate(double currentTimeInSeconds, double timeIntervalInSeconds) override;
106 
107  void Emit();
108  };
109 
111  using VolumeGridEmitter2Ptr = std::shared_ptr<VolumeGridEmitter2>;
112 
117  {
118  public:
120  Builder& WithSourceRegion(const Surface2Ptr& sourceRegion);
121 
123  Builder& WithIsOneShot(bool isOneShot);
124 
126  VolumeGridEmitter2 Build() const;
127 
130 
131  private:
132  ImplicitSurface2Ptr m_sourceRegion;
133  bool m_isOneShot = true;
134  };
135 }
136 
137 #endif
bool GetIsOneShot() const
Returns true if this emits only once.
Builder & WithSourceRegion(const Surface2Ptr &sourceRegion)
Returns builder with surface defining source region.
Builder & WithIsOneShot(bool isOneShot)
Returns builder with one-shot flag.
2-D grid-based volumetric emitter.
Definition: VolumeGridEmitter2.h:25
VolumeGridEmitter2 Build() const
Builds VolumeGridEmitter2.
void AddStepFunctionTarget(const ScalarGrid2Ptr &scalarGridTarget, double minValue, double maxValue)
Adds step function target to the scalar grid.
Abstract base class for 2-D grid-based emitters.
Definition: GridEmitter2.h:20
Front-end to create VolumeGridEmitter2 objects step by step.
Definition: VolumeGridEmitter2.h:116
void AddSignedDistanceTarget(const ScalarGrid2Ptr &scalarGridTarget)
Adds signed-distance target to the scalar grid.
std::function< double(double, const Vector2D &, double)> ScalarMapper
Maps to a scalar value for given signed-dist, location, and old value.
Definition: VolumeGridEmitter2.h:31
void AddTarget(const ScalarGrid2Ptr &scalarGridTarget, const ScalarMapper &customMapper)
Adds a scalar grid target.
virtual ~VolumeGridEmitter2()
Destructor.
Definition: pybind11Utils.h:24
std::shared_ptr< VectorGrid2 > VectorGrid2Ptr
Shared pointer for the VectorGrid2 type.
Definition: VectorGrid2.h:90
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid2.h:179
std::shared_ptr< VolumeGridEmitter2 > VolumeGridEmitter2Ptr
Shared pointer type for the VolumeGridEmitter2.
Definition: VolumeGridEmitter2.h:111
std::function< Vector2D(double, const Vector2D &, const Vector2D &)> VectorMapper
Maps to a vector value for given signed-dist, location, and old value.
Definition: VolumeGridEmitter2.h:34
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition: ImplicitSurface2.h:43
const ImplicitSurface2Ptr & GetSourceRegion() const
Returns implicit surface which defines the source region.
VolumeGridEmitter2Ptr MakeShared() const
Builds shared pointer of VolumeGridEmitter2 instance.
static Builder GetBuilder()
Returns builder fox VolumeGridEmitter2.
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface2.h:100
VolumeGridEmitter2(const ImplicitSurface2Ptr &sourceRegion, bool isOneShot=true)
Constructs an emitter with a source and is-one-shot flag.