My Project
DataGrid.h
1 #pragma once
2 
3 #include "ShapeAABB.h"
4 #include "AssetEntity.h"
5 
6 namespace ParaEngine
7 {
8  class MetaWorldFragment;
9 
14  struct DataGrid : public AssetEntity
15  {
16  public:
17  virtual AssetType GetType(){return datagrid;};
18 
20  enum GridFlags
21  {
23  HAS_GRADIENT = 0x01,
25  HAS_COLOURS = 0x02,
28  };
29 
31  DataGrid();
33  virtual ~DataGrid();
34 
43  void initialize(int numCellsX, int numCellsY, int numCellsZ, float gridScale, int flags);
45  int getNumCellsX() const {return mNumCellsX; }
47  int getNumCellsY() const {return mNumCellsY; }
49  int getNumCellsZ() const {return mNumCellsZ; }
51  float getGridScale() const {return mGridScale; }
53  Vector3 getPosition() {return mPosition;} const
55  inline void setPosition(const Vector3 &pos)
56  {
57  mPosition = pos;
58  float minX, minY, minZ, maxX, maxY, maxZ;
59  minX = pos.x - mNumCellsX * mGridScale * 0.5f;
60  minY = pos.y - mNumCellsY * mGridScale * 0.5f;
61  minZ = pos.z - mNumCellsZ * mGridScale * 0.5f;
62  maxX = pos.x + mNumCellsX * mGridScale * 0.5f;
63  maxY = pos.y + mNumCellsY * mGridScale * 0.5f;
64  maxZ = pos.z + mNumCellsZ * mGridScale * 0.5f;
65 
66  mBoundingBox.SetMinMax(Vector3(minX, minY, minZ), Vector3(maxX, maxY, maxZ));
67  }
68 
70  bool hasGradient() const {return (mGridFlags & HAS_GRADIENT) != 0; }
72  bool hasColours() const {return (mGridFlags & HAS_COLOURS) != 0; }
74  bool hasMetaWorldFragments() const {return (mGridFlags & HAS_WORLD_FRAGMENTS) != 0; }
75 
77  float* getValues() {return mValues; }
79  const Vector3* getVertices() const {return mVertices; }
87  Color* getColours() {return mColours; }
91  std::pair<float, MetaWorldFragment*>* getMetaWorldFragments() {return mMetaWorldFragments; }
92 
94  const CShapeAABB& getBoundingBox() const {return mBoundingBox; }
95  const CShapeAABB& getBoxSize() const {return mBoxSize;}
97  int getGridIndex(int x, int y, int z) const {return z*(mNumCellsX + 1)*(mNumCellsY + 1) + y*(mNumCellsX + 1) + x; }
110  bool mapAABB(const CShapeAABB& aabb, int &x0, int &y0, int &z0, int &x1, int &y1, int &z1) const;
112  void clear();
113 
114  protected:
124  float mGridScale;
130  float* mValues;
144  std::pair<float, MetaWorldFragment*>* mMetaWorldFragments;
145 
148 
155  virtual void initializeVertices();
156 
157  void * lastHostObject;
158  };
159 
161  typedef asset_ptr<DataGrid> DataGridPtr;
162 }
Color * getColours()
Returns a pointer to the array of colour values.
Definition: DataGrid.h:87
int getNumCellsZ() const
Returns the number of grid cells along the z axis.
Definition: DataGrid.h:49
int mNumCellsY
The number of grid cells along the y axis of the grid.
Definition: DataGrid.h:118
int mGridFlags
Flags describing what data is stored in the data grid (see DataGrid::GridFlags).
Definition: DataGrid.h:128
DataGrid()
Constructor.
Definition: DataGrid.cpp:14
The data grid stores gradient vectors.
Definition: DataGrid.h:23
The data grid stores colour values.
Definition: DataGrid.h:25
void clear()
Clears the data grid.
Definition: DataGrid.cpp:158
bool hasMetaWorldFragments() const
Returns true if the grid stores closest world fragment.
Definition: DataGrid.h:74
Vector3 * getGradient()
Returns a pointer to the array of gradient vectors.
Definition: DataGrid.h:83
bool mapAABB(const CShapeAABB &aabb, int &x0, int &y0, int &z0, int &x1, int &y1, int &z1) const
Maps an axis aligned box to the grid points inside it.
Definition: DataGrid.cpp:99
AssetType
each asset type has a unique asset type number
Definition: AssetEntity.h:82
virtual ~DataGrid()
Virtual destructor.
Definition: DataGrid.cpp:20
int getNumCellsY() const
Returns the number of grid cells along the y axis.
Definition: DataGrid.h:47
different physics engine has different winding order.
Definition: EventBinding.h:32
void initialize(int numCellsX, int numCellsY, int numCellsZ, float gridScale, int flags)
Initializes the data grid.
Definition: DataGrid.cpp:29
Class providing a 3d grid of data values and methods for accessing and modifying it.
Definition: DataGrid.h:14
void SetMinMax(const Vector3 &min, const Vector3 &max)
Setups an AABB from min & max vectors.
Definition: ShapeAABB.h:26
int mNumGridPoints
Total number of grid points.
Definition: DataGrid.h:122
GridFlags
Flags describing what data is stored in the data grid.
Definition: DataGrid.h:20
Standard 3-dimensional vector.
Definition: ParaVector3.h:16
int mNumCellsX
The number of grid cells along the x axis of the grid.
Definition: DataGrid.h:116
Vector3 getPosition()
Returns the grids position in space.
Definition: DataGrid.h:53
int getGridIndex(int x, int y, int z) const
Returns the index of the specified grid point.
Definition: DataGrid.h:97
float * getValues()
Returns a pointer to the array of grid values.
Definition: DataGrid.h:77
AABB-related code.
Definition: ShapeAABB.h:11
float getGridScale() const
Returns the grid scale (i.e. the distance along the axes between grid points).
Definition: DataGrid.h:51
bool hasGradient() const
Returns true if the grid stores gradient vectors.
Definition: DataGrid.h:70
The data grid stores closest world fragment.
Definition: DataGrid.h:27
std::pair< float, MetaWorldFragment * > * mMetaWorldFragments
Closest World Fragments of the grid.
Definition: DataGrid.h:144
bool hasColours() const
Returns true if the grid stores colour values.
Definition: DataGrid.h:72
virtual void initializeVertices()
Initializes the position of grid points and the bounding box.
Definition: DataGrid.cpp:67
Vector3 * mGradient
Gradient vectors of the grid.
Definition: DataGrid.h:136
std::pair< float, MetaWorldFragment * > * getMetaWorldFragments()
Returns a pointer to the array of closest world fragments.
Definition: DataGrid.h:91
asset_ptr< DataGrid > DataGridPtr
Reference-counted shared pointer to a DataGrid.
Definition: DataGrid.h:161
const CShapeAABB & getBoundingBox() const
Returns the bounding box of the grid.
Definition: DataGrid.h:94
Vector3 mPosition
Position of this Grid.
Definition: DataGrid.h:126
const Vector3 * getVertices() const
Returns a pointer to the (const) array of grid vertices.
Definition: DataGrid.h:79
CShapeAABB mBoundingBox
Bounding box of the grid.
Definition: DataGrid.h:147
const void setPosition(const Vector3 &pos)
Sets the grids position in space.
Definition: DataGrid.h:55
Color * mColours
Colour values of the grid.
Definition: DataGrid.h:140
Vector3 * mVertices
Vertex positions of the grid points.
Definition: DataGrid.h:132
Definition: ParaColor.h:275
float * mValues
Data grid values.
Definition: DataGrid.h:130
float mGridScale
The scale of grid cells; this influences the position of grid vertices.
Definition: DataGrid.h:124
int getNumCellsX() const
Returns the number of grid cells along the x axis.
Definition: DataGrid.h:45
Base class for managed asset entity in ParaEngine.
Definition: AssetEntity.h:25
int mNumCellsZ
The number of grid cells along the z axis of the grid.
Definition: DataGrid.h:120