101
106
itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
103
108
/** Index typedef support. An index is used to access pixel values. */
104
typedef Index<VImageDimension> IndexType;
105
typedef typename IndexType::IndexValueType IndexValueType;
109
typedef Index<VImageDimension> IndexType;
110
typedef typename IndexType::IndexValueType IndexValueType;
107
112
/** Offset typedef support. An offset represent relative position
108
113
* between indices. */
109
typedef Offset<VImageDimension> OffsetType;
110
typedef typename OffsetType::OffsetValueType OffsetValueType;
114
typedef Offset<VImageDimension> OffsetType;
115
typedef typename OffsetType::OffsetValueType OffsetValueType;
112
117
/** Size typedef support. A size is used to define region bounds. */
113
typedef Size<VImageDimension> SizeType;
114
typedef typename SizeType::SizeValueType SizeValueType;
118
typedef Size<VImageDimension> SizeType;
119
typedef typename SizeType::SizeValueType SizeValueType;
116
121
/** Region typedef support. A region is used to specify a subset of an image. */
117
typedef ImageRegion<VImageDimension> RegionType;
122
typedef ImageRegion<VImageDimension> RegionType;
119
124
/** Spacing typedef support. Spacing holds the size of a pixel. The
120
125
* spacing is the geometric distance between image samples. ITK only
121
126
* supports positive spacing value: negative values may cause
122
* undesirable results.*/
123
typedef Vector<double, VImageDimension> SpacingType;
127
* undesirable results. */
128
typedef Vector<double, VImageDimension> SpacingType;
125
130
/** Origin typedef support. The origin is the geometric coordinates
126
131
* of the index (0,0). */
333
330
index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
336
/** Set the spacing (size of a pixel) of the image. The
337
* spacing is the geometric distance between image samples.
338
* It is stored internally as double, but may be set from
339
* float. These methods also pre-compute the Index to Physical
340
* point transforms of the image.
341
* \sa GetSpacing() */
342
virtual void SetSpacing (const SpacingType & spacing);
343
virtual void SetSpacing (const double spacing[VImageDimension]);
344
virtual void SetSpacing (const float spacing[VImageDimension]);
347
/** Get the index (discrete) from a physical point.
348
* Floating point index results are truncated to integers.
349
* Returns true if the resulting index is within the image, false otherwise
351
#ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
352
template<class TCoordRep>
353
bool TransformPhysicalPointToIndex(
354
const Point<TCoordRep, VImageDimension>& point,
355
IndexType & index ) const
357
ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformPhysicalPointToIndex(
358
this->m_PhysicalPointToIndex, this->m_Origin, point, index);
360
// Now, check to see if the index is within allowed bounds
361
const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
365
template<class TCoordRep>
366
bool TransformPhysicalPointToIndex(
367
const Point<TCoordRep, VImageDimension>& point,
368
IndexType & index ) const
370
for (unsigned int i = 0; i < VImageDimension; i++)
372
TCoordRep sum = NumericTraits<TCoordRep>::Zero;
373
for (unsigned int j = 0; j < VImageDimension; j++)
375
sum += this->m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]);
377
index[i] = static_cast< IndexValueType>( sum );
380
// Now, check to see if the index is within allowed bounds
381
const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
387
/** \brief Get the continuous index from a physical point
389
* Returns true if the resulting index is within the image, false otherwise.
391
template<class TCoordRep>
392
bool TransformPhysicalPointToContinuousIndex(
393
const Point<TCoordRep, VImageDimension>& point,
394
ContinuousIndex<TCoordRep, VImageDimension>& index ) const
396
Vector<double, VImageDimension> cvector;
398
for( unsigned int k = 0; k < VImageDimension; k++ )
400
cvector[k] = point[k] - this->m_Origin[k];
402
cvector = m_PhysicalPointToIndex * cvector;
403
for( unsigned int i = 0; i < VImageDimension; i++ )
405
index[i] = static_cast<TCoordRep>(cvector[i]);
408
// Now, check to see if the index is within allowed bounds
409
const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
415
/** Get a physical point (in the space which
416
* the origin and spacing infomation comes from)
417
* from a continuous index (in the index space)
419
template<class TCoordRep>
420
void TransformContinuousIndexToPhysicalPoint(
421
const ContinuousIndex<TCoordRep, VImageDimension>& index,
422
Point<TCoordRep, VImageDimension>& point ) const
424
for( unsigned int r=0; r<VImageDimension; r++)
426
TCoordRep sum = NumericTraits<TCoordRep>::Zero;
427
for( unsigned int c=0; c<VImageDimension; c++ )
429
sum += this->m_IndexToPhysicalPoint(r,c) * index[c];
431
point[r] = sum + this->m_Origin[r];
435
/** Get a physical point (in the space which
436
* the origin and spacing infomation comes from)
437
* from a discrete index (in the index space)
440
#ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
441
template<class TCoordRep>
442
void TransformIndexToPhysicalPoint(
443
const IndexType & index,
444
Point<TCoordRep, VImageDimension>& point ) const
446
ImageTransformHelper<VImageDimension,VImageDimension-1,VImageDimension-1>::TransformIndexToPhysicalPoint(
447
this->m_IndexToPhysicalPoint, this->m_Origin, index, point);
450
template<class TCoordRep>
451
void TransformIndexToPhysicalPoint(
452
const IndexType & index,
453
Point<TCoordRep, VImageDimension>& point ) const
455
for (unsigned int i = 0; i < VImageDimension; i++)
457
point[i] = this->m_Origin[i];
458
for (unsigned int j = 0; j < VImageDimension; j++)
460
point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
467
/** Get a physical point (in the space which
468
* the origin and spacing infomation comes from)
469
* from a discrete index (in the index space)
473
/** Take a vector or covariant vector that has been computed in the
474
* coordinate system parallel to the image grid and rotate it by the
475
* direction cosines in order to get it in terms of the coordinate system of
476
* the image acquisition device. This implementation in the OrientedImage
477
* multiply the array (vector or covariant vector) by the matrix of Direction
478
* Cosines. The arguments of the method are of type FixedArray to make
479
* possible to use this method with both Vector and CovariantVector.
480
* The Method is implemented differently in the itk::Image.
484
template<class TCoordRep>
485
void TransformLocalVectorToPhysicalVector(
486
const FixedArray<TCoordRep, VImageDimension> & inputGradient,
487
FixedArray<TCoordRep, VImageDimension> & outputGradient ) const
490
// This temporary implementation should be replaced with Template MetaProgramming.
492
#ifdef ITK_USE_ORIENTED_IMAGE_DIRECTION
493
const DirectionType & direction = this->GetDirection();
494
for (unsigned int i = 0; i < VImageDimension; i++)
496
typedef typename NumericTraits<TCoordRep>::AccumulateType CoordSumType;
497
CoordSumType sum = NumericTraits<CoordSumType>::Zero;
498
for (unsigned int j = 0; j < VImageDimension; j++)
500
sum += direction[i][j] * inputGradient[j];
502
outputGradient[i] = static_cast<TCoordRep>( sum );
505
for (unsigned int i = 0; i < VImageDimension; i++)
507
outputGradient[i] = inputGradient[i];
339
512
/** Copy information from the specified data set. This method is
340
513
* part of the pipeline execution model. By default, a ProcessObject