ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkImageAdaptor.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
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 * https://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
23namespace itk
24{
25
26template <typename TPixelType, unsigned int VImageDimension>
27class VectorImage;
28
55template <typename TImage, typename TAccessor>
56class ITK_TEMPLATE_EXPORT ImageAdaptor : public ImageBase<TImage::ImageDimension>
57{
58public:
59 ITK_DISALLOW_COPY_AND_MOVE(ImageAdaptor);
60
65 static constexpr unsigned int ImageDimension = TImage::ImageDimension;
66
73
75 itkOverrideGetNameOfClassMacro(ImageAdaptor);
76
78 using InternalImageType = TImage;
79
81 itkNewMacro(Self);
82
85 using PixelType = typename TAccessor::ExternalType;
86
89 using InternalPixelType = typename TAccessor::InternalType;
90
92
95 using AccessorType = TAccessor;
96
99 using AccessorFunctorType = typename InternalImageType::AccessorFunctorType::template Rebind<Self>::Type;
100
102 using typename Superclass::IndexType;
104
106 using typename Superclass::SizeType;
108
110 using typename Superclass::OffsetType;
112
115 using typename Superclass::RegionType;
116
119 using typename Superclass::SpacingType;
120
123 using typename Superclass::PointType;
124
128 using typename Superclass::DirectionType;
129
130
137 template <typename UPixelType, unsigned int UImageDimension = TImage::ImageDimension>
142
143 template <typename UPixelType, unsigned int VUImageDimension = TImage::ImageDimension>
145
146
153 void
154 SetLargestPossibleRegion(const RegionType & region) override;
155
159 void
160 SetBufferedRegion(const RegionType & region) override;
161
165 void
166 SetRequestedRegion(const RegionType & region) override;
167
172 void
173 SetRequestedRegion(const DataObject * data) override;
174
181 const RegionType &
182 GetRequestedRegion() const override;
183
192 const RegionType &
193 GetLargestPossibleRegion() const override;
194
200 const RegionType &
201 GetBufferedRegion() const override;
202
204 void
205 Allocate(bool initialize = false) override;
206
209 void
210 Initialize() override;
211
213 void
214 SetPixel(const IndexType & index, const PixelType & value)
215 {
216 m_PixelAccessor.Set(m_Image->GetPixel(index), value);
217 }
218
220 PixelType
221 GetPixel(const IndexType & index) const
222 {
223 return m_PixelAccessor.Get(m_Image->GetPixel(index));
224 }
225
227 PixelType
228 operator[](const IndexType & index) const
229 {
230 return m_PixelAccessor.Get(m_Image->GetPixel(index));
231 }
232
234 const OffsetValueType *
236
240
243 ComputeOffset(const IndexType & index) const
244 {
245 return m_Image->ComputeOffset(index);
246 }
247
250 using PixelContainer = typename TImage::PixelContainer;
251 using PixelContainerPointer = typename TImage::PixelContainerPointer;
252 using PixelContainerConstPointer = typename TImage::PixelContainerConstPointer;
253
257 {
258 return m_Image->GetPixelContainer();
259 }
260
261 const PixelContainer *
263 {
264 return m_Image->GetPixelContainer();
265 }
266
269 void
271
282 virtual void
283 Graft(const Self * imgData);
284
285#ifndef ITK_FUTURE_LEGACY_REMOVE
287 using InternalPixelPointerType [[deprecated("Please just use `InternalPixelType *` instead!")]] = InternalPixelType *;
288#endif
289
294
295 const InternalPixelType *
297
299 void
300 SetSpacing(const SpacingType & spacing) override;
301
302 void
303 SetSpacing(const double * spacing /*[ImageDimension]*/) override;
304
305 void
306 SetSpacing(const float * spacing /*[ImageDimension]*/) override;
307
311 const SpacingType &
312 GetSpacing() const override;
313
317 const PointType &
318 GetOrigin() const override;
319
321 void
322 SetOrigin(const PointType origin) override;
323
324 void
325 SetOrigin(const double * origin /*[ImageDimension]*/) override;
326
327 void
328 SetOrigin(const float * origin /*[ImageDimension]*/) override;
329
331 void
332 SetDirection(const DirectionType & direction) override;
333
337 const DirectionType &
338 GetDirection() const override;
339
341 virtual void
342 SetImage(TImage *);
343
345 void
346 Modified() const override;
347
349 [[nodiscard]] ModifiedTimeType
350 GetMTime() const override;
351
355 {
356 return m_PixelAccessor;
357 }
358
360 const AccessorType &
362 {
363 return m_PixelAccessor;
364 }
365
367 void
369 {
370 m_PixelAccessor = accessor;
371 }
372
374 void
375 Update() override;
376
377 void
378 CopyInformation(const DataObject * data) override;
379
382 void
384
385 void
387
388 void
390
391 void
393
394 bool
396
398 template <typename TIndexRep, typename TCoordinate>
404
413 template <typename TCoordinate>
414 ITK_NODISCARD("Call the overload which has the point as the only parameter and returns the index")
416 ContinuousIndex<TCoordinate, Self::ImageDimension> & index) const
417 {
418 return m_Image->TransformPhysicalPointToContinuousIndex(point, index);
419 }
420
422 template <typename TCoordinate>
423 [[nodiscard]] IndexType
425 {
426 return m_Image->TransformPhysicalPointToIndex(point);
427 }
428
437 template <typename TCoordinate>
438 ITK_NODISCARD("Call the overload which has the point as the only parameter and returns the index")
439 bool TransformPhysicalPointToIndex(const Point<TCoordinate, Self::ImageDimension> & point, IndexType & index) const
440 {
441 return m_Image->TransformPhysicalPointToIndex(point, index);
442 }
443
448 template <typename TCoordinate>
449 void
452 {
453 m_Image->TransformContinuousIndexToPhysicalPoint(index, point);
454 }
455
457 template <typename TCoordinate, typename TIndexRep>
463
469 template <typename TCoordinate>
470 void
472 {
473 m_Image->TransformIndexToPhysicalPoint(index, point);
474 }
475
477 template <typename TCoordinate>
480 {
482 }
483
484 template <typename TCoordinate>
485 void
488 {
489 m_Image->TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
490 }
491
492 template <typename TVector>
493 [[nodiscard]] TVector
494 TransformLocalVectorToPhysicalVector(const TVector & inputGradient) const
495 {
496 TVector outputGradient;
497 TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
498 return outputGradient;
499 }
500
501 template <typename TCoordinate>
502 void
505 {
506 m_Image->TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
507 }
508
509 template <typename TVector>
510 [[nodiscard]] TVector
511 TransformPhysicalVectorToLocalVector(const TVector & inputGradient) const
512 {
513 TVector outputGradient;
514 TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
515 return outputGradient;
516 }
517
518protected:
520 ~ImageAdaptor() override = default;
521 void
522 PrintSelf(std::ostream & os, Indent indent) const override;
523 void
524 Graft(const DataObject * data) override;
525 using Superclass::Graft;
526
527private:
528 // a specialized method to update PixelAccessors for VectorImages,
529 // to have the correct vector length of the image.
530 template <typename TPixelType>
531 void
533 {
534 this->m_PixelAccessor.SetVectorLength(this->m_Image->GetNumberOfComponentsPerPixel());
535 }
536
537 // The other image types don't expect an accessor which needs any updates
538 template <typename T>
539 void
540 UpdateAccessor(T * itkNotUsed(dummy))
541 {}
542
543 // Adapted image, most of the calls to ImageAdaptor
544 // will be delegated to this image
545 typename TImage::Pointer m_Image{};
546
547 // Data accessor object,
548 // it converts the presentation of a pixel
550};
551} // end namespace itk
552
553#ifndef ITK_MANUAL_INSTANTIATION
554# include "itkImageAdaptor.hxx"
555#endif
556
557#endif
A templated class holding a point in n-Dimensional image space.
Base class for all data objects in ITK.
Simulate a standard C array with copy semantics.
void SetOrigin(const float *origin) override
void CopyInformation(const DataObject *data) override
typename InternalImageType::AccessorFunctorType::template Rebind< Self >::Type AccessorFunctorType
OffsetValueType ComputeOffset(const IndexType &index) const
void SetOrigin(const double *origin) override
void SetPixelContainer(PixelContainer *container)
void UpdateAccessor(itk::VectorImage< TPixelType, ImageDimension > *dummy)
const PointType & GetOrigin() const override
void Modified() const override
void SetPixel(const IndexType &index, const PixelType &value)
void Initialize() override
PixelContainerPointer GetPixelContainer()
void SetRequestedRegion(const DataObject *data) override
void TransformPhysicalVectorToLocalVector(const FixedArray< TCoordinate, Self::ImageDimension > &inputGradient, FixedArray< TCoordinate, Self::ImageDimension > &outputGradient) const
void PropagateRequestedRegion() override
void SetRequestedRegion(const RegionType &region) override
void UpdateAccessor(T *dummy)
const PixelContainer * GetPixelContainer() const
PixelType operator[](const IndexType &index) const
void TransformLocalVectorToPhysicalVector(const FixedArray< TCoordinate, Self::ImageDimension > &inputGradient, FixedArray< TCoordinate, Self::ImageDimension > &outputGradient) const
const DirectionType & GetDirection() const override
bool VerifyRequestedRegion() override
void UpdateOutputInformation() override
void SetSpacing(const SpacingType &spacing) override
void TransformIndexToPhysicalPoint(const IndexType &index, Point< TCoordinate, Self::ImageDimension > &point) const
void SetBufferedRegion(const RegionType &region) override
void SetSpacing(const double *spacing) override
Point< TCoordinate, TImage::ImageDimension > TransformContinuousIndexToPhysicalPoint(const ContinuousIndex< TIndexRep, Self::ImageDimension > &index) const
void SetDirection(const DirectionType &direction) override
TVector TransformPhysicalVectorToLocalVector(const TVector &inputGradient) const
ModifiedTimeType GetMTime() const override
void UpdateOutputData() override
AccessorType & GetPixelAccessor()
const AccessorType & GetPixelAccessor() const
void TransformContinuousIndexToPhysicalPoint(const ContinuousIndex< TCoordinate, Self::ImageDimension > &index, Point< TCoordinate, Self::ImageDimension > &point) const
TVector TransformLocalVectorToPhysicalVector(const TVector &inputGradient) const
typename Accessor::AbsPixelAccessor< typename TImage::PixelType, TOutputPixelType >::ExternalType PixelType
void Allocate(bool initialize=false) override
void SetPixelAccessor(const AccessorType &accessor)
const RegionType & GetLargestPossibleRegion() const override
void SetRequestedRegionToLargestPossibleRegion() override
Point< TCoordinate, Self::ImageDimension > TransformIndexToPhysicalPoint(const IndexType &index) const
Accessor::AbsPixelAccessor< typename TImage::PixelType, TOutputPixelType > AccessorType
IndexType TransformPhysicalPointToIndex(const Point< TCoordinate, Self::ImageDimension > &point) const
void SetOrigin(const PointType origin) override
~ImageAdaptor() override=default
void PrintSelf(std::ostream &os, Indent indent) const override
void SetSpacing(const float *spacing) override
const OffsetValueType * GetOffsetTable() const
PixelType GetPixel(const IndexType &index) const
void SetLargestPossibleRegion(const RegionType &region) override
const InternalPixelType * GetBufferPointer() const
virtual void SetImage(TImage *)
const RegionType & GetRequestedRegion() const override
IndexType ComputeIndex(OffsetValueType offset) const
const SpacingType & GetSpacing() const override
void Graft(const DataObject *data) override
void Update() override
ContinuousIndex< TIndexRep, TImage::ImageDimension > TransformPhysicalPointToContinuousIndex(const Point< TCoordinate, TImage::ImageDimension > &point) const
InternalPixelType * GetBufferPointer()
virtual void Graft(const Self *imgData)
const RegionType & GetBufferedRegion() const override
typename Accessor::AbsPixelAccessor< typename TImage::PixelType, TOutputPixelType >::InternalType InternalPixelType
Vector< SpacingValueType, VImageDimension > SpacingType
ImageRegion< VImageDimension > RegionType
Index< VImageDimension > IndexType
Offset< VImageDimension > OffsetType
virtual void Graft(const Self *image)
Matrix< SpacePrecisionType, VImageDimension, VImageDimension > DirectionType
Point< PointValueType, VImageDimension > PointType
Templated n-dimensional image class.
Definition itkImage.h:89
Control indentation during Print() invocation.
Definition itkIndent.h:50
A templated class holding a geometric point in n-Dimensional space.
Definition itkPoint.h:54
Implements transparent reference counting.
Templated n-dimensional vector image class.
Implements a weak reference to an object.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
long OffsetValueType
Definition itkIntTypes.h:97
SizeValueType ModifiedTimeType
itk::IndexValueType IndexValueType
Definition itkIndex.h:79
itk::OffsetValueType OffsetValueType
Definition itkOffset.h:77
itk::SizeValueType SizeValueType
Definition itkSize.h:80