RegularGridTopology.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_TOPOLOGY_REGULARGRIDTOPOLOGY_H
00026 #define SOFA_COMPONENT_TOPOLOGY_REGULARGRIDTOPOLOGY_H
00027 
00028 #include <sofa/component/topology/GridTopology.h>
00029 #include <sofa/defaulttype/Vec.h>
00030 
00031 namespace sofa
00032 {
00033 
00034 namespace component
00035 {
00036 
00037 namespace topology
00038 {
00039 
00040 using namespace sofa::defaulttype;
00041 
00042 
00043 class RegularGridTopology : public GridTopology
00044 {
00045 public:
00046     RegularGridTopology(int nx, int ny, int nz);
00047     RegularGridTopology();
00048     
00049     virtual void reinit()
00050     {    
00051       setPos(min.getValue()[0],max.getValue()[0],min.getValue()[1],max.getValue()[1],min.getValue()[2],max.getValue()[2]);
00052 
00053     }
00054     void parse(core::objectmodel::BaseObjectDescription* arg);
00055 
00056     void setP0(const Vector3& val) { p0 = val; }
00057     void setDx(const Vector3& val) { dx = val; inv_dx2 = 1/(dx*dx); }
00058     void setDy(const Vector3& val) { dy = val; inv_dy2 = 1/(dy*dy); }
00059     void setDz(const Vector3& val) { dz = val; inv_dz2 = 1/(dz*dz); }
00060     
00061     void setPos(SReal xmin, SReal xmax, SReal ymin, SReal ymax, SReal zmin, SReal zmax);
00062     
00063     
00064     const Vector3& getP0() const { return p0.getValue(); }
00065     const Vector3& getDx() const { return dx; }
00066     const Vector3& getDy() const { return dy; }
00067     const Vector3& getDz() const { return dz; }
00068     
00069     unsigned getIndex( int i, int j, int k ) const; 
00070     Vector3 getPoint(int i) const;
00071     Vector3 getPoint(int x, int y, int z) const;
00072     bool hasPos()  const{ return true; }
00073     double getPX(int i)  const { return getPoint(i)[0]; }
00074     double getPY(int i) const { return getPoint(i)[1]; }    
00075     double getPZ(int i) const { return getPoint(i)[2]; }
00076     
00077 
00078     unsigned getCubeIndex( int i, int j, int k ) const; 
00079     Vector3 getCubeCoordinate( int i ) const; 
00080     
00081 
00082     Vector3   getMin() const { return min.getValue();}
00083     Vector3   getMax() const { return max.getValue();}
00084 
00085     
00087     virtual int findCube(const Vector3& pos);
00088     int findHexa(const Vector3& pos) { return findCube(pos); }
00089     
00091     virtual int findNearestCube(const Vector3& pos);
00092     int findNearestHexa(const Vector3& pos) { return findNearestCube(pos); }
00093     
00096     virtual int findCube(const Vector3& pos, SReal& fx, SReal &fy, SReal &fz);
00097     int findHexa(const Vector3& pos, SReal& fx, SReal &fy, SReal &fz) { return findCube(pos, fx, fy, fz); }
00098     
00101     virtual int findNearestCube(const Vector3& pos, SReal& fx, SReal &fy, SReal &fz);
00102     int findNearestHexa(const Vector3& pos, SReal& fx, SReal &fy, SReal &fz) { return findNearestCube(pos, fx, fy, fz); }
00103     
00104 protected:
00105     Data< Vector3 > min, max;
00107     Data< Vector3 > p0;
00109     Vector3 dx,dy,dz;
00110     SReal inv_dx2, inv_dy2, inv_dz2;
00111 };
00112 
00113 } // namespace topology
00114 
00115 } // namespace component
00116 
00117 } // namespace sofa
00118 
00119 #endif

Generated on Sun Nov 23 03:45:50 2008 for Sofa by  doxygen 1.5.7.1