]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/Functions.h
272c974f81162e429a8fba9e6ac3ac3b226fbabf
[FrontAlgorithms.git] / appli / CTBronchi / Functions.h
1 // =========================================================================
2 // @author Leonardo Florez Valencia
3 // @email florez-l@javeriana.edu.co
4 // =========================================================================
5 #ifndef __CTBronchi__Functions__h__
6 #define __CTBronchi__Functions__h__
7
8 #include <chrono>
9 #include <itkImageFileReader.h>
10 #include <itkImageFileWriter.h>
11
12 namespace CTBronchi
13 {
14   // -----------------------------------------------------------------------
15   double MeasureTime( itk::ProcessObject* f )
16   {
17     std::chrono::time_point< std::chrono::high_resolution_clock > s, e;
18     std::chrono::duration< double > t;
19     s = std::chrono::high_resolution_clock::now( );
20     f->Update( );
21     e = std::chrono::high_resolution_clock::now( );
22     t = e - s;
23     return( t.count( ) );
24   }
25
26   // -----------------------------------------------------------------------
27   template< class _TImagePtr >
28   void ReadImage( _TImagePtr& image, const std::string& fname )
29   {
30     typedef typename _TImagePtr::ObjectType _TImage;
31     typedef itk::ImageFileReader< _TImage > _TReader;
32     typename _TReader::Pointer reader = _TReader::New( );
33     reader->SetFileName( fname );
34     double t = MeasureTime( reader );
35     std::cout << "Read " << fname << " in " << t << " s" << std::endl;
36     image = reader->GetOutput( );
37     image->DisconnectPipeline( );
38   }
39
40   // -----------------------------------------------------------------------
41   template< class _TImagePtr >
42   void WriteImage( const _TImagePtr& image, const std::string& fname )
43   {
44     typedef typename _TImagePtr::ObjectType _TImage;
45     typedef itk::ImageFileWriter< _TImage > _TWriter;
46     typename _TWriter::Pointer writer = _TWriter::New( );
47     writer->SetFileName( fname );
48     writer->SetInput( image );
49     double t = MeasureTime( writer );
50     std::cout << "Wrote " << fname << " in " << t << " s" << std::endl;
51   }
52
53 } // ecapseman
54
55 #endif // __CTBronchi__Functions__h__
56
57 // eof - $RCSfile$