]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Oct 2017 16:43:45 +0000 (11:43 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Mon, 9 Oct 2017 16:43:45 +0000 (11:43 -0500)
lib/ivq/VTK/ImagePathToPolyDataFilter.h [new file with mode: 0644]
lib/ivq/VTK/ImagePathToPolyDataFilter.hxx [new file with mode: 0644]
lib/ivq/VTK/ImageSkeletonToPolyDataFilter.h [new file with mode: 0644]
lib/ivq/VTK/ImageSkeletonToPolyDataFilter.hxx [new file with mode: 0644]

diff --git a/lib/ivq/VTK/ImagePathToPolyDataFilter.h b/lib/ivq/VTK/ImagePathToPolyDataFilter.h
new file mode 100644 (file)
index 0000000..76e9a9f
--- /dev/null
@@ -0,0 +1,66 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __ivq__VTK__ImagePathToPolyDataFilter__h__
+#define __ivq__VTK__ImagePathToPolyDataFilter__h__
+
+#include <vtkPolyDataAlgorithm.h>
+
+namespace ivq
+{
+  namespace VTK
+  {
+    /**
+     */
+    template< class _TPath >
+    class ImagePathToPolyDataFilter
+      : public vtkPolyDataAlgorithm
+    {
+    public:
+      typedef ImagePathToPolyDataFilter Self;
+      typedef _TPath                    TPath;
+
+    public:
+      vtkTypeMacro( ImagePathToPolyDataFilter, vtkPolyDataAlgorithm );
+
+    public:
+      static Self* New( );
+
+      const TPath* GetInput( ) const;
+      void SetInput( const TPath* path );
+
+    protected:
+      ImagePathToPolyDataFilter( );
+      virtual ~ImagePathToPolyDataFilter( );
+
+      int RequestData(
+        vtkInformation* information,
+        vtkInformationVector** input,
+        vtkInformationVector* output
+        );
+      int RequestInformation(
+        vtkInformation* information,
+        vtkInformationVector** input,
+        vtkInformationVector* output
+        );
+
+    private:
+      // Purposely not implemented
+      ImagePathToPolyDataFilter( const Self& );
+      void operator=( const Self& );
+
+    protected:
+      const TPath* m_Path;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <ivq/VTK/ImagePathToPolyDataFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+#endif // __ivq__VTK__ImagePathToPolyDataFilter__h__
+
+// eof - $RCSfile$
diff --git a/lib/ivq/VTK/ImagePathToPolyDataFilter.hxx b/lib/ivq/VTK/ImagePathToPolyDataFilter.hxx
new file mode 100644 (file)
index 0000000..f212523
--- /dev/null
@@ -0,0 +1,133 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __ivq__VTK__ImagePathToPolyDataFilter__hxx__
+#define __ivq__VTK__ImagePathToPolyDataFilter__hxx__
+
+#include <vtkCellArray.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkPointData.h>
+#include <vtkUnsignedIntArray.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+typename ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+Self* ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+const typename
+ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+TPath* ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+GetInput( ) const
+{
+  return( this->m_Path );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+void ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+SetInput( const TPath* path )
+{
+  if( this->m_Path != path )
+  {
+    this->m_Path = path;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+ImagePathToPolyDataFilter( )
+  : vtkPolyDataAlgorithm( ),
+    m_Path( NULL )
+{
+  this->SetNumberOfInputPorts( 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+~ImagePathToPolyDataFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+int ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+RequestData(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  static const unsigned int dim = TPath::PathDimension;
+  if( this->m_Path == 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
+  const TPath* path = this->GetInput( );
+  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( i ) );
+    if( i > 0 )
+    {
+      lines->InsertNextCell( 2 );
+      lines->InsertCellPoint( points->GetNumberOfPoints( ) - 2 );
+      lines->InsertCellPoint( points->GetNumberOfPoints( ) - 1 );
+
+    } // fi
+
+  } // rof
+  return( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+int ivq::VTK::Image::ImagePathToPolyDataFilter< _TPath >::
+RequestInformation(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  return( 1 );
+}
+
+#endif // __ivq__VTK__ImagePathToPolyDataFilterFilter__hxx__
+// eof - $RCSfile$
diff --git a/lib/ivq/VTK/ImageSkeletonToPolyDataFilter.h b/lib/ivq/VTK/ImageSkeletonToPolyDataFilter.h
new file mode 100644 (file)
index 0000000..2377cec
--- /dev/null
@@ -0,0 +1,67 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __ivq__VTK__ImageSkeletonToPolyDataFilter__h__
+#define __ivq__VTK__ImageSkeletonToPolyDataFilter__h__
+
+#include <vtkPolyDataAlgorithm.h>
+
+namespace ivq
+{
+  namespace VTK
+  {
+    /**
+     */
+    template< class _TSkeleton >
+    class ImageSkeletonToPolyDataFilter
+      : public vtkPolyDataAlgorithm
+    {
+    public:
+      typedef ImageSkeletonToPolyDataFilter Self;
+      typedef _TSkeleton                    TSkeleton;
+
+    public:
+      vtkTypeMacro( ImageSkeletonToPolyDataFilter, vtkPolyDataAlgorithm );
+
+    public:
+      static Self* New( );
+
+      const TSkeleton* GetInput( ) const;
+      void SetInput( const TSkeleton* sk );
+
+    protected:
+      ImageSkeletonToPolyDataFilter( );
+      virtual ~ImageSkeletonToPolyDataFilter( );
+
+      int RequestData(
+        vtkInformation* information,
+        vtkInformationVector** input,
+        vtkInformationVector* output
+        );
+      int RequestInformation(
+        vtkInformation* information,
+        vtkInformationVector** input,
+        vtkInformationVector* output
+        );
+
+    private:
+      // Purposely not implemented
+      ImageSkeletonToPolyDataFilter( const Self& );
+      void operator=( const Self& );
+
+    protected:
+      const TSkeleton* m_Skeleton;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <ivq/VTK/Image/ImageSkeletonToPolyDataFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __ivq__VTK__ImageSkeletonToPolyDataFilter__h__
+
+// eof - $RCSfile$
diff --git a/lib/ivq/VTK/ImageSkeletonToPolyDataFilter.hxx b/lib/ivq/VTK/ImageSkeletonToPolyDataFilter.hxx
new file mode 100644 (file)
index 0000000..51d2576
--- /dev/null
@@ -0,0 +1,154 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __ivq__VTK__ImageSkeletonToPolyDataFilter__hxx__
+#define __ivq__VTK__ImageSkeletonToPolyDataFilter__hxx__
+
+#include <vtkCellArray.h>
+#include <vtkInformation.h>
+#include <vtkInformationVector.h>
+#include <vtkPointData.h>
+#include <vtkUnsignedIntArray.h>
+#include <vtkSmartPointer.h>
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+typename ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+Self* ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+New( )
+{
+  return( new Self( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+const typename
+ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+TSkeleton* ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+GetInput( ) const
+{
+  return( this->m_Skeleton );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+SetInput( const TSkeleton* sk )
+{
+  if( this->m_Skeleton != sk )
+  {
+    this->m_Skeleton = sk;
+    this->Modified( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+ImageSkeletonToPolyDataFilter( )
+  : vtkPolyDataAlgorithm( ),
+    m_Skeleton( NULL )
+{
+  this->SetNumberOfInputPorts( 0 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+~ImageSkeletonToPolyDataFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+int ivq::VTK::ImageSkeletonToPolyDataFilter< _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 ivq::VTK::ImageSkeletonToPolyDataFilter< _TSkeleton >::
+RequestInformation(
+  vtkInformation* information,
+  vtkInformationVector** input,
+  vtkInformationVector* output
+  )
+{
+  return( 1 );
+}
+
+#endif // __ivq__VTK__ImageSkeletonToPolyDataFilterFilter__hxx__
+// eof - $RCSfile$