BaseMeshTopology.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 :: Framework                              *
00020 *                                                                             *
00021 * Authors: M. Adam, J. Allard, B. Andre, P-J. Bensoussan, S. Cotin, C. Duriez,*
00022 * H. Delingette, F. Falipou, F. Faure, S. Fonteneau, L. Heigeas, C. Mendoza,  *
00023 * M. Nesme, P. Neumann, J-P. de la Plata Alcade, F. Poyer and F. Roy          *
00024 *                                                                             *
00025 * Contact information: contact@sofa-framework.org                             *
00026 ******************************************************************************/
00027 #ifndef SOFA_CORE_COMPONENTMODEL_TOPOLOGY_BASEMESHTOPOLOGY_H
00028 #define SOFA_CORE_COMPONENTMODEL_TOPOLOGY_BASEMESHTOPOLOGY_H
00029 
00030 #include <stdlib.h>
00031 #include <list>
00032 #include <string>
00033 #include <iostream>
00034 #include <sofa/core/componentmodel/topology/Topology.h>
00035 #include <sofa/helper/fixed_array.h>
00036 #include <sofa/helper/vector.h>
00037 
00038 namespace sofa
00039 {
00040 
00041 namespace core
00042 {
00043 
00044 namespace componentmodel
00045 {
00046 
00047 namespace topology
00048 {
00049 
00050 using namespace sofa::defaulttype;
00051 using helper::vector;
00052 using helper::fixed_array;
00053 
00054 #define SOFA_NEW_HEXA
00055 
00056  class BaseMeshTopology : public core::componentmodel::topology::Topology
00057 {
00058 public:
00059     //typedef int index_type;
00060     typedef unsigned int index_type;
00061     enum { InvalidID = (unsigned)-1 };
00062     typedef index_type      PointID;
00063     typedef index_type      EdgeID;
00064     typedef index_type      TriangleID;
00065     typedef index_type      QuadID;
00066     typedef index_type      TetraID;
00067     typedef index_type      HexaID;
00068     
00069     typedef fixed_array<PointID,2> Edge;
00070     typedef fixed_array<PointID,3> Triangle;
00071     typedef fixed_array<PointID,4> Quad;
00072     typedef fixed_array<PointID,4> Tetra;
00073     typedef fixed_array<PointID,8> Hexa;
00074     
00075     typedef vector<Edge>        SeqEdges;
00076     typedef vector<Triangle>    SeqTriangles;
00077     typedef vector<Quad>        SeqQuads;
00078     typedef vector<Tetra>       SeqTetras;
00079     typedef vector<Hexa>        SeqHexas;
00080     
00083     typedef EdgeID      LineID;
00084     typedef Edge        Line;
00085     typedef SeqEdges    SeqLines;
00086 #ifndef SOFA_NEW_HEXA
00087     typedef HexaID CubeID;
00088     typedef Hexa Cube;
00089     typedef SeqHexas SeqCubes;
00090 #endif
00092     
00095     typedef fixed_array<EdgeID,3>       TriangleEdges;
00096     typedef fixed_array<QuadID,4>       QuadEdges;
00097     typedef fixed_array<TriangleID,4>   TetraTriangles;
00098     typedef fixed_array<EdgeID,6>       TetraEdges;
00099     typedef fixed_array<QuadID,6>       HexaQuads;
00100     typedef fixed_array<EdgeID,12>      HexaEdges;
00102 
00105     typedef vector<EdgeID>          VertexEdges;
00106     typedef vector<TriangleID>      VertexTriangles;
00107     typedef vector<QuadID>          VertexQuads;
00108     typedef vector<TetraID>         VertexTetras;
00109     typedef vector<HexaID>          VertexHexas;
00110     typedef vector<TriangleID>      EdgeTriangles;
00111     typedef vector<QuadID>          EdgeQuads;
00112     typedef vector<TetraID>         EdgeTetras;
00113     typedef vector<HexaID>          EdgeHexas;
00114     typedef vector<TetraID>         TriangleTetras;
00115     typedef vector<HexaID>          QuadHexas;
00117 
00118     BaseMeshTopology();
00119 
00120     void parse(core::objectmodel::BaseObjectDescription* arg);
00121 
00125     virtual bool load(const char* filename);
00126     virtual std::string getFilename() const {return d_filename.getValue();}
00127 
00128     // defined in Topology
00129     //virtual int getNbPoints() const = 0;  
00130 
00133     virtual const SeqEdges& getEdges() = 0;
00134     virtual const SeqTriangles& getTriangles() = 0;
00135     virtual const SeqQuads& getQuads() = 0;
00136     virtual const SeqTetras& getTetras() = 0;
00137     virtual const SeqHexas& getHexas() = 0;
00139 
00142 
00143     virtual int getNbEdges()     { return getEdges().size(); }
00144     virtual int getNbTriangles() { return getTriangles().size(); }
00145     virtual int getNbQuads()     { return getQuads().size(); }
00146     virtual int getNbTetras()    { return getTetras().size(); }
00147     virtual int getNbHexas()     { return getHexas().size(); }
00148 
00149     virtual Edge getEdge(EdgeID i)             { return getEdges()[i]; }
00150     virtual Triangle getTriangle(TriangleID i) { return getTriangles()[i]; }
00151     virtual Quad getQuad(QuadID i)             { return getQuads()[i]; }
00152     virtual Tetra getTetra(TetraID i)          { return getTetras()[i]; }
00153     virtual Hexa getHexa(HexaID i)             { return getHexas()[i]; }
00155 
00159     virtual const VertexEdges& getEdgeVertexShell(PointID i);
00161     virtual const TriangleEdges& getEdgeTriangleShell(TriangleID i);
00163     virtual const QuadEdges& getEdgeQuadShell(QuadID i);
00165     virtual const TetraEdges& getEdgeTetraShell(TetraID i);
00167     virtual const HexaEdges& getEdgeHexaShell(HexaID i);
00169     virtual const VertexTriangles& getTriangleVertexShell(PointID i);
00171     virtual const EdgeTriangles& getTriangleEdgeShell(EdgeID i);
00173     virtual const TetraTriangles& getTriangleTetraShell(TetraID i);
00175     virtual const VertexQuads& getQuadVertexShell(PointID i);
00177     virtual const EdgeQuads& getQuadEdgeShell(EdgeID i);
00179     virtual const HexaQuads& getQuadHexaShell(HexaID i);
00181     virtual const VertexTetras& getTetraVertexShell(PointID i);
00183     virtual const EdgeTetras& getTetraEdgeShell(EdgeID i);
00185     virtual const TriangleTetras& getTetraTriangleShell(TriangleID i);
00187     virtual const VertexHexas& getHexaVertexShell(PointID i);
00189     virtual const EdgeHexas& getHexaEdgeShell(EdgeID i);
00191     virtual const QuadHexas& getHexaQuadShell(QuadID i);
00193 
00194 
00196     virtual int getEdgeIndex(PointID v1, PointID v2);
00198     virtual int getTriangleIndex(PointID v1, PointID v2, PointID v3);
00200     virtual int getQuadIndex(PointID v1, PointID v2, PointID v3, PointID v4);
00202     virtual int getTetrahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4);
00204     virtual int getHexahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4, PointID v5, PointID v6, PointID v7, PointID v8);
00205 
00206     
00208     virtual int getVertexIndexInTriangle(const Triangle &t, PointID vertexIndex) const;
00210     virtual int getEdgeIndexInTriangle(const TriangleEdges &t, EdgeID edgeIndex) const;
00211 
00213     virtual int getVertexIndexInQuad(Quad &t, PointID vertexIndex) const;
00215     virtual int getEdgeIndexInQuad(QuadEdges &t, EdgeID edgeIndex) const;
00216 
00218     virtual int getVertexIndexInTetrahedron(const Tetra &t, PointID vertexIndex) const;
00220     virtual int getEdgeIndexInTetrahedron(const TetraEdges &t, EdgeID edgeIndex) const;
00222     virtual int getTriangleIndexInTetrahedron(const TetraTriangles &t, TriangleID triangleIndex) const;
00223 
00225     virtual int getVertexIndexInHexahedron(Hexa &t, PointID vertexIndex) const;
00227     virtual int getEdgeIndexInHexahedron(const HexaEdges &t, EdgeID edgeIndex) const;
00229     virtual int getQuadIndexInHexahedron(const HexaQuads &t, QuadID quadIndex) const;
00230 
00232     virtual Edge getLocalTetrahedronEdges (const unsigned int i) const;
00233     
00236     const SeqLines& getLines() { return getEdges(); }
00237     int getNbLines() { return getNbEdges(); }
00238     Line getLine(LineID i) { return getEdge(i); }
00239 #ifndef SOFA_NEW_HEXA
00240     const SeqCubes& getCubes() { return getHexas(); }
00241     int getNbCubes() { return getNbHexas(); }
00242     Cube getCube(CubeID i) { return getHexa(i); }
00243 #endif
00245 
00249     virtual bool hasPos() const { return false; }
00250     virtual double getPX(int) const { return 0.0; }
00251     virtual double getPY(int) const { return 0.0; }
00252     virtual double getPZ(int) const { return 0.0; }
00254 
00257     virtual void clear();
00258     virtual void addPoint(double px, double py, double pz);
00259     virtual void addEdge( int a, int b );
00260     void addLine( int a, int b ) { addEdge(a,b); }
00261     virtual void addTriangle( int a, int b, int c );
00262     virtual void addQuad( int a, int b, int c, int d );
00263     virtual void addTetra( int a, int b, int c, int d );
00264     virtual void addHexa( int a, int b, int c, int d, int e, int f, int g, int h );
00266 
00269     virtual int getRevision() const { return 0; }
00270 
00273     virtual bool isCubeActive(int /*index*/) { return true; }    
00274 
00277 
00280     virtual std::list<const TopologyChange *>::const_iterator firstChange() const;
00281 
00284     virtual std::list<const TopologyChange *>::const_iterator lastChange() const;
00285 
00288     virtual std::list<const TopologyChange *>::const_iterator firstStateChange() const;
00289 
00292     virtual std::list<const TopologyChange *>::const_iterator lastStateChange() const;
00293 
00295 
00296 
00297 protected:
00298 
00299     Data< std::string > d_filename;
00300 };
00301 
00302 } // namespace topology
00303 
00304 } // namespace componentmodel
00305 
00306 } // namespace core
00307 
00308 } // namespace sofa
00309 
00310 #endif

Generated on Sun Nov 23 02:29:24 2008 for Sofa by  doxygen 1.5.7.1