// ========================================================================= // @author Leonardo Florez Valencia // @email florez-l@javeriana.edu.co // ========================================================================= #ifndef __fpa__Image__SkeletonToPolyDataFilter__hxx__ #define __fpa__Image__SkeletonToPolyDataFilter__hxx__ #ifdef USE_VTK # include # include # include # include # include # include #endif // USE_VTK // ------------------------------------------------------------------------- template< class _TSkeleton > typename fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: Self* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: New( ) { return( new Self( ) ); } // ------------------------------------------------------------------------- template< class _TSkeleton > const typename fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: TSkeleton* fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: GetInput( ) const { return( this->m_Skeleton ); } // ------------------------------------------------------------------------- template< class _TSkeleton > void fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: SetInput( const TSkeleton* sk ) { if( this->m_Skeleton != sk ) { this->m_Skeleton = sk; #ifdef USE_VTK this->Modified( ); #endif // USE_VTK } // fi } // ------------------------------------------------------------------------- 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 } // ------------------------------------------------------------------------- template< class _TSkeleton > fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: ~SkeletonToPolyDataFilter( ) { } #ifdef USE_VTK // ------------------------------------------------------------------------- template< class _TSkeleton > int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: RequestData( vtkInformation* information, vtkInformationVector** input, vtkInformationVector* output ) { typedef typename _TSkeleton::TPath _TPath; static const unsigned int dim = _TPath::PathDimension; if( this->m_Skeleton == NULL ) return( 0 ); // Get output vtkInformation* info = output->GetInformationObject( 0 ); vtkPolyData* out = vtkPolyData::SafeDownCast( info->Get( vtkDataObject::DATA_OBJECT( ) ) ); // 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( ); // Assign all data 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 TSkeleton::TMatrixRow::const_iterator rIt = mIt->second.begin( ); for( ; rIt != mIt->second.end( ); ++rIt ) { // TODO: rIt->first; --> this is the column index. typename TSkeleton::TEdges::const_iterator eIt = rIt->second.begin( ); for( ; eIt != rIt->second.end( ); ++eIt ) { _TPath* path = *eIt; for( unsigned long i = 0; i < path->GetSize( ); ++i ) { 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( dcount ) ); if( i > 0 ) { lines->InsertNextCell( 2 ); lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 ); lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 ); } // fi } // rof dcount++; } // rof } // rof } // rof return( 1 ); } // ------------------------------------------------------------------------- template< class _TSkeleton > int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >:: RequestInformation( vtkInformation* information, vtkInformationVector** input, vtkInformationVector* output ) { return( 1 ); } #endif // USE_VTK #endif // __fpa__Image__SkeletonToPolyDataFilterFilter__hxx__ // eof - $RCSfile$