TriangleOctree.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
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 /*THIS STATIC CUBE SIZE MUST BE CHANGE, it represents the size of the occtree cube*/
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     /*the default cube has xmin=-CUBE_SIZE xmax=CUBE_SIZE, ymin=-CUBE_SIZE, ymax=CUBE_SIZE, zmin=-CUBE_SIZE,zmax=CUBE_SIZE*/
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     }               // namespace collision
00107 
00108   }             // namespace component
00109 
00110 }               // namespace sofa
00111 
00112 #endif

Generated on Sun Nov 23 02:37:12 2008 for Sofa by  doxygen 1.5.7.1