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_GRIDMODEL_H 00026 #define SOFA_COMPONENT_COLLISION_GRIDMODEL_H 00027 00028 #include <sofa/core/CollisionModel.h> 00029 #include <sofa/component/MechanicalObject.h> 00030 #include <sofa/defaulttype/Vec3Types.h> 00031 00032 namespace sofa 00033 { 00034 00035 namespace component 00036 { 00037 00038 namespace collision 00039 { 00040 00041 using namespace sofa::defaulttype; 00042 00043 class GridModel; 00044 00045 class GridCell : public core::TCollisionElementIterator<GridModel> 00046 { 00047 public: 00048 GridCell(GridModel* model=NULL, int index=0); 00049 00050 explicit GridCell(const core::CollisionElementIterator& i); 00051 00052 const Vector3& minVect() const; 00053 00054 const Vector3& maxVect() const; 00055 00056 //const std::pair<GridCell,GridCell>& subcells() const; 00057 }; 00058 00059 class GridModel : public core::CollisionModel 00060 { 00061 protected: 00062 00063 public: 00064 typedef core::CollisionElementIterator ChildIterator; 00065 typedef Vec3Types DataTypes; 00066 typedef GridCell Element; 00067 friend class GridCell; 00068 00069 GridModel(); 00070 00071 virtual void resize(int size); 00072 00073 // -- CollisionModel interface 00074 00075 virtual void computeBoundingTree(int maxDepth=0); 00076 00077 virtual std::pair<core::CollisionElementIterator,core::CollisionElementIterator> getInternalChildren(int index) const; 00078 00079 virtual std::pair<core::CollisionElementIterator,core::CollisionElementIterator> getExternalChildren(int index) const; 00080 00081 virtual bool isLeaf( int index ) const; 00082 00083 void draw(int index); 00084 00085 void draw(); 00086 }; 00087 00088 inline GridCell::GridCell(GridModel* model, int index) 00089 : core::TCollisionElementIterator<GridModel>(model, index) 00090 { 00091 } 00092 00093 inline GridCell::GridCell(const core::CollisionElementIterator& i) 00094 : core::TCollisionElementIterator<GridModel>(static_cast<GridModel*>(i.getCollisionModel()), i.getIndex()) 00095 { 00096 } 00097 00098 //inline const Vector3& GridCell::minVect() const 00099 //{ 00100 // return model->elems[index].minBBox; 00101 //} 00102 00103 //inline const Vector3& GridCell::maxVect() const 00104 //{ 00105 // return model->elems[index].maxBBox; 00106 //} 00107 00108 //inline const std::pair<GridCell,GridCell>& GridCell::subcells() const 00109 //{ 00110 // return model->elems[index].subcells; 00111 //} 00112 00113 } // namespace collision 00114 00115 } // namespace component 00116 00117 } // namespace sofa 00118 00119 #endif
1.5.7.1