Jet  v1.3.3
grid3.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_GRID3_H_
8 #define INCLUDE_JET_GRID3_H_
9 
10 #include <jet/bounding_box3.h>
11 #include <jet/serialization.h>
12 #include <jet/size3.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 Grid3 : public Serializable {
31  public:
33  typedef std::function<Vector3D(size_t, size_t, size_t)> DataPositionFunc;
34 
36  Grid3();
37 
39  virtual ~Grid3();
40 
42  virtual std::string typeName() const = 0;
43 
45  const Size3& resolution() const;
46 
48  const Vector3D& origin() const;
49 
51  const Vector3D& gridSpacing() const;
52 
54  const BoundingBox3D& boundingBox() const;
55 
58 
67  const std::function<void(size_t, size_t, size_t)>& func) const;
68 
78  const std::function<void(size_t, size_t, size_t)>& func) const;
79 
81  virtual void serialize(std::vector<uint8_t>* buffer) const = 0;
82 
84  virtual void deserialize(const std::vector<uint8_t>& buffer) = 0;
85 
87  bool hasSameShape(const Grid3& other) const;
88 
90  virtual void swap(Grid3* other) = 0;
91 
92  protected:
96  const Vector3D& origin);
97 
99  void swapGrid(Grid3* other);
100 
102  void setGrid(const Grid3& other);
103 
105  virtual void getData(std::vector<double>* data) const = 0;
106 
108  virtual void setData(const std::vector<double>& data) = 0;
109 
110  private:
111  Size3 _resolution;
112  Vector3D _gridSpacing = Vector3D(1, 1, 1);
113  Vector3D _origin;
114  BoundingBox3D _boundingBox = BoundingBox3D(Vector3D(), Vector3D());
115 };
116 
117 typedef std::shared_ptr<Grid3> Grid3Ptr;
118 
119 #define JET_GRID3_TYPE_NAME(DerivedClassName) \
120  std::string typeName() const override { return #DerivedClassName; }
121 
122 } // namespace jet
123 
124 #endif // INCLUDE_JET_GRID3_H_
jet::Grid3::deserialize
virtual void deserialize(const std::vector< uint8_t > &buffer)=0
Deserializes the input buffer to the grid instance.
jet::Grid3::cellCenterPosition
DataPositionFunc cellCenterPosition() const
Returns the function that maps grid index to the cell-center position.
jet::Grid3::boundingBox
const BoundingBox3D & boundingBox() const
Returns the bounding box of the grid.
jet::Grid3::~Grid3
virtual ~Grid3()
Default destructor.
size3.h
jet::Grid3::swapGrid
void swapGrid(Grid3 *other)
Swaps the size parameters with given grid other.
jet::Grid3
Abstract base class for 3-D cartesian grid structure.
Definition: grid3.h:30
jet::Grid3::parallelForEachCellIndex
void parallelForEachCellIndex(const std::function< void(size_t, size_t, size_t)> &func) const
Invokes the given function func for each grid cell parallelly.
jet::BoundingBox< T, 3 >
3-D axis-aligned bounding box class.
Definition: bounding_box3.h:41
jet::Grid3::Grid3
Grid3()
Constructs an empty grid.
jet::Grid3::hasSameShape
bool hasSameShape(const Grid3 &other) const
Returns true if resolution, grid-spacing and origin are same.
jet
Definition: advection_solver2.h:18
jet::BoundingBox3D
BoundingBox3< double > BoundingBox3D
Double-type 3-D BoundingBox.
Definition: bounding_box3.h:127
jet::Grid3::swap
virtual void swap(Grid3 *other)=0
Swaps the data with other grid.
jet::Grid3::setData
virtual void setData(const std::vector< double > &data)=0
Sets the data from a continuous linear array.
jet::Grid3::origin
const Vector3D & origin() const
Returns the grid origin.
jet::Grid3::setGrid
void setGrid(const Grid3 &other)
Sets the size parameters with given grid other.
jet::Grid3::resolution
const Size3 & resolution() const
Returns the grid resolution.
jet::Grid3::serialize
virtual void serialize(std::vector< uint8_t > *buffer) const =0
Serializes the grid instance to the output buffer.
jet::Grid3::gridSpacing
const Vector3D & gridSpacing() const
Returns the grid spacing.
jet::Size3
3-D size class.
Definition: size3.h:19
jet::Grid3::typeName
virtual std::string typeName() const =0
Returns the type name of derived grid.
jet::Serializable
Abstract base class for any serializable class.
Definition: serialization.h:17
jet::Grid3::DataPositionFunc
std::function< Vector3D(size_t, size_t, size_t)> DataPositionFunc
Function type for mapping data index to actual position.
Definition: grid3.h:33
jet::Grid3::forEachCellIndex
void forEachCellIndex(const std::function< void(size_t, size_t, size_t)> &func) const
Invokes the given function func for each grid cell.
jet::Grid3::setSizeParameters
void setSizeParameters(const Size3 &resolution, const Vector3D &gridSpacing, const Vector3D &origin)
jet::Vector3D
Vector3< double > Vector3D
Double-type 3D vector.
Definition: vector3.h:349
jet::Vector< T, 3 >
3-D vector class.
Definition: vector3.h:25
serialization.h
bounding_box3.h
jet::Grid3Ptr
std::shared_ptr< Grid3 > Grid3Ptr
Definition: grid3.h:117
jet::Grid3::getData
virtual void getData(std::vector< double > *data) const =0
Fetches the data into a continuous linear array.