28 #ifndef itkImageBase_h
29 #define itkImageBase_h
41 #include <vxl_version.h>
42 #include "vnl/vnl_matrix_fixed.hxx"
113 template <
unsigned int VImageDimension = 2>
129 itkOverrideGetNameOfClassMacro(
ImageBase);
132 using ImageDimensionType =
unsigned int;
138 static constexpr ImageDimensionType ImageDimension = VImageDimension;
175 Initialize()
override;
178 static constexpr
unsigned int
181 return VImageDimension;
190 SetOrigin(
const double origin[VImageDimension]);
192 SetOrigin(
const float origin[VImageDimension]);
237 itkGetConstReferenceMacro(Spacing, SpacingType);
243 itkGetConstReferenceMacro(Origin,
PointType);
253 Allocate(
bool initialize =
false);
260 return this->Allocate(
true);
270 SetLargestPossibleRegion(
const RegionType & region);
281 return m_LargestPossibleRegion;
296 return m_BufferedRegion;
307 SetRequestedRegion(
const RegionType & region);
317 SetRequestedRegion(
const DataObject * data)
override;
326 return m_RequestedRegion;
335 this->SetLargestPossibleRegion(region);
336 this->SetBufferedRegion(region);
337 this->SetRequestedRegion(region);
347 this->Self::SetRegions(region);
363 return m_OffsetTable;
379 this->GetBufferedRegion().GetIndex(), ind, m_OffsetTable, offset);
441 SetSpacing(
const SpacingType & spacing);
443 SetSpacing(
const double spacing[VImageDimension]);
445 SetSpacing(
const float spacing[VImageDimension]);
463 template <
typename TCoordRep>
470 for (
unsigned int i = 0; i < VImageDimension; ++i)
473 for (
unsigned int j = 0; j < VImageDimension; ++j)
475 sum += this->m_PhysicalPointToIndex[i][j] * (
point[j] - this->m_Origin[j]);
477 index[i] = Math::RoundHalfIntegerUp<IndexValueType>(sum);
490 template <
typename TCoordRep>
491 ITK_NODISCARD(
"Call the overload which has the point as the only parameter and returns the index")
492 bool TransformPhysicalPointToIndex(const
Point<TCoordRep, VImageDimension> &
point,
IndexType & index)
const
494 index = TransformPhysicalPointToIndex(
point);
497 const bool isInside = this->GetLargestPossibleRegion().IsInside(index);
516 template <
typename TIndexRep,
typename TCoordRep>
523 for (
unsigned int k = 0; k < VImageDimension; ++k)
525 cvector[k] =
point[k] - this->m_Origin[k];
527 cvector = m_PhysicalPointToIndex * cvector;
528 for (
unsigned int i = 0; i < VImageDimension; ++i)
530 index[i] = static_cast<TIndexRep>(cvector[i]);
543 template <
typename TCoordRep,
typename TIndexRep>
544 ITK_NODISCARD(
"Call the overload which has the point as the only parameter and returns the index")
545 bool TransformPhysicalPointToContinuousIndex(const
Point<TCoordRep, VImageDimension> &
point,
548 index = TransformPhysicalPointToContinuousIndex<TIndexRep>(
point);
551 const bool isInside = this->GetLargestPossibleRegion().IsInside(index);
559 template <
typename TCoordRep,
typename TIndexRep>
564 for (
unsigned int r = 0; r < VImageDimension; ++r)
567 for (
unsigned int c = 0; c < VImageDimension; ++c)
569 sum += this->m_IndexToPhysicalPoint(r, c) * index[c];
571 point[r] = sum + this->m_Origin[r];
580 template <
typename TCoordRep,
typename TIndexRep>
585 TransformContinuousIndexToPhysicalPoint(index,
point);
595 template <
typename TCoordRep>
599 for (
unsigned int i = 0; i < VImageDimension; ++i)
601 point[i] = this->m_Origin[i];
602 for (
unsigned int j = 0; j < VImageDimension; ++j)
604 point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
615 template <
typename TCoordRep>
620 TransformIndexToPhysicalPoint(index,
point);
639 template <
typename TCoordRep>
648 for (
unsigned int i = 0; i < VImageDimension; ++i)
652 for (
unsigned int j = 0; j < VImageDimension; ++j)
654 sum += direction[i][j] * inputGradient[j];
656 outputGradient[i] = static_cast<TCoordRep>(sum);
666 template <
typename TVector>
667 [[nodiscard]] TVector
670 TVector outputGradient;
671 TransformLocalVectorToPhysicalVector(inputGradient, outputGradient);
672 return outputGradient;
689 template <
typename TCoordRep>
694 const DirectionType & inverseDirection = this->GetInverseDirection();
698 for (
unsigned int i = 0; i < VImageDimension; ++i)
702 for (
unsigned int j = 0; j < VImageDimension; ++j)
704 sum += inverseDirection[i][j] * inputGradient[j];
706 outputGradient[i] = static_cast<TCoordRep>(sum);
716 template <
typename TVector>
717 [[nodiscard]] TVector
720 TVector outputGradient;
721 TransformPhysicalVectorToLocalVector(inputGradient, outputGradient);
722 return outputGradient;
736 CopyInformation(
const DataObject * data)
override;
749 Graft(
const Self * image);
759 UpdateOutputInformation()
override;
769 UpdateOutputData()
override;
775 SetRequestedRegionToLargestPossibleRegion()
override;
787 RequestedRegionIsOutsideOfTheBufferedRegion()
override;
798 VerifyRequestedRegion()
override;
804 IsCongruentImageGeometry(
const ImageBase * otherImage,
double coordinateTolerance,
double directionTolerance)
const;
814 IsSameImageGeometryAs(
const ImageBase * otherImage,
837 GetNumberOfComponentsPerPixel()
const;
839 SetNumberOfComponentsPerPixel(
unsigned int);
846 PrintSelf(std::ostream & os,
Indent indent)
const override;
853 ComputeOffsetTable();
861 ComputeIndexToPhysicalPointMatrices();
884 InitializeBufferedRegion();
901 Self::GetBufferedRegion().GetIndex(), ind, m_OffsetTable, offset);
939 #ifndef ITK_MANUAL_INSTANTIATION
940 # include "itkImageBase.hxx"