#ifndef __fpa__Image__SkeletonToPolyDataFilter__h__
#define __fpa__Image__SkeletonToPolyDataFilter__h__
-#include <vtkPolyDataAlgorithm.h>
+#include <fpa/Config.h>
+
+#ifdef USE_VTK
+# include <vtkPolyDataAlgorithm.h>
+#endif // USE_VTK
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( );
SkeletonToPolyDataFilter( );
virtual ~SkeletonToPolyDataFilter( );
+#ifdef USE_VTK
int RequestData(
vtkInformation* information,
vtkInformationVector** input,
vtkInformationVector** input,
vtkInformationVector* output
);
+#endif // USE_VTK
private:
// Purposely not implemented
#ifndef __fpa__Image__SkeletonToPolyDataFilter__hxx__
#define __fpa__Image__SkeletonToPolyDataFilter__hxx__
-#include <vtkCellArray.h>
-#include <vtkInformation.h>
-#include <vtkInformationVector.h>
-#include <vtkSmartPointer.h>
+#ifdef USE_VTK
+# include <vtkCellArray.h>
+# include <vtkInformation.h>
+# include <vtkInformationVector.h>
+# include <vtkPointData.h>
+# include <vtkUnsignedIntArray.h>
+# include <vtkSmartPointer.h>
+#endif // USE_VTK
// -------------------------------------------------------------------------
template< class _TSkeleton >
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
}
// -------------------------------------------------------------------------
{
}
+#ifdef USE_VTK
// -------------------------------------------------------------------------
template< class _TSkeleton >
int fpa::Image::SkeletonToPolyDataFilter< _TSkeleton >::
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;
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 );
} // fi
} // rof
+ dcount++;
} // rof
{
return( 1 );
}
+#endif // USE_VTK
#endif // __fpa__Image__SkeletonToPolyDataFilterFilter__hxx__
--- /dev/null
+
+#include <vtkPolyDataWriter.h>
+#include <vtkSmartPointer.h>
+
+#include <fpa/Image/Skeleton.h>
+#include <fpa/Image/SkeletonReader.h>
+#include <fpa/Image/SkeletonToPolyDataFilter.h>
+
+// -------------------------------------------------------------------------
+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$