Orfeo Toolbox  4.0
itkImageBase.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 /*=========================================================================
19  *
20  * Portions of this file are subject to the VTK Toolkit Version 3 copyright.
21  *
22  * Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
23  *
24  * For complete copyright, license and disclaimer of warranty information
25  * please refer to the NOTICE file at the top of the ITK source tree.
26  *
27  *=========================================================================*/
28 #ifndef __itkImageBase_h
29 #define __itkImageBase_h
30 
31 #include "itkDataObject.h"
32 
33 #include "itkImageRegion.h"
34 #include "itkMatrix.h"
35 #include "itkObjectFactory.h"
36 #include "itkOffset.h"
37 #include "itkFixedArray.h"
38 #include "itkImageHelper.h"
39 #include "itkFloatTypes.h"
40 
41 //HACK: vnl/vnl_matrix_fixed.txx is needed here?
42 // to avoid undefined symbol vnl_matrix_fixed<double, 8u, 8u>::set_identity()", referenced from
43 #include "vnl/vnl_matrix_fixed.txx"
44 
46 
47 namespace itk
48 {
49 
50 /* Forward declaration (ImageTransformHelper include's ImageBase) */
51 template< unsigned int NImageDimension, unsigned int R, unsigned int C, typename TPointValue, typename TMatrixValue >
53 
111 template< unsigned int VImageDimension = 2 >
112 class ImageBase:public DataObject
113 {
114 public:
116  typedef ImageBase Self;
120 
122  itkNewMacro(Self);
123 
125  itkTypeMacro(ImageBase, DataObject);
126 
131  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
132 
136 
141 
145 
148 
155 
160 
165 
167  void Initialize();
168 
170  static unsigned int GetImageDimension()
171  { return VImageDimension; }
172 
177  itkSetMacro(Origin, PointType);
178  virtual void SetOrigin(const double origin[VImageDimension]);
179  virtual void SetOrigin(const float origin[VImageDimension]);
180 
206  virtual void SetDirection(const DirectionType & direction);
207 
211  itkGetConstReferenceMacro(Direction, DirectionType);
212 
216  itkGetConstReferenceMacro(InverseDirection, DirectionType);
217 
222  itkGetConstReferenceMacro(Spacing, SpacingType);
223 
228  itkGetConstReferenceMacro(Origin, PointType);
229 
236  virtual void Allocate() {}
237 
244  virtual void SetLargestPossibleRegion(const RegionType & region);
245 
252  virtual const RegionType & GetLargestPossibleRegion() const
253  { return m_LargestPossibleRegion; }
254 
258  virtual void SetBufferedRegion(const RegionType & region);
259 
263  virtual const RegionType & GetBufferedRegion() const
264  { return m_BufferedRegion; }
265 
273  virtual void SetRequestedRegion(const RegionType & region);
274 
282  virtual void SetRequestedRegion( const DataObject *data );
283 
288  virtual const RegionType & GetRequestedRegion() const
289  { return m_RequestedRegion; }
290 
294  virtual void SetRegions(const RegionType& region)
295  {
296  this->SetLargestPossibleRegion(region);
297  this->SetBufferedRegion(region);
298  this->SetRequestedRegion(region);
299  }
300 
301  virtual void SetRegions(const SizeType& size)
302  {
303  RegionType region; region.SetSize(size);
304 
305  this->SetLargestPossibleRegion(region);
306  this->SetBufferedRegion(region);
307  this->SetRequestedRegion(region);
308  }
309 
320  const OffsetValueType * GetOffsetTable() const { return m_OffsetTable; }
321 
328  inline OffsetValueType ComputeOffset(const IndexType & ind) const
329  {
330  OffsetValueType offset = 0;
331 
333  ind,
335  offset);
336  return offset;
337  /* NON TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING data version
338  * Leaving here for documentation purposes
339  * OffsetValueType ComputeOffset(const IndexType & ind) const
340  * {
341  * // need to add bounds checking for the region/buffer?
342  * OffsetValueType offset = 0;
343  * const IndexType & bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
344  * // data is arranged as [][][][slice][row][col]
345  * // with Index[0] = col, Index[1] = row, Index[2] = slice
346  * for ( int i = VImageDimension - 1; i > 0; i-- )
347  * {
348  * offset += ( ind[i] - bufferedRegionIndex[i] ) * m_OffsetTable[i];
349  * }
350  * offset += ( ind[0] - bufferedRegionIndex[0] );
351  * return offset;
352  * }
353  */
354  }
355 
364  {
365  IndexType index;
366  const IndexType & bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
367 
369  offset,
371  index);
372  return index;
373  /* NON TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING data version
374  * Leaving here for documentation purposes
375  * IndexType ComputeIndex(OffsetValueType offset) const
376  * {
377  * IndexType index;
378  * const IndexType & bufferedRegionIndex = this->GetBufferedRegion().GetIndex();
379  * for ( int i = VImageDimension - 1; i > 0; i-- )
380  * {
381  * index[i] = static_cast< IndexValueType >( offset / m_OffsetTable[i] );
382  * offset -= ( index[i] * m_OffsetTable[i] );
383  * index[i] += bufferedRegionIndex[i];
384  * }
385  * index[0] = bufferedRegionIndex[0] + static_cast< IndexValueType >( offset );
386  * return index;
387  * }
388  */
389 
390  }
391 
398  virtual void SetSpacing(const SpacingType & spacing);
399  virtual void SetSpacing(const double spacing[VImageDimension]);
400  virtual void SetSpacing(const float spacing[VImageDimension]);
401 
406  template< typename TCoordRep >
409  IndexType & index) const
410  {
413 
414  // Now, check to see if the index is within allowed bounds
415  const bool isInside = this->GetLargestPossibleRegion().IsInside(index);
416  return isInside;
417  /* NON TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING data version
418  * Leaving here for documentation purposes
419  * template< typename TCoordRep >
420  * bool TransformPhysicalPointToIndex(
421  * const Point< TCoordRep, VImageDimension > & point,
422  * IndexType & index) const
423  * {
424  * for ( unsigned int i = 0; i < VImageDimension; i++ )
425  * {
426  * TCoordRep sum = NumericTraits< TCoordRep >::Zero;
427  * for ( unsigned int j = 0; j < VImageDimension; j++ )
428  * {
429  * sum += this->m_PhysicalPointToIndex[i][j] * ( point[j] - this->m_Origin[j] );
430  * }
431  * index[i] = Math::RoundHalfIntegerUp< IndexValueType >(sum);
432  * }
433  * // Now, check to see if the index is within allowed bounds
434  * const bool isInside = this->GetLargestPossibleRegion().IsInside(index);
435  * return isInside;
436  * }
437  */
438  }
439 
444  template< typename TCoordRep, typename TIndexRep >
448  {
450 
451  for ( unsigned int k = 0; k < VImageDimension; k++ )
452  {
453  cvector[k] = point[k] - this->m_Origin[k];
454  }
455  cvector = m_PhysicalPointToIndex * cvector;
456  for ( unsigned int i = 0; i < VImageDimension; i++ )
457  {
458  index[i] = static_cast< TIndexRep >( cvector[i] );
459  }
460 
461  // Now, check to see if the index is within allowed bounds
462  const bool isInside = this->GetLargestPossibleRegion().IsInside(index);
463 
464  return isInside;
465  }
466 
471  template< typename TCoordRep, typename TIndexRep >
475  {
476  for ( unsigned int r = 0; r < VImageDimension; r++ )
477  {
478  TCoordRep sum = NumericTraits< TCoordRep >::Zero;
479  for ( unsigned int c = 0; c < VImageDimension; c++ )
480  {
481  sum += this->m_IndexToPhysicalPoint(r, c) * index[c];
482  }
483  point[r] = sum + this->m_Origin[r];
484  }
485  }
486 
492  template< typename TCoordRep >
494  const IndexType & index,
496  {
499  /* NON TEMPLATE_META_PROGRAMMING_LOOP_UNROLLING data version
500  * Leaving here for documentation purposes
501  * template< typename TCoordRep >
502  * void TransformIndexToPhysicalPoint(
503  * const IndexType & index,
504  * Point< TCoordRep, VImageDimension > & point) const
505  * {
506  * for ( unsigned int i = 0; i < VImageDimension; i++ )
507  * {
508  * point[i] = this->m_Origin[i];
509  * for ( unsigned int j = 0; j < VImageDimension; j++ )
510  * {
511  * point[i] += m_IndexToPhysicalPoint[i][j] * index[j];
512  * }
513  * }
514  * }
515  */
516  }
517 
529  template< typename TCoordRep >
531  const FixedArray< TCoordRep, VImageDimension > & inputGradient,
532  FixedArray< TCoordRep, VImageDimension > & outputGradient) const
533  {
534  //
535  //TODO: This temporary implementation should be replaced with Template
536  // MetaProgramming.
537  //
538  const DirectionType & direction = this->GetDirection();
539 
540  for ( unsigned int i = 0; i < VImageDimension; i++ )
541  {
542  typedef typename NumericTraits< TCoordRep >::AccumulateType CoordSumType;
543  CoordSumType sum = NumericTraits< CoordSumType >::Zero;
544  for ( unsigned int j = 0; j < VImageDimension; j++ )
545  {
546  sum += direction[i][j] * inputGradient[j];
547  }
548  outputGradient[i] = static_cast< TCoordRep >( sum );
549  }
550  }
551 
560  template< typename TCoordRep >
562  const FixedArray< TCoordRep, VImageDimension > & inputGradient,
563  FixedArray< TCoordRep, VImageDimension > & outputGradient) const
564  {
565  //
566  //TODO: This temporary implementation should be replaced with Template
567  // MetaProgramming.
568  //
569  const DirectionType & inverseDirection = this->GetInverseDirection();
570 
571  for ( unsigned int i = 0; i < VImageDimension; i++ )
572  {
573  typedef typename NumericTraits< TCoordRep >::AccumulateType CoordSumType;
574  CoordSumType sum = NumericTraits< CoordSumType >::Zero;
575  for ( unsigned int j = 0; j < VImageDimension; j++ )
576  {
577  sum += inverseDirection[i][j] * inputGradient[j];
578  }
579  outputGradient[i] = static_cast< TCoordRep >( sum );
580  }
581  }
582 
592  virtual void CopyInformation(const DataObject *data);
593 
604  virtual void Graft(const DataObject *data);
605 
613  virtual void UpdateOutputInformation();
614 
622  virtual void UpdateOutputData();
623 
628 
639 
648  virtual bool VerifyRequestedRegion();
649 
668  virtual unsigned int GetNumberOfComponentsPerPixel() const;
669  virtual void SetNumberOfComponentsPerPixel(unsigned int);
670 
671 protected:
672  ImageBase();
673  ~ImageBase();
674  virtual void PrintSelf(std::ostream & os, Indent indent) const;
675 
680  void ComputeOffsetTable();
681 
688 
689 protected:
697 
702 
707  virtual void InitializeBufferedRegion(void);
708 
709 private:
710  ImageBase(const Self &); //purposely not implemented
711  void operator=(const Self &); //purposely not implemented
712 
713  void InternalSetSpacing(const SpacingValueType spacing[VImageDimension])
714  {
715  SpacingType s(spacing);
716  this->SetSpacing(s);
717  }
718 
719  template <typename TSpacingValue>
720  void InternalSetSpacing(const TSpacingValue spacing[VImageDimension])
721  {
723  SpacingType s;
724  s.CastFrom(sf);
725  this->SetSpacing(s);
726  }
727 
728  OffsetValueType m_OffsetTable[VImageDimension + 1];
729 
733 };
734 } // end namespace itk
735 
736 #ifndef ITK_MANUAL_INSTANTIATION
737 #include "itkImageBase.hxx"
738 #endif
739 
740 #endif

Generated at Sat Mar 8 2014 14:50:01 for Orfeo Toolbox with doxygen 1.8.3.1