Loading...
Searching...
No Matches
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
16#include <Core/Grid/Grid.hpp>
17
18namespace CubbyFlow
19{
21template <size_t N>
22class VectorGrid : public VectorField<N>, public Grid<N>
23{
24 public:
27
30
31 using Grid<N>::Resolution;
32 using Grid<N>::GridSpacing;
33 using Grid<N>::Origin;
34
36 VectorGrid() = default;
37
39 ~VectorGrid() override = default;
40
43
46
49
52
54 void Clear();
55
60 const Vector<double, N>& origin = Vector<double, N>{},
62
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
99 const Vector<double, N>& origin,
101};
102
105
108
110using VectorGrid2Ptr = std::shared_ptr<VectorGrid2>;
111
113using VectorGrid3Ptr = std::shared_ptr<VectorGrid3>;
114
116template <size_t N>
118{
119 public:
121 VectorGridBuilder() = default;
122
124 virtual ~VectorGridBuilder() = default;
125
128
131
134
137
139 [[nodiscard]] virtual std::shared_ptr<VectorGrid<N>> Build(
143 const Vector<double, N>& initialVal) const = 0;
144};
145
148
151
153using VectorGridBuilder2Ptr = std::shared_ptr<VectorGridBuilder2>;
154
156using VectorGridBuilder3Ptr = std::shared_ptr<VectorGridBuilder3>;
157} // namespace CubbyFlow
158
159#endif
Generic N-dimensional array class interface.
Definition ArrayView.hpp:26
Abstract base class for N-D cartesian grid structure.
Definition Grid.hpp:59
virtual void SetData(const ConstArrayView1< double > &data)=0
Sets the data from a continuous linear array.
const Vector< double, N > & Origin() const
Returns the grid origin.
void SetSizeParameters(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &origin)
const Vector< size_t, N > & Resolution() const
Returns the grid resolution.
const Vector< double, N > & GridSpacing() const
Returns the grid spacing.
virtual void GetData(Array1< double > &data) const =0
Fetches the data into a continuous linear array.
Definition Matrix.hpp:30
Abstract base class for N-D vector field.
Definition VectorField.hpp:43
Abstract base class for N-D vector grid builder.
Definition VectorGrid.hpp:118
virtual std::shared_ptr< VectorGrid< N > > Build(const Vector< size_t, N > &resolution, const Vector< double, N > &gridSpacing, const Vector< double, N > &gridOrigin, const Vector< double, N > &initialVal) const =0
Returns N-D vector grid with given parameters.
VectorGridBuilder & operator=(VectorGridBuilder &&other) noexcept=delete
Deleted move assignment operator.
VectorGridBuilder()=default
Creates a builder.
virtual ~VectorGridBuilder()=default
Default virtual destructor.
VectorGridBuilder(const VectorGridBuilder &other)=delete
Deleted copy constructor.
VectorGridBuilder & operator=(const VectorGridBuilder &other)=delete
Deleted copy assignment operator.
VectorGridBuilder(VectorGridBuilder &&other) noexcept=delete
Deleted move constructor.
Abstract base class for N-D vector grid structure.
Definition VectorGrid.hpp:23
VectorGrid()=default
Constructs an empty grid.
VectorGrid & operator=(const VectorGrid &other)
Copy assignment operator.
virtual std::shared_ptr< VectorGrid< N > > Clone() const =0
Returns the copy of the grid instance.
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< double, N > &gridSpacing, const Vector< double, N > &origin)
Resizes the grid using given parameters.
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.
VectorGrid(const VectorGrid &other)
Copy constructor.
VectorGrid(VectorGrid &&other) noexcept
Move constructor.
void Clear()
Clears the contents of the grid.
virtual void Fill(const std::function< Vector< double, N >(const Vector< double, N > &)> &func, ExecutionPolicy policy=ExecutionPolicy::Parallel)=0
Fills the grid with given position-to-value mapping function.
~VectorGrid() override=default
Default virtual destructor.
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the input buffer to the grid instance.
VectorGrid & operator=(VectorGrid &&other) noexcept
Move assignment operator.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the grid instance to the output buffer.
Definition pybind11Utils.hpp:21
std::shared_ptr< VectorGrid3 > VectorGrid3Ptr
Shared pointer for the VectorGrid3 type.
Definition VectorGrid.hpp:113
std::shared_ptr< VectorGridBuilder2 > VectorGridBuilder2Ptr
Shared pointer for the VectorGridBuilder2 type.
Definition VectorGrid.hpp:153
std::shared_ptr< VectorGridBuilder3 > VectorGridBuilder3Ptr
Shared pointer for the VectorGridBuilder3 type.
Definition VectorGrid.hpp:156
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738
std::shared_ptr< VectorGrid2 > VectorGrid2Ptr
Shared pointer for the VectorGrid2 type.
Definition VectorGrid.hpp:110
ExecutionPolicy
Execution policy tag.
Definition Parallel.hpp:18