vrecko
virtual reality framework
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VoxelGrid_Object_Data.h
Go to the documentation of this file.
1 #ifndef VOXELGRID_OBJECT_DATA_H
2 #define VOXELGRID_OBJECT_DATA_H
3 
4 #include "GeometryLoaderBase.h"
5 #include <vrecko/Ability.h>
7 
8 #include <helpers/BufFile.h>
9 
10 #include <osg/BoundingBox>
11 
12 
13 namespace APSpacePartitioning {
14 
16 public:
19 
20  virtual void preInitialize();
21  virtual void postInitialize();
22  virtual void update();
23 
24  virtual bool loadXMLParameters(XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node);
25 
26  virtual bool isHierarchyCreated() { return bGridCreated && bGridFilled; }
27 
28  virtual bool createHierarchy(void);
29 
30  inline unsigned long getXDFDim() { return dFXDim; }
31  inline unsigned long getYDFDim() { return dFYDim; }
32  inline unsigned long getZDFDim() { return dFZDim; }
33 
34 
35  inline osg::BoundingBox& getBBoxDF() {return bboxDF;}
36  inline float getDistanceFieldValue(int x, int y, int z){
37  if (x >= dFXDim || y >= dFYDim || z >= dFZDim || x < 0 || y < 0 || z < 0) {
38  return 0;
39  }
40  return distanceField[ x * (dFYDim * dFZDim) + y * dFZDim + z];
41  }
42 
43  inline int getDistanceFieldValueEffect(unsigned long x, unsigned long y, unsigned long z, int level){
44  if (getDistanceFieldValue( x, y, z) > level){
45  return 0;
46  } else {
47  return 1;
48  }
49  }
50 
51  inline float getDistanceTempFieldValue(int x, int y, int z){
52  if (x >= dFXDim || y >= dFYDim || z >= dFZDim || x < 0 || y < 0 || z < 0) {
53  return 0;
54  }
55  return distanceFieldTemp[ x * (dFYDim * dFZDim) + y * dFZDim + z];
56  }
57 
58  inline float getRequestedCellSize() {return dRequestedCellLength;}
59  inline osg::Vec3& getBBoxDFSize() {return bboxSizeDF;}
60 
62  distanceFieldCollsions[ x * (dFYDim * dFZDim) + y * dFZDim + z]++;
63  }
64  void VoxelGrid_Object_Data::setVoxelValueCollisions(int x, int y, int z, int value){
65  distanceFieldCollsions[ x * (dFYDim * dFZDim) + y * dFZDim + z] = value;
66  }
67  int VoxelGrid_Object_Data::getCollisions(int x, int y, int z){
68  return distanceFieldCollsions[ x * (dFYDim * dFZDim) + y * dFZDim + z];
69  }
70 
71  osg::Vec4f returnColorOfVoxel(int x, int y, int z){
72  // function : (4 + log(x*10))/6.5 where x = 0 to 1 (viz. wolfram alpha)
73  // gathering information around is necessary to suppress the hich frequencies in a voxel grid of collisions.
74  // high frequencies generated unreadable represenation for human (high frequencies were visible and mid range lost)
75  /*
76  * used grid for filtration :
77  *
78  * |1|1|1| |1|1|1| |1|1|1|
79  * |1|1|1| |1|4|1| |1|1|1|
80  * |1|1|1| |1|1|1| |1|1|1|
81  */
82  float collisionsDetected = 0;
83  if (x > 0 && y > 0 && z > 0 && x < dFXDim && y < dFYDim && z < dFZDim){
84  int c = 0;
85  for (int xT = x-1; xT < x+2; xT++){
86  for (int yT = y-1; yT < y+2; yT++){
87  for (int zT = z-1; zT < z+2; zT++){
88  c += getCollisions(xT,yT,zT);
89  }
90  }
91  }
92  c += getCollisions(x,y,z) * 3;
93  collisionsDetected = (float)c / 30.0;
94  } else {
95  collisionsDetected = (float)getCollisions(x,y,z);
96  }
97 
98  float percentage = collisionsDetected/(float)iMaxCollisionsFromLoadedVoxel;
99  float red = (4.0 + log(percentage*10))/6.5;
100  float green = 1.0 - red;
101  return osg::Vec4f(red,green,0.0,0.5);
102  };
103 
104 protected:
105  bool bGridCreated;
108 
110 
111  int dFXDim, dFYDim, dFZDim; // dimesntion of the distanceField
112 
115  int iDilatationStrategy; // can be 0, 1, 2 - meaning 6, 18 or 26-around
116  int iGenType; // 0 is Dilatation. 1 is Precise
117 
121 
122  osg::BoundingBox bboxDF;
123  osg::Vec3f bboxSizeDF;
124 
127 
130 
133 
134  inline void setDistanceFieldValue(unsigned long x, unsigned long y, unsigned long z, float newValue){
135  distanceField[ x * (dFYDim * dFZDim) + y * dFZDim + z] = newValue;
136  }
137 
138  inline void setDistanceFieldTempValue(unsigned long x, unsigned long y, unsigned long z, float newValue){
139  distanceFieldTemp[ x * (dFYDim * dFZDim) + y * dFZDim + z] = newValue;
140  }
141 
142  bool constructCacheDataName(char *pOutDataName);
143 
144  bool loadFromCache(const char *pModelFileName);
145  bool saveToCache(const char *pModelFileName);
146 
149 
150  // storing a collisions
151  bool saveCollisions();
153 
154  bool loadCollisions();
156 
157  bool updateDataInformation(char* data, char* file);
158 
159 };
160 
161 } // namespace APSpacePartitioning
162 
163 
164 #endif
165