GridTopology.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_GRIDTOPOLOGY_H
00026 #define SOFA_COMPONENT_TOPOLOGY_GRIDTOPOLOGY_H
00027
00028 #include <sofa/component/topology/MeshTopology.h>
00029
00030 namespace sofa
00031 {
00032
00033 namespace component
00034 {
00035
00036 namespace topology
00037 {
00038
00039 using namespace sofa::defaulttype;
00040
00041 class GridTopology : public MeshTopology
00042 {
00043 public:
00044 GridTopology();
00045
00046 GridTopology(int nx, int ny, int nz);
00047
00048 void setSize(int nx, int ny, int nz);
00049
00050 void parse(core::objectmodel::BaseObjectDescription* arg)
00051 {
00052 this->MeshTopology::parse(arg);
00053
00054
00055 if (arg->getAttribute("nx")!=NULL && arg->getAttribute("ny")!=NULL && arg->getAttribute("nz")!=NULL )
00056 {
00057 const char* nx = arg->getAttribute("nx");
00058 const char* ny = arg->getAttribute("ny");
00059 const char* nz = arg->getAttribute("nz");
00060 n.setValue(Vec<3,int>(atoi(nx),atoi(ny),atoi(nz)));
00061 }
00062
00063 this->setSize();
00064 }
00065
00066 int getNx() const { return n.getValue()[0]; }
00067 int getNy() const { return n.getValue()[1]; }
00068 int getNz() const { return n.getValue()[2]; }
00069
00070 void setNx(int n_) { (*n.beginEdit())[0] = n_; setSize(); }
00071 void setNy(int n_) { (*n.beginEdit())[1] = n_; setSize(); }
00072 void setNz(int n_) { (*n.beginEdit())[2] = n_; setSize(); }
00073
00074
00075
00076 virtual int getNbHexas() { return (n.getValue()[0]-1)*(n.getValue()[1]-1)*(n.getValue()[2]-1); }
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089 Hexa getHexaCopy(int i);
00090 Hexa getHexa(int x, int y, int z);
00091
00092 #ifndef SOFA_NEW_HEXA
00093 Cube getCubeCopy(int i) { return getHexaCopy(i); }
00094 Cube getCube(int x, int y, int z) { return getHexa(x,y,z); }
00095 #endif
00096
00097 Quad getQuadCopy(int i);
00098 Quad getQuad(int x, int y, int z);
00099
00100 int point(int x, int y, int z) const { return x+n.getValue()[0]*(y+n.getValue()[1]*z); }
00101 int hexa(int x, int y, int z) const { return x+(n.getValue()[0]-1)*(y+(n.getValue()[1]-1)*z); }
00102 int cube(int x, int y, int z) const { return hexa(x,y,z); }
00103
00104 protected:
00105 Data< Vec<3, int> > n;
00106
00107 virtual void setSize();
00108 virtual void updateEdges();
00109 virtual void updateQuads();
00110 virtual void updateHexas();
00111 };
00112
00113 }
00114
00115 }
00116
00117 }
00118
00119 #endif