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
|
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: itkImageToListGenerator.h,v $
Language: C++
Date: $Date: 2007-04-25 22:25:16 $
Version: $Revision: 1.3 $
Copyright (c) Insight Software Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.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 notices for more information.
=========================================================================*/
#ifndef __itkImageToListGenerator_h
#define __itkImageToListGenerator_h
#include "itkListSample.h"
#include "itkPixelTraits.h"
#include "itkProcessObject.h"
#include "itkDataObject.h"
#include "itkDataObjectDecorator.h"
#include "itkFixedArray.h"
namespace itk {
namespace Statistics {
/** \class ImageToListGenerator
* \brief The class takes an image as input and generates a list sample as
* output.
*
* There are differences between this class and ImageToListAdaptor. This
* class is not an adaptor. It creates a new list sample and does not
* provide a pseudo interface to the actual image to make it look like a
* list sample.
*
* The class optionally allows you to specify a mask image as an input. The
* list sample (if a mask is specified) is constructed from pixels that are
* within the mask
*
* \todo
* In future allow the filter to take a Spatial object as input so a
* generic spatial object like an ellipse etc can be used as a mask.
* Sure the ImageMaskSpatialObject
* can represent image masks too, so why not make SpatialObjects the default. I
* think the ImageMaskSpatialObject is slow in terms of inefficient iteration
* through the image.
*
* \sa ImageToListAdaptor
*/
template < class TImage, class TMaskImage = TImage >
class ITK_EXPORT ImageToListGenerator :
public ProcessObject
{
public:
/** Standard class typedefs */
typedef ImageToListGenerator Self;
typedef ProcessObject Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer<const Self> ConstPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(ImageToListGenerator, ProcessObject);
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Image typedefs */
typedef TImage ImageType;
typedef typename ImageType::Pointer ImagePointer;
typedef typename ImageType::ConstPointer ImageConstPointer;
typedef typename ImageType::PixelType PixelType;
typedef FixedArray< PixelType, 1 > MeasurementVectorType;
/** Mask Image typedefs */
typedef TMaskImage MaskImageType;
typedef typename MaskImageType::Pointer MaskImagePointer;
typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
typedef typename MaskImageType::PixelType MaskPixelType;
/** Type of the output list sample */
typedef ListSample< MeasurementVectorType > ListSampleType;
/** Superclass typedefs for Measurement vector, measurement,
* Instance Identifier, frequency, size, size element value */
typedef PixelTraits< typename ImageType::PixelType > PixelTraitsType;
typedef typename ListSampleType::MeasurementVectorSizeType
MeasurementVectorSizeType;
typedef DataObject::Pointer DataObjectPointer;
/** ListSample is not a DataObject, we need to decorate it to push it down
* a ProcessObject's pipeline */
typedef DataObjectDecorator< ListSampleType > ListSampleOutputType;
/** the number of components in a measurement vector */
itkStaticConstMacro(MeasurementVectorSize, unsigned int,
PixelTraitsType::Dimension);
/** Standard itk::ProcessObject subclass method. */
virtual DataObjectPointer MakeOutput(unsigned int idx);
virtual void SetMeasurementVectorSize( const MeasurementVectorSizeType s )
{
// Measurement vector size for this class is fixed as the pixel's
// dimension. This method should throw an exception if the user tries to
// set the dimension to a different value.
if( s != MeasurementVectorSize )
{
itkExceptionMacro(
<< "Measurement vector size for the image adaptor obtained"
<< " from the pixel dimension is: "
<< MeasurementVectorSize << " but you "
<< "are setting it to " << s);
}
}
unsigned int GetMeasurementVectorSize() const
{
return MeasurementVectorSize;
}
/** Method to set/get the image */
void SetInput( const ImageType* image );
const ImageType* GetInput() const;
/** Method to set/get the mask */
void SetMaskImage( const MaskImageType* image );
const MaskImageType* GetMaskImage() const;
/** Method to get the list sample, the generated output. Note that this does
* not invoke Update(). You should have called update on this class to get
* any meaningful output. */
const ListSampleType * GetListSample() const;
/** Set the pixel value treated as on in the mask. If a mask has been
* specified, only pixels with this value will be added to the list sample, if
* no mask has been specified all pixels will be added as measurement vectors
* to the list sample. */
itkSetMacro( MaskValue, MaskPixelType );
itkGetMacro( MaskValue, MaskPixelType );
/** This method causes the filter to generate its output. */
virtual void GenerateData();
/** This method ensures that a mask image if specified has requested regions
* that at least contain the input image's buffered region. */
virtual void GenerateInputRequestedRegion()
throw(InvalidRequestedRegionError);
virtual void GenerateOutputInformation();
protected:
ImageToListGenerator();
virtual ~ImageToListGenerator() {}
void PrintSelf(std::ostream& os, Indent indent) const;
private:
ImageToListGenerator(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
MaskPixelType m_MaskValue;
}; // end of class ImageToListGenerator
} // end of namespace Statistics
} // end of namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkImageToListGenerator.txx"
#endif
#endif
|