VectorGrid2.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: VectorGrid2.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for 2-D vector grid structure.
6 > Created Time: 2017/07/26
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_VECTOR_GRID2_H
10 #define CUBBYFLOW_VECTOR_GRID2_H
11 
14 #include <Core/Grid/Grid2.h>
15 
16 namespace CubbyFlow
17 {
19  class VectorGrid2 : public VectorField2, public Grid2
20  {
21  public:
24 
27 
29  VectorGrid2();
30 
32  virtual ~VectorGrid2();
33 
35  void Clear();
36 
38  void Resize(
39  size_t resolutionX, size_t resolutionY,
40  double gridSpacingX = 1.0, double gridSpacingY = 1.0,
41  double originX = 0.0, double originY = 0.0,
42  double initialValueX = 0.0, double initialValueY = 0.0);
43 
45  void Resize(
46  const Size2& resolution,
47  const Vector2D& gridSpacing = Vector2D(1, 1),
48  const Vector2D& origin = Vector2D(),
49  const Vector2D& initialValue = Vector2D());
50 
52  void Resize(
53  double gridSpacingX, double gridSpacingY,
54  double originX, double originY);
55 
57  void Resize(const Vector2D& gridSpacing, const Vector2D& origin);
58 
60  virtual void Fill(const Vector2D& value, ExecutionPolicy policy = ExecutionPolicy::Parallel) = 0;
61 
63  virtual void Fill(const std::function<Vector2D(const Vector2D&)>& func, ExecutionPolicy policy = ExecutionPolicy::Parallel) = 0;
64 
66  virtual std::shared_ptr<VectorGrid2> Clone() const = 0;
67 
69  void Serialize(std::vector<uint8_t>* buffer) const override;
70 
72  void Deserialize(const std::vector<uint8_t>& buffer) override;
73 
74  protected:
82  virtual void OnResize(
83  const Size2& resolution,
84  const Vector2D& gridSpacing,
85  const Vector2D& origin,
86  const Vector2D& initialValue) = 0;
87  };
88 
90  using VectorGrid2Ptr = std::shared_ptr<VectorGrid2>;
91 
94  {
95  public:
98 
100  virtual ~VectorGridBuilder2();
101 
103  virtual VectorGrid2Ptr Build(
104  const Size2& resolution,
105  const Vector2D& gridSpacing,
106  const Vector2D& gridOrigin,
107  const Vector2D& initialVal) const = 0;
108  };
109 
111  using VectorGridBuilder2Ptr = std::shared_ptr<VectorGridBuilder2>;
112 }
113 
114 #endif
2-D read-only array accessor class.
Definition: ArrayAccessor2.h:261
Abstract base class for 2-D vector grid builder.
Definition: VectorGrid2.h:93
Abstract base class for 2-D cartesian grid structure.
Definition: Grid2.h:30
Abstract base class for 2-D vector grid structure.
Definition: VectorGrid2.h:19
void Deserialize(const std::vector< uint8_t > &buffer) override
Deserializes the input buffer to the grid instance.
2-D point class.
Definition: Point2.h:25
virtual VectorGrid2Ptr Build(const Size2 &resolution, const Vector2D &gridSpacing, const Vector2D &gridOrigin, const Vector2D &initialVal) const =0
Returns 2-D vector grid with given parameters.
2-D array accessor class.
Definition: ArrayAccessor2.h:31
virtual ~VectorGrid2()
Default destructor.
VectorGrid2()
Constructs an empty grid.
virtual std::shared_ptr< VectorGrid2 > Clone() const =0
Returns the copy of the grid instance.
Definition: pybind11Utils.h:24
std::shared_ptr< VectorGrid2 > VectorGrid2Ptr
Shared pointer for the VectorGrid2 type.
Definition: VectorGrid2.h:90
void Resize(size_t resolutionX, size_t resolutionY, double gridSpacingX=1.0, double gridSpacingY=1.0, double originX=0.0, double originY=0.0, double initialValueX=0.0, double initialValueY=0.0)
Resizes the grid using given parameters.
Vector2< double > Vector2D
Double-type 2D vector.
Definition: Vector2.h:341
virtual void Fill(const Vector2D &value, ExecutionPolicy policy=ExecutionPolicy::Parallel)=0
Fills the grid with given value.
virtual void OnResize(const Size2 &resolution, const Vector2D &gridSpacing, const Vector2D &origin, const Vector2D &initialValue)=0
Invoked when the resizing happens.
VectorGridBuilder2()
Creates a builder.
void Serialize(std::vector< uint8_t > *buffer) const override
Serializes the grid instance to the output buffer.
2-D vector class.
Definition: Vector2.h:26
std::shared_ptr< VectorGridBuilder2 > VectorGridBuilder2Ptr
Shared pointer for the VectorGridBuilder2 type.
Definition: VectorGrid2.h:111
void Clear()
Clears the contents of the grid.
Abstract base class for 2-D vector field.
Definition: VectorField2.h:21
virtual ~VectorGridBuilder2()
Default destructor.
ExecutionPolicy
Execution policy tag.
Definition: Parallel.h:15