1 #ifndef __CPM__ALGORITHMS__SIMPLEX__DEFORMATIONFILTER__HXX__
2 #define __CPM__ALGORITHMS__SIMPLEX__DEFORMATIONFILTER__HXX__
4 // -------------------------------------------------------------------------
6 void cpm::Algorithms::Simplex::DeformationFilter< M >::
7 AddForce( TForceFunction* f, const TScalar& w )
9 this->m_Forces.push_back( TFunctionPair( f, w ) );
13 // -------------------------------------------------------------------------
15 cpm::Algorithms::Simplex::DeformationFilter< M >::
18 m_Damping( TScalar( 1 ) )
22 // -------------------------------------------------------------------------
24 cpm::Algorithms::Simplex::DeformationFilter< M >::
29 // -------------------------------------------------------------------------
31 void cpm::Algorithms::Simplex::DeformationFilter< M >::
34 typedef typename M::VectorType TVector;
36 const M* in = this->GetInput( );
37 M* out = this->GetOutput( );
38 unsigned int nPoints = in->GetNumberOfPoints( );
39 std::vector< TVector > final_forces[ 2 ];
40 unsigned int aForces = 0;
41 final_forces[ 0 ].resize( nPoints, TVector( TScalar( 0 ) ) );
42 final_forces[ 1 ].resize( nPoints, TVector( TScalar( 0 ) ) );
45 typename TFunctionContainer::iterator fIt = this->m_Forces.begin( );
46 for( ; fIt != this->m_Forces.end( ); ++fIt )
47 fIt->first->SetMesh( in );
50 while( leo < 20000 ) // TODO: !!!!
53 TScalar damping = TScalar( 1 ) - this->m_Damping;
54 unsigned int pForces = ( aForces + 1 ) % 2;
57 for( TPointId pId = 0; pId < nPoints; ++pId )
59 if( in->FindEdge( pId )->IsOriginInternal( ) )
61 fIt = this->m_Forces.begin( );
62 TVector f = fIt->first->Evaluate( pId ) * fIt->second;
63 for( ++fIt; fIt != this->m_Forces.end( ); ++fIt )
64 f += fIt->first->Evaluate( pId ) * fIt->second;
65 f += final_forces[ pForces ][ pId ] * damping;
66 final_forces[ aForces ][ pId ] = f;
69 final_forces[ aForces ][ pId ].Fill( TScalar( 0 ) );
74 for( TPointId pId = 0; pId < nPoints; ++pId )
76 typename M::PointType pnt = in->GetPoint( pId );
77 pnt += final_forces[ aForces ][ pId ];
78 out->SetPoint( pId, pnt );
79 this->InvokeEvent( PointUpdatedEvent( pId ) );
84 this->InvokeEvent( AllMeshUpdatedEvent( ) );
89 #endif // __CPM__ALGORITHMS__SIMPLEX__DEFORMATIONFILTER__HXX__