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 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
|
/*=========================================================================
Program: ITK-SNAP
Module: $RCSfile: ScalarImageWrapper.h,v $
Language: C++
Date: $Date: 2009/01/23 20:09:38 $
Version: $Revision: 1.3 $
Copyright (c) 2007 Paul A. Yushkevich
This file is part of ITK-SNAP
ITK-SNAP is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-----
Copyright (c) 2003 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 __ScalarImageWrapper_h_
#define __ScalarImageWrapper_h_
#include "ImageWrapper.h"
#include "vtkSmartPointer.h"
// Forward references
template<class TIn> class ThreadedHistogramImageFilter;
namespace itk {
template<class TIn> class MinimumMaximumImageFilter;
template<class TInputImage> class VTKImageExport;
template<class TOut> class ImageSource;
}
class vtkImageImport;
/**
* \class ScalarImageWrapper
* \brief A wrapper around an itk::Image and related pipelines.
*
* ScalarImage Wrapper serves as a wrapper around an image pointer, and
* is used to unify the treatment of different kinds of scalar images in
* SNaP.
*/
template<class TTraits, class TBase = ScalarImageWrapperBase>
class ScalarImageWrapper : public ImageWrapper<TTraits, TBase>
{
public:
// Standard ITK business
typedef ScalarImageWrapper<TTraits, TBase> Self;
typedef ImageWrapper<TTraits, TBase> Superclass;
typedef SmartPtr<Self> Pointer;
typedef SmartPtr<const Self> ConstPointer;
itkTypeMacro(ScalarImageWrapper, ImageWrapper)
itkNewMacro(Self)
// Image Types
typedef typename Superclass::ImageBaseType ImageBaseType;
typedef typename Superclass::ImageType ImageType;
typedef typename Superclass::ImagePointer ImagePointer;
typedef typename Superclass::PixelType PixelType;
typedef typename Superclass::CommonFormatImageType CommonFormatImageType;
typedef typename Superclass::PreviewImageType PreviewImageType;
// Floating point image type
typedef itk::Image<float, 3> FloatImageType;
typedef itk::ImageSource<FloatImageType> FloatImageSource;
// Double precision floating point image type
typedef itk::Image<double, 3> DoubleImageType;
typedef itk::ImageSource<DoubleImageType> DoubleImageSource;
// Vector image types
typedef itk::VectorImage<float, 3> FloatVectorImageType;
typedef itk::ImageSource<FloatVectorImageType> FloatVectorImageSource;
typedef itk::VectorImage<double, 3> DoubleVectorImageType;
typedef itk::ImageSource<DoubleVectorImageType> DoubleVectorImageSource;
// Slice image type
typedef typename Superclass::SliceType SliceType;
typedef typename Superclass::SlicePointer SlicePointer;
// Slicer type
typedef typename Superclass::SlicerType SlicerType;
typedef typename Superclass::SlicerPointer SlicerPointer;
// Display types
typedef typename Superclass::DisplaySliceType DisplaySliceType;
typedef typename Superclass::DisplayPixelType DisplayPixelType;
// MinMax calculator type
typedef itk::MinimumMaximumImageFilter<ImageType> MinMaxFilter;
// Histogram filter
typedef ThreadedHistogramImageFilter<ImageType> HistogramFilterType;
// Iterator types
typedef typename Superclass::Iterator Iterator;
typedef typename Superclass::ConstIterator ConstIterator;
// Output channels
typedef typename Superclass::ExportChannel ExportChannel;
// Pipeline objects wrapped around values
typedef typename Superclass::ComponentTypeObject ComponentTypeObject;
typedef typename Superclass::NativeIntensityMapping NativeIntensityMapping;
typedef typename Superclass::ITKTransformType ITKTransformType;
virtual bool IsScalar() const { return true; }
/**
* This function just returns the pointer to itself, as the scalar representation
* of a scalar image wrapper is itself.
* @see ImageWrapperBase::GetScalarRepresentation
*/
ScalarImageWrapperBase *GetDefaultScalarRepresentation() { return this; }
/** Access the min/max filter */
irisGetMacro(MinMaxFilter, MinMaxFilter *)
/**
* Get the scaling factor used to convert between intensities stored
* in this image and the 'true' image intensities
*/
virtual double GetImageScaleFactor();
typedef typename ImageWrapperBase::ShortImageType ShortImageType;
/** This image type has only one component */
virtual size_t GetNumberOfComponents() const { return 1; }
/** Voxel access */
virtual double GetVoxelAsDouble(const itk::Index<3> &idx) const
{ return (double) Superclass::GetVoxel(idx); }
virtual double GetVoxelAsDouble(const Vector3ui &v) const
{ return (double) Superclass::GetVoxel(v); }
virtual void GetVoxelAsDouble(const Vector3ui &x, double *out) const
{ out[0] = Superclass::GetVoxel(x); }
virtual void GetVoxelAsDouble(const itk::Index<3> &idx, double *out) const
{ out[0] = Superclass::GetVoxel(idx); }
/**
* Get voxel intensity in native space
*/
double GetVoxelMappedToNative(const Vector3ui &vec) const
{ return this->m_NativeMapping(this->GetVoxel(vec)); }
double GetVoxelMappedToNative(const itk::Index<3> &idx) const
{ return this->m_NativeMapping(this->GetVoxel(idx)); }
virtual void GetVoxelMappedToNative(const Vector3ui &vec, double *out) const
{ out[0] = this->m_NativeMapping(Superclass::GetVoxel(vec)); }
virtual void GetVoxelMappedToNative(const itk::Index<3> &idx, double *out) const
{ out[0] = this->m_NativeMapping(Superclass::GetVoxel(idx)); }
/** Compute statistics over a run of voxels in the image starting at the index
* startIdx. Appends the statistics to a running sum and sum of squared. The
* statistics are returned in internal (not native mapped) format */
virtual void GetRunLengthIntensityStatistics(
const itk::ImageRegion<3> ®ion,
const itk::Index<3> &startIdx, long runlength,
double *out_sum, double *out_sumsq) const;
/**
* This method returns a vector of values for the voxel under the cursor.
* This is the natural value or set of values that should be displayed to
* the user. The value depends on the current display mode. For scalar
* images, it's just the value of the voxel, but for multi-component images,
* it's the value of the selected component (if there is one) or the value
* of the multiple components when the mode is RGB. In the second parameter,
* the method returns the RGB appearance of the voxel under the cursor
*/
virtual void GetVoxelUnderCursorDisplayedValueAndAppearance(
vnl_vector<double> &out_value, DisplayPixelType &out_appearance);
virtual ComponentTypeObject *GetImageMinObject() const;
virtual ComponentTypeObject *GetImageMaxObject() const;
/**
Compute the image histogram. The histogram is cached inside of the
object, so repeated calls to this function with the same nBins parameter
will not require additional computation.
Calling with default parameter (0) will use the same number of bins that
is currently in the histogram (i.e., return/recompute current histogram).
If there is no current histogram, a default histogram with 128 entries
will be generated.
For multi-component data, the histogram is pooled over all components.
*/
const ScalarImageHistogram *GetHistogram(size_t nBins = 0);
/**
Get the maximum possible value of the gradient magnitude. This will
compute the gradient magnitude of the image (without Gaussian smoothing)
and return the maximum. The value will be cached so repeated calls to
this are not expensive.
*/
double GetImageGradientMagnitudeUpperLimit();
/**
Get the maximum possible value of the gradient magnitude in native units
*/
double GetImageGradientMagnitudeUpperLimitNative();
/**
This method creates an ITK mini-pipeline that can be used to cast the internal
image to a floating point image. The ownership of the mini-pipeline is passed
to the caller of this method. This method should be used with caution, since
there is potential to create duplicates of the internally stored image without
need. The best practice is to use this method with filters that only access a
portion of the casted image at a time, such as streaming filters.
When you call Update() on the returned mini-pipeline, the data will be cast to
floating point, and if necessary, converted to the native intensity range.
*/
SmartPtr<FloatImageSource> CreateCastToFloatPipeline() const;
/** Same as above, but casts to double. For compatibility with C3D, until we
* safely switch C3D to use float instead of double */
SmartPtr<DoubleImageSource> CreateCastToDoublePipeline() const;
/** Same as CreateCastToFloatPipeline, but for vector images of single dimension */
SmartPtr<FloatVectorImageSource> CreateCastToFloatVectorPipeline() const;
/** Same as CreateCastToFloatPipeline, but for vector images of single dimension */
SmartPtr<DoubleVectorImageSource> CreateCastToDoubleVectorPipeline() const;
/**
* Get an image cast to a common representation.
* @see ScalarImageWrapperBase::GetCommonFormatImage()
*/
CommonFormatImageType* GetCommonFormatImage(
ExportChannel channel = ScalarImageWrapperBase::WHOLE_IMAGE);
/** Return the intensity curve for this layer if it exists */
virtual IntensityCurveInterface *GetIntensityCurve() const;
/** Return the color map for this layer if it exists */
virtual ColorMap *GetColorMap() const;
/** Get a version of this image that is usable in VTK pipelines */
vtkImageImport *GetVTKImporter();
/** Extends parent method */
virtual void SetNativeMapping(NativeIntensityMapping mapping);
protected:
/**
* Default constructor. Creates an image wrapper with a blank internal
* image
*/
ScalarImageWrapper();
/**
* Copy constructor. Copies the contents of the passed-in image wrapper.
*/
ScalarImageWrapper(const Self ©);
/** Destructor */
virtual ~ScalarImageWrapper();
/**
* The min-max filter used to compute the range of the image on demand.
*/
SmartPtr<MinMaxFilter> m_MinMaxFilter;
/**
* The filter used for histogram computation
*/
SmartPtr<HistogramFilterType> m_HistogramFilter;
// The policy used to extract a common representation image
typedef typename TTraits::CommonRepresentationPolicy CommonRepresentationPolicy;
CommonRepresentationPolicy m_CommonRepresentationPolicy;
/** The intensity scaling factor */
double m_ImageScaleFactor;
/**
* Compute the intensity range of the image if it's out of date.
* This is done before calling GetImateMin, GetImateMax and GetImageScaleFactor methods.
*/
void CheckImageIntensityRange();
/**
* Handle a change in the image pointer (i.e., a load operation on the image or
* an initialization operation)
*/
virtual void UpdateImagePointer(ImageType *image,
ImageBaseType *refSpace = NULL,
ITKTransformType *tran = NULL);
//typedef itk::VTKImageExport<ImageType> VTKExporter;
//SmartPtr<VTKExporter> m_VTKExporter;
vtkSmartPointer<vtkImageImport> m_VTKImporter;
//void SetupVTKImportExport();
};
#endif // __ScalarImageWrapper_h_
|