]> Creatis software - FrontAlgorithms.git/blobdiff - appli/CTBronchi/Image.hxx
...
[FrontAlgorithms.git] / appli / CTBronchi / Image.hxx
diff --git a/appli/CTBronchi/Image.hxx b/appli/CTBronchi/Image.hxx
new file mode 100644 (file)
index 0000000..4b6fa9b
--- /dev/null
@@ -0,0 +1,119 @@
+// =========================================================================
+// @author Leonardo Florez Valencia (florez-l@javeriana.edu.co)
+// =========================================================================
+#ifndef __CTBronchi__Image__hxx__
+#define __CTBronchi__Image__hxx__
+
+#include <itkImageFileReader.h>
+#include <itkImageFileWriter.h>
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+CTBronchi::Image< _TPixel, _VDim >::
+Image( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+CTBronchi::Image< _TPixel, _VDim >::
+~Image( )
+{
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+bool CTBronchi::Image< _TPixel, _VDim >::
+IsNotNull( ) const
+{
+  return( this->m_Image.IsNotNull( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+bool CTBronchi::Image< _TPixel, _VDim >::
+IsNull( ) const
+{
+  return( this->m_Image.IsNull( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+typename CTBronchi::Image< _TPixel, _VDim >::
+TImage* CTBronchi::Image< _TPixel, _VDim >::
+Get( )
+{
+  return( this->m_Image.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+const typename CTBronchi::Image< _TPixel, _VDim >::
+TImage* CTBronchi::Image< _TPixel, _VDim >::
+Get( ) const
+{
+  return( this->m_Image.GetPointer( ) );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+void CTBronchi::Image< _TPixel, _VDim >::
+Set( TImage* image )
+{
+  this->m_Image = image;
+  this->m_Image->DisconnectPipeline( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+void CTBronchi::Image< _TPixel, _VDim >::
+Set( const TImage::Pointer& image )
+{
+  this->m_Image = image.GetPointer( );
+  this->m_Image->DisconnectPipeline( );
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+void CTBronchi::Image< _TPixel, _VDim >::
+Load( const std::string& fname )
+{
+  typedef itk::ImageFileReader< TImage > _TReader;
+  typename _TReader::Pointer r = _TReader::New( );
+  r->SetFileName( fname );
+  try
+  {
+    r->Update( );
+    this->Set( r->GetOutput( ) );
+  }
+  catch( ... )
+  {
+    this->Set( NULL );
+
+  } // yrt
+}
+
+// -------------------------------------------------------------------------
+template< class _TPixel, unsigned int _VDim >
+void CTBronchi::Image< _TPixel, _VDim >::
+Save( const std::string& fname )
+{
+  typedef itk::ImageFileWriter< TImage > _TWriter;
+
+  if( this->IsNotNull( ) )
+  {
+    typename _TWriter::Pointer w = _TWriter::New( );
+    w->SetFileName( fname );
+    w->SetInput( this->m_Image );
+    try
+    {
+      w->Update( );
+    }
+    catch( ... ) { }
+
+  } // fi
+}
+
+#endif // __CTBronchi__Image__hxx__
+
+// eof - $RCSfile$