VolumeGridEmitter2.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_GRID_EMITTER2_HPP
12 #define CUBBYFLOW_VOLUME_GRID_EMITTER2_HPP
13 
16 #include <Core/Grid/ScalarGrid.hpp>
17 #include <Core/Grid/VectorGrid.hpp>
18 #include <Core/Matrix/Matrix.hpp>
19 
20 #include <memory>
21 
22 namespace CubbyFlow
23 {
27 class VolumeGridEmitter2 final : public GridEmitter2
28 {
29  public:
30  class Builder;
31 
33  using ScalarMapper = std::function<double(double, const Vector2D&, double)>;
34 
36  using VectorMapper =
37  std::function<Vector2D(double, const Vector2D&, const Vector2D&)>;
38 
46  explicit VolumeGridEmitter2(ImplicitSurface2Ptr sourceRegion,
47  bool isOneShot = true);
48 
50  VolumeGridEmitter2(const VolumeGridEmitter2&) = default;
51 
53  VolumeGridEmitter2(VolumeGridEmitter2&&) noexcept = default;
54 
56  ~VolumeGridEmitter2() override = default;
57 
59  VolumeGridEmitter2& operator=(const VolumeGridEmitter2&) = default;
60 
62  VolumeGridEmitter2& operator=(VolumeGridEmitter2&&) noexcept = default;
63 
65  void AddSignedDistanceTarget(const ScalarGrid2Ptr& scalarGridTarget);
66 
74  void AddStepFunctionTarget(const ScalarGrid2Ptr& scalarGridTarget,
75  double minValue, double maxValue);
76 
91  void AddTarget(const ScalarGrid2Ptr& scalarGridTarget,
92  const ScalarMapper& customMapper);
93 
108  void AddTarget(const VectorGrid2Ptr& vectorGridTarget,
109  const VectorMapper& customMapper);
110 
112  [[nodiscard]] const ImplicitSurface2Ptr& GetSourceRegion() const;
113 
115  [[nodiscard]] bool GetIsOneShot() const;
116 
118  [[nodiscard]] static Builder GetBuilder();
119 
120  private:
121  using ScalarTarget = std::tuple<ScalarGrid2Ptr, ScalarMapper>;
122  using VectorTarget = std::tuple<VectorGrid2Ptr, VectorMapper>;
123 
124  void OnUpdate(double currentTimeInSeconds,
125  double timeIntervalInSeconds) override;
126 
127  void Emit();
128 
129  ImplicitSurface2Ptr m_sourceRegion;
130  std::vector<ScalarTarget> m_customScalarTargets;
131  std::vector<VectorTarget> m_customVectorTargets;
132  bool m_isOneShot = true;
133  bool m_hasEmitted = false;
134 };
135 
137 using VolumeGridEmitter2Ptr = std::shared_ptr<VolumeGridEmitter2>;
138 
142 class VolumeGridEmitter2::Builder final
143 {
144  public:
146  [[nodiscard]] Builder& WithSourceRegion(const Surface2Ptr& sourceRegion);
147 
149  [[nodiscard]] Builder& WithIsOneShot(bool isOneShot);
150 
152  [[nodiscard]] VolumeGridEmitter2 Build() const;
153 
155  [[nodiscard]] VolumeGridEmitter2Ptr MakeShared() const;
156 
157  private:
158  ImplicitSurface2Ptr m_sourceRegion;
159  bool m_isOneShot = true;
160 };
161 } // namespace CubbyFlow
162 
163 #endif
bool GetIsOneShot() const
Returns true if this emits only once.
2-D grid-based volumetric emitter.
Definition: VolumeGridEmitter2.hpp:27
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.hpp:22
Front-end to create VolumeGridEmitter2 objects step by step.
Definition: VolumeGridEmitter2.hpp:142
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.hpp:33
void AddTarget(const ScalarGrid2Ptr &scalarGridTarget, const ScalarMapper &customMapper)
Adds a scalar grid target.
Definition: pybind11Utils.hpp:20
std::shared_ptr< VectorGrid2 > VectorGrid2Ptr
Shared pointer for the VectorGrid2 type.
Definition: VectorGrid.hpp:110
std::shared_ptr< ScalarGrid2 > ScalarGrid2Ptr
Shared pointer for the ScalarGrid2 type.
Definition: ScalarGrid.hpp:266
std::shared_ptr< VolumeGridEmitter2 > VolumeGridEmitter2Ptr
Shared pointer type for the VolumeGridEmitter2.
Definition: VolumeGridEmitter2.hpp:137
std::function< Vector2D(double, const Vector2D &, const Vector2D &)> VectorMapper
Maps to a vector value for given signed-dist, location, and old value.
Definition: VolumeGridEmitter2.hpp:37
std::shared_ptr< ImplicitSurface2 > ImplicitSurface2Ptr
Shared pointer type for the ImplicitSurface2.
Definition: ImplicitSurface.hpp:67
VolumeGridEmitter2(ImplicitSurface2Ptr sourceRegion, bool isOneShot=true)
Constructs an emitter with a source and is-one-shot flag.
const ImplicitSurface2Ptr & GetSourceRegion() const
Returns implicit surface which defines the source region.
static Builder GetBuilder()
Returns builder fox VolumeGridEmitter2.
std::shared_ptr< Surface2 > Surface2Ptr
Shared pointer for the Surface2 type.
Definition: Surface.hpp:144