1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242
|
/*=========================================================================
Copyright (c) Kitware, Inc.
All rights reserved.
See Copyright.txt or http://www.kitware.com/VolViewCopyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
/** Generic interface for protocol communication between an ITK filter
and the VolView Plugin Interface */
#ifndef _vvITKFilterModuleRGBDoubleOutput_h
#define _vvITKFilterModuleRGBDoubleOutput_h
#include "vvITKFilterModule.h"
#include "itkRGBPixel.h"
#include "itkImportImageFilter.h"
namespace VolView
{
namespace PlugIn
{
template <class TFilterType >
class FilterModuleRGBDoubleOutput : public FilterModuleBase {
public:
typedef FilterModuleBase Superclass;
// Instantiate the image types
typedef TFilterType FilterType;
typedef typename FilterType::InputImageType InputImageType;
typedef typename FilterType::OutputImageType OutputImageType;
typedef typename InputImageType::PixelType InputPixelType;
typedef unsigned char OutputPixelType;
itkStaticConstMacro( Dimension, unsigned int,
itk::GetImageDimension< InputImageType >::ImageDimension );
// Instantiate the ImportImageFilter
// This filter is used for building an ITK image using
// the data passed in a buffer.
typedef itk::ImportImageFilter< InputPixelType,
Dimension > ImportFilterType;
typedef typename InputImageType::SizeType SizeType;
typedef typename InputImageType::IndexType IndexType;
typedef typename InputImageType::RegionType RegionType;
public:
/** Constructor */
FilterModuleRGBDoubleOutput()
{
m_ProduceDoubleOutput = false;
m_ImportFilter = ImportFilterType::New();
m_Filter = FilterType::New();
m_Filter->SetInput( m_ImportFilter->GetOutput() );
// Set the Observer for updating progress in the GUI
m_Filter->AddObserver( itk::ProgressEvent(), this->GetCommandObserver() );
m_Filter->AddObserver( itk::StartEvent(), this->GetCommandObserver() );
m_Filter->AddObserver( itk::EndEvent(), this->GetCommandObserver() );
}
/** Destructor */
virtual ~FilterModuleRGBDoubleOutput()
{
}
/** Enable/Disable the production of the second output */
void SetProduceDoubleOutput( bool value )
{
m_ProduceDoubleOutput = value;
}
/** Return a pointer to the internal filter */
FilterType * GetFilter()
{
return m_Filter.GetPointer();
}
/** Copy the result of the processing to the output */
virtual void CopyOutputData( const vtkVVProcessDataStruct * pds )
{
// Copy the data (with casting) to the output buffer provided by the PlugIn API
typename OutputImageType::ConstPointer outputImage =
this->GetFilter()->GetOutput();
typedef itk::ImageRegionConstIterator< OutputImageType > OutputIteratorType;
OutputIteratorType ot( outputImage, outputImage->GetBufferedRegion() );
typename InputImageType::ConstPointer inputImage =
this->GetFilter()->GetInput();
typedef itk::ImageRegionConstIterator< InputImageType > InputIteratorType;
InputIteratorType it( inputImage, inputImage->GetBufferedRegion() );
OutputPixelType * outData = (OutputPixelType *)(pds->outData);
ot.GoToBegin();
if( !m_ProduceDoubleOutput )
{
while( !ot.IsAtEnd() )
{
*outData = ot.Get(); // copy output pixel
++outData;
++ot;
}
}
else
{
while( !ot.IsAtEnd() )
{
*outData = static_cast< OutputPixelType >( it.Get().GetRed() ); // copy input pixel
++outData;
*outData = static_cast< OutputPixelType >( it.Get().GetGreen() ); // copy input pixel
++outData;
*outData = static_cast< OutputPixelType >( it.Get().GetBlue() ); // copy input pixel
++outData;
*outData = ot.Get(); // copy output pixel
++outData;
++ot;
++it;
}
}
}
/** ProcessData performs the actual filtering on the data */
virtual void
ProcessData( const vtkVVProcessDataStruct * pds )
{
this->InitializeProgressValue();
this->SetCurrentFilterProgressWeight( 1.0 );
const unsigned int numberOfComponents = this->GetPluginInfo()->InputVolumeNumberOfComponents;
this->ImportPixelBuffer( pds );
// Execute the filter
try
{
m_Filter->Update();
}
catch( itk::ProcessAborted & )
{
return;
}
this->CopyOutputData( pds );
}
virtual void
ImportPixelBuffer( const vtkVVProcessDataStruct * pds )
{
SizeType size;
IndexType start;
double origin[3];
double spacing[3];
size[0] = this->GetPluginInfo()->InputVolumeDimensions[0];
size[1] = this->GetPluginInfo()->InputVolumeDimensions[1];
size[2] = pds->NumberOfSlicesToProcess;
for(unsigned int i=0; i<3; i++)
{
origin[i] = this->GetPluginInfo()->InputVolumeOrigin[i];
spacing[i] = this->GetPluginInfo()->InputVolumeSpacing[i];
start[i] = 0;
}
RegionType region;
region.SetIndex( start );
region.SetSize( size );
m_ImportFilter->SetSpacing( spacing );
m_ImportFilter->SetOrigin( origin );
m_ImportFilter->SetRegion( region );
const unsigned int totalNumberOfPixels = region.GetNumberOfPixels();
const unsigned int numberOfComponents = this->GetPluginInfo()->InputVolumeNumberOfComponents;
const unsigned int numberOfPixelsPerSlice = size[0] * size[1];
const bool importFilterWillDeleteTheInputBuffer = false;
InputPixelType * dataBlockStart =
static_cast< InputPixelType * >( pds->inData )
+ numberOfPixelsPerSlice * pds->StartSlice;
m_ImportFilter->SetImportPointer( dataBlockStart,
totalNumberOfPixels,
importFilterWillDeleteTheInputBuffer );
} // end of ImportPixelBuffer
private:
typename FilterType::Pointer m_Filter;
typename ImportFilterType::Pointer m_ImportFilter;
bool m_ProduceDoubleOutput;
};
} // end namespace PlugIn
} // end namespace VolView
#endif
|