X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2Ffpa%2FVTK%2FImage%2FPathToPolyDataFilter.hxx;h=49657781bb8bb944c9d9a997f51b547e27563a54;hb=5be07a28290fed315829547221848a0ee90558d1;hp=d66fee640005b2588e450de46d9b5c3208f9a305;hpb=56b8bb48cc05a297a3faa264f8f2a88de21ef203;p=FrontAlgorithms.git diff --git a/lib/fpa/VTK/Image/PathToPolyDataFilter.hxx b/lib/fpa/VTK/Image/PathToPolyDataFilter.hxx index d66fee6..4965778 100644 --- a/lib/fpa/VTK/Image/PathToPolyDataFilter.hxx +++ b/lib/fpa/VTK/Image/PathToPolyDataFilter.hxx @@ -1,178 +1,133 @@ -#ifndef __FPA__VTK__IMAGE__PATHTOPOLYDATAFILTER__HXX__ -#define __FPA__VTK__IMAGE__PATHTOPOLYDATAFILTER__HXX__ +// ========================================================================= +// @author Leonardo Florez Valencia +// @email florez-l@javeriana.edu.co +// ========================================================================= +#ifndef __fpa__VTK__Image__PathToPolyDataFilter__hxx__ +#define __fpa__VTK__Image__PathToPolyDataFilter__hxx__ #include #include #include #include -#include +#include #include -#include // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -typename fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -Self* fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: +template< class _TPath > +typename fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: +Self* fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -const typename fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -TMinimumSpanningTree* -fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -GetMinimumSpanningTree( ) const +template< class _TPath > +const typename +fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: +TPath* fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: +GetInput( ) const { - return( this->m_MST ); + return( this->m_Path ); } // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -const typename fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -TImage* fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -GetImage( ) const +template< class _TPath > +void fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: +SetInput( const TPath* path ) { - return( this->m_Image ); -} - -// ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -void fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -SetMinimumSpanningTree( const TMinimumSpanningTree* mst ) -{ - if( this->m_MST != mst ) + if( this->m_Path != path ) { - this->m_MST = mst; + this->m_Path = path; this->Modified( ); } // fi } // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -void fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -SetImage( const TImage* image ) -{ - if( this->m_Image != image ) - { - this->m_Image = image; - this->Modified( ); - - } // fi -} - -// ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: +template< class _TPath > +fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: PathToPolyDataFilter( ) : vtkPolyDataAlgorithm( ), - m_MST( NULL ), - m_Image( NULL ) + m_Path( NULL ) { this->SetNumberOfInputPorts( 0 ); } - + // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: +template< class _TPath > +fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: ~PathToPolyDataFilter( ) { } // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -int fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: +template< class _TPath > +int fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: RequestData( vtkInformation* information, vtkInformationVector** input, vtkInformationVector* output ) { - if( this->m_MST == NULL || this->m_Image == NULL ) - return( 0 ); - auto path = this->m_MST->GetPath( this->Seed0, this->Seed1 ); - if( path.size( ) == 0 ) + static const unsigned int dim = TPath::PathDimension; + if( this->m_Path == NULL ) return( 0 ); - // Prepare output + // Get output vtkInformation* info = output->GetInformationObject( 0 ); vtkPolyData* out = vtkPolyData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) ); - this->_PrepareOutput( out ); + + // Prepare data + out->SetPoints( vtkSmartPointer< vtkPoints >::New( ) ); + out->SetVerts( vtkSmartPointer< vtkCellArray >::New( ) ); + out->SetLines( vtkSmartPointer< vtkCellArray >::New( ) ); + out->SetPolys( vtkSmartPointer< vtkCellArray >::New( ) ); + out->SetStrips( vtkSmartPointer< vtkCellArray >::New( ) ); + vtkSmartPointer< vtkUnsignedIntArray > darray = + vtkSmartPointer< vtkUnsignedIntArray >::New( ); + darray->SetNumberOfComponents( 1 ); + out->GetPointData( )->SetScalars( darray ); vtkPoints* points = out->GetPoints( ); vtkCellArray* lines = out->GetLines( ); - unsigned int i = 0; - for( auto pIt = path.begin( ); pIt != path.end( ); ++pIt, ++i ) + // Assign all data + const TPath* path = this->GetInput( ); + for( unsigned long i = 0; i < path->GetSize( ); ++i ) { - typename TImage::PointType p; - this->m_Image->TransformIndexToPhysicalPoint( *pIt, p ); - if( TImage::ImageDimension == 1 ) - points->InsertNextPoint( double( p[ 0 ] ), double( 0 ), double( 0 ) ); - else if( TImage::ImageDimension == 2 ) - points->InsertNextPoint( double( p[ 0 ] ), double( p[ 1 ] ), double( 0 ) ); - else if( TImage::ImageDimension > 2 ) - points->InsertNextPoint( double( p[ 0 ] ), double( p[ 1 ] ), double( p[ 2 ] ) ); - + auto pnt = path->GetPoint( i ); + if( dim == 1 ) + points->InsertNextPoint( pnt[ 0 ], 0, 0 ); + else if( dim == 2 ) + points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 ); + else + points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] ); + darray->InsertNextTuple1( double( i ) ); if( i > 0 ) { lines->InsertNextCell( 2 ); - lines->InsertCellPoint( i - 1 ); - lines->InsertCellPoint( i ); + lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 ); + lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 ); } // fi } // rof - out->Modified( ); return( 1 ); } // ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -int fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: +template< class _TPath > +int fpa::VTK::Image::PathToPolyDataFilter< _TPath >:: RequestInformation( vtkInformation* information, vtkInformationVector** input, vtkInformationVector* output ) { - vtkInformation* out = output->GetInformationObject( 0 ); - out->Set( CAN_HANDLE_PIECE_REQUEST( ), 1 ); return( 1 ); } -// ------------------------------------------------------------------------- -template< class _TMinimumSpanningTree > -void fpa::VTK::Image::PathToPolyDataFilter< _TMinimumSpanningTree >:: -_PrepareOutput( vtkPolyData* out ) -{ - // Prepare points - vtkPoints* points = out->GetPoints( ); - if( points == NULL ) - { - points = vtkPoints::New( ); - out->SetPoints( points ); - points->Delete( ); - - } // fi - - // Prepare points - vtkCellArray* lines = out->GetLines( ); - if( lines == NULL ) - { - lines = vtkCellArray::New( ); - out->SetLines( lines ); - out->SetVerts( vtkCellArray::New( ) ); - out->SetPolys( vtkCellArray::New( ) ); - out->SetStrips( vtkCellArray::New( ) ); - lines->Delete( ); - - } // fi -} - -#endif // __FPA__VTK__IMAGE__PATHTOPOLYDATAFILTER__HXX__ - +#endif // __fpa__VTK__Image__PathToPolyDataFilterFilter__hxx__ // eof - $RCSfile$