Orfeo Toolbox  3.16
itkImageBase.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkImageBase.h,v $
5  Language: C++
6  Date: $Date: 2009-12-14 16:28:26 $
7  Version: $Revision: 1.83 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  Portions of this code are covered under the VTK copyright.
13  See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 #ifndef __itkImageBase_h
21 #define __itkImageBase_h
22 
23 #include "itkDataObject.h"
24 
25 #include "itkImageRegion.h"
26 #include "itkIndex.h"
27 #include "itkObjectFactory.h"
28 #include "itkOffset.h"
29 #include "itkPoint.h"
30 #include "itkSize.h"
31 #include "itkFixedArray.h"
32 #include "itkPoint.h"
33 #include "itkMatrix.h"
34 #include "itkContinuousIndex.h"
35 #include "itkImageHelper.h"
36 #include <vnl/vnl_matrix_fixed.txx>
37 
38 #include "itkImageRegion.h"
39 
40 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
42 #endif
43 
44 namespace itk
45 {
46 
53 template <typename TImage>
55 {
56  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
57 };
58 
86 template<unsigned int VImageDimension=2>
88 {
89 public:
91  typedef ImageBase Self;
95 
97  itkNewMacro(Self);
98 
100  itkTypeMacro(ImageBase, DataObject);
101 
106  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension );
107 
111 
115  typedef typename OffsetType::OffsetValueType OffsetValueType;
116 
120 
123 
128  typedef double SpacingValueType;
130 
133  typedef double PointValueType;
135 
140 
142  void Initialize();
143 
145  static unsigned int GetImageDimension()
146  { return VImageDimension; }
147 
152  itkSetMacro(Origin, PointType);
153  virtual void SetOrigin( const double origin[VImageDimension] );
154  virtual void SetOrigin( const float origin[VImageDimension] );
155 
182  virtual void SetDirection( const DirectionType direction );
183 
187  itkGetConstReferenceMacro(Direction, DirectionType);
188 
193  itkGetConstReferenceMacro(Spacing, SpacingType);
194 
199  itkGetConstReferenceMacro(Origin, PointType);
200 
207  virtual void Allocate() {};
208 
215  virtual void SetLargestPossibleRegion(const RegionType &region);
216 
223  virtual const RegionType& GetLargestPossibleRegion() const
224  { return m_LargestPossibleRegion;};
225 
229  virtual void SetBufferedRegion(const RegionType &region);
230 
234  virtual const RegionType& GetBufferedRegion() const
235  { return m_BufferedRegion;};
236 
244  virtual void SetRequestedRegion(const RegionType &region);
245 
253  virtual void SetRequestedRegion(DataObject *data);
254 
259  virtual const RegionType& GetRequestedRegion() const
260  { return m_RequestedRegion;};
261 
272  const OffsetValueType *GetOffsetTable() const { return m_OffsetTable; };
273 
282 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
283  inline OffsetValueType ComputeOffset(const IndexType &ind) const
284  {
285  OffsetValueType offset = 0;
286  ImageHelper<VImageDimension,VImageDimension>::ComputeOffset(this->GetBufferedRegion().GetIndex(),
287  ind,
288  m_OffsetTable,
289  offset);
290  return offset;
291  }
292 #else
293  OffsetValueType ComputeOffset(const IndexType &ind) const
294  {
295  // need to add bounds checking for the region/buffer?
296  OffsetValueType offset=0;
297  const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
298 
299  // data is arranged as [][][][slice][row][col]
300  // with Index[0] = col, Index[1] = row, Index[2] = slice
301  for (int i=VImageDimension-1; i > 0; i--)
302  {
303  offset += (ind[i] - bufferedRegionIndex[i])*m_OffsetTable[i];
304  }
305  offset += (ind[0] - bufferedRegionIndex[0]);
306 
307  return offset;
308  }
309 #endif
310 
317 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
318  inline IndexType ComputeIndex(OffsetValueType offset) const
319  {
320  IndexType index;
321  const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
323  offset,
324  m_OffsetTable,
325  index);
326  return index;
327  }
328 #else
329  IndexType ComputeIndex(OffsetValueType offset) const
330  {
331  IndexType index;
332  const IndexType &bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
333 
334  for (int i=VImageDimension-1; i > 0; i--)
335  {
336  index[i] = static_cast<IndexValueType>(offset / m_OffsetTable[i]);
337  offset -= (index[i] * m_OffsetTable[i]);
338  index[i] += bufferedRegionIndex[i];
339  }
340  index[0] = bufferedRegionIndex[0] + static_cast<IndexValueType>(offset);
341 
342  return index;
343  }
344 #endif
345 
352  virtual void SetSpacing (const SpacingType & spacing);
353  virtual void SetSpacing (const double spacing[VImageDimension]);
354  virtual void SetSpacing (const float spacing[VImageDimension]);
355 
356 
363 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
364  template<class TCoordRep>
365  bool TransformPhysicalPointToIndex(
367  IndexType & index ) const
368  {
370  this->m_PhysicalPointToIndex, this->m_Origin, point, index);
371 
372  // Now, check to see if the index is within allowed bounds
373  const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
374  return isInside;
375  }
376 #else
377  template<class TCoordRep>
378  bool TransformPhysicalPointToIndex(
380  IndexType & index ) const
381  {
382  for (unsigned int i = 0; i < VImageDimension; i++)
383  {
384  TCoordRep sum = NumericTraits<TCoordRep>::Zero;
385  for (unsigned int j = 0; j < VImageDimension; j++)
386  {
387  sum += this->m_PhysicalPointToIndex[i][j] * (point[j] - this->m_Origin[j]);
388  }
389 #ifdef ITK_USE_CENTERED_PIXEL_COORDINATES_CONSISTENTLY
390  index[i] = Math::RoundHalfIntegerUp< IndexValueType>( sum );
391 #else
392  index[i] = static_cast< IndexValueType>( sum );
393 #endif
394  }
395 
396  // Now, check to see if the index is within allowed bounds
397  const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
398 
399  return isInside;
400  }
401 #endif
402 
407  template<class TCoordRep>
408  bool TransformPhysicalPointToContinuousIndex(
411  {
413 
414  for( unsigned int k = 0; k < VImageDimension; k++ )
415  {
416  cvector[k] = point[k] - this->m_Origin[k];
417  }
418  cvector = m_PhysicalPointToIndex * cvector;
419  for( unsigned int i = 0; i < VImageDimension; i++ )
420  {
421  index[i] = static_cast<TCoordRep>(cvector[i]);
422  }
423 
424  // Now, check to see if the index is within allowed bounds
425  const bool isInside = this->GetLargestPossibleRegion().IsInside( index );
426 
427  return isInside;
428  }
429 
430 
435  template<class TCoordRep>
436  void TransformContinuousIndexToPhysicalPoint(
438  Point<TCoordRep, VImageDimension>& point ) const
439  {
440  for( unsigned int r=0; r<VImageDimension; r++)
441  {
442  TCoordRep sum = NumericTraits<TCoordRep>::Zero;
443  for( unsigned int c=0; c<VImageDimension; c++ )
444  {
445  sum += this->m_IndexToPhysicalPoint(r,c) * index[c];
446  }
447  point[r] = sum + this->m_Origin[r];
448  }
449  }
450 
456 #ifdef ITK_USE_TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING
457  template<class TCoordRep>
458  void TransformIndexToPhysicalPoint(
459  const IndexType & index,
460  Point<TCoordRep, VImageDimension>& point ) const
461  {
463  this->m_IndexToPhysicalPoint, this->m_Origin, index, point);
464  }
465 #else
466  template<class TCoordRep>
467  void TransformIndexToPhysicalPoint(
468  const IndexType & index,
469  Point<TCoordRep, VImageDimension>& point ) const
470  {
471  for (unsigned int i = 0; i < VImageDimension; i++)
472  {
473  point[i] = this->m_Origin[i];
474  for (unsigned int j = 0; j < VImageDimension; j++)
475  {
476  point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
477  }
478  }
479  }
480 #endif
481 
482 
500  template<class TCoordRep>
501  void TransformLocalVectorToPhysicalVector(
502  const FixedArray<TCoordRep, VImageDimension> & inputGradient,
503  FixedArray<TCoordRep, VImageDimension> & outputGradient ) const
504  {
505  //
506  // This temporary implementation should be replaced with Template MetaProgramming.
507  //
508 #ifdef ITK_USE_ORIENTED_IMAGE_DIRECTION
509  const DirectionType & direction = this->GetDirection();
510  for (unsigned int i = 0; i < VImageDimension; i++)
511  {
512  typedef typename NumericTraits<TCoordRep>::AccumulateType CoordSumType;
513  CoordSumType sum = NumericTraits<CoordSumType>::Zero;
514  for (unsigned int j = 0; j < VImageDimension; j++)
515  {
516  sum += direction[i][j] * inputGradient[j];
517  }
518  outputGradient[i] = static_cast<TCoordRep>( sum );
519  }
520 #else
521  for (unsigned int i = 0; i < VImageDimension; i++)
522  {
523  outputGradient[i] = inputGradient[i];
524  }
525 #endif
526  }
527 
537  virtual void CopyInformation(const DataObject *data);
538 
549  virtual void Graft(const DataObject *data);
550 
558  virtual void UpdateOutputInformation();
559 
567  virtual void UpdateOutputData();
568 
572  virtual void SetRequestedRegionToLargestPossibleRegion();
573 
583  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion();
584 
593  virtual bool VerifyRequestedRegion();
594 
611  virtual unsigned int GetNumberOfComponentsPerPixel() const;
612  virtual void SetNumberOfComponentsPerPixel( unsigned int );
613 
614 protected:
615  ImageBase();
616  ~ImageBase();
617  virtual void PrintSelf(std::ostream& os, Indent indent) const;
618 
623  void ComputeOffsetTable();
624 
630  virtual void ComputeIndexToPhysicalPointMatrices();
631 
632 protected:
639 
644 
649  virtual void InitializeBufferedRegion(void);
650 
651 private:
652  ImageBase(const Self&); //purposely not implemented
653  void operator=(const Self&); //purposely not implemented
654 
655  OffsetValueType m_OffsetTable[VImageDimension+1];
656 
660 
661 };
662 
663 } // end namespace itk
664 
665 // Define instantiation macro for this template.
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; } \
669  }
670 
671 #if ITK_TEMPLATE_EXPLICIT
672 # include "Templates/itkImageBase+-.h"
673 #endif
674 
675 #if ITK_TEMPLATE_TXX
676 # include "itkImageBase.txx"
677 #endif
678 
679 #endif

Generated at Sat Feb 2 2013 23:42:40 for Orfeo Toolbox with doxygen 1.8.1.1