CubeTopology.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_CUBETOPOLOGY_H
00026 #define SOFA_COMPONENT_TOPOLOGY_CUBETOPOLOGY_H
00027
00028 #include <sofa/component/topology/MeshTopology.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 class CubeTopology : public MeshTopology
00043 {
00044 public:
00045
00046 CubeTopology(int nx, int ny, int nz);
00047 CubeTopology();
00048
00049 void setSize(int nx, int ny, int nz);
00050
00051 void parse(core::objectmodel::BaseObjectDescription* arg);
00052
00053 int getNx() const { return nx.getValue(); }
00054 int getNy() const { return ny.getValue(); }
00055 int getNz() const { return nz.getValue(); }
00056
00057 void setNx(int n) { nx.setValue(n); setSize(); }
00058 void setNy(int n) { ny.setValue(n); setSize(); }
00059 void setNz(int n) { nz.setValue(n); setSize(); }
00060
00061 virtual void init();
00062 virtual void reinit();
00063
00064
00065
00066
00067
00068 enum Plane { PLANE_UNKNOWN=0,
00069 PLANE_X0,
00070 PLANE_X1,
00071 PLANE_Y0,
00072 PLANE_Y1,
00073 PLANE_Z0,
00074 PLANE_Z1 };
00075
00076 int point(int x, int y, int z, Plane p = PLANE_UNKNOWN) const;
00077
00078 void setP0(const Vector3& val) { p0 = val; }
00079 void setDx(const Vector3& val) { dx = val; inv_dx2 = 1/(dx*dx); }
00080 void setDy(const Vector3& val) { dy = val; inv_dy2 = 1/(dy*dy); }
00081 void setDz(const Vector3& val) { dz = val; inv_dz2 = 1/(dz*dz); }
00082
00083 void setPos(SReal xmin, SReal xmax, SReal ymin, SReal ymax, SReal zmin, SReal zmax);
00084
00085 const Vector3& getP0() const { return p0; }
00086 const Vector3& getDx() const { return dx; }
00087 const Vector3& getDy() const { return dy; }
00088 const Vector3& getDz() const { return dz; }
00089
00090 Vector3 getMin() const { return min.getValue();}
00091 Vector3 getMax() const { return max.getValue();}
00092
00093 Vector3 getPoint(int i) const;
00094 Vector3 getPoint(int x, int y, int z) const;
00095 bool hasPos() const{ return true; }
00096 double getPX(int i) const { return getPoint(i)[0]; }
00097 double getPY(int i) const { return getPoint(i)[1]; }
00098 double getPZ(int i) const { return getPoint(i)[2]; }
00099
00100 void setSplitNormals(bool b){splitNormals.setValue(b);}
00101
00102 protected:
00103 Data<int> nx;
00104 Data<int> ny;
00105 Data<int> nz;
00106 Data<bool> internalPoints;
00107 Data<bool> splitNormals;
00108
00109 Data< Vector3 > min, max;
00111 Vector3 p0;
00113 Vector3 dx,dy,dz;
00114 SReal inv_dx2, inv_dy2, inv_dz2;
00115
00116 virtual void setSize();
00117 void updateEdges();
00118 void updateQuads();
00119
00120 };
00121
00122 }
00123
00124 }
00125
00126 }
00127
00128 #endif