VolumeGridEmitter3.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VolumeGridEmitter3.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: 3-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_EMITTER3_H
10 #define CUBBYFLOW_VOLUME_GRID_EMITTER3_H
11 
13 #include <Core/Grid/ScalarGrid3.h>
14 #include <Core/Grid/VectorGrid3.h>
16 #include <Core/Vector/Vector3.h>
17 
18 #include <memory>
19 
20 namespace CubbyFlow
21 {
25  class VolumeGridEmitter3 final : public GridEmitter3
26  {
27  public:
28  class Builder;
29 
31  using ScalarMapper = std::function<double(double, const Vector3D&, double)>;
32 
34  using VectorMapper = std::function<Vector3D(double, const Vector3D&, const Vector3D&)>;
35 
37  explicit VolumeGridEmitter3(const ImplicitSurface3Ptr& sourceRegion, bool isOneShot = true);
38 
40  virtual ~VolumeGridEmitter3();
41 
43  void AddSignedDistanceTarget(const ScalarGrid3Ptr& scalarGridTarget);
44 
52  void AddStepFunctionTarget(const ScalarGrid3Ptr& scalarGridTarget, double minValue, double maxValue);
53 
68  void AddTarget(const ScalarGrid3Ptr& scalarGridTarget, const ScalarMapper& customMapper);
69 
84  void AddTarget(const VectorGrid3Ptr& vectorGridTarget, const VectorMapper& customMapper);
85 
87  const ImplicitSurface3Ptr& GetSourceRegion() const;
88 
90  bool GetIsOneShot() const;
91 
93  static Builder GetBuilder();
94 
95  private:
96  using ScalarTarget = std::tuple<ScalarGrid3Ptr, ScalarMapper>;
97  using VectorTarget = std::tuple<VectorGrid3Ptr, VectorMapper>;
98 
99  ImplicitSurface3Ptr 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 VolumeGridEmitter3Ptr = std::shared_ptr<VolumeGridEmitter3>;
112 
117  {
118  public:
120  Builder& WithSourceRegion(const Surface3Ptr& sourceRegion);
121 
123  Builder& WithIsOneShot(bool isOneShot);
124 
126  VolumeGridEmitter3 Build() const;
127 
130 
131  private:
132  ImplicitSurface3Ptr m_sourceRegion;
133  bool m_isOneShot = true;
134  };
135 }
136 
137 #endif
bool GetIsOneShot() const
Returns true if this emits only once.
VolumeGridEmitter3 Build() const
Builds VolumeGridEmitter3.
VolumeGridEmitter3(const ImplicitSurface3Ptr &sourceRegion, bool isOneShot=true)
Constructs an emitter with a source and is-one-shot flag.
Front-end to create VolumeGridEmitter3 objects step by step.
Definition: VolumeGridEmitter3.h:116
std::shared_ptr< ImplicitSurface3 > ImplicitSurface3Ptr
Shared pointer type for the ImplicitSurface3.
Definition: ImplicitSurface3.h:43
std::shared_ptr< ScalarGrid3 > ScalarGrid3Ptr
Shared pointer for the ScalarGrid3 type.
Definition: ScalarGrid3.h:179
virtual ~VolumeGridEmitter3()
Destructor.
static Builder GetBuilder()
Returns builder fox VolumeGridEmitter3.
std::function< Vector3D(double, const Vector3D &, const Vector3D &)> VectorMapper
Maps to a vector value for given signed-dist, location, and old value.
Definition: VolumeGridEmitter3.h:34
Definition: pybind11Utils.h:24
VolumeGridEmitter3Ptr MakeShared() const
Builds shared pointer of VolumeGridEmitter3 instance.
Builder & WithIsOneShot(bool isOneShot)
Returns builder with one-shot flag.
std::shared_ptr< Surface3 > Surface3Ptr
Shared pointer for the Surface3 type.
Definition: Surface3.h:100
std::function< double(double, const Vector3D &, double)> ScalarMapper
Maps to a scalar value for given signed-dist, location, and old value.
Definition: VolumeGridEmitter3.h:31
void AddStepFunctionTarget(const ScalarGrid3Ptr &scalarGridTarget, double minValue, double maxValue)
Adds step function target to the scalar grid.
const ImplicitSurface3Ptr & GetSourceRegion() const
Returns implicit surface which defines the source region.
3-D grid-based volumetric emitter.
Definition: VolumeGridEmitter3.h:25
Builder & WithSourceRegion(const Surface3Ptr &sourceRegion)
Returns builder with surface defining source region.
std::shared_ptr< VectorGrid3 > VectorGrid3Ptr
Shared pointer for the VectorGrid3 type.
Definition: VectorGrid3.h:90
Abstract base class for 3-D grid-based emitters.
Definition: GridEmitter3.h:20
void AddSignedDistanceTarget(const ScalarGrid3Ptr &scalarGridTarget)
Adds signed-distance target to the scalar grid.
void AddTarget(const ScalarGrid3Ptr &scalarGridTarget, const ScalarMapper &customMapper)
Adds a scalar grid target.
std::shared_ptr< VolumeGridEmitter3 > VolumeGridEmitter3Ptr
Shared pointer type for the VolumeGridEmitter3.
Definition: VolumeGridEmitter3.h:111