From: Leonardo Flórez-Valencia Date: Tue, 20 Jun 2017 01:20:27 +0000 (-0500) Subject: ... X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=5316aea88898a23d42b50aff9d0cb56c3a3afa1d;p=FrontAlgorithms.git ... --- diff --git a/lib/fpa/Config.h.in b/lib/fpa/Config.h.in index 18294bf..708dec1 100644 --- a/lib/fpa/Config.h.in +++ b/lib/fpa/Config.h.in @@ -6,6 +6,13 @@ #ifndef __fpa__Config__h__ #define __fpa__Config__h__ +#define VTK_FOUND @VTK_FOUND@ +#if VTK_FOUND == 1 +# define USE_VTK +#else +# undef USE_VTK +#endif + #define ivq_FOUND @ivq_FOUND@ #if ivq_FOUND == 1 # define USE_ivq diff --git a/lib/fpa/Image/SkeletonFilter.hxx b/lib/fpa/Image/SkeletonFilter.hxx index 224829b..6a32237 100644 --- a/lib/fpa/Image/SkeletonFilter.hxx +++ b/lib/fpa/Image/SkeletonFilter.hxx @@ -218,6 +218,7 @@ GenerateData( ) it = mst->GetParent( it ); } // elihw + tags[ it ] = nTag; branches[ bIt->first ] = p; } else diff --git a/lib/fpa/Image/SkeletonToPolyDataFilter.h b/lib/fpa/Image/SkeletonToPolyDataFilter.h index f98e8bc..9c2b941 100644 --- a/lib/fpa/Image/SkeletonToPolyDataFilter.h +++ b/lib/fpa/Image/SkeletonToPolyDataFilter.h @@ -6,7 +6,11 @@ #ifndef __fpa__Image__SkeletonToPolyDataFilter__h__ #define __fpa__Image__SkeletonToPolyDataFilter__h__ -#include +#include + +#ifdef USE_VTK +# include +#endif // USE_VTK namespace fpa { @@ -16,14 +20,18 @@ namespace fpa */ template< class _TSkeleton > class SkeletonToPolyDataFilter +#ifdef USE_VTK : public vtkPolyDataAlgorithm +#endif // USE_VTK { public: typedef SkeletonToPolyDataFilter Self; - typedef _TSkeleton TSkeleton; + typedef _TSkeleton TSkeleton; public: +#ifdef USE_VTK vtkTypeMacro( SkeletonToPolyDataFilter, vtkPolyDataAlgorithm ); +#endif // USE_VTK public: static Self* New( ); @@ -35,6 +43,7 @@ namespace fpa SkeletonToPolyDataFilter( ); virtual ~SkeletonToPolyDataFilter( ); +#ifdef USE_VTK int RequestData( vtkInformation* information, vtkInformationVector** input, @@ -45,6 +54,7 @@ namespace fpa vtkInformationVector** input, vtkInformationVector* output ); +#endif // USE_VTK private: // Purposely not implemented diff --git a/lib/fpa/Image/SkeletonToPolyDataFilter.hxx b/lib/fpa/Image/SkeletonToPolyDataFilter.hxx index 9468c4b..c9d1136 100644 --- a/lib/fpa/Image/SkeletonToPolyDataFilter.hxx +++ b/lib/fpa/Image/SkeletonToPolyDataFilter.hxx @@ -6,10 +6,14 @@ #ifndef __fpa__Image__SkeletonToPolyDataFilter__hxx__ #define __fpa__Image__SkeletonToPolyDataFilter__hxx__ -#include -#include -#include -#include +#ifdef USE_VTK +# include +# include +# include +# include +# include +# include +#endif // USE_VTK // ------------------------------------------------------------------------- template< class _TSkeleton > @@ -38,7 +42,9 @@ SetInput( const TSkeleton* sk ) if( this->m_Skeleton != sk ) { this->m_Skeleton = sk; +#ifdef USE_VTK this->Modified( ); +#endif // USE_VTK } // fi } @@ -47,10 +53,14 @@ SetInput( const TSkeleton* sk ) template< class _TSkeleton > fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: SkeletonToPolyDataFilter( ) +#ifdef USE_VTK : vtkPolyDataAlgorithm( ), m_Skeleton( NULL ) +#endif // USE_VTK { +#ifdef USE_VTK this->SetNumberOfInputPorts( 0 ); +#endif // USE_VTK } // ------------------------------------------------------------------------- @@ -60,6 +70,7 @@ fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: { } +#ifdef USE_VTK // ------------------------------------------------------------------------- template< class _TSkeleton > int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: @@ -87,19 +98,24 @@ RequestData( 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( ); // Assign all data - typename TMatrix::const_iterator mIt = this->m_Skeleton->BeginEdgesRows( ); + unsigned int dcount = 0; + typename TSkeleton::TMatrix::const_iterator mIt = this->m_Skeleton->BeginEdgesRows( ); for( ; mIt != this->m_Skeleton->EndEdgesRows( ); ++mIt ) { // TODO: mIt->first; --> this is the row index. <-- - typename TMatrixRow::const_iterator rIt = mIt->second.begin( ); + typename TSkeleton::TMatrixRow::const_iterator rIt = mIt->second.begin( ); for( ; rIt != mIt->second.end( ); ++rIt ) { // TODO: rIt->first; --> this is the column index. - typename TEdges::const_iterator eIt = rIt->second.begin( ); + typename TSkeleton::TEdges::const_iterator eIt = rIt->second.begin( ); for( ; eIt != rIt->second.end( ); ++eIt ) { _TPath* path = *eIt; @@ -112,6 +128,7 @@ RequestData( points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], 0 ); else points->InsertNextPoint( pnt[ 0 ], pnt[ 1 ], pnt[ 2 ] ); + darray->InsertNextTuple1( double( dcount ) ); if( i > 0 ) { lines->InsertNextCell( 2 ); @@ -121,6 +138,7 @@ RequestData( } // fi } // rof + dcount++; } // rof @@ -141,6 +159,7 @@ RequestInformation( { return( 1 ); } +#endif // USE_VTK #endif // __fpa__Image__SkeletonToPolyDataFilterFilter__hxx__ diff --git a/tests/image/CMakeLists.txt b/tests/image/CMakeLists.txt index 00facdf..c51ed18 100644 --- a/tests/image/CMakeLists.txt +++ b/tests/image/CMakeLists.txt @@ -6,6 +6,7 @@ set( Dijkstra_Gaussian RandomWalker SkeletonFilter + SkeletonToPolyData ) foreach(_e ${_examples}) add_executable(${_pfx}${_e} ${_e}.cxx) diff --git a/tests/image/SkeletonToPolyData.cxx b/tests/image/SkeletonToPolyData.cxx new file mode 100644 index 0000000..6ee6fd8 --- /dev/null +++ b/tests/image/SkeletonToPolyData.cxx @@ -0,0 +1,63 @@ + +#include +#include + +#include +#include +#include + +// ------------------------------------------------------------------------- +const unsigned int Dim = 3; +typedef fpa::Image::Skeleton< Dim > TSkeleton; +typedef fpa::Image::SkeletonToPolyDataFilter< TSkeleton > TFilter; + +// ------------------------------------------------------------------------- +int main( int argc, char* argv[] ) +{ +#ifdef USE_VTK + // Get arguments + if( argc < 3 ) + { + std::cerr + << "Usage: " << argv[ 0 ] + << " input_skeleton output_polydata" + << std::endl; + return( 1 ); + + } // fi + std::string input_skeleton_filename = argv[ 1 ]; + std::string output_polydata_filename = argv[ 2 ]; + + fpa::Image::SkeletonReader< TSkeleton >::Pointer reader = + fpa::Image::SkeletonReader< TSkeleton >::New( ); + reader->SetFileName( input_skeleton_filename ); + try + { + reader->Update( ); + } + catch( std::exception& err ) + { + std::cerr << "Error caught: " << err.what( ) << std::endl; + return( 1 ); + + } // yrt + + vtkSmartPointer< TFilter > filter = vtkSmartPointer< TFilter >::New( ); + filter->SetInput( reader->GetOutput( ) ); + + vtkSmartPointer< vtkPolyDataWriter > writer = + vtkSmartPointer< vtkPolyDataWriter >::New( ); + writer->SetInputConnection( filter->GetOutputPort( ) ); + writer->SetFileName( output_polydata_filename.c_str( ) ); + writer->Update( ); + + return( 0 ); +#else // USE_VTK + std::cerr + << "Error: FrontAlgorithms was compiled without VTK support." + << std::endl; + return( 1 ); +#endif // USE_VTK +} + +// eof - $RCSfile$