/usr/include/ITK-4.9/itkImageAdaptor.h is in libinsighttoolkit4-dev 4.9.0-4ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | /*=========================================================================
*
* Copyright Insight Software Consortium
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#ifndef itkImageAdaptor_h
#define itkImageAdaptor_h
#include "itkImage.h"
namespace itk
{
template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
/**
* \class ImageAdaptor
* \brief Give access to partial aspects of voxels from an Image
*
* ImageAdaptors are templated over the ImageType and over a functor
* that will specify what part of the pixel can be accessed
*
* The basic aspects of this class are the types it defines.
*
* Image adaptors can be used as intermediate classes that allow
* the sending of an image to a filter, specifying what part of the
* image pixels the filter will act on.
*
* The TAccessor class should implement the Get and Set methods
* These two will specify how data can be put
* and get from parts of each pixel. It should define the types
* ExternalType and InternalType too.
*
* \ingroup ImageAdaptors
*
* \ingroup ITKImageAdaptors
*
* \wiki
* \wikiexample{ImageProcessing/ImageAdaptorExtractVectorComponent,Present an image by first performing an operation}
* \endwiki
*/
template< typename TImage, typename TAccessor >
class ImageAdaptor:public ImageBase< TImage::ImageDimension >
{
public:
/** Dimension of the image. This constant is used by functions that are
* templated over image type (as opposed to being templated over pixel
* type and dimension) when they need compile time access to the dimension
* of the image. */
itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
/** Standard class typedefs. */
typedef ImageAdaptor Self;
typedef ImageBase< itkGetStaticConstMacro(ImageDimension) > Superclass;
typedef SmartPointer< Self > Pointer;
typedef SmartPointer< const Self > ConstPointer;
typedef WeakPointer< const Self > ConstWeakPointer;
/** Run-time type information (and related methods). */
itkTypeMacro(ImageAdaptor, ImageBase);
/** Typedef of unadapted image */
typedef TImage InternalImageType;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Pixel typedef support. Used to declare pixel type in filters
* or other operations. */
typedef typename TAccessor::ExternalType PixelType;
/** Pixel typedef support. Used to declare pixel type in filters
* or other operations. */
typedef typename TAccessor::InternalType InternalPixelType;
typedef PixelType IOPixelType;
/** Accessor type that convert data between internal and external
* representations. */
typedef TAccessor AccessorType;
/** typedef of the functor that chooses the appropriate accessor
* Image or VectorImage. */
typedef typename InternalImageType::AccessorFunctorType::template Rebind< Self >::Type AccessorFunctorType;
/** Index typedef support. An index is used to access pixel values. */
typedef typename Superclass::IndexType IndexType;
typedef typename IndexType::IndexValueType IndexValueType;
/** Size typedef support. A size is used to define region bounds. */
typedef typename Superclass::SizeType SizeType;
typedef typename SizeType::SizeValueType SizeValueType;
/** Offset typedef support. */
typedef typename Superclass::OffsetType OffsetType;
typedef typename OffsetType::OffsetValueType OffsetValueType;
/** Region typedef support. A region is used to specify a subset of
* an image. */
typedef typename Superclass::RegionType RegionType;
/** Spacing typedef support. Spacing holds the size of a pixel. The
* spacing is the geometric distance between image samples. */
typedef typename Superclass::SpacingType SpacingType;
/** Origin typedef support. The origin is the geometric coordinates
* of the index (0,0). */
typedef typename Superclass::PointType PointType;
/** Direction typedef support. The Direction is a matix of
* direction cosines that specify the direction between samples.
* */
typedef typename Superclass::DirectionType DirectionType;
/**
* example usage:
* typedef typename ImageAdaptorType::template Rebind< float >::Type OutputImageType;
*
*/
template <typename UPixelType, unsigned int UImageDimension = TImage::ImageDimension>
struct Rebind
{
typedef Image<UPixelType, UImageDimension> Type;
};
/** Set the region object that defines the size and starting index
* for the largest possible region this image could represent. This
* is used in determining how much memory would be needed to load an
* entire dataset. It is also used to determine boundary
* conditions.
* \sa ImageRegion, SetBufferedRegion(), SetRequestedRegion() */
virtual void SetLargestPossibleRegion(const RegionType & region) ITK_OVERRIDE;
/** Set the region object that defines the size and starting index
* of the region of the image currently load in memory.
* \sa ImageRegion, SetLargestPossibleRegion(), SetRequestedRegion() */
virtual void SetBufferedRegion(const RegionType & region) ITK_OVERRIDE;
/** Set the region object that defines the size and starting index
* for the region of the image requested.
* \sa ImageRegion, SetLargestPossibleRegion(), SetBufferedRegion() */
virtual void SetRequestedRegion(const RegionType & region) ITK_OVERRIDE;
/** Set the requested region from this data object to match the requested
* region of the data object passed in as a parameter. This method
* implements the API from DataObject. The data object parameter must be
* castable to an ImageBase. */
virtual void SetRequestedRegion(const DataObject *data) ITK_OVERRIDE;
/** Get the region object that defines the size and starting index
* for the region of the image requested (i.e., the region of the
* image to be operated on by a filter).
* This method overloads the one in ImageBase in order to delegate
* to the adapted image.
* \sa ImageRegion, SetLargestPossibleRegion(), SetBufferedRegion() */
virtual const RegionType & GetRequestedRegion() const ITK_OVERRIDE;
/** Get the region object that defines the size and starting index
* for the largest possible region this image could represent. This
* is used in determining how much memory would be needed to load an
* entire dataset. It is also used to determine boundary
* conditions.
* This method overloads the one in ImageBase in order to delegate
* to the adapted image.
* \sa ImageRegion, GetBufferedRegion(), GetRequestedRegion() */
virtual const RegionType & GetLargestPossibleRegion() const ITK_OVERRIDE;
/** Get the region object that defines the size and starting index
* of the region of the image currently loaded in memory.
* This method overloads the one in ImageBase in order to delegate
* to the adapted image.
* \sa ImageRegion, SetLargestPossibleRegion(), SetRequestedRegion() */
virtual const RegionType & GetBufferedRegion() const ITK_OVERRIDE;
/** Allocate the image memory. Dimension and Size must be set a priori. */
virtual void Allocate(bool initialize = false) ITK_OVERRIDE;
/** Restore the data object to its initial state. This means releasing
* memory. */
virtual void Initialize() ITK_OVERRIDE;
/** Set a pixel. */
void SetPixel(const IndexType & index, const PixelType & value)
{ m_PixelAccessor.Set(m_Image->GetPixel(index), value); }
/** Get a pixel (read only version) */
PixelType GetPixel(const IndexType & index) const
{ return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
/** Access a pixel. This version can only be an rvalue. */
PixelType operator[](const IndexType & index) const
{ return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
/** Get the OffsetTable from the adapted image */
const OffsetValueType * GetOffsetTable() const;
/** Compute Index given an Offset */
IndexType ComputeIndex(OffsetValueType offset) const;
/** PixelContainer typedef support. Used to construct a container for
* the pixel data. */
typedef typename TImage::PixelContainer PixelContainer;
typedef typename TImage::PixelContainerPointer PixelContainerPointer;
typedef typename TImage::PixelContainerConstPointer PixelContainerConstPointer;
/** Return a pointer to the container. */
PixelContainerPointer GetPixelContainer()
{ return m_Image->GetPixelContainer(); }
const PixelContainer * GetPixelContainer() const
{ return m_Image->GetPixelContainer(); }
/** Set the container to use. Note that this does not cause the
* DataObject to be modified. */
void SetPixelContainer(PixelContainer *container);
/** Graft the data and information from one image to another. This
* is a convenience method to setup a second image with all the meta
* information of another image and use the same pixel
* container. Note that this method is different than just using two
* SmartPointers to the same image since separate DataObjects are
* still maintained. This method is similar to
* ImageSource::GraftOutput(). The implementation in ImageBase
* simply calls CopyInformation() and copies the region ivars.
* The implementation here refers to the superclass' implementation
* and then copies over the pixel container. */
virtual void Graft(const DataObject *data) ITK_OVERRIDE;
/** Convenient typedef. */
typedef InternalPixelType *InternalPixelPointerType;
/** Return a pointer to the beginning of the buffer. This is used by
* the image iterator class. */
InternalPixelType * GetBufferPointer();
const InternalPixelType * GetBufferPointer() const;
/** Set the spacing (size of a pixel) of the image. */
virtual void SetSpacing(const SpacingType & values) ITK_OVERRIDE;
virtual void SetSpacing(const double *values /*[ImageDimension]*/) ITK_OVERRIDE;
virtual void SetSpacing(const float *values /*[ImageDimension]*/) ITK_OVERRIDE;
/** Get the spacing (size of a pixel) of the image. The
* spacing is the geometric distance between image samples.
* \sa SetSpacing() */
virtual const SpacingType & GetSpacing() const ITK_OVERRIDE;
/** Get the origin of the image. The origin is the geometric
* coordinates of the image origin.
* \sa SetOrigin() */
virtual const PointType & GetOrigin() const ITK_OVERRIDE;
/** Set the origin of the image. */
virtual void SetOrigin(const PointType values) ITK_OVERRIDE;
virtual void SetOrigin(const double *values /*[ImageDimension]*/) ITK_OVERRIDE;
virtual void SetOrigin(const float *values /*[ImageDimension]*/) ITK_OVERRIDE;
/** Set the direction of the image. */
virtual void SetDirection(const DirectionType & direction) ITK_OVERRIDE;
/** Get the direction cosines of the image. The direction cosines
* are vectors that point from one pixel to the next.
* For ImageBase and Image, the default direction is identity. */
virtual const DirectionType & GetDirection() const ITK_OVERRIDE;
/** Set Internal Image */
virtual void SetImage(TImage *);
/** Delegate Modified to the Internal Image */
virtual void Modified() const ITK_OVERRIDE;
/** Delegate GetMTime to the Internal Image */
virtual ModifiedTimeType GetMTime() const ITK_OVERRIDE;
/** Return the Data Accesor object */
AccessorType & GetPixelAccessor(void)
{ return m_PixelAccessor; }
/** Return the Data Accesor object */
const AccessorType & GetPixelAccessor(void) const
{ return m_PixelAccessor; }
/** Sets the Data Accesor object */
void SetPixelAccessor(const AccessorType & accessor)
{ m_PixelAccessor = accessor; }
/** Return the Data Accesor object */
virtual void Update() ITK_OVERRIDE;
virtual void CopyInformation(const DataObject *data) ITK_OVERRIDE;
/** Methods to update the pipeline. Called internally by the
* pipeline mechanism. */
virtual void UpdateOutputInformation() ITK_OVERRIDE;
virtual void SetRequestedRegionToLargestPossibleRegion() ITK_OVERRIDE;
virtual void PropagateRequestedRegion() ITK_OVERRIDE;
virtual void UpdateOutputData() ITK_OVERRIDE;
virtual bool VerifyRequestedRegion() ITK_OVERRIDE;
/** \brief Get the continuous index from a physical point
*
* Returns true if the resulting index is within the image, false otherwise.
* \sa Transform */
template< typename TCoordRep >
bool TransformPhysicalPointToContinuousIndex(
const Point< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & point,
ContinuousIndex< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & index) const
{
return m_Image->TransformPhysicalPointToContinuousIndex(point, index);
}
/** Get the index (discrete) from a physical point.
* Floating point index results are truncated to integers.
* Returns true if the resulting index is within the image, false otherwise
* \sa Transform */
template< typename TCoordRep >
bool TransformPhysicalPointToIndex(
const Point< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & point,
IndexType & index) const
{
return m_Image->TransformPhysicalPointToIndex(point, index);
}
/** Get a physical point (in the space which
* the origin and spacing information comes from)
* from a continuous index (in the index space)
* \sa Transform */
template< typename TCoordRep >
void TransformContinuousIndexToPhysicalPoint(
const ContinuousIndex< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & index,
Point< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & point) const
{
m_Image->TransformContinuousIndexToPhysicalPoint(index, point);
}
/** Get a physical point (in the space which
* the origin and spacing information comes from)
* from a discrete index (in the index space)
*
* \sa Transform */
template< typename TCoordRep >
void TransformIndexToPhysicalPoint(
const IndexType & index,
Point< TCoordRep,
itkGetStaticConstMacro(ImageDimension) > & point) const
{
m_Image->TransformIndexToPhysicalPoint(index, point);
}
template< typename TCoordRep >
void TransformLocalVectorToPhysicalVector(
const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & inputGradient,
FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & outputGradient) const
{
m_Image->TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
}
template< typename TCoordRep >
void TransformPhysicalVectorToLocalVector(
const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & inputGradient,
FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & outputGradient) const
{
m_Image->TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
}
protected:
ImageAdaptor();
virtual ~ImageAdaptor();
void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
private:
ImageAdaptor(const Self &) ITK_DELETE_FUNCTION;
void operator=(const Self &) ITK_DELETE_FUNCTION;
// a specialized method to update PixelAccessors for VectorImages,
// to have the correct vector length of the image.
template< typename TPixelType >
void UpdateAccessor( typename ::itk::VectorImage< TPixelType, ImageDimension > * itkNotUsed( dummy ) )
{
this->m_PixelAccessor.SetVectorLength( this->m_Image->GetNumberOfComponentsPerPixel() );
}
// The other image types don't expect an accessor which needs any updates
template< typename T > void UpdateAccessor( T *itkNotUsed( dummy ) ) { }
// Adapted image, most of the calls to ImageAdaptor
// will be delegated to this image
typename TImage::Pointer m_Image;
// Data accessor object,
// it converts the presentation of a pixel
AccessorType m_PixelAccessor;
};
} // end namespace itk
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkImageAdaptor.hxx"
#endif
#endif
|