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_TRIANGLEOCTREE_H
00026 #define SOFA_COMPONENT_COLLISION_TRIANGLEOCTREE_H
00027
00028 #include <sofa/component/collision/TriangleOctreeModel.h>
00029
00030 #include <sofa/core/CollisionModel.h>
00031 #include <sofa/component/MechanicalObject.h>
00032 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00033 #include <sofa/defaulttype/Vec3Types.h>
00034
00035 #define CUBE_SIZE 200
00036 #define bb_max(a,b) (((a)>(b))?(a):(b))
00037 #define bb_max3(a,b,c) bb_max((bb_max(a,b)),c)
00038
00039 #define bb_min(a,b) (((a)<(b))?(a):(b))
00040 #define bb_min3(a,b,c) bb_min(bb_min(a,b),c)
00041
00042 namespace sofa
00043 {
00044
00045 namespace component
00046 {
00047
00048 namespace collision
00049 {
00050
00051 using namespace sofa::defaulttype;
00052
00053 class TriangleOctreeModel;
00054 class TriangleOctree
00055 {
00056 public:
00057 class vertexData
00058 {
00059 public:
00060 TriangleOctree * parent;
00061 int childId;
00062 vertexData (TriangleOctree * _parent,
00063 int _childId):parent (_parent), childId (_childId)
00064 {
00065 }
00066 };
00067 class traceResult{
00068 public:
00069 traceResult():t(0),u(0),v(0){}
00070 double t,u,v;
00071 };
00072 double x, y, z;
00073 bool visited;
00074
00075 double size;
00076 bool val;
00077 bool is_leaf;
00078 bool internal;
00079 TriangleOctreeModel *tm;
00080 vector < int >objects;
00081 TriangleOctree *childVec[8];
00082
00083
00084 ~TriangleOctree ();
00085
00086 TriangleOctree (TriangleOctreeModel * _tm, double _x = (double)-CUBE_SIZE, double _y = (double)-CUBE_SIZE, double _z =(double) -CUBE_SIZE, double _size = 2 * CUBE_SIZE):x (_x), y (_y), z (_z), size (_size),
00087 tm
00088 (_tm)
00089 {
00090 is_leaf = true;
00091 internal = false;
00092 for (int i = 0; i < 8; i++)
00093 childVec[i] = NULL;
00094 }
00095 void draw ();
00096 int nearestTriangle (int minIndex, const Vector3 & origin,
00097 const Vector3 & direction,traceResult &result);
00098 void insert (double _x, double _y, double _z, double _inc, int t);
00099 int trace (Vector3 origin, Vector3 direction, traceResult &result);
00100 int trace (const Vector3 & origin, const Vector3 & direction,
00101 double tx0, double ty0, double tz0, double tx1, double ty1,
00102 double tz1, unsigned int a, unsigned int b,Vector3 &origin1,Vector3 &direction1, traceResult &result);
00103
00104 };
00105
00106 }
00107
00108 }
00109
00110 }
00111
00112 #endif