--- /dev/null
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonReader__h__
+#define __cpExtensions__Algorithms__SkeletonReader__h__
+
+#include <cpExtensions/Config.h>
+#include <itkProcessObject.h>
+
+// -------------------------------------------------------------------------
+namespace cpExtensions
+{
+ namespace Algorithms
+ {
+ /**
+ */
+ template< class _TSkeleton >
+ class SkeletonReader
+ : public itk::ProcessObject
+ {
+ public:
+ // Basic types
+ typedef SkeletonReader Self;
+ typedef itk::ProcessObject Superclass;
+ typedef itk::SmartPointer< Self > Pointer;
+ typedef itk::SmartPointer< const Self > ConstPointer;
+
+ typedef _TSkeleton TSkeleton;
+
+ public:
+ itkNewMacro( Self );
+ itkTypeMacro( SkeletonReader, itk::ImageSource );
+
+ itkGetConstMacro( FileName, std::string );
+ itkSetMacro( FileName, std::string );
+
+ public:
+ TSkeleton* GetOutput( );
+ TSkeleton* GetOutput( unsigned int i );
+
+ virtual void GraftOutput( itk::DataObject* out );
+ virtual void GraftOutput(
+ const typename Superclass::DataObjectIdentifierType& key,
+ itk::DataObject* out
+ );
+ virtual void GraftNthOutput( unsigned int i, itk::DataObject* out );
+ virtual itk::DataObject::Pointer MakeOutput(
+ itk::ProcessObject::DataObjectPointerArraySizeType i
+ ) cpExtensions_OVERRIDE;
+
+ virtual void Update( ) cpExtensions_OVERRIDE
+ { this->GenerateData( ); }
+
+ protected:
+ SkeletonReader( );
+ virtual ~SkeletonReader( );
+
+ virtual void GenerateData( ) cpExtensions_OVERRIDE;
+
+ // Do nothing
+ virtual void GenerateOutputInformation( ) cpExtensions_OVERRIDE
+ { }
+
+ private:
+ // Purposely not implemented
+ SkeletonReader( const Self& );
+ void operator=( const Self& );
+
+ protected:
+ std::string m_FileName;
+ };
+
+ } // ecapseman
+
+} // ecapseman
+
+// -------------------------------------------------------------------------
+#ifndef ITK_MANUAL_INSTANTIATION
+# include <cpExtensions/Algorithms/SkeletonReader.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __cpExtensions__Algorithms__SkeletonReader__h__
+
+// eof - $RCSfile$
--- /dev/null
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonReader__hxx__
+#define __cpExtensions__Algorithms__SkeletonReader__hxx__
+
+#include <cpExtensions/Utility.h>
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+_TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GetOutput( )
+{
+ return(
+ itkDynamicCastInDebugMode< TSkeleton* >( this->GetPrimaryOutput( ) )
+ );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+_TSkeleton* cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GetOutput( unsigned int i )
+{
+ return(
+ itkDynamicCastInDebugMode< TSkeleton* >(
+ this->itk::ProcessObject::GetOutput( i )
+ )
+ );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GraftOutput( itk::DataObject* out )
+{
+ this->GraftNthOutput( 0, out );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GraftOutput(
+ const typename Superclass::DataObjectIdentifierType& key,
+ itk::DataObject* out
+ )
+{
+ if( out == NULL )
+ {
+ itkExceptionMacro(
+ << "Requested to graft output that is a NULL pointer"
+ );
+
+ } // fi
+ itk::DataObject* output = this->itk::ProcessObject::GetOutput( key );
+ output->Graft( out );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GraftNthOutput( unsigned int i, itk::DataObject* out )
+{
+ if( i >= this->GetNumberOfIndexedOutputs( ) )
+ {
+ itkExceptionMacro(
+ << "Requested to graft output " << i
+ << " but this filter only has "
+ << this->GetNumberOfIndexedOutputs( )
+ << " indexed Outputs."
+ );
+
+ } // fi
+ this->GraftOutput( this->MakeNameFromOutputIndex( i ), out );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+itk::DataObject::Pointer
+cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+MakeOutput( itk::ProcessObject::DataObjectPointerArraySizeType i )
+{
+ return( TSkeleton::New( ).GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+SkeletonReader( )
+ : Superclass( )
+{
+ typename TSkeleton::Pointer out =
+ static_cast< TSkeleton* >( this->MakeOutput( 0 ).GetPointer( ) );
+ this->itk::ProcessObject::SetNumberOfRequiredInputs( 0 );
+ this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
+ this->itk::ProcessObject::SetNthOutput( 0, out.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+~SkeletonReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonReader< _TSkeleton >::
+GenerateData( )
+{
+ typedef typename TSkeleton::TPath _TPath;
+ typedef typename _TPath::TSpacing _TSpacing;
+ typedef typename _TPath::TPoint _TPoint;
+ typedef typename _TPath::TDirection _TDirection;
+ typedef typename _TPath::TContinuousIndex _TContinuousIndex;
+
+ std::string buffer;
+ if( !( cpExtensions::Read( buffer, this->m_FileName ) ) )
+ {
+ itkExceptionMacro(
+ << "Error reading skeleton from \"" << this->m_FileName << "\""
+ );
+ return;
+
+ } // fi
+
+ std::istringstream in( buffer );
+ unsigned int dim;
+ in >> dim;
+ if( dim != TSkeleton::Dimension )
+ {
+ itkExceptionMacro(
+ << "Mismatched skeletons dimension: " << dim
+ << " != " << TSkeleton::Dimension
+ );
+ return;
+
+ } // fi
+
+ TSkeleton* out = this->GetOutput( );
+ unsigned long size;
+ in >> size;
+ while( size > 0 )
+ {
+ _TSpacing spa;
+ _TPoint ori;
+ _TDirection dir;
+ for( unsigned int d = 0; d < dim; ++d )
+ in >> spa[ d ];
+ for( unsigned int d = 0; d < dim; ++d )
+ in >> ori[ d ];
+ for( unsigned int d = 0; d < dim; ++d )
+ for( unsigned int e = 0; e < dim; ++e )
+ in >> dir[ d ][ e ];
+
+ typename _TPath::Pointer path = _TPath::New( );
+ path->SetSpacing( spa );
+ path->SetOrigin( ori );
+ path->SetDirection( dir );
+ for( unsigned long s = 0; s < size; ++s )
+ {
+ _TContinuousIndex idx;
+ for( unsigned int d = 0; d < dim; ++d )
+ in >> idx[ d ];
+ path->AddVertex( idx );
+
+ } // rof
+ out->AddBranch( path );
+ in >> size;
+
+ } // elihw
+}
+
+#endif // __cpExtensions__Algorithms__SkeletonReader__hxx__
+
+// eof - $RCSfile$
#ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
#define __cpExtensions__Algorithms__SkeletonWriter__hxx__
-#include <cpPlugins/Utility.h>
+#include <cpExtensions/Utility.h>
// -------------------------------------------------------------------------
template< class _TSkeleton >
out << v[ d ] << " ";
} // rof
- std::cout << std::endl;
+ out << std::endl;
} // rof
} // rof
out << "0" << std::endl;
- if( !( cpPlugins::Write( out.str( ), this->m_FileName ) ) )
+ if( !( cpExtensions::Write( out.str( ), this->m_FileName ) ) )
itkExceptionMacro(
<< "Unable to write skeleton to \""
<< this->m_FileName
#include <cpInstances/Skeleton_Demanglers.h>
#include <itkProcessObject.h>
-class vtkSkeletonData;
-
namespace cpInstances
{
/**
auto bb = this->GetInput< _TBBox >( "BoundingBox" );
+ _TRegion in_region = input->GetRequestedRegion( );
+ _TIndex in_i0 = in_region.GetIndex( );
+ _TIndex in_i1 = in_i0 + in_region.GetSize( );
_TIndex i0, i1;
input->TransformPhysicalPointToIndex( bb->GetMinimum< _TPoint >( ), i0 );
input->TransformPhysicalPointToIndex( bb->GetMaximum< _TPoint >( ), i1 );
+ for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
+ {
+ if( i0[ d ] < in_i0[ d ] ) i0[ d ] = in_i0[ d ];
+ if( i1[ d ] > in_i1[ d ] ) i1[ d ] = in_i1[ d ];
+
+ } // rof
_TSize size;
for( unsigned int d = 0; d < _TImage::ImageDimension; ++d )
--- /dev/null
+#include <cpExtensions/SkeletonReader.h>
+#include <cpInstances/Skeleton.h>
+
+#include <cpExtensions/DataStructures/Skeleton.h>
+#include <cpExtensions/Algorithms/SkeletonReader.h>
+#include <cpPlugins/QT/OpenFileDialog.h>
+
+#ifdef cpPlugins_QT4
+# include <QApplication>
+#endif // cpPlugins_QT4
+
+// -------------------------------------------------------------------------
+QDialog* cpPluginscpExtensions::SkeletonReader::
+CreateQDialog( )
+{
+#ifdef cpPlugins_QT4
+ cpPlugins::QT::OpenFileDialog* dlg = NULL;
+ if( QApplication::instance( ) != NULL )
+ {
+ dlg = new cpPlugins::QT::OpenFileDialog( );
+ dlg->SetParameters( &( this->m_Parameters ), "FileName" );
+
+ } // fi
+ return( dlg );
+#else // cpPlugins_QT4
+ return( NULL );
+#endif // cpPlugins_QT4
+}
+
+// -------------------------------------------------------------------------
+cpPluginscpExtensions::SkeletonReader::
+SkeletonReader( )
+ : Superclass( )
+{
+ this->_ConfigureOutput< cpInstances::Skeleton >( "Output" );
+ this->m_Parameters.ConfigureAsOpenFileName( "FileName", "" );
+ this->m_Parameters.SetAcceptedFileExtensions(
+ "FileName",
+ "Skeleton files (*.txt)"
+ );
+}
+
+// -------------------------------------------------------------------------
+cpPluginscpExtensions::SkeletonReader::
+~SkeletonReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginscpExtensions::SkeletonReader::
+_GenerateData( )
+{
+ std::string success = "";
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+ success = this->_GD0< 1 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_1
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+ if( success != "" ) success = this->_GD0< 2 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_2
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+ if( success != "" ) success = this->_GD0< 3 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_3
+#ifdef cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+ if( success != "" ) success = this->_GD0< 4 >( );
+#endif // cpPlugins_CONFIG_PROCESS_DIMENSIONS_4
+ if( success != "" )
+ this->_Error( success );
+}
+
+// -------------------------------------------------------------------------
+template< unsigned int _VDim >
+std::string cpPluginscpExtensions::SkeletonReader::
+_GD0( )
+{
+ typedef cpExtensions::DataStructures::Skeleton< _VDim > _TSkeleton;
+ typedef cpExtensions::Algorithms::SkeletonReader< _TSkeleton > _TReader;
+
+ auto filter = this->_CreateITK< _TReader >( );
+ filter->SetFileName( this->m_Parameters.GetOpenFileName( "FileName" ) );
+ try
+ {
+ filter->Update( );
+ }
+ catch( std::exception& err )
+ {
+ return( err.what( ) );
+
+ } // yrt
+ this->GetOutput( "Output" )->SetITK( filter->GetOutput( ) );
+ return( "" );
+}
+
+// eof - $RCSfile$
--- /dev/null
+#ifndef __cpPluginscpExtensions__SkeletonReader__h__
+#define __cpPluginscpExtensions__SkeletonReader__h__
+
+#include <cpPluginscpExtensions_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginscpExtensions
+{
+ /**
+ */
+ class cpPluginscpExtensions_EXPORT SkeletonReader
+ : public cpPlugins::BaseObjects::ProcessObject
+ {
+ cpPluginsObject(
+ SkeletonReader,
+ cpPlugins::BaseObjects::ProcessObject,
+ IO
+ );
+
+ public:
+ virtual QDialog* CreateQDialog( ) cpPlugins_OVERRIDE;
+
+ protected:
+ template< unsigned int _VDim >
+ inline std::string _GD0( );
+ };
+
+} // ecapseman
+
+#endif // __cpPluginscpExtensions__SkeletonReader__h__
+
+
+// eof - $RCSfile$
void cpPluginscpExtensions::SkeletonWriter::
_GenerateData( )
{
- auto o = this->GetInputData( "Skeleton" );
+ auto o = this->GetInputData( "Input" );
cpPlugins_Demangle_Skeleton_All_1( o, _GD0 )
this->_Error( "Invalid input skeleton." );
}
header #define ITK_MANUAL_INSTANTIATION
tinclude cpExtensions/Algorithms/SkeletonToImageFilter:h|hxx
+tinclude cpExtensions/Algorithms/SkeletonReader:h|hxx
tinclude cpExtensions/Algorithms/SkeletonWriter:h|hxx
cinclude cpExtensions/DataStructures/Skeleton.h
instances cpExtensions::Algorithms::SkeletonToImageFilter< cpExtensions::DataStructures::Skeleton< #pdims# >, itk::Image< unsigned char, #pdims# > >
+instances cpExtensions::Algorithms::SkeletonReader< cpExtensions::DataStructures::Skeleton< #pdims# > >
instances cpExtensions::Algorithms::SkeletonWriter< cpExtensions::DataStructures::Skeleton< #pdims# > >
** eof - $RCSfile$