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