QuadSetTopologyContainer.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_QUADSETTOPOLOGYCONTAINER_H
00026 #define SOFA_COMPONENT_TOPOLOGY_QUADSETTOPOLOGYCONTAINER_H
00027 
00028 #include <sofa/component/topology/EdgeSetTopologyContainer.h>
00029 
00030 namespace sofa
00031 {
00032 namespace component
00033 {
00034 namespace topology
00035 {
00036     class QuadSetTopologyModifier;
00037 
00038     using core::componentmodel::topology::BaseMeshTopology;
00039 
00040     typedef BaseMeshTopology::PointID           PointID;
00041     typedef BaseMeshTopology::EdgeID            EdgeID;
00042     typedef BaseMeshTopology::QuadID            QuadID;
00043     typedef BaseMeshTopology::Edge              Edge;
00044     typedef BaseMeshTopology::Quad              Quad;
00045     typedef BaseMeshTopology::SeqQuads          SeqQuads;
00046     typedef BaseMeshTopology::QuadEdges         QuadEdges;
00047     typedef BaseMeshTopology::VertexQuads       VertexQuads;
00048     typedef BaseMeshTopology::EdgeQuads         EdgeQuads;
00049 
00052     class QuadSetTopologyContainer : public EdgeSetTopologyContainer 
00053     {
00054         friend class QuadSetTopologyModifier;
00055         
00056     public:
00057         QuadSetTopologyContainer();
00058 
00059         QuadSetTopologyContainer(const sofa::helper::vector< Quad >& quads );
00060 
00061         virtual ~QuadSetTopologyContainer() {}
00062 
00065         virtual void clear();
00066         virtual void addQuad( int a, int b, int c, int d );
00068 
00069         virtual void init();
00070 
00073 
00074         const SeqQuads& getQuads()   
00075         { 
00076             return getQuadArray(); 
00077         }
00078 
00080         const QuadEdges& getEdgeQuadShell(QuadID i) 
00081         { 
00082             return getQuadEdge(i); 
00083         }       
00084 
00088         virtual const VertexQuads& getQuadVertexShell(PointID i);
00089 
00093         virtual const EdgeQuads& getQuadEdgeShell(EdgeID i);
00094 
00096         virtual int getQuadIndex(PointID v1, PointID v2, PointID v3, PointID v4);
00097 
00099 
00104         virtual bool checkTopology() const;
00105 
00109         const sofa::helper::vector<Quad> &getQuadArray();
00110 
00114         const sofa::helper::vector< sofa::helper::vector<unsigned int> > &getQuadVertexShellArray();
00115 
00119         const sofa::helper::vector< QuadEdges > &getQuadEdgeArray() ;
00120 
00124         const sofa::helper::vector< sofa::helper::vector<unsigned int> > &getQuadEdgeShellArray() ;
00125 
00129         unsigned int getNumberOfQuads() const;
00130 
00134         const QuadEdges &getQuadEdge(const unsigned int i) ;
00135 
00137         int getVertexIndexInQuad(Quad &t,unsigned int vertexIndex) const;
00138 
00140         int getEdgeIndexInQuad(QuadEdges &t,unsigned int edheIndex) const;
00141 
00142         inline friend std::ostream& operator<< (std::ostream& out, const QuadSetTopologyContainer& t)
00143         {
00144             out << t.m_quad.size() << " " << t.m_quad << " "
00145                 << t.m_quadEdge.size() << " " << t.m_quadEdge << " "
00146                 << t.m_quadVertexShell.size();
00147             for (unsigned int i=0; i<t.m_quadVertexShell.size(); i++)
00148             {
00149                 out << " " << t.m_quadVertexShell[i].size();
00150                 out << " " <<t.m_quadVertexShell[i] ;
00151             }
00152             out  << " " << t.m_quadEdgeShell.size();
00153             for (unsigned int i=0; i<t.m_quadEdgeShell.size(); i++)
00154             {
00155                 out  << " " << t.m_quadEdgeShell[i].size();
00156                 out  << " " << t.m_quadEdgeShell[i];
00157             }
00158 
00159             return out;
00160         }
00161 
00163         inline friend std::istream& operator>>(std::istream& in, QuadSetTopologyContainer& t)
00164         {
00165             unsigned int s;
00166             in >> s;
00167             for (unsigned int i=0;i<s;i++) 
00168             {
00169                 Quad T; in >> T;
00170                 t.m_quad.push_back(T);
00171             }
00172             in >> s;
00173             for (unsigned int i=0;i<s;i++) 
00174             {
00175                 QuadEdges T; in >> T;
00176                 t.m_quadEdge.push_back(T);
00177             }
00178 
00179             unsigned int sub;
00180             in >> s;
00181             for (unsigned int i=0;i<s;i++)
00182             {
00183                 in >> sub;
00184                 sofa::helper::vector< unsigned int > v;
00185                 for (unsigned int j=0;j<sub;j++)
00186                 {
00187                     unsigned int value;
00188                     in >> value;
00189                     v.push_back(value);
00190                 }
00191                 t.m_quadVertexShell.push_back(v);
00192             }
00193 
00194             in >> s;
00195             for (unsigned int i=0;i<s;i++)
00196             {
00197                 in >> sub;
00198                 sofa::helper::vector< unsigned int > v;
00199                 for (unsigned int j=0;j<sub;j++)
00200                 {
00201                     unsigned int value;
00202                     in >> value;
00203                     v.push_back(value);
00204                 }
00205                 t.m_quadEdgeShell.push_back(v);
00206             }  
00207 
00208             return in;
00209         }
00210 
00211     protected:
00216         virtual void createQuadSetArray();
00217 
00222         virtual void createEdgeSetArray();
00223 
00224         bool hasQuads() const;
00225 
00226         bool hasQuadEdges() const;
00227 
00228         bool hasQuadVertexShell() const;
00229 
00230         bool hasQuadEdgeShell() const;
00231 
00232         void clearQuads();
00233 
00234         void clearQuadEdges();
00235 
00236         void clearQuadVertexShell();
00237 
00238         void clearQuadEdgeShell();
00239 
00240     private:
00246         void createQuadEdgeArray();
00247 
00253         void createQuadVertexShellArray();
00254 
00260         void createQuadEdgeShellArray();
00261 
00265         sofa::helper::vector< unsigned int > &getQuadVertexShellForModification(const unsigned int vertexIndex); 
00266 
00270         sofa::helper::vector< unsigned int > &getQuadEdgeShellForModification(const unsigned int edgeIndex); 
00271 
00272     protected:
00274         sofa::helper::vector<Quad> m_quad;
00276         sofa::helper::vector<QuadEdges> m_quadEdge;
00278         sofa::helper::vector< sofa::helper::vector< unsigned int > > m_quadVertexShell;
00280         sofa::helper::vector< sofa::helper::vector< unsigned int > > m_quadEdgeShell;
00281 
00282         virtual void loadFromMeshLoader(sofa::component::MeshLoader* loader);
00283     };
00284 
00285 } // namespace topology
00286 
00287 } // namespace component
00288 
00289 } // namespace sofa
00290 
00291 #endif

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