]> Creatis software - FrontAlgorithms.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Tue, 20 Jun 2017 01:20:27 +0000 (20:20 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Tue, 20 Jun 2017 01:20:27 +0000 (20:20 -0500)
lib/fpa/Config.h.in
lib/fpa/Image/SkeletonFilter.hxx
lib/fpa/Image/SkeletonToPolyDataFilter.h
lib/fpa/Image/SkeletonToPolyDataFilter.hxx
tests/image/CMakeLists.txt
tests/image/SkeletonToPolyData.cxx [new file with mode: 0644]

index 18294bf750c8374c4ca1f5dfe0ac272729ff0a3b..708dec1f9f21d52b344660b0e93949f41188ce1f 100644 (file)
@@ -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
index 224829b93f5a37119a5ceea5f3421b26814b9f43..6a322371c3a5a4d0b6b4d447ce422417de12a554 100644 (file)
@@ -218,6 +218,7 @@ GenerateData( )
         it = mst->GetParent( it );
 
       } // elihw
+      tags[ it ] = nTag;
       branches[ bIt->first ] = p;
     }
     else
index f98e8bc68a8100d643d20e71b64f12632b04c337..9c2b94105f610a9446a848961f82b74e94f595c5 100644 (file)
@@ -6,7 +6,11 @@
 #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
 {
@@ -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
index 9468c4baf5debe3b728708c34965f3aab22aacb2..c9d1136e99f5d3aa8ad78321d2d5cb4a038d0ecf 100644 (file)
@@ -6,10 +6,14 @@
 #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 >
@@ -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__
 
index 00facdf649ed3889c6f3cd36870cfb77e4c7ddf2..c51ed1858267349084a18045235d1c8a0f05a2de 100644 (file)
@@ -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 (file)
index 0000000..6ee6fd8
--- /dev/null
@@ -0,0 +1,63 @@
+
+#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$