DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSpatiallyDenseSparseVectorImageNeighborhoodAccessorFunctor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Spatially Dense Sparse Vector Image Neighborhood Accessor Functor
4 
5  Copyright (c) Pew-Thian Yap. All rights reserved.
6  See http://www.unc.edu/~ptyap/ for details.
7 
8  This software is distributed WITHOUT ANY WARRANTY; without even
9  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10  PURPOSE. See the above copyright notices for more information.
11 
12  =========================================================================*/
13 
14 #ifndef __itkSpatiallyDenseSparseVectorImageNeighborhoodAccessorFunctor_h
15 #define __itkSpatiallyDenseSparseVectorImageNeighborhoodAccessorFunctor_h
16 
17 #include "itkImageBoundaryCondition.h"
18 #include "itkNeighborhood.h"
19 #include "itkImageBase.h"
20 #include "itkNumericTraits.h"
21 
22 
23 namespace itk
24 {
25 
35 template< class TImage >
37 {
38 public:
39  typedef TImage ImageType;
40  typedef typename ImageType::PixelType PixelType;
41  typedef typename ImageType::InternalPixelType InternalPixelType;
42  typedef typename ImageType::OffsetType OffsetType;
43  typedef unsigned int VectorLengthType;
44 
45  typedef Neighborhood< InternalPixelType *, TImage::ImageDimension>
47 
48  typedef ImageBoundaryCondition< ImageType > const
50 
52  PixelType fillBufferValue , VectorLengthType length)
53  : m_FillBufferValue( fillBufferValue ), m_VectorLength( length ) {};
55  : m_FillBufferValue( NumericTraits<PixelType>::Zero, m_VectorLength( 0 ) ) {};
56 
70  inline void SetBegin( const InternalPixelType * begin ) // NOTE: begin is always 0
71  { this->m_Begin = const_cast< InternalPixelType * >( begin ); }
72 
80  inline PixelType Get( const InternalPixelType *pixelPointer ) const
81  {
82  PixelType pixel;
83  pixel.SetSize(m_VectorLength);
84 
85  const typename InternalPixelType::InternalDataType *map =
86  pixelPointer->GetDataPointer();
87 
88  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
89  {
90  typename InternalPixelType::InternalDataType::const_iterator it = map->find( i );
91 
92  if ( it == map->end() )
93  {
94  pixel[i] = m_FillBufferValue[i];
95  }
96  else
97  {
98  pixel[i] = it->second;
99  }
100  }
101 
102  return pixel;
103  }
104 
106  inline void Set( InternalPixelType* &pixelPointer, const PixelType &p ) const
107  {
108  typename InternalPixelType::InternalDataType *map =
109  pixelPointer->GetDataPointer();
110 
111  map->clear();
112 
113  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
114  {
115  if ( p[i] != 0 )
116  {
117  (*map)[i] = p[i];
118  }
119  }
120  }
121 
122  inline PixelType BoundaryCondition(
123  const OffsetType& point_index,
124  const OffsetType &boundary_offset,
125  const NeighborhoodType *data,
126  const ImageBoundaryConditionConstPointerType boundaryCondition) const
127  {
128  return boundaryCondition->operator()(point_index, boundary_offset, data, *this);
129  }
130 
132  void SetVectorLength( VectorLengthType length )
133  {
134  m_VectorLength = length;
135  }
136 
138  VectorLengthType GetVectorLength()
139  {
140  return m_VectorLength;
141  }
142 
143 private:
144  PixelType m_FillBufferValue;
145  InternalPixelType *m_Begin; // Begin of the buffer, always 0
146 
147  VectorLengthType m_VectorLength;
148 
149 };
150 
151 } // end namespace itk
152 #endif
PixelType BoundaryCondition(const OffsetType &point_index, const OffsetType &boundary_offset, const NeighborhoodType *data, const ImageBoundaryConditionConstPointerType boundaryCondition) const
Provides accessor interfaces to Access pixels and is meant to be used on pointers to pixels held by t...