]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/Functions.h
...
[FrontAlgorithms.git] / appli / CTBronchi / Functions.h
diff --git a/appli/CTBronchi/Functions.h b/appli/CTBronchi/Functions.h
new file mode 100644 (file)
index 0000000..272c974
--- /dev/null
@@ -0,0 +1,57 @@
+// =========================================================================
+// @author Leonardo Florez Valencia
+// @email florez-l@javeriana.edu.co
+// =========================================================================
+#ifndef __CTBronchi__Functions__h__
+#define __CTBronchi__Functions__h__
+
+#include <chrono>
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+
+namespace CTBronchi
+{
+  // -----------------------------------------------------------------------
+  double MeasureTime( itk::ProcessObject* f )
+  {
+    std::chrono::time_point< std::chrono::high_resolution_clock > s, e;
+    std::chrono::duration< double > t;
+    s = std::chrono::high_resolution_clock::now( );
+    f->Update( );
+    e = std::chrono::high_resolution_clock::now( );
+    t = e - s;
+    return( t.count( ) );
+  }
+
+  // -----------------------------------------------------------------------
+  template< class _TImagePtr >
+  void ReadImage( _TImagePtr& image, const std::string& fname )
+  {
+    typedef typename _TImagePtr::ObjectType _TImage;
+    typedef itk::ImageFileReader< _TImage > _TReader;
+    typename _TReader::Pointer reader = _TReader::New( );
+    reader->SetFileName( fname );
+    double t = MeasureTime( reader );
+    std::cout << "Read " << fname << " in " << t << " s" << std::endl;
+    image = reader->GetOutput( );
+    image->DisconnectPipeline( );
+  }
+
+  // -----------------------------------------------------------------------
+  template< class _TImagePtr >
+  void WriteImage( const _TImagePtr& image, const std::string& fname )
+  {
+    typedef typename _TImagePtr::ObjectType _TImage;
+    typedef itk::ImageFileWriter< _TImage > _TWriter;
+    typename _TWriter::Pointer writer = _TWriter::New( );
+    writer->SetFileName( fname );
+    writer->SetInput( image );
+    double t = MeasureTime( writer );
+    std::cout << "Wrote " << fname << " in " << t << " s" << std::endl;
+  }
+
+} // ecapseman
+
+#endif // __CTBronchi__Functions__h__
+
+// eof - $RCSfile$