20 #ifndef __itkImageBase_h
21 #define __itkImageBase_h
36 #include <vnl/vnl_matrix_fixed.txx>
40 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
53 template <
typename TImage>
86 template<
unsigned int VImageDimension=2>
106 itkStaticConstMacro(ImageDimension,
unsigned int, VImageDimension );
146 {
return VImageDimension; }
152 itkSetMacro(Origin, PointType);
153 virtual void SetOrigin(
const double origin[VImageDimension] );
154 virtual void SetOrigin(
const float origin[VImageDimension] );
182 virtual void SetDirection(
const DirectionType direction );
187 itkGetConstReferenceMacro(Direction, DirectionType);
193 itkGetConstReferenceMacro(Spacing, SpacingType);
199 itkGetConstReferenceMacro(Origin, PointType);
215 virtual void SetLargestPossibleRegion(
const RegionType ®ion);
224 {
return m_LargestPossibleRegion;};
229 virtual void SetBufferedRegion(
const RegionType ®ion);
235 {
return m_BufferedRegion;};
244 virtual void SetRequestedRegion(
const RegionType ®ion);
253 virtual void SetRequestedRegion(
DataObject *data);
260 {
return m_RequestedRegion;};
282 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
283 inline OffsetValueType ComputeOffset(
const IndexType &ind)
const
285 OffsetValueType offset = 0;
301 for (
int i=VImageDimension-1; i > 0; i--)
303 offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
305 offset += (ind[0] - bufferedRegionIndex[0]);
317 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
318 inline IndexType ComputeIndex(OffsetValueType offset)
const
321 const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
334 for (
int i=VImageDimension-1; i > 0; i--)
336 index[i] =
static_cast<IndexValueType>(offset / m_OffsetTable[i]);
337 offset -= (index[i] * m_OffsetTable[i]);
338 index[i] += bufferedRegionIndex[i];
340 index[0] = bufferedRegionIndex[0] +
static_cast<IndexValueType>(offset);
352 virtual void SetSpacing (
const SpacingType & spacing);
353 virtual void SetSpacing (
const double spacing[VImageDimension]);
354 virtual void SetSpacing (
const float spacing[VImageDimension]);
363 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
364 template<
class TCoordRep>
365 bool TransformPhysicalPointToIndex(
367 IndexType & index )
const
370 this->m_PhysicalPointToIndex, this->m_Origin, point, index);
373 const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
377 template<
class TCoordRep>
378 bool TransformPhysicalPointToIndex(
382 for (
unsigned int i = 0; i < VImageDimension; i++)
384 TCoordRep sum = NumericTraits<TCoordRep>::Zero;
385 for (
unsigned int j = 0; j < VImageDimension; j++)
387 sum += this->m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]);
389 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
390 index[i] = Math::RoundHalfIntegerUp< IndexValueType>( sum );
397 const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
407 template<
class TCoordRep>
408 bool TransformPhysicalPointToContinuousIndex(
414 for(
unsigned int k = 0; k < VImageDimension; k++ )
416 cvector[k] = point[k] - this->m_Origin[k];
418 cvector = m_PhysicalPointToIndex * cvector;
419 for(
unsigned int i = 0; i < VImageDimension; i++ )
421 index[i] =
static_cast<TCoordRep
>(cvector[i]);
425 const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
435 template<
class TCoordRep>
436 void TransformContinuousIndexToPhysicalPoint(
440 for(
unsigned int r=0; r<VImageDimension; r++)
442 TCoordRep sum = NumericTraits<TCoordRep>::Zero;
443 for(
unsigned int c=0; c<VImageDimension; c++ )
445 sum += this->m_IndexToPhysicalPoint(r,c) * index[c];
447 point[r] = sum + this->m_Origin[r];
456 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
457 template<
class TCoordRep>
458 void TransformIndexToPhysicalPoint(
459 const IndexType & index,
463 this->m_IndexToPhysicalPoint, this->m_Origin, index, point);
466 template<
class TCoordRep>
467 void TransformIndexToPhysicalPoint(
471 for (
unsigned int i = 0; i < VImageDimension; i++)
473 point[i] = this->m_Origin[i];
474 for (
unsigned int j = 0; j < VImageDimension; j++)
476 point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
500 template<
class TCoordRep>
501 void TransformLocalVectorToPhysicalVector(
508 #ifdef ITK_USE_ORIENTED_IMAGE_DIRECTION
510 for (
unsigned int i = 0; i < VImageDimension; i++)
512 typedef typename NumericTraits<TCoordRep>::AccumulateType CoordSumType;
513 CoordSumType sum = NumericTraits<CoordSumType>::Zero;
514 for (
unsigned int j = 0; j < VImageDimension; j++)
516 sum += direction[i][j] * inputGradient[j];
518 outputGradient[i] =
static_cast<TCoordRep
>( sum );
521 for (
unsigned int i = 0; i < VImageDimension; i++)
523 outputGradient[i] = inputGradient[i];
537 virtual void CopyInformation(
const DataObject *data);
558 virtual void UpdateOutputInformation();
567 virtual void UpdateOutputData();
572 virtual void SetRequestedRegionToLargestPossibleRegion();
583 virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
593 virtual bool VerifyRequestedRegion();
611 virtual unsigned int GetNumberOfComponentsPerPixel()
const;
612 virtual void SetNumberOfComponentsPerPixel(
unsigned int );
617 virtual void PrintSelf(std::ostream& os,
Indent indent)
const;
623 void ComputeOffsetTable();
630 virtual void ComputeIndexToPhysicalPointMatrices();
649 virtual void InitializeBufferedRegion(
void);
653 void operator=(
const Self&);
666 #define ITK_TEMPLATE_ImageBase(_, EXPORT, x, y) namespace itk { \
667 _(1(class EXPORT ImageBase< ITK_TEMPLATE_1 x >)) \
668 namespace Templates { typedef ImageBase< ITK_TEMPLATE_1 x > ImageBase##y; } \
671 #if ITK_TEMPLATE_EXPLICIT
672 # include "Templates/itkImageBase+-.h"