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_MANIFOLDEDGESETTOPOLOGYCONTAINER_H 00026 #define SOFA_COMPONENT_TOPOLOGY_MANIFOLDEDGESETTOPOLOGYCONTAINER_H 00027 00028 #include <sofa/component/topology/EdgeSetTopologyContainer.h> 00029 00030 namespace sofa 00031 { 00032 00033 namespace component 00034 { 00035 00036 namespace topology 00037 { 00038 class ManifoldEdgeSetTopologyModifier; 00039 00040 using core::componentmodel::topology::BaseMeshTopology; 00041 00042 typedef BaseMeshTopology::PointID PointID; 00043 typedef BaseMeshTopology::EdgeID EdgeID; 00044 typedef BaseMeshTopology::Edge Edge; 00045 typedef BaseMeshTopology::SeqEdges SeqEdges; 00046 typedef BaseMeshTopology::VertexEdges VertexEdges; 00047 00050 class ManifoldEdgeSetTopologyContainer : public EdgeSetTopologyContainer 00051 { 00052 friend class ManifoldEdgeSetTopologyModifier; 00053 00054 public: 00055 ManifoldEdgeSetTopologyContainer(); 00056 00057 ManifoldEdgeSetTopologyContainer(const sofa::helper::vector< Edge > &edges); 00058 00059 virtual ~ManifoldEdgeSetTopologyContainer() {} 00060 00061 virtual void init(); 00062 00063 virtual void clear(); 00064 00069 virtual bool checkTopology() const; 00070 00074 virtual int getNumberConnectedComponents(sofa::helper::vector<unsigned int>& components); 00075 00076 inline friend std::ostream& operator<< (std::ostream& out, const ManifoldEdgeSetTopologyContainer& t) 00077 { 00078 out << t.m_edge.size(); 00079 for (unsigned int i=0; i<t.m_edge.size(); i++) 00080 out << " " << t.m_edge[i][0] << " " << t.m_edge[i][1] ; 00081 00082 return out; 00083 } 00084 00086 inline friend std::istream& operator>>(std::istream& in, ManifoldEdgeSetTopologyContainer& t) 00087 { 00088 unsigned int s; 00089 in >> s; 00090 for (unsigned int i=0; i<s; i++) 00091 { 00092 Edge T; in >> T; 00093 t.m_edge.push_back(T); 00094 } 00095 return in; 00096 } 00097 protected: 00104 virtual void createEdgeVertexShellArray(); 00105 00106 private: 00107 // Describe each connected component, which can be seen as an oriented line 00108 class ConnectedComponent 00109 { 00110 public: 00111 00112 ConnectedComponent(unsigned int FirstVertexIndex=-1, unsigned int LastVertexIndex=-1, unsigned int size=0,unsigned int ccIndex=0) 00113 : FirstVertexIndex(FirstVertexIndex), LastVertexIndex(LastVertexIndex), size(size), ccIndex(ccIndex) 00114 {} 00115 00116 virtual ~ConnectedComponent() {} 00117 00118 public: 00119 unsigned int FirstVertexIndex; // index of the first vertex on the line 00120 unsigned int LastVertexIndex; // index of the last vertex on the line 00121 00122 unsigned int size; // number of the vertices on the line 00123 00124 unsigned int ccIndex; // index of the connected component stored in the m_ConnectedComponentArray 00125 }; 00126 00130 void resetConnectedComponent() 00131 { 00132 m_ComponentVertexArray.clear(); 00133 m_ConnectedComponentArray.clear(); 00134 } 00135 00139 bool isvoid_ConnectedComponent() 00140 { 00141 return m_ConnectedComponentArray.size()==0; 00142 } 00143 00147 void computeConnectedComponent(); 00148 00152 virtual int getNumberOfConnectedComponents() 00153 { 00154 computeConnectedComponent(); 00155 return m_ConnectedComponentArray.size(); 00156 } 00157 00161 virtual int getFirstVertexIndex(unsigned int i) 00162 { 00163 computeConnectedComponent(); 00164 assert(i<m_ConnectedComponentArray.size()); 00165 return m_ConnectedComponentArray[i].FirstVertexIndex; 00166 } 00167 00171 virtual int getLastVertexIndex(unsigned int i) 00172 { 00173 computeConnectedComponent(); 00174 assert(i<m_ConnectedComponentArray.size()); 00175 return m_ConnectedComponentArray[i].LastVertexIndex; 00176 } 00177 00181 virtual int getComponentSize(unsigned int i) 00182 { 00183 computeConnectedComponent(); 00184 assert(i<m_ConnectedComponentArray.size()); 00185 return m_ConnectedComponentArray[i].size; 00186 } 00187 00191 virtual int getComponentIndex(unsigned int i) 00192 { 00193 computeConnectedComponent(); 00194 assert(i<m_ConnectedComponentArray.size()); 00195 return m_ConnectedComponentArray[i].ccIndex; 00196 } 00197 00201 virtual bool isComponentClosed(unsigned int i) 00202 { 00203 computeConnectedComponent(); 00204 assert(i<m_ConnectedComponentArray.size()); 00205 return (m_ConnectedComponentArray[i].FirstVertexIndex == m_ConnectedComponentArray[i].LastVertexIndex); 00206 } 00207 00210 int getNextVertex(const unsigned int i) 00211 { 00212 assert(getEdgeVertexShell(i).size()>0); 00213 if((getEdgeVertexShell(i)).size()==1 && (getEdge((getEdgeVertexShell(i))[0]))[1]==i){ 00214 return -1; 00215 }else{ 00216 return (getEdge((getEdgeVertexShell(i))[0]))[1]; 00217 } 00218 } 00219 00222 int getPreviousVertex(const unsigned int i) 00223 { 00224 assert(getEdgeVertexShell(i).size()>0); 00225 if((getEdgeVertexShell(i)).size()==1 && (getEdge((getEdgeVertexShell(i))[0]))[0]==i){ 00226 return -1; 00227 }else{ 00228 return (getEdge((getEdgeVertexShell(i))[0]))[0]; 00229 } 00230 } 00231 00234 int getNextEdge(const unsigned int i) 00235 { 00236 if((getEdgeVertexShell(getEdge(i)[1])).size()==1){ 00237 return -1; 00238 }else{ 00239 return (getEdgeVertexShell(getEdge(i)[1]))[1]; 00240 } 00241 } 00242 00245 int getPreviousEdge(const unsigned int i) 00246 { 00247 if((getEdgeVertexShell(getEdge(i)[0])).size()==1){ 00248 return -1; 00249 }else{ 00250 return (getEdgeVertexShell(getEdge(i)[0]))[0]; 00251 } 00252 } 00253 00257 const sofa::helper::vector< unsigned int > &getComponentVertexArray() const 00258 { 00259 return m_ComponentVertexArray; 00260 } 00261 00265 const sofa::helper::vector< ConnectedComponent > &getConnectedComponentArray() const 00266 { 00267 return m_ConnectedComponentArray; 00268 } 00269 00270 private: 00272 sofa::helper::vector< unsigned int > m_ComponentVertexArray; 00273 00275 sofa::helper::vector< ConnectedComponent > m_ConnectedComponentArray; 00276 }; 00277 00278 } // namespace topology 00279 00280 } // namespace component 00281 00282 } // namespace sofa 00283 00284 #endif
1.5.7.1