X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=lib%2Ffpa%2FImage%2FEndPointsFilter.hxx;h=c2e1d1c3d2b8b8108bc2711d5c090a15e4dece16;hb=86a6d5df2aa1aa5292a5fa851d98bfc13939bdf3;hp=a4c170ef5b74af9a46b0df03d993da589fb8a2d2;hpb=89cb3fe6360b8ff2513bb84eaeb35a2e7fb4ec8d;p=FrontAlgorithms.git diff --git a/lib/fpa/Image/EndPointsFilter.hxx b/lib/fpa/Image/EndPointsFilter.hxx index a4c170e..c2e1d1c 100644 --- a/lib/fpa/Image/EndPointsFilter.hxx +++ b/lib/fpa/Image/EndPointsFilter.hxx @@ -33,10 +33,20 @@ Compute( ) typedef itk::ImageRegionConstIteratorWithIndex< _TCostMap > _TCostMapIt; typedef std::multimap< double, TIndex, std::greater< double > > _TQueue; typedef typename _TQueue::value_type _TQueueValue; + typedef itk::Image< unsigned char, _TCostMap::ImageDimension > _TMarks; // Some values typename _TDistanceMap::RegionType region = this->m_DistanceMap->GetRequestedRegion( ); + typename _TMarks::Pointer marks = _TMarks::New( ); + marks->SetLargestPossibleRegion( this->m_DistanceMap->GetLargestPossibleRegion( ) ); + marks->SetRequestedRegion( this->m_DistanceMap->GetRequestedRegion( ) ); + marks->SetBufferedRegion( this->m_DistanceMap->GetBufferedRegion( ) ); + marks->SetSpacing( this->m_DistanceMap->GetSpacing( ) ); + marks->SetOrigin( this->m_DistanceMap->GetOrigin( ) ); + marks->SetDirection( this->m_DistanceMap->GetDirection( ) ); + marks->Allocate( ); + marks->FillBuffer( 0 ); // Create queue _TQueue queue; @@ -49,7 +59,7 @@ Compute( ) double d = double( dIt.Get( ) ); if( d > 0 ) { - double v = double( cIt.Get( ) ) / d; + double v = double( cIt.Get( ) ) / ( d * d ); queue.insert( _TQueueValue( v, dIt.GetIndex( ) ) ); } // fi @@ -57,18 +67,20 @@ Compute( ) } // rof // BFS from maximum queue - TIndices marks; while( queue.size( ) > 0 ) { // Get node auto nIt = queue.begin( ); auto n = *nIt; queue.erase( nIt ); - if( marks.find( n.second ) != marks.end( ) ) + + unsigned char m = marks->GetPixel( n.second ); + if( ( m & 0x01 ) == 0x01 ) continue; // Mark it - marks.insert( n.second ); + m |= 0x01; + marks->SetPixel( n.second, m ); this->m_EndPoints.insert( n.second ); // Get path @@ -76,78 +88,49 @@ Compute( ) this->m_MST->GetPath( path, n.second ); for( unsigned long i = 0; i < path->GetSize( ); ++i ) { - typename TMST::TPath::TContinuousIndex cidx = path->GetVertex( i ); + TIndex idx = path->GetVertex( path->GetSize( ) - 1 - i ); typename _TCostMap::PointType cnt; - this->m_CostMap->TransformContinuousIndexToPhysicalPoint( cidx, cnt ); - TIndex idx; - this->m_CostMap->TransformPhysicalPointToIndex( cnt, idx ); + this->m_CostMap->TransformIndexToPhysicalPoint( idx, cnt ); double d = double( this->m_DistanceMap->GetPixel( idx ) ); - - /* TODO - TIndex idx; - for( unsigned int d = 0; d < _TCostMap::ImageDimension; ++d ) - idx[ d ] = cidx[ d ]; - */ + d *= double( 2 ); + + // Mark sphere + std::queue< TIndex > q; + q.push( idx ); + while( q.size( ) > 0 ) + { + TIndex v = q.front( ); + q.pop( ); + unsigned char m = marks->GetPixel( v ); + if( ( m & 0x02 ) == 0x02 ) + continue; + m |= 0x03; + marks->SetPixel( v, m ); + + for( unsigned int x = 0; x < _TCostMap::ImageDimension; ++x ) + { + for( int y = -1; y <= 1; y += 2 ) + { + TIndex w = v; + w[ x ] += y; + if( region.IsInside( w ) ) + { + typename _TCostMap::PointType p; + this->m_CostMap->TransformIndexToPhysicalPoint( w, p ); + if( cnt.EuclideanDistanceTo( p ) <= d ) + q.push( w ); + + } // fi + + } // rof + + } // rof + + } // elihw } // rof - // TODO: temporary - queue.clear( ); - } // elihw - - /* TODO - while( queue.size( ) > 0 ) - { - marks.insert( n.second ); - this->m_EndPoints.insert( n.second ); - auto path = this->m_MST->GetPath( n.second ); - std::cout << path.size( ) << std::endl; - for( auto pIt = path.begin( ); pIt != path.end( ); ++pIt ) - { - double d = double( this->m_DistanceMap->GetPixel( *pIt ) ); - d = std::sqrt( std::fabs( d ) ); - typename _TCostMap::PointType center; - - - std::queue< TIndex > q; - TIndices m; - q.push( *pIt ); - while( q.size( ) > 0 ) - { - TIndex idx = q.front( ); - q.pop( ); - if( m.find( idx ) != m.end( ) ) - continue; - m.insert( idx ); - marks.insert( idx ); - for( unsigned int x = 0; x < _TCostMap::ImageDimension; ++x ) - { - for( int y = -1; y <= 1; y += 2 ) - { - TIndex idx2 = idx; - idx2[ x ] += y; - typename _TCostMap::PointType c; - this->m_CostMap->TransformIndexToPhysicalPoint( idx2, c ); - if( this->m_CostMap->GetRequestedRegion( ).IsInside( idx2 ) ) - { - if( center.EuclideanDistanceTo( c ) <= ( d * 1.5 ) ) - q.push( idx2 ); - - } // fi - - } // rof - - } // rof - - } // elihw - - } // rof - - } // fi - - } // elihw - */ } // -------------------------------------------------------------------------