]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/VTK/Image/SkeletonToPolyDataFilter.hxx
...
[FrontAlgorithms.git] / lib / fpa / VTK / Image / SkeletonToPolyDataFilter.hxx
diff --git a/lib/fpa/VTK/Image/SkeletonToPolyDataFilter.hxx b/lib/fpa/VTK/Image/SkeletonToPolyDataFilter.hxx
new file mode 100644 (file)
index 0000000..6b1aeef
--- /dev/null
@@ -0,0 +1,154 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __fpa__VTK__Image__SkeletonToPolyDataFilter__hxx__
+#define __fpa__VTK__Image__SkeletonToPolyDataFilter__hxx__
+
+#include <vtkCellArray.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkPointData.h>
+#include <vtkUnsignedIntArray.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+typename fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+Self* fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+const typename
+fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+TSkeleton* fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+GetInput( ) const
+{
+  return( this->m_Skeleton );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+SetInput( const TSkeleton* sk )
+{
+  if( this->m_Skeleton != sk )
+  {
+    this->m_Skeleton = sk;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+SkeletonToPolyDataFilter( )
+  : vtkPolyDataAlgorithm( ),
+    m_Skeleton( NULL )
+{
+  this->SetNumberOfInputPorts( 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+fpa::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+~SkeletonToPolyDataFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+int fpa::VTK::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::VTK::Image::SkeletonToPolyDataFilter< _TSkeleton >::
+RequestInformation(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  return( 1 );
+}
+
+#endif // __fpa__VTK__Image__SkeletonToPolyDataFilterFilter__hxx__
+// eof - $RCSfile$