MeshTopology.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_MESHTOPOLOGY_H
00026 #define SOFA_COMPONENT_TOPOLOGY_MESHTOPOLOGY_H
00027 
00028 #include <stdlib.h>
00029 #include <vector>
00030 #include <string>
00031 #include <iostream>
00032 #include <sofa/core/componentmodel/topology/Topology.h>
00033 #include <sofa/core/componentmodel/topology/BaseMeshTopology.h>
00034 #include <sofa/helper/fixed_array.h>
00035 #include <sofa/helper/vector.h>
00036 
00037 namespace sofa
00038 {
00039 
00040 namespace component
00041 {
00042 
00043 class MeshLoader;
00044 
00045 namespace topology
00046 {
00047 
00048 using namespace sofa::defaulttype;
00049 using helper::vector;
00050 using helper::fixed_array;
00051 
00052 
00053 class MeshTopology : public core::componentmodel::topology::BaseMeshTopology
00054 {
00055   public:
00056 
00057     MeshTopology();
00058         
00059     virtual void init();
00060     
00061     virtual int getNbPoints() const;
00062 
00063     virtual void setNbPoints(int n);
00064     
00065     // Complete sequence accessors
00066     
00067     virtual const SeqEdges& getEdges();
00068     virtual const SeqTriangles& getTriangles();
00069     virtual const SeqQuads& getQuads();
00070     virtual const SeqTetras& getTetras();
00071     virtual const SeqHexas& getHexas();
00072     
00073     // Random accessors
00074     
00075     virtual int getNbEdges();
00076     virtual int getNbTriangles();
00077     virtual int getNbQuads();
00078     virtual int getNbTetras();
00079     virtual int getNbHexas();
00080     
00081     virtual Edge getEdge(EdgeID i);
00082     virtual Triangle getTriangle(TriangleID i);
00083     virtual Quad getQuad(QuadID i);
00084     virtual Tetra getTetra(TetraID i);
00085     virtual Hexa getHexa(HexaID i);
00086 
00090     virtual const VertexEdges &getEdgeVertexShell(PointID i);
00092     virtual const TriangleEdges &getEdgeTriangleShell(TriangleID i);
00094     virtual const QuadEdges &getEdgeQuadShell(QuadID i);
00096     virtual const TetraEdges& getEdgeTetraShell(TetraID i);
00098     virtual const HexaEdges& getEdgeHexaShell(HexaID i);
00100     virtual const VertexTriangles &getTriangleVertexShell(PointID i);
00102     virtual const EdgeTriangles &getTriangleEdgeShell(EdgeID i);
00104     virtual const TetraTriangles& getTriangleTetraShell(TetraID i);
00106     virtual const VertexQuads &getQuadVertexShell(PointID i);
00108     virtual const EdgeQuads &getQuadEdgeShell(EdgeID i);
00110     virtual const HexaQuads& getQuadHexaShell(HexaID i);
00112     virtual const VertexTetras& getTetraVertexShell(PointID i);
00114     virtual const EdgeTetras& getTetraEdgeShell(EdgeID i);
00116     virtual const TriangleTetras& getTetraTriangleShell(TriangleID i);
00118     virtual const VertexHexas& getHexaVertexShell(PointID i);
00120     virtual const EdgeHexas& getHexaEdgeShell(EdgeID i);
00122     virtual const QuadHexas& getHexaQuadShell(QuadID i);
00124         
00125     // Points accessors (not always available)
00126 
00127     virtual bool hasPos() const;
00128     virtual double getPX(int i) const;
00129     virtual double getPY(int i) const;
00130     virtual double getPZ(int i) const;
00131 
00132     // for procedural creation without file loader
00133     virtual void clear();
00134     void addPoint(double px, double py, double pz);
00135     void addEdge( int a, int b );
00136     void addTriangle( int a, int b, int c );
00137     void addQuad( int a, int b, int c, int d );
00138     void addTetra( int a, int b, int c, int d );
00139     void addHexa( int a, int b, int c, int d, int e, int f, int g, int h );
00140 
00142     int getRevision() const { return revision; }
00143     
00146     virtual bool isCubeActive(int /*index*/) { return true; }    
00147 
00148     void draw();
00149 
00150 protected:
00151     int nbPoints;
00152     vector< fixed_array<SReal,3> > seqPoints;
00153     
00154     Data<SeqEdges> seqEdges;
00155     bool validEdges;
00156     
00157     //SeqTriangles   seqTriangles;
00158         Data<SeqTriangles> seqTriangles;
00159     bool         validTriangles;
00160     
00161     //SeqQuads       seqQuads;
00162     Data<SeqQuads>       seqQuads;
00163     bool         validQuads;
00164     
00165     //SeqTetras      seqTetras;
00166     Data<SeqTetras>      seqTetras;
00167     bool         validTetras;
00168     
00169 #ifdef SOFA_NEW_HEXA
00170     //SeqHexas     seqHexas;
00171     Data<SeqHexas>     seqHexas;
00172 #else
00173     Data<SeqCubes>       seqHexas;
00174 #endif
00175     bool         validHexas;
00176     
00177 
00179     vector< VertexEdges > m_edgeVertexShell;
00180 
00182     vector< TriangleEdges > m_edgeTriangleShell;
00183 
00185     vector< QuadEdges > m_edgeQuadShell;
00186 
00188     vector< TetraEdges > m_edgeTetraShell;
00189 
00191     vector< HexaEdges > m_edgeHexaShell;
00192 
00194     vector< VertexTriangles > m_triangleVertexShell;
00195 
00197     vector< EdgeTriangles > m_triangleEdgeShell;
00198     
00200     vector< TetraTriangles > m_triangleTetraShell;
00201 
00203     vector< VertexQuads > m_quadVertexShell;
00204     
00206     vector< EdgeQuads > m_quadEdgeShell;
00207     
00209     vector< HexaQuads > m_quadHexaShell;
00210     
00212     vector< VertexTetras> m_tetraVertexShell;
00213 
00215     vector< EdgeTetras > m_tetraEdgeShell;
00216     
00218     vector< TriangleTetras > m_tetraTriangleShell;
00219 
00221     vector< VertexHexas > m_hexaVertexShell;
00222     
00224     vector< EdgeHexas > m_hexaEdgeShell;
00225     
00227     vector< QuadHexas > m_hexaQuadShell;
00228         
00235     void createEdgeVertexShellArray();
00236 
00242     void createEdgeTriangleShellArray();
00243 
00249     void createEdgeQuadShellArray();
00250 
00256     void createEdgeTetraShellArray();
00257 
00263     void createEdgeHexaShellArray();
00264 
00270     void createTriangleVertexShellArray();
00271 
00277     void createTriangleEdgeShellArray();
00278 
00284     void createTriangleTetraShellArray ();
00285 
00291     void createQuadVertexShellArray ();
00292 
00298     void createQuadEdgeShellArray();
00299 
00305     void createQuadHexaShellArray ();
00306 
00312     void createTetraVertexShellArray ();
00313 
00319     void createTetraEdgeShellArray();
00320 
00326     void createTetraTriangleShellArray();
00327 
00333     void createHexaVertexShellArray();
00334 
00340     void createHexaEdgeShellArray ();
00341 
00347     void createHexaQuadShellArray();
00348 
00349 
00350 
00354     const vector< VertexTriangles > &getTriangleVertexShellArray() ;
00355 
00359     const vector< VertexQuads >& getQuadVertexShellArray();
00360 
00361 
00362 
00366     int getEdgeIndex(PointID v1, PointID v2);
00367     
00369     int getTriangleIndex(PointID v1, PointID v2, PointID v3);
00370         
00374     int getQuadIndex(PointID v1, PointID v2, PointID v3,  PointID v4);
00375 
00379     int getTetrahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4);
00380 
00384     int getHexahedronIndex(PointID v1, PointID v2, PointID v3, PointID v4, PointID v5, PointID v6, PointID v7, PointID v8);
00385     
00389     int getVertexIndexInTriangle(const Triangle &t, PointID vertexIndex) const;
00390 
00394     int getEdgeIndexInTriangle(const TriangleEdges &t, EdgeID edgeIndex) const;
00395 
00399     int getVertexIndexInQuad(Quad &t, PointID vertexIndex) const;
00400 
00404     int getEdgeIndexInQuad(QuadEdges &t, EdgeID edgeIndex) const;
00405 
00409     int getVertexIndexInTetrahedron(const Tetra &t, PointID vertexIndex) const;
00410 
00414     int getEdgeIndexInTetrahedron(const TetraEdges &t, EdgeID edgeIndex) const;
00415 
00419     int getTriangleIndexInTetrahedron(const TetraTriangles &t, TriangleID triangleIndex) const;
00420 
00424     int getVertexIndexInHexahedron(Hexa &t, PointID vertexIndex) const;
00425 
00429     int getEdgeIndexInHexahedron(const HexaEdges &t, EdgeID edgeIndex) const;
00430 
00434     int getQuadIndexInHexahedron(const HexaQuads &t, QuadID quadIndex) const;
00435 
00439     Edge getLocalTetrahedronEdges (const unsigned int i) const;
00440 
00441     int revision;
00442 
00443     Data< bool > _draw;
00444 
00445     void invalidate();
00446     
00447     virtual void updateEdges()     { }
00448     virtual void updateTriangles() { }
00449     virtual void updateQuads()     { }
00450     virtual void updateTetras()    { }
00451     virtual void updateHexas()     { }
00452 
00453     protected:
00454         virtual void loadFromMeshLoader(sofa::component::MeshLoader* loader);
00455 };
00456 
00457 } // namespace topology
00458 
00459 } // namespace component
00460 
00461 } // namespace sofa
00462 
00463 #endif

Generated on Sun Nov 23 03:44:45 2008 for Sofa by  doxygen 1.5.7.1