]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 16 Nov 2016 21:56:23 +0000 (16:56 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 16 Nov 2016 21:56:23 +0000 (16:56 -0500)
lib/cpExtensions/Algorithms/SkeletonToImageFilter.h [new file with mode: 0644]
lib/cpExtensions/Algorithms/SkeletonToImageFilter.hxx [new file with mode: 0644]
lib/cpExtensions/DataStructures/Skeleton.h
plugins/IO/SkeletonToImageFilter.cxx [new file with mode: 0644]
plugins/IO/SkeletonToImageFilter.h [new file with mode: 0644]
plugins/ImageSliceFilters/ResampleImageFilter.cxx [new file with mode: 0644]
plugins/ImageSliceFilters/ResampleImageFilter.h [new file with mode: 0644]

diff --git a/lib/cpExtensions/Algorithms/SkeletonToImageFilter.h b/lib/cpExtensions/Algorithms/SkeletonToImageFilter.h
new file mode 100644 (file)
index 0000000..cd2f8c1
--- /dev/null
@@ -0,0 +1,81 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonToImageFilter__h__
+#define __cpExtensions__Algorithms__SkeletonToImageFilter__h__
+
+#include <cpExtensions/Config.h>
+#include <itkImageSource.h>
+
+// -------------------------------------------------------------------------
+namespace cpExtensions
+{
+  namespace Algorithms
+  {
+    /**
+     */
+    template< class _TSkeleton, class _TImage >
+    class SkeletonToImageFilter
+      : public itk::ImageSource< _TImage >
+    {
+    public:
+      // Basic types
+      typedef SkeletonToImageFilter             Self;
+      typedef itk::ImageSource< _TImage >     Superclass;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
+
+      typedef _TSkeleton TSkeleton;
+      typedef _TImage    TImage;
+      typedef typename _TImage::IndexType  TIndex;
+      typedef typename _TImage::PixelType  TPixel;
+      typedef typename _TImage::PointType  TPoint;
+      typedef typename _TImage::RegionType TRegion;
+      typedef itk::ImageBase< _TImage::ImageDimension > TImageBase;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( SkeletonToImageFilter, itk::ImageSource );
+
+      itkGetConstMacro( InsideValue, TPixel );
+      itkGetConstMacro( OutsideValue, TPixel );
+
+      itkSetMacro( InsideValue, TPixel );
+      itkSetMacro( OutsideValue, TPixel );
+
+    public:
+      const TImageBase* GetTemplateImage( ) const;
+      void SetTemplateImage( TImageBase* image );
+
+      const TSkeleton* GetSkeleton( ) const;
+      void SetSkeleton( TSkeleton* skeleton );
+
+    protected:
+      SkeletonToImageFilter( );
+      virtual ~SkeletonToImageFilter( );
+
+      virtual void GenerateData( ) cpExtensions_OVERRIDE;
+
+    private:
+      // Purposely not implemented
+      SkeletonToImageFilter( const Self& );
+      void operator=( const Self& );
+
+    protected:
+      TPixel m_InsideValue;
+      TPixel m_OutsideValue;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+// -------------------------------------------------------------------------
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <cpExtensions/Algorithms/SkeletonToImageFilter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __cpExtensions__Algorithms__SkeletonToImageFilter__h__
+
+// eof - $RCSfile$
diff --git a/lib/cpExtensions/Algorithms/SkeletonToImageFilter.hxx b/lib/cpExtensions/Algorithms/SkeletonToImageFilter.hxx
new file mode 100644 (file)
index 0000000..237fa79
--- /dev/null
@@ -0,0 +1,103 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonToImageFilter__hxx__
+#define __cpExtensions__Algorithms__SkeletonToImageFilter__hxx__
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+const typename
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+TImageBase*
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+GetTemplateImage( ) const
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+void 
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+SetTemplateImage( TImageBase* image )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+const typename
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+TSkeleton*
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+GetSkeleton( ) const
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+void
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+SetSkeleton( TSkeleton* skeleton )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+SkeletonToImageFilter( )
+  : Superclass( ),
+    m_InsideValue( TPixel( 1 ) ),
+    m_OutsideValue( TPixel( 0 ) )
+{
+  this->SetNumberOfRequiredInputs( 2 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+~SkeletonToImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton, class _TImage >
+void cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage >::
+GenerateData( )
+{
+  const TSkeleton* sk = this->GetSkeleton( );
+  const TImageBase* im = this->GetTemplateImage( );
+  TImage* out = this->GetOutput( 0 );
+
+  out->SetLargestPossibleRegion( im->GetLargestPossibleRegion( ) );
+  out->SetRequestedRegion( im->GetRequestedRegion( ) );
+  out->SetBufferedRegion( im->GetBufferedRegion( ) );
+  out->SetSpacing( im->GetSpacing( ) );
+  out->SetOrigin( im->GetOrigin( ) );
+  out->SetDirection( im->GetDirection( ) );
+  out->Allocate( );
+  out->FillBuffer( this->m_OutsideValue );
+
+  // Fill skeleton
+  auto mIt = sk->BeginEdgesRows( );
+  for( ; mIt != sk->EndEdgesRows( ); ++mIt )
+  {
+    auto rIt = mIt->second.begin( );
+    for( ; rIt != mIt->second.end( ); ++rIt )
+    {
+      auto eIt = rIt->second.begin( );
+      for( ; eIt != rIt->second.end( ); ++eIt )
+      {
+        auto path = *eIt;
+        for( unsigned int i = 0; i < path->GetSize( ); ++i )
+          out->SetPixel( path->GetVertex( i ), this->m_InsideValue );
+
+      } // rof
+
+    } // rof
+
+  } // rof
+}
+
+#endif // __cpExtensions__Algorithms__SkeletonToImageFilter__hxx__
+
+// eof - $RCSfile$
index f30b601714b59a490e03d33be62836041087af4c..70d1dfb2c5bab28947fa6ed7774760f6d9795af9 100644 (file)
@@ -29,6 +29,8 @@ namespace cpExtensions
       itkNewMacro( Self );
       itkTypeMacro( Skeleton, Graph );
 
+      itkStaticConstMacro( Dimension, unsigned int, _VDim );
+
     public:
       void AddBranch( TPath* path );
       const TPath* GetBranch( const TIndex& a, const TIndex& b ) const;
diff --git a/plugins/IO/SkeletonToImageFilter.cxx b/plugins/IO/SkeletonToImageFilter.cxx
new file mode 100644 (file)
index 0000000..a872c05
--- /dev/null
@@ -0,0 +1,60 @@
+#include <IO/SkeletonToImageFilter.h>
+
+#include <cpPluginsExtensions/Skeleton.h>
+#include <cpExtensions/DataStructures/Skeleton.h>
+#include <cpExtensions/Utility.h>
+#include <cpPlugins/DataObjects/Image.h>
+#include <cpPlugins/DataObjects/Image_Demanglers.h>
+#include <cpExtensions/Algorithms/SkeletonToImageFilter.h>
+#include <cpExtensions/Algorithms/SkeletonToImageFilter.hxx>
+
+// -------------------------------------------------------------------------
+cpPluginsIO::SkeletonToImageFilter::
+SkeletonToImageFilter( )
+  : Superclass( )
+{
+  typedef cpPlugins::DataObjects::Image _TImage;
+  typedef cpPluginsExtensions::Skeleton _TSkeleton;
+  this->_ConfigureInput< _TImage >( "TemplateImage", true, false );
+  this->_ConfigureInput< _TSkeleton >( "Skeleton", true, false );
+  this->_ConfigureOutput< _TImage >( "Output" );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsIO::SkeletonToImageFilter::
+~SkeletonToImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsIO::SkeletonToImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Skeleton" );
+  cpPlugins_Demangle_Skeleton_All_1( o, _GD0 )
+    this->_Error( "Invalid input skeleton type." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpPluginsIO::SkeletonToImageFilter::
+_GD0( _TSkeleton* skeleton )
+{
+  typedef itk::Image< unsigned char, _TSkeleton::Dimension > _TImage;
+  typedef typename _TImage::Superclass _TImageBase;
+  typedef cpExtensions::Algorithms::SkeletonToImageFilter< _TSkeleton, _TImage > _TFilter;
+
+  auto image = this->GetInputData< _TImageBase >( "TemplateImage" );
+  if( image == NULL )
+    this->_Error( "Invalid input image." );
+
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetSkeleton( skeleton );
+  filter->SetTemplateImage( image );
+  filter->SetInsideValue( 100 );
+  filter->SetOutsideValue( 0 );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/IO/SkeletonToImageFilter.h b/plugins/IO/SkeletonToImageFilter.h
new file mode 100644 (file)
index 0000000..20cb467
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __cpPluginsIO__SkeletonToImageFilter__h__
+#define __cpPluginsIO__SkeletonToImageFilter__h__
+
+#include <cpPluginsIO_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsIO
+{
+  /**
+   */
+  class cpPluginsIO_EXPORT SkeletonToImageFilter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      SkeletonToImageFilter,
+      cpPlugins::BaseObjects::ProcessObject,
+      IO
+      );
+
+  protected:
+    template< class _TSkeleton >
+    inline void _GD0( _TSkeleton* skeleton );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsIO__SkeletonToImageFilter__h__
+
+// eof - $RCSfile$
diff --git a/plugins/ImageSliceFilters/ResampleImageFilter.cxx b/plugins/ImageSliceFilters/ResampleImageFilter.cxx
new file mode 100644 (file)
index 0000000..5b2cd6c
--- /dev/null
@@ -0,0 +1,73 @@
+#include <ImageSliceFilters/ResampleImageFilter.h>
+#include <cpPlugins/DataObjects/Image.h>
+
+#include <itkImage.h>
+#include <itkResampleImageFilter.h>
+#include <itkIdentityTransform.h>
+
+// -------------------------------------------------------------------------
+cpPluginsImageSliceFilters::ResampleImageFilter::
+ResampleImageFilter( )
+  : Superclass( )
+{
+  typedef cpPlugins::DataObjects::Image _TImage;
+  this->_ConfigureInput< _TImage >( "Image", true, false );
+  this->_ConfigureOutput< _TImage >( "Output" );
+
+  this->m_Parameters.ConfigureAsReal( "ReductionFactor", 1 );
+}
+
+// -------------------------------------------------------------------------
+cpPluginsImageSliceFilters::ResampleImageFilter::
+~ResampleImageFilter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginsImageSliceFilters::ResampleImageFilter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Image" );
+  cpPlugins_Demangle_Image_ScalarPixels_1( o, _GD0, 3 )
+    this->_Error( "Invalid input image." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TImage >
+void cpPluginsImageSliceFilters::ResampleImageFilter::
+_GD0( _TImage* image )
+{
+  typedef itk::ResampleImageFilter< _TImage, _TImage > _TFilter;
+  typedef itk::IdentityTransform< double, _TImage::ImageDimension > _TTransform;
+
+  double r = this->m_Parameters.GetReal( "ReductionFactor" );
+
+  typename _TImage::SizeType in_size = image->GetRequestedRegion( ).GetSize( );
+  typename _TImage::SizeType out_size;
+  for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
+    out_size[ d ] =
+      ( unsigned long )( /*std::ceil*/( double( in_size[ d ] ) * r ) );
+
+  typename _TImage::SpacingType in_spac = image->GetSpacing( );
+  typename _TImage::SpacingType out_spac;
+  for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
+    out_spac[ d ] = in_spac[ d ] * ( double( in_size[ d ] ) / double( out_size[ d ] ) );
+
+  typename _TImage::IndexType idx;
+  idx.Fill( 0 );
+
+  auto filter = this->_CreateITK< _TFilter >( );
+  filter->SetInput( image );
+  filter->SetDefaultPixelValue( 100 );
+  filter->SetSize( out_size );
+  filter->SetOutputSpacing( out_spac );
+  filter->SetOutputOrigin( image->GetOrigin( ) );
+  filter->SetOutputDirection( image->GetDirection( ) );
+  filter->SetOutputStartIndex( idx );
+  filter->SetTransform( _TTransform::New( ) );
+  filter->UpdateLargestPossibleRegion( );
+  filter->Update( );
+  this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+}
+
+// eof - $RCSfile$
diff --git a/plugins/ImageSliceFilters/ResampleImageFilter.h b/plugins/ImageSliceFilters/ResampleImageFilter.h
new file mode 100644 (file)
index 0000000..73fb873
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef __cpPluginsImageSliceFilters__ResampleImageFilter__h__
+#define __cpPluginsImageSliceFilters__ResampleImageFilter__h__
+
+#include <cpPluginsImageSliceFilters_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginsImageSliceFilters
+{
+  /**
+   */
+  class cpPluginsImageSliceFilters_EXPORT ResampleImageFilter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      ResampleImageFilter,
+      cpPlugins::BaseObjects::ProcessObject,
+      ImageSliceFilters
+      );
+
+  protected:
+    template< class _TImage >
+    inline void _GD0( _TImage* image );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginsImageSliceFilters__ResampleImageFilter__h__
+
+// eof - $RCSfile$