]> Creatis software - FrontAlgorithms.git/blobdiff - lib/fpa/IO/UniqueValuesContainerReader.hxx
Skeletonization ready to use
[FrontAlgorithms.git] / lib / fpa / IO / UniqueValuesContainerReader.hxx
diff --git a/lib/fpa/IO/UniqueValuesContainerReader.hxx b/lib/fpa/IO/UniqueValuesContainerReader.hxx
new file mode 100644 (file)
index 0000000..16719f2
--- /dev/null
@@ -0,0 +1,82 @@
+#ifndef __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
+#define __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
+
+#include <fstream>
+
+// -------------------------------------------------------------------------
+template< class T >
+T* fpa::IO::UniqueValuesContainerReader< T >::
+GetOutput( )
+{
+  return( itkDynamicCastInDebugMode< T* >( this->GetPrimaryOutput( ) ) );
+}
+
+// -------------------------------------------------------------------------
+template< class T >
+void fpa::IO::UniqueValuesContainerReader< T >::
+Update( )
+{
+  this->GenerateData( );
+}
+
+// -------------------------------------------------------------------------
+template< class T >
+fpa::IO::UniqueValuesContainerReader< T >::
+UniqueValuesContainerReader( )
+  : Superclass( ),
+    m_FileName( "" )
+{
+  this->itk::ProcessObject::SetNumberOfRequiredOutputs( 1 );
+  this->itk::ProcessObject::SetNthOutput( 0, T::New( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class T >
+fpa::IO::UniqueValuesContainerReader< T >::
+~UniqueValuesContainerReader( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class T >
+void fpa::IO::UniqueValuesContainerReader< T >::
+GenerateData( )
+{
+  T* output = this->GetOutput( );
+  output->Clear( );
+
+  std::ifstream in( this->m_FileName.c_str( ) );
+  if( !in )
+  {
+    itkExceptionMacro(
+      << "Error opening file to read a minimum spanning tree: \""
+      << this->m_FileName
+      << "\""
+      );
+    return;
+
+  } // fi
+
+  unsigned int dim;
+  unsigned long nVertices;
+  in >> dim >> nVertices;
+  for( unsigned long vId = 0; vId < nVertices; ++vId )
+  {
+    typename T::TValue v;
+    for( unsigned int d = 0; d < dim; ++d )
+    {
+      long val;
+      in >> val;
+      if( d < T::TValue::Dimension )
+        v[ d ] = val;
+
+    } // rof
+    output->Insert( v );
+
+  } // rof
+  in.close( );
+}
+
+#endif // __FPA__IO__UNIQUEVALUESCONTAINERREADER__HXX__
+
+// eof - $RCSfile$