]> Creatis software - FrontAlgorithms.git/blob - appli/CTBronchi/Image.hxx
4b6fa9b8ff1c37ae2285b89e2bfbe1349a59c000
[FrontAlgorithms.git] / appli / CTBronchi / Image.hxx
1 // =========================================================================
2 // @author Leonardo Florez Valencia (florez-l@javeriana.edu.co)
3 // =========================================================================
4 #ifndef __CTBronchi__Image__hxx__
5 #define __CTBronchi__Image__hxx__
6
7 #include <itkImageFileReader.h>
8 #include <itkImageFileWriter.h>
9
10 // -------------------------------------------------------------------------
11 template< class _TPixel, unsigned int _VDim >
12 CTBronchi::Image< _TPixel, _VDim >::
13 Image( )
14 {
15 }
16
17 // -------------------------------------------------------------------------
18 template< class _TPixel, unsigned int _VDim >
19 CTBronchi::Image< _TPixel, _VDim >::
20 ~Image( )
21 {
22 }
23
24 // -------------------------------------------------------------------------
25 template< class _TPixel, unsigned int _VDim >
26 bool CTBronchi::Image< _TPixel, _VDim >::
27 IsNotNull( ) const
28 {
29   return( this->m_Image.IsNotNull( ) );
30 }
31
32 // -------------------------------------------------------------------------
33 template< class _TPixel, unsigned int _VDim >
34 bool CTBronchi::Image< _TPixel, _VDim >::
35 IsNull( ) const
36 {
37   return( this->m_Image.IsNull( ) );
38 }
39
40 // -------------------------------------------------------------------------
41 template< class _TPixel, unsigned int _VDim >
42 typename CTBronchi::Image< _TPixel, _VDim >::
43 TImage* CTBronchi::Image< _TPixel, _VDim >::
44 Get( )
45 {
46   return( this->m_Image.GetPointer( ) );
47 }
48
49 // -------------------------------------------------------------------------
50 template< class _TPixel, unsigned int _VDim >
51 const typename CTBronchi::Image< _TPixel, _VDim >::
52 TImage* CTBronchi::Image< _TPixel, _VDim >::
53 Get( ) const
54 {
55   return( this->m_Image.GetPointer( ) );
56 }
57
58 // -------------------------------------------------------------------------
59 template< class _TPixel, unsigned int _VDim >
60 void CTBronchi::Image< _TPixel, _VDim >::
61 Set( TImage* image )
62 {
63   this->m_Image = image;
64   this->m_Image->DisconnectPipeline( );
65 }
66
67 // -------------------------------------------------------------------------
68 template< class _TPixel, unsigned int _VDim >
69 void CTBronchi::Image< _TPixel, _VDim >::
70 Set( const TImage::Pointer& image )
71 {
72   this->m_Image = image.GetPointer( );
73   this->m_Image->DisconnectPipeline( );
74 }
75
76 // -------------------------------------------------------------------------
77 template< class _TPixel, unsigned int _VDim >
78 void CTBronchi::Image< _TPixel, _VDim >::
79 Load( const std::string& fname )
80 {
81   typedef itk::ImageFileReader< TImage > _TReader;
82   typename _TReader::Pointer r = _TReader::New( );
83   r->SetFileName( fname );
84   try
85   {
86     r->Update( );
87     this->Set( r->GetOutput( ) );
88   }
89   catch( ... )
90   {
91     this->Set( NULL );
92
93   } // yrt
94 }
95
96 // -------------------------------------------------------------------------
97 template< class _TPixel, unsigned int _VDim >
98 void CTBronchi::Image< _TPixel, _VDim >::
99 Save( const std::string& fname )
100 {
101   typedef itk::ImageFileWriter< TImage > _TWriter;
102
103   if( this->IsNotNull( ) )
104   {
105     typename _TWriter::Pointer w = _TWriter::New( );
106     w->SetFileName( fname );
107     w->SetInput( this->m_Image );
108     try
109     {
110       w->Update( );
111     }
112     catch( ... ) { }
113
114   } // fi
115 }
116
117 #endif // __CTBronchi__Image__hxx__
118
119 // eof - $RCSfile$