]> Creatis software - cpPlugins.git/commitdiff
...
authorLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Tue, 6 Dec 2016 03:47:02 +0000 (22:47 -0500)
committerLeonardo Flórez-Valencia <leonardo.florez@gmail.com>
Tue, 6 Dec 2016 03:47:02 +0000 (22:47 -0500)
lib/cpExtensions/Algorithms/SkeletonWriter.h [new file with mode: 0644]
lib/cpExtensions/Algorithms/SkeletonWriter.hxx [new file with mode: 0644]
plugins/cpExtensions/SkeletonWriter.cxx [new file with mode: 0644]
plugins/cpExtensions/SkeletonWriter.h [new file with mode: 0644]
plugins/cpExtensions/cpExtensions.i

diff --git a/lib/cpExtensions/Algorithms/SkeletonWriter.h b/lib/cpExtensions/Algorithms/SkeletonWriter.h
new file mode 100644 (file)
index 0000000..3112693
--- /dev/null
@@ -0,0 +1,69 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonWriter__h__
+#define __cpExtensions__Algorithms__SkeletonWriter__h__
+
+#include <cpExtensions/Config.h>
+#include <itkProcessObject.h>
+
+// -------------------------------------------------------------------------
+namespace cpExtensions
+{
+  namespace Algorithms
+  {
+    /**
+     */
+    template< class _TSkeleton >
+    class SkeletonWriter
+      : public itk::ProcessObject
+    {
+    public:
+      // Basic types
+      typedef SkeletonWriter                  Self;
+      typedef itk::ProcessObject              Superclass;
+      typedef itk::SmartPointer< Self >       Pointer;
+      typedef itk::SmartPointer< const Self > ConstPointer;
+
+      typedef _TSkeleton TSkeleton;
+
+    public:
+      itkNewMacro( Self );
+      itkTypeMacro( SkeletonWriter, itk::ImageSource );
+
+      itkGetConstMacro( FileName, std::string );
+      itkSetMacro( FileName, std::string );
+
+    public:
+      const TSkeleton* GetInput( ) const;
+      void SetInput( const TSkeleton* skeleton );
+      virtual void Update( ) cpExtensions_OVERRIDE;
+
+    protected:
+      SkeletonWriter( );
+      virtual ~SkeletonWriter( );
+
+      virtual void GenerateData( ) cpExtensions_OVERRIDE;
+
+    private:
+      // Purposely not implemented
+      SkeletonWriter( const Self& );
+      void operator=( const Self& );
+
+    protected:
+      std::string m_FileName;
+    };
+
+  } // ecapseman
+
+} // ecapseman
+
+// -------------------------------------------------------------------------
+#ifndef ITK_MANUAL_INSTANTIATION
+#  include <cpExtensions/Algorithms/SkeletonWriter.hxx>
+#endif // ITK_MANUAL_INSTANTIATION
+
+#endif // __cpExtensions__Algorithms__SkeletonWriter__h__
+
+// eof - $RCSfile$
diff --git a/lib/cpExtensions/Algorithms/SkeletonWriter.hxx b/lib/cpExtensions/Algorithms/SkeletonWriter.hxx
new file mode 100644 (file)
index 0000000..be39b90
--- /dev/null
@@ -0,0 +1,127 @@
+// -------------------------------------------------------------------------
+// @author Leonardo Florez-Valencia (florez-l@javeriana.edu.co)
+// -------------------------------------------------------------------------
+
+#ifndef __cpExtensions__Algorithms__SkeletonWriter__hxx__
+#define __cpExtensions__Algorithms__SkeletonWriter__hxx__
+
+#include <cpPlugins/Utility.h>
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+const _TSkeleton* cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+GetInput( ) const
+{
+  return(
+    dynamic_cast< const TSkeleton* >(
+      this->itk::ProcessObject::GetInput( 0 )
+      )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+SetInput( const _TSkeleton* skeleton )
+{
+  this->itk::ProcessObject::SetNthInput(
+    0, const_cast< TSkeleton* >( skeleton )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+Update( )
+{
+  TSkeleton* input = const_cast< TSkeleton* >( this->GetInput( ) );
+  if( input != NULL )
+  {
+    input->UpdateOutputInformation( );
+    input->UpdateOutputData( );
+    this->GenerateData( );
+    this->ReleaseInputs( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+SkeletonWriter( )
+  : Superclass( ),
+    m_FileName( "" )
+{
+  this->SetNumberOfRequiredInputs( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+~SkeletonWriter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpExtensions::Algorithms::SkeletonWriter< _TSkeleton >::
+GenerateData( )
+{
+  const TSkeleton* sk = this->GetInput( );
+  std::stringstream out;
+  out << TSkeleton::Dimension << std::endl;
+
+  // Write
+  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;
+        unsigned int size = path->GetSize( );
+        auto spa = path->GetSpacing( );
+        auto ori = path->GetOrigin( );
+        auto dir = path->GetDirection( );
+        out << size << std::endl;
+        for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+          out << spa[ d ] << " ";
+        out << std::endl;
+        for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+          out << ori[ d ] << " ";
+        out << std::endl;
+        for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+          for( unsigned int e = 0; e < TSkeleton::Dimension; ++e )
+          out << dir[ d ][ e ] << " ";
+        out << std::endl;
+
+        for( unsigned int i = 0; i < path->GetSize( ); ++i )
+        {
+          auto v = path->GetVertex( i );
+          for( unsigned int d = 0; d < TSkeleton::Dimension; ++d )
+            out << v[ d ] << " ";
+
+        } // rof
+        std::cout << std::endl;
+
+      } // rof
+
+    } // rof
+
+  } // rof
+  out << "0" << std::endl;
+
+  if( !( cpPlugins::Write( out.str( ), this->m_FileName ) ) )
+    itkExceptionMacro(
+      << "Unable to write skeleton to \""
+      << this->m_FileName
+      << "\""
+      );
+}
+
+#endif // __cpExtensions__Algorithms__SkeletonWriter__hxx__
+
+// eof - $RCSfile$
diff --git a/plugins/cpExtensions/SkeletonWriter.cxx b/plugins/cpExtensions/SkeletonWriter.cxx
new file mode 100644 (file)
index 0000000..a192cfa
--- /dev/null
@@ -0,0 +1,79 @@
+#include <cpExtensions/SkeletonWriter.h>
+#include <cpInstances/Skeleton.h>
+
+#include <cpExtensions/DataStructures/Skeleton.h>
+#include <cpExtensions/Algorithms/SkeletonWriter.h>
+#include <cpPlugins/QT/SaveFileDialog.h>
+
+#ifdef cpPlugins_QT4
+#  include <QApplication>
+#endif // cpPlugins_QT4
+
+// -------------------------------------------------------------------------
+QDialog* cpPluginscpExtensions::SkeletonWriter::
+CreateQDialog( )
+{
+#ifdef cpPlugins_QT4
+  cpPlugins::QT::SaveFileDialog* dlg = NULL;
+  if( QApplication::instance( ) != NULL )
+  {
+    dlg = new cpPlugins::QT::SaveFileDialog( );
+    dlg->SetParameters( &( this->m_Parameters ), "FileName" );
+
+  } // fi
+  return( dlg );
+#else // cpPlugins_QT4
+  return( NULL );
+#endif // cpPlugins_QT4
+}
+
+// -------------------------------------------------------------------------
+cpPluginscpExtensions::SkeletonWriter::
+SkeletonWriter( )
+  : Superclass( )
+{
+  this->_ConfigureInput< cpInstances::Skeleton >( "Input", true, false );
+  this->m_Parameters.ConfigureAsSaveFileName( "FileName", "" );
+  this->m_Parameters.SetAcceptedFileExtensions(
+    "FileName",
+    "Skeleton files (*.txt)"
+    );
+}
+
+// -------------------------------------------------------------------------
+cpPluginscpExtensions::SkeletonWriter::
+~SkeletonWriter( )
+{
+}
+
+// -------------------------------------------------------------------------
+void cpPluginscpExtensions::SkeletonWriter::
+_GenerateData( )
+{
+  auto o = this->GetInputData( "Skeleton" );
+  cpPlugins_Demangle_Skeleton_All_1( o, _GD0 )
+    this->_Error( "Invalid input skeleton." );
+}
+
+// -------------------------------------------------------------------------
+template< class _TSkeleton >
+void cpPluginscpExtensions::SkeletonWriter::
+_GD0( _TSkeleton* skeleton )
+{
+  typedef cpExtensions::Algorithms::SkeletonWriter< _TSkeleton > _TWriter;
+
+  auto filter = this->_CreateITK< _TWriter >( );
+  filter->SetInput( skeleton );
+  filter->SetFileName( this->m_Parameters.GetSaveFileName( "FileName" ) );
+  try
+  {
+    filter->Update( );
+  }
+  catch( itk::ExceptionObject& err )
+  {
+    this->_Error( err.GetDescription( ) );
+
+  } // yrt
+}
+
+// eof - $RCSfile$
diff --git a/plugins/cpExtensions/SkeletonWriter.h b/plugins/cpExtensions/SkeletonWriter.h
new file mode 100644 (file)
index 0000000..1fb8ecb
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef __cpPluginscpExtensions__SkeletonWriter__h__
+#define __cpPluginscpExtensions__SkeletonWriter__h__
+
+#include <cpPluginscpExtensions_Export.h>
+#include <cpPlugins/BaseObjects/ProcessObject.h>
+
+namespace cpPluginscpExtensions
+{
+  /**
+   */
+  class cpPluginscpExtensions_EXPORT SkeletonWriter
+    : public cpPlugins::BaseObjects::ProcessObject
+  {
+    cpPluginsObject(
+      SkeletonWriter,
+      cpPlugins::BaseObjects::ProcessObject,
+      IO
+      );
+
+  public:
+    virtual QDialog* CreateQDialog( ) cpPlugins_OVERRIDE;
+
+  protected:
+    template< class _TSkeleton >
+    inline void _GD0( _TSkeleton* skeleton );
+  };
+
+} // ecapseman
+
+#endif // __cpPluginscpExtensions__SkeletonWriter__h__
+
+
+// eof - $RCSfile$
index f0099eb78f300a1801b62979f9d4a6a5d8791adc..7a182f8f63ccbb66d4e3bac5c2d67a1871acc9db 100644 (file)
@@ -1,8 +1,11 @@
 header #define ITK_MANUAL_INSTANTIATION
 
 tinclude cpExtensions/Algorithms/SkeletonToImageFilter: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::SkeletonToImageFilter< cpExtensions::DataStructures::Skeleton< #pdims# >, itk::Image< unsigned char, #pdims# > >
+
+instances cpExtensions::Algorithms::SkeletonWriter< cpExtensions::DataStructures::Skeleton< #pdims# > >
 
 ** eof - $RCSfile$