Slicer 4.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
vtkITKImageToImageFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
00004 
00005   See COPYRIGHT.txt
00006   or http://www.slicer.org/copyright/copyright.txt for details.
00007 
00008   Program:   vtkITK
00009   Module:    $HeadURL: http://svn.slicer.org/Slicer4/trunk/Libs/vtkITK/vtkITKImageToImageFilter.h $
00010   Date:      $Date: 2012-09-18 20:49:07 -0400 (Tue, 18 Sep 2012) $
00011   Version:   $Revision: 21009 $
00012 
00013 ==========================================================================*/
00014 
00015 #ifndef __vtkITKImageToImageFilter_h
00016 #define __vtkITKImageToImageFilter_h
00017 
00018 #include "itkCommand.h"
00019 #include "vtkCommand.h"
00020 #include "itkProcessObject.h"
00021 #include "vtkImageImport.h"
00022 #include "vtkImageExport.h"
00023 #include "vtkImageToImageFilter.h"
00024 #include "vtkImageCast.h"
00025 #include "vtkImageData.h"
00026 
00027 #include "vtkITK.h"
00028 
00029 #undef itkExceptionMacro  
00030 #define itkExceptionMacro(x) \
00031   { \
00032   ::std::ostringstream message; \
00033   message << "itk::ERROR: " << this->GetNameOfClass() \
00034           << "(" << this << "): "; \
00035   std::cout << message.str().c_str() << std::endl; \
00036   }
00037 
00038 #undef itkGenericExceptionMacro  
00039 #define itkGenericExceptionMacro(x) \
00040   { \
00041   ::std::ostringstream message; \
00042   message << "itk::ERROR: " x; \
00043   std::cout << message.str() << std::endl; \
00044   }
00045 
00049 class VTK_ITK_EXPORT vtkITKImageToImageFilter : public vtkImageToImageFilter
00050 {
00051 public:
00052   static vtkITKImageToImageFilter *New()
00053    {
00054      return new vtkITKImageToImageFilter;
00055    };
00056   
00057   vtkTypeMacro(vtkITKImageToImageFilter,vtkImageToImageFilter);
00058 
00059   void PrintSelf(ostream& os, vtkIndent indent)
00060   {
00061     Superclass::PrintSelf ( os, indent );
00062     this->vtkExporter->PrintSelf ( os, indent );
00063     this->vtkImporter->PrintSelf ( os, indent );
00064   };
00065   
00069   unsigned long int GetMTime()
00070   {
00071     unsigned long int t1, t2;
00072   
00073     t1 = this->Superclass::GetMTime();
00074     t2 = this->vtkExporter->GetMTime();
00075     if (t2 > t1)
00076       {
00077       t1 = t2;
00078       }
00079     t2 = this->vtkImporter->GetMTime();
00080     if (t2 > t1)
00081       {
00082       t1 = t2;
00083       }
00084     return t1;
00085   };
00086 
00089   void Modified()
00090   {
00091     this->Superclass::Modified();
00092     if (this->m_Process)
00093       {
00094       m_Process->Modified();
00095       }
00096   };
00097   
00100   void DebugOn()
00101   {
00102     this->m_Process->DebugOn();
00103   };
00104   
00107   void DebugOff()
00108   {
00109     this->m_Process->DebugOff();
00110   };
00111   
00114   void SetNumberOfThreads(int val)
00115   {
00116     this->m_Process->SetNumberOfThreads(val);
00117   };
00118   
00121   int GetNumberOfThreads()
00122   {
00123     return this->m_Process->GetNumberOfThreads();
00124   };
00125   
00129   void SetOutput ( vtkImageData* d ) { this->vtkImporter->SetOutput ( d ); };
00130   virtual vtkImageData *GetOutput() { return this->vtkImporter->GetOutput(); };
00131   virtual vtkImageData *GetOutput(int idx)
00132   {
00133     return (vtkImageData *) this->vtkImporter->GetOutput(idx);
00134   };
00135 
00138   virtual void SetInput(vtkImageData *Input)
00139   {
00140     this->vtkCast->SetInput(Input);
00141   };
00142 
00145   virtual vtkDataObject* GetInput()
00146   {
00147     return (vtkDataObject::SafeDownCast( this->vtkCast->GetInput() ));
00148   };
00149 
00152   void Update()
00153     {
00154       if (this->GetOutput(0))
00155         {
00156         this->GetOutput(0)->Update();
00157         if ( this->GetOutput(0)->GetSource() )
00158           {
00160           }
00161         }
00162     }
00163   void HandleProgressEvent ()
00164   {
00165     if ( this->m_Process )
00166       {
00167       this->UpdateProgress ( m_Process->GetProgress() );
00168       }
00169   };
00170   void HandleStartEvent ()
00171   {
00172     this->InvokeEvent(vtkCommand::StartEvent,NULL);
00173   };
00174   void HandleEndEvent ()
00175   {
00176     this->InvokeEvent(vtkCommand::EndEvent,NULL);
00177   };
00179 
00180  protected:
00181 
00184   void ExecuteData (vtkDataObject *)
00185   {
00186     vtkWarningMacro(<< "This filter does not respond to Update(). Doing a GetOutput->Update() instead.");
00187   }
00189 
00190   vtkITKImageToImageFilter()
00191   {
00193     this->vtkCast = vtkImageCast::New();
00194     this->vtkExporter = vtkImageExport::New();
00195     this->vtkImporter = vtkImageImport::New();
00196     this->vtkExporter->SetInput ( this->vtkCast->GetOutput() );
00197     this->m_Process = NULL;
00198     this->m_ProgressCommand = MemberCommand::New();
00199     this->m_ProgressCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleProgressEvent );
00200     this->m_StartEventCommand = MemberCommand::New();
00201     this->m_StartEventCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleStartEvent );
00202     this->m_EndEventCommand = MemberCommand::New();
00203     this->m_EndEventCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleEndEvent );
00204   };
00205   ~vtkITKImageToImageFilter()
00206   {
00207     vtkDebugMacro ("Destructing vtkITKImageToImageFilter");
00208     this->vtkExporter->Delete();
00209     this->vtkImporter->Delete();
00210     this->vtkCast->Delete();
00211   };
00212 
00214   void LinkITKProgressToVTKProgress ( itk::ProcessObject* process )
00215   {
00216     if ( process )
00217       {
00218       this->m_Process = process;
00219       this->m_Process->AddObserver ( itk::ProgressEvent(), this->m_ProgressCommand );
00220       this->m_Process->AddObserver ( itk::StartEvent(), this->m_StartEventCommand );
00221       this->m_Process->AddObserver ( itk::EndEvent(), this->m_EndEventCommand );
00222       }
00223   };
00224 
00225   typedef itk::SimpleMemberCommand<vtkITKImageToImageFilter> MemberCommand;
00226   typedef MemberCommand::Pointer MemberCommandPointer;
00227 
00228   itk::ProcessObject::Pointer m_Process;
00229   MemberCommandPointer m_ProgressCommand;
00230   MemberCommandPointer m_StartEventCommand;
00231   MemberCommandPointer m_EndEventCommand;
00232   
00235   vtkImageCast* vtkCast;
00236   vtkImageImport* vtkImporter;
00237   vtkImageExport* vtkExporter;  
00238   
00239 private:
00240   vtkITKImageToImageFilter(const vtkITKImageToImageFilter&);  
00241   void operator=(const vtkITKImageToImageFilter&);  
00242 };
00243 
00244 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines