X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=plugins%2FRegionGrowFunctors%2FBinaryThreshold.cxx;fp=plugins%2FRegionGrowFunctors%2FBinaryThreshold.cxx;h=3a4da319d5356fec385fcabb4857ed9fbbcdd200;hb=40fb0405cfef444001429f8ba49c407ce9168a94;hp=f385e4aa3d4d3a3c62d0ad75519668ed4561f0bd;hpb=cf298be2de026712c5ab3487978e3a6954a809cd;p=FrontAlgorithms.git diff --git a/plugins/RegionGrowFunctors/BinaryThreshold.cxx b/plugins/RegionGrowFunctors/BinaryThreshold.cxx index f385e4a..3a4da31 100644 --- a/plugins/RegionGrowFunctors/BinaryThreshold.cxx +++ b/plugins/RegionGrowFunctors/BinaryThreshold.cxx @@ -42,82 +42,84 @@ template< class _TImage > void fpaPluginsRegionGrowFunctors::BinaryThreshold:: _GD0( _TImage* image ) { - typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt; - typedef - fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage > - _TFunctor; - auto out = this->GetOutput( "Output" ); - auto f = out->GetITK< _TFunctor >( ); - if( f == NULL ) - { - typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); - f = ptr_f.GetPointer( ); - out->SetITK( f ); - - } // fi - - // Compute thresholds from seeds - auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); - if( seeds != NULL ) - { - std::vector< typename _TImage::IndexType > indices; - typename _TImage::PointType pnt; - typename _TImage::IndexType idx; - unsigned int dim = - ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; - - for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) - { - double buf[ 3 ]; - seeds->GetPoint( i, buf ); - pnt.Fill( 0 ); - for( unsigned int d = 0; d < dim; ++d ) - pnt[ d ] = buf[ d ]; - if( image->TransformPhysicalPointToIndex( pnt, idx ) ) - indices.push_back( idx ); - - } // rof - - typename _TImage::SizeType r; - r.Fill( this->m_Parameters.GetUint( "Radius" ) ); - - _TInIt iIt( r, image, image->GetRequestedRegion( ) ); - double v_s1 = double( 0 ); - double v_s2 = double( 0 ); - double v_n = double( 0 ); - double v_min = std::numeric_limits< double >::max( ); - double v_max = -v_min; - for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt ) - { - iIt.SetLocation( *idxIt ); - for( unsigned int i = 0; i < iIt.Size( ); ++i ) - { - double v = double( iIt.GetPixel( i ) ); - v_s1 += v; - v_s2 += v * v; - v_n += double( 1 ); - v_min = ( v < v_min )? v: v_min; - v_max = ( v_max < v )? v: v_max; - - } // rof - - } // rof - double m = v_s1 / v_n; - double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) ); - s = std::sqrt( s ); - v_min = m - s; - v_max = m + s; - f->SetLower( v_min ); - f->SetUpper( v_max ); - this->m_Parameters.SetReal( "Lower", f->GetLower( ) ); - this->m_Parameters.SetReal( "Upper", f->GetUpper( ) ); - } - else - { - f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); - f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); - - } // fi + /* TODO + typedef itk::ConstNeighborhoodIterator< _TImage > _TInIt; + typedef + fpa::Image::Functors::RegionGrow::BinaryThreshold< _TImage > + _TFunctor; + auto out = this->GetOutput( "Output" ); + auto f = out->GetITK< _TFunctor >( ); + if( f == NULL ) + { + typename _TFunctor::Pointer ptr_f = _TFunctor::New( ); + f = ptr_f.GetPointer( ); + out->SetITK( f ); + + } // fi + + // Compute thresholds from seeds + auto seeds = this->GetInputData< vtkPolyData >( "Seeds" ); + if( seeds != NULL ) + { + std::vector< typename _TImage::IndexType > indices; + typename _TImage::PointType pnt; + typename _TImage::IndexType idx; + unsigned int dim = + ( _TImage::ImageDimension < 3 )? _TImage::ImageDimension: 3; + + for( int i = 0; i < seeds->GetNumberOfPoints( ); ++i ) + { + double buf[ 3 ]; + seeds->GetPoint( i, buf ); + pnt.Fill( 0 ); + for( unsigned int d = 0; d < dim; ++d ) + pnt[ d ] = buf[ d ]; + if( image->TransformPhysicalPointToIndex( pnt, idx ) ) + indices.push_back( idx ); + + } // rof + + typename _TImage::SizeType r; + r.Fill( this->m_Parameters.GetUint( "Radius" ) ); + + _TInIt iIt( r, image, image->GetRequestedRegion( ) ); + double v_s1 = double( 0 ); + double v_s2 = double( 0 ); + double v_n = double( 0 ); + double v_min = std::numeric_limits< double >::max( ); + double v_max = -v_min; + for( auto idxIt = indices.begin( ); idxIt != indices.end( ); ++idxIt ) + { + iIt.SetLocation( *idxIt ); + for( unsigned int i = 0; i < iIt.Size( ); ++i ) + { + double v = double( iIt.GetPixel( i ) ); + v_s1 += v; + v_s2 += v * v; + v_n += double( 1 ); + v_min = ( v < v_min )? v: v_min; + v_max = ( v_max < v )? v: v_max; + + } // rof + + } // rof + double m = v_s1 / v_n; + double s = ( v_s2 - ( ( v_s1 * v_s1 ) / v_n ) ) / ( v_n - double( 1 ) ); + s = std::sqrt( s ); + v_min = m - s; + v_max = m + s; + f->SetLower( v_min ); + f->SetUpper( v_max ); + this->m_Parameters.SetReal( "Lower", f->GetLower( ) ); + this->m_Parameters.SetReal( "Upper", f->GetUpper( ) ); + } + else + { + f->SetLower( this->m_Parameters.GetReal( "Lower" ) ); + f->SetUpper( this->m_Parameters.GetReal( "Upper" ) ); + + } // fi + */ } // eof - $RCSfile$