ITK  4.13.0
Insight Segmentation and Registration Toolkit
itkImageAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkImageAdaptor_h
19 #define itkImageAdaptor_h
20 
21 #include "itkImage.h"
22 
23 namespace itk
24 {
25 
26 template <typename TPixelType, unsigned int VImageDimension > class VectorImage;
27 
54 template< typename TImage, typename TAccessor >
55 class ITK_TEMPLATE_EXPORT ImageAdaptor:public ImageBase< TImage::ImageDimension >
56 {
57 public:
58 
63  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
64 
66  typedef ImageAdaptor Self;
71 
73  itkTypeMacro(ImageAdaptor, ImageBase);
74 
76  typedef TImage InternalImageType;
77 
79  itkNewMacro(Self);
80 
83  typedef typename TAccessor::ExternalType PixelType;
84 
87  typedef typename TAccessor::InternalType InternalPixelType;
88 
90 
93  typedef TAccessor AccessorType;
94 
97  typedef typename InternalImageType::AccessorFunctorType::template Rebind< Self >::Type AccessorFunctorType;
98 
102 
104  typedef typename Superclass::SizeType SizeType;
106 
108  typedef typename Superclass::OffsetType OffsetType;
110 
113  typedef typename Superclass::RegionType RegionType;
114 
117  typedef typename Superclass::SpacingType SpacingType;
118 
122 
127 
128 
134  template <typename UPixelType, unsigned int UImageDimension = TImage::ImageDimension>
135  struct Rebind
136  {
138  };
139 
140 
147  virtual void SetLargestPossibleRegion(const RegionType & region) ITK_OVERRIDE;
148 
152  virtual void SetBufferedRegion(const RegionType & region) ITK_OVERRIDE;
153 
157  virtual void SetRequestedRegion(const RegionType & region) ITK_OVERRIDE;
158 
163  virtual void SetRequestedRegion(const DataObject *data) ITK_OVERRIDE;
164 
171  virtual const RegionType & GetRequestedRegion() const ITK_OVERRIDE;
172 
181  virtual const RegionType & GetLargestPossibleRegion() const ITK_OVERRIDE;
182 
188  virtual const RegionType & GetBufferedRegion() const ITK_OVERRIDE;
189 
191  virtual void Allocate(bool initialize = false) ITK_OVERRIDE;
192 
195  virtual void Initialize() ITK_OVERRIDE;
196 
198  void SetPixel(const IndexType & index, const PixelType & value)
199  { m_PixelAccessor.Set(m_Image->GetPixel(index), value); }
200 
202  PixelType GetPixel(const IndexType & index) const
203  { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
204 
206  PixelType operator[](const IndexType & index) const
207  { return m_PixelAccessor.Get( m_Image->GetPixel(index) ); }
208 
210  const OffsetValueType * GetOffsetTable() const;
211 
213  IndexType ComputeIndex(OffsetValueType offset) const;
214 
217  typedef typename TImage::PixelContainer PixelContainer;
218  typedef typename TImage::PixelContainerPointer PixelContainerPointer;
219  typedef typename TImage::PixelContainerConstPointer PixelContainerConstPointer;
220 
223  { return m_Image->GetPixelContainer(); }
224 
226  { return m_Image->GetPixelContainer(); }
227 
230  void SetPixelContainer(PixelContainer *container);
231 
242  virtual void Graft(const Self *imgData);
243 
246 
249  InternalPixelType * GetBufferPointer();
250 
251  const InternalPixelType * GetBufferPointer() const;
252 
254  virtual void SetSpacing(const SpacingType & values) ITK_OVERRIDE;
255 
256  virtual void SetSpacing(const double *values /*[ImageDimension]*/) ITK_OVERRIDE;
257 
258  virtual void SetSpacing(const float *values /*[ImageDimension]*/) ITK_OVERRIDE;
259 
263  virtual const SpacingType & GetSpacing() const ITK_OVERRIDE;
264 
268  virtual const PointType & GetOrigin() const ITK_OVERRIDE;
269 
271  virtual void SetOrigin(const PointType values) ITK_OVERRIDE;
272 
273  virtual void SetOrigin(const double *values /*[ImageDimension]*/) ITK_OVERRIDE;
274 
275  virtual void SetOrigin(const float *values /*[ImageDimension]*/) ITK_OVERRIDE;
276 
278  virtual void SetDirection(const DirectionType & direction) ITK_OVERRIDE;
279 
283  virtual const DirectionType & GetDirection() const ITK_OVERRIDE;
284 
286  virtual void SetImage(TImage *);
287 
289  virtual void Modified() const ITK_OVERRIDE;
290 
292  virtual ModifiedTimeType GetMTime() const ITK_OVERRIDE;
293 
295  AccessorType & GetPixelAccessor(void)
296  { return m_PixelAccessor; }
297 
299  const AccessorType & GetPixelAccessor(void) const
300  { return m_PixelAccessor; }
301 
303  void SetPixelAccessor(const AccessorType & accessor)
304  { m_PixelAccessor = accessor; }
305 
307  virtual void Update() ITK_OVERRIDE;
308 
309  virtual void CopyInformation(const DataObject *data) ITK_OVERRIDE;
310 
313  virtual void UpdateOutputInformation() ITK_OVERRIDE;
314 
315  virtual void SetRequestedRegionToLargestPossibleRegion() ITK_OVERRIDE;
316 
317  virtual void PropagateRequestedRegion() ITK_OVERRIDE;
318 
319  virtual void UpdateOutputData() ITK_OVERRIDE;
320 
321  virtual bool VerifyRequestedRegion() ITK_OVERRIDE;
322 
327  template< typename TCoordRep >
328  bool TransformPhysicalPointToContinuousIndex(
329  const Point< TCoordRep,
330  itkGetStaticConstMacro(ImageDimension) > & point,
331  ContinuousIndex< TCoordRep,
332  itkGetStaticConstMacro(ImageDimension) > & index) const
333  {
334  return m_Image->TransformPhysicalPointToContinuousIndex(point, index);
335  }
336 
341  template< typename TCoordRep >
343  const Point< TCoordRep,
344  itkGetStaticConstMacro(ImageDimension) > & point,
345  IndexType & index) const
346  {
347  return m_Image->TransformPhysicalPointToIndex(point, index);
348  }
349 
354  template< typename TCoordRep >
356  const ContinuousIndex< TCoordRep,
357  itkGetStaticConstMacro(ImageDimension) > & index,
358  Point< TCoordRep,
359  itkGetStaticConstMacro(ImageDimension) > & point) const
360  {
361  m_Image->TransformContinuousIndexToPhysicalPoint(index, point);
362  }
363 
369  template< typename TCoordRep >
371  const IndexType & index,
372  Point< TCoordRep,
373  itkGetStaticConstMacro(ImageDimension) > & point) const
374  {
375  m_Image->TransformIndexToPhysicalPoint(index, point);
376  }
377 
378  template< typename TCoordRep >
380  const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & inputGradient,
381  FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & outputGradient) const
382  {
383  m_Image->TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
384  }
385 
386  template< typename TCoordRep >
388  const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & inputGradient,
389  FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > & outputGradient) const
390  {
391  m_Image->TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
392  }
393 
394 protected:
395 
396  ImageAdaptor();
397  virtual ~ImageAdaptor() ITK_OVERRIDE;
398  void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
399  virtual void Graft(const DataObject *data) ITK_OVERRIDE;
400  using Superclass::Graft;
401 
402 private:
403 
404  ITK_DISALLOW_COPY_AND_ASSIGN(ImageAdaptor);
405 
406  // a specialized method to update PixelAccessors for VectorImages,
407  // to have the correct vector length of the image.
408  template< typename TPixelType >
409  void UpdateAccessor( typename ::itk::VectorImage< TPixelType, ImageDimension > * itkNotUsed( dummy ) )
410  {
411  this->m_PixelAccessor.SetVectorLength( this->m_Image->GetNumberOfComponentsPerPixel() );
412  }
413 
414  // The other image types don't expect an accessor which needs any updates
415  template< typename T > void UpdateAccessor( T *itkNotUsed( dummy ) ) { }
416 
417  // Adapted image, most of the calls to ImageAdaptor
418  // will be delegated to this image
419  typename TImage::Pointer m_Image;
420 
421  // Data accessor object,
422  // it converts the presentation of a pixel
424 };
425 } // end namespace itk
426 
427 #ifndef ITK_MANUAL_INSTANTIATION
428 #include "itkImageAdaptor.hxx"
429 #endif
430 
431 #endif
SizeType::SizeValueType SizeValueType
void UpdateAccessor(T *)
Superclass::RegionType RegionType
void TransformIndexToPhysicalPoint(const IndexType &index, Point< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &point) const
itk::SizeValueType SizeValueType
Definition: itkSize.h:60
const PixelContainer * GetPixelContainer() const
Superclass::SpacingType SpacingType
TImage::PixelContainer PixelContainer
signed long OffsetValueType
Definition: itkIntTypes.h:154
IndexType::IndexValueType IndexValueType
void TransformContinuousIndexToPhysicalPoint(const ContinuousIndex< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &index, Point< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &point) const
ImageBase< itkGetStaticConstMacro(ImageDimension) > Superclass
unsigned long ModifiedTimeType
Definition: itkIntTypes.h:164
InternalPixelType * InternalPixelPointerType
Image< UPixelType, UImageDimension > Type
AccessorType m_PixelAccessor
ImageAdaptor Self
Templated n-dimensional vector image class.
Implements a weak reference to an object.
PixelType GetPixel(const IndexType &index) const
SmartPointer< Self > Pointer
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
InternalImageType::AccessorFunctorType::template Rebind< Self >::Type AccessorFunctorType
const AccessorType & GetPixelAccessor(void) const
PixelContainerPointer GetPixelContainer()
WeakPointer< const Self > ConstWeakPointer
void SetPixelAccessor(const AccessorType &accessor)
TImage::PixelContainerConstPointer PixelContainerConstPointer
::itk::IndexValueType IndexValueType
Definition: itkIndex.h:80
TAccessor::InternalType InternalPixelType
TAccessor::ExternalType PixelType
Superclass::DirectionType DirectionType
Superclass::SizeType SizeType
PixelType operator[](const IndexType &index) const
void TransformLocalVectorToPhysicalVector(const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &inputGradient, FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &outputGradient) const
Base class for templated image classes.
Definition: itkImageBase.h:114
A templated class holding a point in n-Dimensional image space.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
OffsetType::OffsetValueType OffsetValueType
bool TransformPhysicalPointToIndex(const Point< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &point, IndexType &index) const
Superclass::IndexType IndexType
Superclass::PointType PointType
TImage::PixelContainerPointer PixelContainerPointer
Give access to partial aspects of voxels from an Image.
itk::OffsetValueType OffsetValueType
Definition: itkOffset.h:70
Superclass::OffsetType OffsetType
void TransformPhysicalVectorToLocalVector(const FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &inputGradient, FixedArray< TCoordRep, itkGetStaticConstMacro(ImageDimension) > &outputGradient) const
SmartPointer< const Self > ConstPointer
Base class for all data objects in ITK.
Templated n-dimensional image class.
Definition: itkImage.h:75
TAccessor AccessorType
TImage::Pointer m_Image