VoxelGrid.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_COLLISION_VOXELGRID_H
00026 #define SOFA_COMPONENT_COLLISION_VOXELGRID_H
00027
00028 #include <sofa/core/componentmodel/collision/BroadPhaseDetection.h>
00029 #include <sofa/component/collision/NarrowPhaseDetection.h>
00030 #include <sofa/defaulttype/Vec.h>
00031 #include <sofa/simulation/tree/GNode.h>
00032 #include <vector>
00033
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace collision
00042 {
00043
00044 using namespace sofa::defaulttype;
00045
00046 class VoxelGrid;
00047
00048 class GridCell
00049 {
00050 private:
00051
00052 sofa::helper::vector<core::CollisionElementIterator> collisElems;
00053 sofa::helper::vector<core::CollisionElementIterator> collisElemsImmobile[2];
00054
00055 Vector3 minCell, maxCell;
00056 int timeStamp;
00057 public:
00058
00059
00060
00061 void add(VoxelGrid* grid, core::CollisionElementIterator collElem, sofa::helper::vector<core::CollisionElementIterator> &vectCollis, int phase);
00062 void eraseAll(int timeStampMethod);
00063 GridCell();
00064
00065 void draw(int timeStampMethod);
00066 void setMinMax(const Vector3 &minimum, const Vector3& maximum);
00067 };
00068
00069 class VoxelGrid : public BroadPhaseDetection, public NarrowPhaseDetection
00070 {
00071 private:
00072 Vector3 nbSubDiv;
00073 GridCell ***grid;
00074 bool bDraw;
00075 Vector3 minVect, maxVect, step;
00076 void posToIdx (const Vector3& pos, Vector3 &indices);
00077 simulation::tree::GNode* timeLogger;
00078 simulation::tree::GNode::ctime_t timeInter;
00079 friend class GridCell;
00080 public:
00081 VoxelGrid (Vector3 minVect = Vector3(-20.0, -20.0, -20.0), Vector3 maxVect = Vector3(-20.0, -20.0, -20.0), Vector3 nbSubdivision = Vector3(5.0, 5.0, 5.0), bool draw=false)
00082 {
00083 createVoxelGrid (minVect, maxVect, nbSubdivision);
00084 timeStamp = 0;
00085 bDraw = draw;
00086 timeLogger = NULL;
00087 timeInter = 0;
00088 }
00089
00090 ~VoxelGrid () {}
00091
00092
00093 void createVoxelGrid (const Vector3 &min, const Vector3 &max, const Vector3 &nbSubdivision);
00094
00095 void draw();
00096
00097 void add(core::CollisionModel *cm, int phase);
00098
00099 void addCollisionModel(core::CollisionModel *cm);
00100 void addCollisionPair(const std::pair<core::CollisionModel*, core::CollisionModel*>& cmPair);
00101 void add (core::CollisionModel *cm);
00102
00103 void clearBroadPhase()
00104 {
00105 BroadPhaseDetection::clearBroadPhase();
00106 timeStamp++;
00107 }
00108 void clearNarrowPhase()
00109 {
00110 NarrowPhaseDetection::clearNarrowPhase();
00111 timeStamp++;
00112 }
00113
00114 };
00115
00116 }
00117
00118 }
00119
00120 }
00121
00122 #endif