PointSetTopologyModifier.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
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
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
00109 std::sort( indices.begin(), indices.end(), std::greater<unsigned int>() );
00110
00111
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
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> &,
00151 const sofa::helper::vector<unsigned int> &,
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
00166 m_container->resetTopologyChangeList();
00167 }
00168
00169 void PointSetTopologyModifier::propagateStateChanges()
00170 {
00171 sofa::simulation::StateChangeVisitor a;
00172 getContext()->executeVisitor(&a);
00173
00174
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 }
00185
00186 }
00187
00188 }
00189