]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/Common/Image/PathWriter.hxx
...
[FrontAlgorithms.git] / lib / fpa / Common / Image / PathWriter.hxx
diff --git a/lib/fpa/Common/Image/PathWriter.hxx b/lib/fpa/Common/Image/PathWriter.hxx
new file mode 100644 (file)
index 0000000..fc3d840
--- /dev/null
@@ -0,0 +1,111 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __fpa__Common__Image__PathWriter__hxx__
+#define __fpa__Common__Image__PathWriter__hxx__
+
+#include <fstream>
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+const _TPath* fpa::Common::Image::PathWriter< _TPath >::
+GetInput( ) const
+{
+  return(
+    dynamic_cast< const TPath* >(
+      this->itk::ProcessObject::GetInput( 0 )
+      )
+    );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+void fpa::Common::Image::PathWriter< _TPath >::
+SetInput( const _TPath* path )
+{
+  this->itk::ProcessObject::SetNthInput( 0, const_cast< TPath* >( path ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+void fpa::Common::Image::PathWriter< _TPath >::
+Update( )
+{
+  TPath* input = const_cast< TPath* >( this->GetInput( ) );
+  if( input != NULL )
+  {
+    input->UpdateOutputInformation( );
+    input->UpdateOutputData( );
+    this->GenerateData( );
+    this->ReleaseInputs( );
+
+  } // fi
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+fpa::Common::Image::PathWriter< _TPath >::
+PathWriter( )
+  : Superclass( ),
+    m_FileName( "" )
+{
+  this->SetNumberOfRequiredInputs( 1 );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+fpa::Common::Image::PathWriter< _TPath >::
+~PathWriter( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TPath >
+void fpa::Common::Image::PathWriter< _TPath >::
+GenerateData( )
+{
+  const TPath* path = this->GetInput( );
+
+  // Write base information
+  std::stringstream out1, out2;
+  out1 << TPath::Dimension << std::endl;
+  typename TPath::TSpacing spa = path->GetSpacing( );
+  for( unsigned int d = 0; d < TPath::Dimension; ++d )
+    out1 << spa[ d ] << " ";
+  out1 << std::endl;
+  typename TPath::TDirection dir = path->GetDirection( );
+  for( unsigned int d = 0; d < TPath::Dimension; ++d )
+    for( unsigned int e = 0; e < TPath::Dimension; ++e )
+      out1 << dir[ d ][ e ] << " ";
+  out1 << std::endl;
+  typename TPath::TPoint ori = path->GetOrigin( );
+  for( unsigned int d = 0; d < TPath::Dimension; ++d )
+    out1 << ori[ d ] << " ";
+  out1 << std::endl;
+
+  // Write path
+  unsigned int size = path->GetSize( );
+  out2 << size << std::endl;
+  for( unsigned int i = 0; i < path->GetSize( ); ++i )
+  {
+    typename TPath::TIndex v = path->GetVertex( i );
+    for( unsigned int d = 0; d < TPath::Dimension; ++d )
+      out2 << v[ d ] << " ";
+
+  } // rof
+
+  // Real write
+  std::ofstream file_stream( this->m_FileName.c_str( ), std::ofstream::binary );
+  if( !file_stream )
+    itkExceptionMacro(
+      << "Unable to write skeleton to \""
+      << this->m_FileName
+      << "\""
+      );
+  file_stream.write( out1.str( ).c_str( ), out1.str( ).size( ) );
+}
+
+#endif // __fpa__Common__Image__PathWriter__hxx__
+
+// eof - $RCSfile$