]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Dec 2016 17:10:14 +0000 (12:10 -0500)
committerLeonardo Flórez-Valencia <florez-l@javeriana.edu.co>
Wed, 7 Dec 2016 17:10:14 +0000 (12:10 -0500)
lib/cpExtensions/Algorithms/SkeletonReader.h [new file with mode: 0644]
lib/cpExtensions/Algorithms/SkeletonReader.hxx [new file with mode: 0644]
lib/cpExtensions/Algorithms/SkeletonWriter.hxx
lib/cpInstances/Skeleton.h
plugins/ITKImageGenericFilters_1/RegionOfInterestImageFilter.cxx
plugins/cpExtensions/SkeletonReader.cxx [new file with mode: 0644]
plugins/cpExtensions/SkeletonReader.h [new file with mode: 0644]
plugins/cpExtensions/SkeletonWriter.cxx
plugins/cpExtensions/cpExtensions.i

diff --git a/lib/cpExtensions/Algorithms/SkeletonReader.h b/lib/cpExtensions/Algorithms/SkeletonReader.h
new file mode 100644 (file)
index 0000000..e1a3064
--- /dev/null
@@ -0,0 +1,85 @@
+// -------------------------------------------------------------------------
+// @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$
diff --git a/lib/cpExtensions/Algorithms/SkeletonReader.hxx b/lib/cpExtensions/Algorithms/SkeletonReader.hxx
new file mode 100644 (file)
index 0000000..744bd04
--- /dev/null
@@ -0,0 +1,176 @@
+// -------------------------------------------------------------------------
+// @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$
index be39b90909bfc854710f693c939ceef7725f8ead..3be1d79d573dbeabba080d830092eeea8ceecf5d 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
 #define __cpExtensions__Algorithms__SkeletonWriter__hxx__
 
-#include <cpPlugins/Utility.h>
+#include <cpExtensions/Utility.h>
 
 // -------------------------------------------------------------------------
 template< class _TSkeleton >
@@ -105,7 +105,7 @@ GenerateData( )
             out << v[ d ] << " ";
 
         } // rof
-        std::cout << std::endl;
+        out << std::endl;
 
       } // rof
 
@@ -114,7 +114,7 @@ GenerateData( )
   } // 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
index b86aed04f1784a232f496dbc400586a246e6efa9..7a1bba276daebdf9e95fdfdad58db105e7835934 100644 (file)
@@ -6,8 +6,6 @@
 #include <cpInstances/Skeleton_Demanglers.h>
 #include <itkProcessObject.h>
 
-class vtkSkeletonData;
-
 namespace cpInstances
 {
   /**
index 9254bf4d83aa5a0c7f461938bf106b0e88aa71dd..61f2f58ef87049b4f72099e57d9e0c1e13c8a50e 100644 (file)
@@ -48,9 +48,18 @@ _GD0( _TImage* input )
 
   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 )
diff --git a/plugins/cpExtensions/SkeletonReader.cxx b/plugins/cpExtensions/SkeletonReader.cxx
new file mode 100644 (file)
index 0000000..7792a32
--- /dev/null
@@ -0,0 +1,93 @@
+#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$
diff --git a/plugins/cpExtensions/SkeletonReader.h b/plugins/cpExtensions/SkeletonReader.h
new file mode 100644 (file)
index 0000000..0d2903e
--- /dev/null
@@ -0,0 +1,33 @@
+#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$
index a192cfa2bf72c91488d06f80abb5401aa22fab32..4770b8dd408e5d5acd23f551ccf6a1d24161706e 100644 (file)
@@ -50,7 +50,7 @@ cpPluginscpExtensions::SkeletonWriter::
 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." );
 }
index 7a182f8f63ccbb66d4e3bac5c2d67a1871acc9db..4d3e1ea74db7a716f596b7726c15391d850cb36a 100644 (file)
@@ -1,11 +1,13 @@
 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$