GridTopology.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_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     //int getNbPoints() const { return n.getValue()[0]*n.getValue()[1]*n.getValue()[2]; }
00075     
00076     virtual int getNbHexas() { return (n.getValue()[0]-1)*(n.getValue()[1]-1)*(n.getValue()[2]-1); }
00077 
00078     /*
00079     int getNbQuads() {
00080       if (n.getValue()[2] == 1)
00081         return (n.getValue()[0]-1)*(n.getValue()[1]-1);
00082       else if (n.getValue()[1] == 1)
00083         return (n.getValue()[0]-1)*(n.getValue()[2]-1);
00084       else
00085         return (n.getValue()[1]-1)*(n.getValue()[2]-1);
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     } // namespace topology
00114 
00115   } // namespace component
00116 
00117 } // namespace sofa
00118 
00119 #endif

Generated on Sun Nov 23 03:43:31 2008 for Sofa by  doxygen 1.5.7.1