Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef _vtkKWEITKPaintbrushFilterModule_h
00023 #define _vtkKWEITKPaintbrushFilterModule_h
00024
00025 #include "vtkKWEITKFilterModule.h"
00026
00027 namespace vtkitk
00028 {
00029
00030 template <class TFilterType >
00031 class PaintbrushFilterModule : public FilterModule< TFilterType > {
00032
00033 public:
00034
00035
00036 typedef typename Superclass::FilterType FilterType;
00037 typedef typename Superclass::InputImageType InputImageType;
00038 typedef typename Superclass::OutputImageType OutputImageType;
00039 typedef typename Superclass::PixelType InputPixelType;
00040 typedef typename Superclass::PixelType OutputPixelType;
00041
00042 typedef typename Superclass::SizeType SizeType;
00043 typedef typename Superclass::IndexType IndexType;
00044 typedef typename Superclass::RegionType RegionType;
00045
00047 FilterModule()
00048 {
00049 this->m_ImportFilter = ImportFilterType::New();
00050 this->m_ExportFilter = ExportFilterType::New();
00051 this->m_Filter = FilterType::New();
00052 this->m_Filter->ReleaseDataFlagOn();
00053
00054 this->m_Filter->SetInput( this->m_ImportFilter->GetOutput() );
00055 this->m_ExportFilter->SetInput( this->m_Filter->GetOutput() );
00056
00057
00058 this->m_Filter->AddObserver( itk::ProgressEvent(), this->GetCommandObserver() );
00059 this->m_Filter->AddObserver( itk::StartEvent(), this->GetCommandObserver() );
00060 this->m_Filter->AddObserver( itk::EndEvent(), this->GetCommandObserver() );
00061 this->m_LetITKAllocateOutputMemory = false;
00062 }
00063
00065 virtual ~FilterModule()
00066 {
00067 }
00068
00070 void SetInput(vtkImageData * image)
00071 {
00072 this->m_ImportFilter->SetInput(image);
00073 }
00074
00076 const InputImageType * GetInput()
00077 {
00078 this->m_ImportFilter->Update();
00079 return this->m_ImportFilter->GetOutput();
00080 }
00081
00083 FilterType * GetFilter()
00084 {
00085 return this->m_Filter.GetPointer();
00086 }
00087
00088 void SetLetITKAllocateOutputMemory(bool s)
00089 {
00090 this->m_LetITKAllocateOutputMemory = s;
00091 }
00092
00093
00094
00095 void SetOutputBuffer( void * buffer )
00096 {
00097 this->m_LetITKAllocateOutputMemory = false;
00098 RegionType region = this->m_Filter->GetOutput()->GetLargestPossibleRegion();
00099 const unsigned long nPixels = region.GetNumberOfPixels();
00100 this->m_Filter->GetOutput()->SetImportPointer(
00101 static_cast< OutputPixelType * >(buffer), nPixels );
00102 this->m_Filter->GetOutput()->Allocate( );
00103 }
00104
00105 void SetOutputRegion( RegionType region )
00106 {
00107 this->m_Filter->GetOutput()->SetRegions( region );
00108 }
00109
00111 virtual void Update( const vtkVVProcessDataStruct * pds )
00112 {
00113
00114
00115 this->InitializeProgressValue();
00116 this->SetCurrentFilterProgressWeight( 1.0 );
00117
00118
00119 try
00120 {
00121 this->m_ImportFilter->Update();
00122 }
00123 catch( itk::ProcessAborted & e )
00124 {
00125 }
00126
00127
00128 try
00129 {
00130 this->m_Filter->Update();
00131 }
00132 catch( itk::ProcessAborted & e)
00133 {
00134 std::cerr << "ITK error " << e.what() << std::endl;
00135 }
00136
00137
00138 try
00139 {
00140 this->m_ExportFilter->Update();
00141 }
00142 catch( itk::ProcessAborted & e)
00143 {
00144 std::cerr << "ITK error " << e.what() << std::endl;
00145 }
00146 }
00147
00148 vtkImageData * GetOutput()
00149 {
00150 return this->m_ExportFilter->GetOutput();
00151 }
00152
00153 private:
00154
00155 typename ImportFilterType::Pointer m_ImportFilter;
00156 typename FilterType::Pointer m_Filter;
00157 bool m_LetITKAllocateOutputMemory;
00158 typename ExportFilterType::Pointer m_ExportFilter;
00159 };
00160
00161 }
00162
00163 #endif