--- /dev/null
+// -------------------------------------------------------------------------
+// @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$
--- /dev/null
+// -------------------------------------------------------------------------
+// @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$
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;
--- /dev/null
+#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$
--- /dev/null
+#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$
--- /dev/null
+#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$
--- /dev/null
+#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$