Jet  v1.3.3
grid2.h
Go to the documentation of this file.
1 // Copyright (c) 2018 Doyub Kim
2 //
3 // I am making my contributions/submissions to this project solely in my
4 // personal capacity and am not conveying any rights to any intellectual
5 // property of any third parties.
6 
7 #ifndef INCLUDE_JET_GRID2_H_
8 #define INCLUDE_JET_GRID2_H_
9 
10 #include <jet/bounding_box2.h>
11 #include <jet/serialization.h>
12 #include <jet/size2.h>
13 
14 #include <functional>
15 #include <memory>
16 #include <string>
17 #include <utility> // just make cpplint happy..
18 #include <vector>
19 
20 namespace jet {
21 
30 class Grid2 : public Serializable {
31  public:
33  typedef std::function<Vector2D(size_t, size_t)> DataPositionFunc;
34 
36  Grid2();
37 
39  virtual ~Grid2();
40 
42  virtual std::string typeName() const = 0;
43 
45  const Size2& resolution() const;
46 
48  const Vector2D& origin() const;
49 
51  const Vector2D& gridSpacing() const;
52 
54  const BoundingBox2D& boundingBox() const;
55 
58 
67  const std::function<void(size_t, size_t)>& func) const;
68 
78  const std::function<void(size_t, size_t)>& func) const;
79 
81  bool hasSameShape(const Grid2& other) const;
82 
84  virtual void swap(Grid2* other) = 0;
85 
86  protected:
90  const Vector2D& origin);
91 
93  void swapGrid(Grid2* other);
94 
96  void setGrid(const Grid2& other);
97 
99  virtual void getData(std::vector<double>* data) const = 0;
100 
102  virtual void setData(const std::vector<double>& data) = 0;
103 
104  private:
105  Size2 _resolution;
106  Vector2D _gridSpacing = Vector2D(1, 1);
107  Vector2D _origin;
108  BoundingBox2D _boundingBox = BoundingBox2D(Vector2D(), Vector2D());
109 };
110 
111 typedef std::shared_ptr<Grid2> Grid2Ptr;
112 
113 #define JET_GRID2_TYPE_NAME(DerivedClassName) \
114  std::string typeName() const override { return #DerivedClassName; }
115 
116 } // namespace jet
117 
118 #endif // INCLUDE_JET_GRID2_H_
jet::Grid2::swapGrid
void swapGrid(Grid2 *other)
Swaps the size parameters with given grid other.
jet::Grid2::typeName
virtual std::string typeName() const =0
Returns the type name of derived grid.
jet::Grid2::forEachCellIndex
void forEachCellIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each grid cell.
jet::Grid2::getData
virtual void getData(std::vector< double > *data) const =0
Fetches the data into a continuous linear array.
jet::Grid2::origin
const Vector2D & origin() const
Returns the grid origin.
jet::Grid2::setData
virtual void setData(const std::vector< double > &data)=0
Sets the data from a continuous linear array.
jet::Vector2D
Vector2< double > Vector2D
Double-type 2D vector.
Definition: vector2.h:340
jet::Grid2::setGrid
void setGrid(const Grid2 &other)
Sets the size parameters with given grid other.
jet::Grid2::Grid2
Grid2()
Constructs an empty grid.
size2.h
jet::BoundingBox2D
BoundingBox2< double > BoundingBox2D
Double-type 2-D BoundingBox.
Definition: bounding_box2.h:124
jet::Grid2
Abstract base class for 2-D cartesian grid structure.
Definition: grid2.h:30
jet::Grid2::DataPositionFunc
std::function< Vector2D(size_t, size_t)> DataPositionFunc
Function type for mapping data index to actual position.
Definition: grid2.h:33
jet::Grid2::setSizeParameters
void setSizeParameters(const Size2 &resolution, const Vector2D &gridSpacing, const Vector2D &origin)
jet
Definition: advection_solver2.h:18
jet::Vector< T, 2 >
2-D vector class.
Definition: vector2.h:24
jet::Grid2::swap
virtual void swap(Grid2 *other)=0
Swaps the data with other grid.
jet::Grid2::~Grid2
virtual ~Grid2()
Default destructor.
bounding_box2.h
jet::Serializable
Abstract base class for any serializable class.
Definition: serialization.h:17
jet::BoundingBox< T, 2 >
2-D axis-aligned bounding box class.
Definition: bounding_box2.h:41
jet::Size2
2-D size class.
Definition: size2.h:19
jet::Grid2::hasSameShape
bool hasSameShape(const Grid2 &other) const
Returns true if resolution, grid-spacing and origin are same.
jet::Grid2::resolution
const Size2 & resolution() const
Returns the grid resolution.
serialization.h
jet::Grid2Ptr
std::shared_ptr< Grid2 > Grid2Ptr
Definition: grid2.h:111
jet::Grid2::gridSpacing
const Vector2D & gridSpacing() const
Returns the grid spacing.
jet::Grid2::parallelForEachCellIndex
void parallelForEachCellIndex(const std::function< void(size_t, size_t)> &func) const
Invokes the given function func for each grid cell parallelly.
jet::Grid2::boundingBox
const BoundingBox2D & boundingBox() const
Returns the bounding box of the grid.
jet::Grid2::cellCenterPosition
DataPositionFunc cellCenterPosition() const
Returns the function that maps grid index to the cell-center position.