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
|
/*=========================================================================
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 _vvITKFilterModuleDoubleOutput_h
#define _vvITKFilterModuleDoubleOutput_h
#include "vvITKFilterModule.h"
namespace VolView
{
namespace PlugIn
{
template <class TFilterType >
class FilterModuleDoubleOutput : public FilterModule<TFilterType> {
public:
typedef FilterModule<TFilterType> Superclass;
// Instantiate the image types
typedef typename Superclass::FilterType FilterType;
typedef typename Superclass::InputImageType InputImageType;
typedef typename Superclass::OutputImageType OutputImageType;
typedef typename Superclass::InputPixelType InputPixelType;
typedef typename Superclass::OutputPixelType OutputPixelType;
itkStaticConstMacro( Dimension, unsigned int,
itk::GetImageDimension< InputImageType >::ImageDimension );
typedef typename Superclass::ImportFilterType ImportFilterType;
typedef typename Superclass::SizeType SizeType;
typedef typename Superclass::IndexType IndexType;
typedef typename Superclass::RegionType RegionType;
public:
/** Constructor */
FilterModuleDoubleOutput()
{
m_ProduceDoubleOutput = false;
}
/** Destructor */
virtual ~FilterModuleDoubleOutput()
{
}
/** Enable/Disable the production of the second output */
void SetProduceDoubleOutput( bool value )
{
m_ProduceDoubleOutput = value;
}
/** 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() );
ot.GoToBegin();
if( m_ProduceDoubleOutput )
{
typename InputImageType::ConstPointer inputImage =
this->GetFilter()->GetInput();
typedef itk::ImageRegionConstIterator< InputImageType > InputIteratorType;
InputIteratorType it( inputImage, inputImage->GetBufferedRegion() );
it.GoToBegin();
// When producing composite output, the output image must have the same
// type as the input image. Therefore, we use InputPixelType instead of
// OutputPixelType.
InputPixelType * outData = (InputPixelType *)(pds->outData);
while( !ot.IsAtEnd() )
{
*outData = static_cast< InputPixelType >( it.Get() ); // copy input pixel
++outData;
*outData = static_cast< InputPixelType >(ot.Get()); // copy output pixel
++outData;
++ot;
++it;
}
}
else
{
OutputPixelType * outData = (OutputPixelType *)(pds->outData);
while( !ot.IsAtEnd() )
{
*outData = ot.Get(); // copy output pixel
++outData;
++ot;
}
}
}
/** 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;
if( numberOfComponents != 1 )
{
itk::ExceptionObject excp;
excp.SetDescription("This filter is intendended to be used with single-componente data only");
throw excp;
}
this->ImportPixelBuffer( 0, pds );
if( !m_ProduceDoubleOutput )
{
this->ExportPixelBuffer( 0, pds );
}
// Execute the filter
try
{
this->GetFilter()->Update();
}
catch( itk::ProcessAborted & )
{
return;
}
this->CopyOutputData( pds );
}
private:
bool m_ProduceDoubleOutput;
};
} // end namespace PlugIn
} // end namespace VolView
#endif
|