RegularGridTopology.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_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 }
00114
00115 }
00116
00117 }
00118
00119 #endif