VectorGrid.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_VECTOR_GRID_HPP
12 #define CUBBYFLOW_VECTOR_GRID_HPP
13 
14 #include <Core/Array/ArrayView.hpp>
16 #include <Core/Grid/Grid.hpp>
17 
18 namespace CubbyFlow
19 {
21 template <size_t N>
22 class VectorGrid : public VectorField<N>, public Grid<N>
23 {
24  public:
27 
30 
31  using Grid<N>::Resolution;
33  using Grid<N>::Origin;
34 
36  VectorGrid() = default;
37 
39  ~VectorGrid() override = default;
40 
42  VectorGrid(const VectorGrid& other);
43 
45  VectorGrid(VectorGrid&& other) noexcept;
46 
48  VectorGrid& operator=(const VectorGrid& other);
49 
51  VectorGrid& operator=(VectorGrid&& other) noexcept;
52 
54  void Clear();
55 
57  void Resize(const Vector<size_t, N>& resolution,
58  const Vector<double, N>& gridSpacing =
60  const Vector<double, N>& origin = Vector<double, N>{},
61  const Vector<double, N>& initialValue = Vector<double, N>{});
62 
64  void Resize(const Vector<double, N>& gridSpacing,
65  const Vector<double, N>& origin);
66 
68  virtual void Fill(const Vector<double, N>& value,
70 
72  virtual void Fill(
73  const std::function<Vector<double, N>(const Vector<double, N>&)>& func,
75 
77  [[nodiscard]] virtual std::shared_ptr<VectorGrid<N>> Clone() const = 0;
78 
80  void Serialize(std::vector<uint8_t>* buffer) const override;
81 
83  void Deserialize(const std::vector<uint8_t>& buffer) override;
84 
85  protected:
87  using Grid<N>::GetData;
88  using Grid<N>::SetData;
89 
97  virtual void OnResize(const Vector<size_t, N>& resolution,
98  const Vector<double, N>& gridSpacing,
99  const Vector<double, N>& origin,
100  const Vector<double, N>& initialValue) = 0;
101 };
102 
105 
108 
110 using VectorGrid2Ptr = std::shared_ptr<VectorGrid2>;
111 
113 using VectorGrid3Ptr = std::shared_ptr<VectorGrid3>;
114 
116 template <size_t N>
118 {
119  public:
121  VectorGridBuilder() = default;
122 
124  virtual ~VectorGridBuilder() = default;
125 
127  VectorGridBuilder(const VectorGridBuilder& other) = delete;
128 
130  VectorGridBuilder(VectorGridBuilder&& other) noexcept = delete;
131 
133  VectorGridBuilder& operator=(const VectorGridBuilder& other) = delete;
134 
136  VectorGridBuilder& operator=(VectorGridBuilder&& other) noexcept = delete;
137 
139  [[nodiscard]] virtual std::shared_ptr<VectorGrid<N>> Build(
140  const Vector<size_t, N>& resolution,
141  const Vector<double, N>& gridSpacing,
142  const Vector<double, N>& gridOrigin,
143  const Vector<double, N>& initialVal) const = 0;
144 };
145 
148 
151 
153 using VectorGridBuilder2Ptr = std::shared_ptr<VectorGridBuilder2>;
154 
156 using VectorGridBuilder3Ptr = std::shared_ptr<VectorGridBuilder3>;
157 } // namespace CubbyFlow
158 
159 #endif
virtual void OnResize(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &origin, const Vector< double, N > &initialValue)=0
Invoked when the resizing happens.
void Resize(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing=Vector< double, N >::MakeConstant(1.0), const Vector< double, N > &origin=Vector< double, N >{}, const Vector< double, N > &initialValue=Vector< double, N >{})
Resizes the grid using given parameters.
virtual void Fill(const Vector< double, N > &value, ExecutionPolicy policy=ExecutionPolicy::Parallel)=0
Fills the grid with given value.
Abstract base class for N-D cartesian grid structure.
Definition: Grid.hpp:58
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the grid instance to the output buffer.
Abstract base class for N-D vector grid builder.
Definition: VectorGrid.hpp:117
Definition: Matrix.hpp:27
Definition: pybind11Utils.hpp:20
std::shared_ptr< VectorGrid2 > VectorGrid2Ptr
Shared pointer for the VectorGrid2 type.
Definition: VectorGrid.hpp:110
Abstract base class for N-D vector grid structure.
Definition: VectorGrid.hpp:22
VectorGrid()=default
Constructs an empty grid.
Generic N-dimensional array class interface.
Definition: Array.hpp:32
~VectorGrid() override=default
Default virtual destructor.
std::shared_ptr< VectorGridBuilder2 > VectorGridBuilder2Ptr
Shared pointer for the VectorGridBuilder2 type.
Definition: VectorGrid.hpp:153
void Clear()
Clears the contents of the grid.
Abstract base class for N-D vector field.
Definition: VectorField.hpp:42
virtual std::shared_ptr< VectorGrid< N > > Clone() const =0
Returns the copy of the grid instance.
ExecutionPolicy
Execution policy tag.
Definition: Parallel.hpp:17
VectorGrid & operator=(const VectorGrid &other)
Copy assignment operator.
std::shared_ptr< VectorGrid3 > VectorGrid3Ptr
Shared pointer for the VectorGrid3 type.
Definition: VectorGrid.hpp:113
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the input buffer to the grid instance.
std::shared_ptr< VectorGridBuilder3 > VectorGridBuilder3Ptr
Shared pointer for the VectorGridBuilder3 type.
Definition: VectorGrid.hpp:156