Slicer  4.10
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.
1 /*=========================================================================
2 
3  Copyright Brigham and Women's Hospital (BWH) All Rights Reserved.
4 
5  See COPYRIGHT.txt
6  or http://www.slicer.org/copyright/copyright.txt for details.
7 
8  Program: vtkITK
9  Module: $HeadURL$
10  Date: $Date$
11  Version: $Revision$
12 
13 ==========================================================================*/
14 
15 #ifndef __vtkITKImageToImageFilter_h
16 #define __vtkITKImageToImageFilter_h
17 
18 #include "vtkITK.h"
19 
20 // ITK includes
21 #include <itkCommand.h>
22 #include <itkProcessObject.h>
23 
24 // VTK includes
25 #include <vtkCommand.h>
26 #include <vtkImageAlgorithm.h>
27 #include <vtkImageCast.h>
28 #include <vtkImageData.h>
29 #include <vtkImageExport.h>
30 #include <vtkImageImport.h>
31 #include <vtkVersion.h>
32 
33 #undef itkExceptionMacro
34 #define itkExceptionMacro(x) \
35  { \
36  ::std::ostringstream message; \
37  message << "itk::ERROR: " << this->GetNameOfClass() \
38  << "(" << this << "): "; \
39  std::cout << message.str().c_str() << std::endl; \
40  }
41 
42 #undef itkGenericExceptionMacro
43 #define itkGenericExceptionMacro(x) \
44  { \
45  ::std::ostringstream message; \
46  message << "itk::ERROR: " x; \
47  std::cout << message.str() << std::endl; \
48  }
49 
53 class VTK_ITK_EXPORT vtkITKImageToImageFilter
54  : public vtkImageAlgorithm
55 {
56 public:
58  {
60 #ifdef VTK_HAS_INITIALIZE_OBJECT_BASE
61  result->InitializeObjectBase();
62 #endif
63  return result;
64  };
65 
66  vtkTypeMacro(vtkITKImageToImageFilter, vtkImageAlgorithm);
67 
68  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE
69  {
70  Superclass::PrintSelf ( os, indent );
71  this->vtkExporter->PrintSelf ( os, indent );
72  this->vtkImporter->PrintSelf ( os, indent );
73  };
74 
78  vtkMTimeType GetMTime() VTK_OVERRIDE
79  {
80  vtkMTimeType t1, t2;
81 
82  t1 = this->Superclass::GetMTime();
83  t2 = this->vtkExporter->GetMTime();
84  if (t2 > t1)
85  {
86  t1 = t2;
87  }
88  t2 = this->vtkImporter->GetMTime();
89  if (t2 > t1)
90  {
91  t1 = t2;
92  }
93  return t1;
94  };
95 
98  void Modified() VTK_OVERRIDE
99  {
100  this->Superclass::Modified();
101  if (this->m_Process)
102  {
103  m_Process->Modified();
104  }
105  };
106 
109  void DebugOn() VTK_OVERRIDE
110  {
111  this->m_Process->DebugOn();
112  };
113 
116  void DebugOff() VTK_OVERRIDE
117  {
118  this->m_Process->DebugOff();
119  };
120 
123  void SetNumberOfThreads(int val)
124  {
125  this->m_Process->SetNumberOfThreads(val);
126  };
127 
131  {
132  return this->m_Process->GetNumberOfThreads();
133  };
134 
138  virtual void SetOutput ( vtkDataObject* d ) VTK_OVERRIDE { this->vtkImporter->SetOutput ( d ); };
139  virtual vtkImageData *GetOutput() { return this->vtkImporter->GetOutput(); };
140  virtual vtkImageData *GetOutput(int idx)
141  {
142  return (vtkImageData *) this->vtkImporter->GetOutput(idx);
143  };
144 
147  virtual void SetInput(vtkImageData *Input)
148  {
149  this->vtkCast->SetInputData(Input);
150  };
151 
152  virtual void SetInputConnection(vtkAlgorithmOutput* input) VTK_OVERRIDE
153  {
154  this->vtkCast->SetInputConnection(input);
155  };
156 
157  virtual void SetInputConnection(int port, vtkAlgorithmOutput* input) VTK_OVERRIDE
158  {
159  this->vtkCast->SetInputConnection(port, input);
160  };
161 
164  virtual vtkDataObject* GetInput()
165  {
166  return (vtkDataObject::SafeDownCast( this->vtkCast->GetInput() ));
167  };
168 
171  using vtkAlgorithm::Update;
172  virtual void Update() VTK_OVERRIDE
173  {
174  this->vtkCast->Update();
175  this->vtkImporter->Update();
176  }
177  virtual void Update(int port) VTK_OVERRIDE
178  {
179  this->vtkCast->Update();
180  this->vtkImporter->Update(port);
181  }
183  {
184  if ( this->m_Process )
185  {
186  this->UpdateProgress ( m_Process->GetProgress() );
187  }
188  };
190  {
191  this->InvokeEvent(vtkCommand::StartEvent,NULL);
192  };
194  {
195  this->InvokeEvent(vtkCommand::EndEvent,NULL);
196  };
198 
199  protected:
200 
203  void ExecuteData (vtkDataObject *) VTK_OVERRIDE
204  {
205  vtkWarningMacro(<< "This filter does not respond to Update(). Doing a GetOutput->Update() instead.");
206  }
208 
210  {
212  this->vtkCast = vtkImageCast::New();
213  this->vtkExporter = vtkImageExport::New();
214  this->vtkImporter = vtkImageImport::New();
215  this->vtkExporter->SetInputConnection( this->vtkCast->GetOutputPort() );
216  this->m_Process = NULL;
217  this->m_ProgressCommand = MemberCommand::New();
218  this->m_ProgressCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleProgressEvent );
219  this->m_StartEventCommand = MemberCommand::New();
220  this->m_StartEventCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleStartEvent );
221  this->m_EndEventCommand = MemberCommand::New();
222  this->m_EndEventCommand->SetCallbackFunction ( this, &vtkITKImageToImageFilter::HandleEndEvent );
223  };
225  {
226  vtkDebugMacro ("Destructing vtkITKImageToImageFilter");
227  this->vtkExporter->Delete();
228  this->vtkImporter->Delete();
229  this->vtkCast->Delete();
230  };
231 
233  void LinkITKProgressToVTKProgress ( itk::ProcessObject* process )
234  {
235  if ( process )
236  {
237  this->m_Process = process;
238  this->m_Process->AddObserver ( itk::ProgressEvent(), this->m_ProgressCommand );
239  this->m_Process->AddObserver ( itk::StartEvent(), this->m_StartEventCommand );
240  this->m_Process->AddObserver ( itk::EndEvent(), this->m_EndEventCommand );
241  }
242  };
243 
244  typedef itk::SimpleMemberCommand<vtkITKImageToImageFilter> MemberCommand;
245  typedef MemberCommand::Pointer MemberCommandPointer;
246 
247  itk::ProcessObject::Pointer m_Process;
251 
254  vtkImageCast* vtkCast;
255  vtkImageImport* vtkImporter;
256  vtkImageExport* vtkExporter;
257 
258 private:
260  void operator=(const vtkITKImageToImageFilter&);
261 };
262 
263 #endif
MemberCommandPointer m_ProgressCommand
MemberCommand::Pointer MemberCommandPointer
virtual vtkImageData * GetOutput()
void SetNumberOfThreads(int val)
Pass SetNumberOfThreads.
MemberCommandPointer m_StartEventCommand
Abstract base class for connecting ITK and VTK.
void ExecuteData(vtkDataObject *) VTK_OVERRIDE
ETX.
int GetNumberOfThreads()
Pass SetNumberOfThreads.
virtual void SetOutput(vtkDataObject *d) VTK_OVERRIDE
MemberCommandPointer m_EndEventCommand
void DebugOn() VTK_OVERRIDE
Pass DebugOn.
vtkMTimeType GetMTime() VTK_OVERRIDE
virtual void Update() VTK_OVERRIDE
void PrintSelf(ostream &os, vtkIndent indent) VTK_OVERRIDE
virtual void SetInputConnection(vtkAlgorithmOutput *input) VTK_OVERRIDE
virtual void SetInput(vtkImageData *Input)
Set the Input of the filter.
void LinkITKProgressToVTKProgress(itk::ProcessObject *process)
BTX.
virtual vtkDataObject * GetInput()
Return the input to the filter
itk::ProcessObject::Pointer m_Process
void DebugOff() VTK_OVERRIDE
Pass DebugOff.
virtual vtkImageData * GetOutput(int idx)
virtual void Update(int port) VTK_OVERRIDE
virtual void SetInputConnection(int port, vtkAlgorithmOutput *input) VTK_OVERRIDE
static vtkITKImageToImageFilter * New()
void Modified() VTK_OVERRIDE
Pass modified message to itk filter