X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FBase%2FMinimumSpanningTree.hxx;h=ad0d06bc00a315e654c77692f9fcef4e5ed4588d;hb=ab4b440668b2007d94345967ac154c4b20aa389f;hp=1140e4022f717616c2aadee581d2898a1488962d;hpb=db33ebb226fd58f493b7db245fc8b807f895ee6e;p=FrontAlgorithms.git diff --git a/lib/fpa/Base/MinimumSpanningTree.hxx b/lib/fpa/Base/MinimumSpanningTree.hxx index 1140e40..ad0d06b 100644 --- a/lib/fpa/Base/MinimumSpanningTree.hxx +++ b/lib/fpa/Base/MinimumSpanningTree.hxx @@ -56,7 +56,6 @@ SetCollisions( const TCollisions& collisions ) } // rof } // rof - this->Modified( ); } @@ -65,8 +64,14 @@ template< class V, class C, class B > void fpa::Base::MinimumSpanningTree< V, C, B >:: GetPath( std::vector< V >& path, const V& a, const V& b ) const { - long fa = this->_FrontId( a ); - long fb = this->_FrontId( b ); + typename TDecorated::const_iterator aIt = this->Get( ).find( a ); + typename TDecorated::const_iterator bIt = this->Get( ).find( b ); + + if( aIt == this->Get( ).end( ) || bIt == this->Get( ).end( ) ) + return; + + short fa = aIt->second.second; + short fb = bIt->second.second; if( fa == fb ) { @@ -144,6 +149,59 @@ GetPath( std::vector< V >& path, const V& a, const V& b ) const } // fi } +// ------------------------------------------------------------------------- +template< class V, class C, class B > +template< class I, class P > +void fpa::Base::MinimumSpanningTree< V, C, B >:: +GetPathFromImage( + std::vector< P >& path, const V& a, const V& b, + const I* image, unsigned int kernel + ) const +{ + std::vector< V > vertices; + this->GetPath( vertices, a, b ); + path.clear( ); + for( unsigned int i = 0; i < vertices.size( ); ++i ) + { + P p; + image->TransformIndexToPhysicalPoint( vertices[ i ], p ); + path.push_back( p ); + + } // rof + + // Lowpass filter + if( kernel > 0 ) + { + int k = int( kernel ) >> 1; + std::vector< P > lowpass_path; + for( unsigned int i = 0; i < path.size( ); ++i ) + { + P p; + p.Fill( ( typename P::ValueType )( 0 ) ); + unsigned int c = 0; + for( int j = -k; j <= k; ++j ) + { + int l = int( i ) + j; + if( l >= 0 && l < path.size( ) ) + { + p += path[ l ].GetVectorFromOrigin( ); + c++; + + } // fi + + } // rof + if( c > 0 ) + for( unsigned int d = 0; d < P::PointDimension; ++d ) + p[ d ] /= ( typename P::ValueType )( c ); + lowpass_path.push_back( p ); + + } // rof + + path = lowpass_path; + + } // fi +} + // ------------------------------------------------------------------------- template< class V, class C, class B > fpa::Base::MinimumSpanningTree< V, C, B >:: @@ -164,14 +222,20 @@ template< class V, class C, class B > void fpa::Base::MinimumSpanningTree< V, C, B >:: _Path( std::vector< V >& path, const V& a ) const { - V it = a; - do + typename TDecorated::const_iterator dIt = this->Get( ).find( a ); + if( dIt != this->Get( ).end( ) ) { - path.push_back( it ); - it = this->_Parent( it ); + do + { + path.push_back( dIt->first ); + dIt = this->Get( ).find( dIt->second.first ); - } while( it != this->_Parent( it ) ); - path.push_back( it ); + } while( dIt->first != dIt->second.first && dIt != this->Get( ).end( ) ); + + if( dIt != this->Get( ).end( ) ) + path.push_back( dIt->first ); + + } // fi } #endif // __FPA__BASE__MINIMUMSPANNINGTREE__HXX__