ManifoldEdgeSetTopologyModifier.cpp

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 #include <sofa/component/topology/ManifoldEdgeSetTopologyModifier.h>
00026 #include <sofa/component/topology/EdgeSetTopologyChange.h>
00027 #include <sofa/component/topology/ManifoldEdgeSetTopologyContainer.h>
00028 #include <algorithm>
00029 #include <functional>
00030 #include <iostream>
00031 #include <sofa/core/ObjectFactory.h>
00032 
00033 namespace sofa
00034 {
00035 
00036 namespace component
00037 {
00038 
00039 namespace topology
00040 {
00041     using namespace sofa::defaulttype;
00042   SOFA_DECL_CLASS(ManifoldEdgeSetTopologyModifier)
00043        int ManifoldEdgeSetTopologyModifierClass = core::RegisterObject("ManifoldEdge set topology modifier")    
00044     .add< ManifoldEdgeSetTopologyModifier >();
00045 
00046     using namespace std;
00047     using namespace sofa::defaulttype;
00048     using namespace sofa::core::componentmodel::behavior;
00049         
00050     void ManifoldEdgeSetTopologyModifier::init()
00051     {
00052         EdgeSetTopologyModifier::init();
00053         getContext()->get(m_container);
00054     }
00055 
00056     void ManifoldEdgeSetTopologyModifier::addEdgeProcess(Edge e) 
00057     {
00058         m_container->resetConnectedComponent(); // invalidate the connected components by default
00059 
00060         EdgeSetTopologyModifier::addEdgeProcess(e);
00061     }
00062 
00063     void ManifoldEdgeSetTopologyModifier::addEdgesProcess(const sofa::helper::vector< Edge > &edges) 
00064     {
00065         m_container->resetConnectedComponent(); // invalidate the connected components by default
00066 
00067         EdgeSetTopologyModifier::addEdgesProcess(edges);
00068     }
00069 
00070     void ManifoldEdgeSetTopologyModifier::removeEdgesProcess(const sofa::helper::vector<unsigned int> &indices,
00071                                                                         const bool removeIsolatedItems)
00072     {       
00073         m_container->resetConnectedComponent(); // invalidate the connected components by default
00074 
00075         EdgeSetTopologyModifier::removeEdgesProcess(indices, removeIsolatedItems);
00076     }
00077 
00078     void ManifoldEdgeSetTopologyModifier::removeEdges(sofa::helper::vector< unsigned int >& edges, 
00079                                                             const bool removeIsolatedPoints)
00080     {
00082         removeEdgesWarning(edges);
00083         // inform other objects that the edges are going to be removed
00084         propagateTopologicalChanges();
00085         // now destroy the old edges.
00086         removeEdgesProcess( edges, removeIsolatedPoints );
00087         
00088         m_container->checkTopology();
00089     }
00090     
00091     void ManifoldEdgeSetTopologyModifier::removeItems(sofa::helper::vector< unsigned int >& items)
00092     {
00093         removeEdges(items);
00094     }
00095 
00096     void ManifoldEdgeSetTopologyModifier::renumberPoints( const sofa::helper::vector<unsigned int> &index, 
00097                                                                         const sofa::helper::vector<unsigned int> &inv_index)
00098     {           
00100         renumberPointsWarning(index, inv_index);
00101         // inform other objects that the triangles are going to be removed
00102         propagateTopologicalChanges();
00103         // now renumber the points      
00104         renumberPointsProcess(index, inv_index);
00105                         
00106         m_container->checkTopology();  
00107      }
00108 
00109     void ManifoldEdgeSetTopologyModifier::addEdges(const sofa::helper::vector< Edge >& edges) 
00110     {
00111         unsigned int nEdges = m_container->getNumberOfEdges();
00112 
00114         addEdgesProcess(edges);
00115 
00116         sofa::helper::vector<unsigned int> edgesIndex;
00117         edgesIndex.reserve(edges.size());
00118 
00119         for (unsigned int i=0; i<edges.size(); ++i) 
00120         {
00121             edgesIndex.push_back(nEdges+i);
00122         }
00123 
00124         // add topology event in the stack of topological events
00125         addEdgesWarning( edges.size(), edges, edgesIndex);
00126 
00127         // inform other objects that the edges are already added
00128         propagateTopologicalChanges();
00129     }
00130     
00131     void ManifoldEdgeSetTopologyModifier::addEdges(const sofa::helper::vector< Edge >& edges,
00132         const sofa::helper::vector< sofa::helper::vector< unsigned int > > & ancestors ,
00133         const sofa::helper::vector< sofa::helper::vector< double > >& baryCoefs) 
00134     {
00135         unsigned int nEdges = m_container->getNumberOfEdges();
00136 
00138         addEdgesProcess(edges);
00139 
00140         sofa::helper::vector<unsigned int> edgesIndex;
00141         
00142         for (unsigned int i=0;i<edges.size();++i) 
00143         {
00144             edgesIndex[i]=nEdges+i;
00145         }
00146 
00147         // add topology event in the stack of topological events
00148         addEdgesWarning( edges.size(), edges,edgesIndex,ancestors,baryCoefs);
00149 
00150         // inform other objects that the edges are already added
00151         propagateTopologicalChanges();
00152     }
00153       
00154     void ManifoldEdgeSetTopologyModifier::swapEdges(const sofa::helper::vector< sofa::helper::vector< unsigned int > >& edgesPairs)
00155     {
00156         swapEdgesProcess(edgesPairs);
00157         m_container->checkTopology();
00158     }
00159     
00160     
00161     void ManifoldEdgeSetTopologyModifier::fuseEdges(const sofa::helper::vector< sofa::helper::vector< unsigned int > >& edgesPairs, const bool removeIsolatedPoints)
00162     {
00163         fuseEdgesProcess(edgesPairs, removeIsolatedPoints);
00164         m_container->checkTopology();
00165     }
00166          
00167     void ManifoldEdgeSetTopologyModifier::splitEdges( sofa::helper::vector<unsigned int> &indices,
00168         const bool removeIsolatedPoints) 
00169     {
00170         splitEdgesProcess(indices, removeIsolatedPoints);
00171         m_container->checkTopology();
00172     }
00173 
00174     void ManifoldEdgeSetTopologyModifier::splitEdges( sofa::helper::vector<unsigned int> &indices,
00175         const sofa::helper::vector< sofa::helper::vector< double > >& baryCoefs,
00176         const bool removeIsolatedPoints) 
00177     {
00178         splitEdgesProcess(indices, baryCoefs, removeIsolatedPoints);
00179         m_container->checkTopology();
00180     }
00181 
00182 } // namespace topology
00183 
00184 } // namespace component
00185 
00186 } // namespace sofa
00187 

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