PointSetTopologyModifier.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/PointSetTopologyModifier.h>
00026 #include <sofa/simulation/common/StateChangeVisitor.h>
00027 #include <sofa/simulation/common/TopologyChangeVisitor.h>
00028 #include <sofa/component/topology/PointSetTopologyChange.h>
00029 #include <sofa/component/topology/PointSetTopologyContainer.h>
00030 #include <sofa/core/ObjectFactory.h>
00031 
00032 namespace sofa
00033 {
00034 
00035 namespace component
00036 {
00037 
00038 namespace topology
00039 {
00040   SOFA_DECL_CLASS(PointSetTopologyModifier)
00041   int PointSetTopologyModifierClass = core::RegisterObject("Point set topology modifier")   
00042     .add< PointSetTopologyModifier >();
00043 
00044     using namespace std;
00045     using namespace sofa::defaulttype;
00046     using namespace sofa::core::componentmodel::behavior;
00047 
00048     
00049     void PointSetTopologyModifier::init()
00050     {
00051         core::componentmodel::topology::TopologyModifier::init();       
00052         this->getContext()->get(m_container);
00053     }
00054 
00055     
00056     void PointSetTopologyModifier::swapPoints(const int i1, const int i2) 
00057     {
00058         PointsIndicesSwap *e2 = new PointsIndicesSwap( i1, i2 );
00059         addStateChange(e2);     
00060         propagateStateChanges();
00061 
00062         PointsIndicesSwap *e = new PointsIndicesSwap( i1, i2 ); 
00063         this->addTopologyChange(e);
00064     }
00065 
00066     
00067     void PointSetTopologyModifier::addPointsProcess(const unsigned int nPoints) 
00068     {
00069         m_container->addPoints(nPoints);
00070     }
00071 
00072     void PointSetTopologyModifier::addPointsWarning(const unsigned int nPoints, const bool addDOF) 
00073     {
00074         if(addDOF)
00075         {                              
00076             PointsAdded *e2 = new PointsAdded(nPoints);
00077             addStateChange(e2);     
00078             propagateStateChanges();
00079         }
00080 
00081         // Warning that vertices just got created
00082         PointsAdded *e = new PointsAdded(nPoints);
00083         this->addTopologyChange(e);
00084     }
00085 
00086     
00087     void PointSetTopologyModifier::addPointsWarning(const unsigned int nPoints, 
00088         const sofa::helper::vector< sofa::helper::vector< unsigned int > > &ancestors,
00089         const sofa::helper::vector< sofa::helper::vector< double       > >& coefs, 
00090         const bool addDOF) 
00091     {
00092         if(addDOF)
00093         {                              
00094             PointsAdded *e2 = new PointsAdded(nPoints, ancestors, coefs);
00095             addStateChange(e2);     
00096             propagateStateChanges();
00097         }
00098 
00099         // Warning that vertices just got created
00100         PointsAdded *e = new PointsAdded(nPoints, ancestors, coefs);
00101         this->addTopologyChange(e);
00102     }
00103 
00104     
00105     void PointSetTopologyModifier::removePointsWarning(sofa::helper::vector<unsigned int> &indices, 
00106                                                     const bool removeDOF) 
00107     { 
00108         // sort points so that they are removed in a descending order
00109         std::sort( indices.begin(), indices.end(), std::greater<unsigned int>() );  
00110 
00111         // Warning that these vertices will be deleted
00112         PointsRemoved *e = new PointsRemoved(indices);
00113         this->addTopologyChange(e);
00114 
00115         if(removeDOF)
00116         {       
00117             PointsRemoved *e2 = new PointsRemoved(indices);
00118             addStateChange(e2);
00119         }
00120     }
00121 
00122     
00123     void PointSetTopologyModifier::removePointsProcess(const sofa::helper::vector<unsigned int> & indices,
00124                                                                 const bool removeDOF) 
00125     {
00126         if(removeDOF)
00127         {
00128             propagateStateChanges();
00129         }
00130         m_container->removePoints(indices.size());
00131     }
00132 
00133     
00134     void PointSetTopologyModifier::renumberPointsWarning( const sofa::helper::vector<unsigned int> &index, 
00135                                                         const sofa::helper::vector<unsigned int> &inv_index, 
00136                                                         const bool renumberDOF)
00137     {
00138         // Warning that these vertices will be deleted
00139         PointsRenumbering *e = new PointsRenumbering(index, inv_index);
00140         this->addTopologyChange(e);
00141 
00142         if(renumberDOF)
00143         {
00144             PointsRenumbering *e2 = new PointsRenumbering(index, inv_index);
00145             addStateChange(e2);
00146         }
00147     }
00148 
00149     
00150     void PointSetTopologyModifier::renumberPointsProcess( const sofa::helper::vector<unsigned int> &/*index*/, 
00151                                                         const sofa::helper::vector<unsigned int> &/*inv_index*/, 
00152                                                         const bool renumberDOF) 
00153     {
00154         if(renumberDOF)
00155         {
00156             propagateStateChanges();                                        
00157         }
00158     }
00159 
00160     void PointSetTopologyModifier::propagateTopologicalChanges()
00161     {
00162         sofa::simulation::TopologyChangeVisitor a;
00163         getContext()->executeVisitor(&a);
00164 
00165         // remove the changes we just propagated, so that we don't send then again next time
00166         m_container->resetTopologyChangeList();
00167     }
00168 
00169     void PointSetTopologyModifier::propagateStateChanges()
00170     {
00171         sofa::simulation::StateChangeVisitor a;
00172         getContext()->executeVisitor(&a);
00173 
00174         // remove the changes we just propagated, so that we don't send then again next time
00175         m_container->resetStateChangeList();
00176     }
00177 
00178     void PointSetTopologyModifier::notifyEndingEvent() 
00179     {
00180         sofa::core::componentmodel::topology::EndingEvent *e=new sofa::core::componentmodel::topology::EndingEvent();
00181         m_container->addTopologyChange(e);
00182     }
00183 
00184 } // namespace topology
00185 
00186 } // namespace component
00187 
00188 } // namespace sofa
00189 

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