DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkSpatiallyDenseSparseVectorImagePixelAccessor.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Spatially Dense Sparse Vector Image Pixel Accessor
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 __itkSpatiallyDenseSparseVectorImagePixelAccessor_h
15 #define __itkSpatiallyDenseSparseVectorImagePixelAccessor_h
16 
17 #include "itkMacro.h"
18 #include "itkVariableLengthVector.h"
19 #include "itkSparseVector.h"
20 #include "itkIntTypes.h"
21 
22 
23 namespace itk
24 {
25 
42 template <class TValueType, class TKeyType>
44 {
45 public:
46 
49  typedef VariableLengthVector<TValueType> ExternalType;
50 
54 
55  typedef unsigned long VectorLengthType;
56 
58  inline void Set(InternalType & output,
59  const ExternalType & input,
60  const SizeValueType offset) const
61  {
62  output.Clear();
63  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
64  {
65  if ( input[i] != 0 )
66  {
67  output[i] = input[i];
68  }
69  }
70  }
71 
73  inline ExternalType Get(const InternalType & input,
74  const SizeValueType offset) const
75  {
76  ExternalType pixel;
77  pixel.SetSize(m_VectorLength);
78 
79  for ( VectorLengthType i = 0; i < m_VectorLength; i++ )
80  {
81 // typename InternalType::const_iterator it = input.find( i );
82 
83 // if ( it == input.end() )
84 // {
85 // pixel[i] = m_FillBufferValue[i];
86 // }
87 // else
88 // {
89 // pixel[i] = it->second;
90 // }
91  pixel[i] = input[i];
92  }
93 
94  return pixel;
95  }
96 
98  void SetVectorLength(VectorLengthType length)
99  {
100  m_VectorLength = length;
101  }
102 
104  VectorLengthType GetVectorLength() const { return m_VectorLength; }
105 
107 
109  SpatiallyDenseSparseVectorImagePixelAccessor(ExternalType fillBufferValue,
110  VectorLengthType length)
111  {
112  m_FillBufferValue = fillBufferValue;
113  m_VectorLength = length;
114  }
115 
117 
118 private:
119  ExternalType m_FillBufferValue;
120  VectorLengthType m_VectorLength;
121 };
122 
123 } // end namespace itk
124 
125 
126 #endif
void Set(InternalType &output, const ExternalType &input, const SizeValueType offset) const
Represents a sparse array.
ExternalType Get(const InternalType &input, const SizeValueType offset) const
SpatiallyDenseSparseVectorImagePixelAccessor(ExternalType fillBufferValue, VectorLengthType length)