18 #ifndef sitkTemplateFunctions_h
19 #define sitkTemplateFunctions_h
32 template <
unsigned int VImageDimension>
66 std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(os,
", "));
67 return os << v.back() <<
" ]";
70 template <
typename TITKPo
intVector,
typename TType>
75 using itkPointVectorType = TITKPointVector;
76 itkPointVectorType out;
78 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
82 typename itkPointVectorType::value_type pt(&in[i]);
94 template <
typename TITKVector,
typename TType>
98 using itkVectorType = TITKVector;
99 if (in.size() < itkVectorType::Dimension)
102 <<
"Expected vector of length " << itkVectorType::Dimension <<
" but only got " << in.size()
106 for (
unsigned int i = 0; i < itkVectorType::Dimension; ++i)
115 template <
typename TType,
typename TITKVector>
119 std::vector<TType> out(TITKVector::Dimension);
120 for (
unsigned int i = 0; i < TITKVector::Dimension; ++i)
122 out[i] =
static_cast<TType
>(in[i]);
131 template <
typename TType,
typename TVectorOfITKVector>
135 using ITKVectorType =
typename TVectorOfITKVector::ValueType;
136 std::vector<TType> out;
137 out.reserve(in.Size() * ITKVectorType::Dimension);
138 for (
unsigned int i = 0; i < in.Size(); ++i)
140 const std::vector<TType> & temp = sitkITKVectorToSTL<TType>(in[i]);
141 out.insert(out.end(), temp.begin(), temp.end());
147 template <
typename TType,
typename TITKVector>
151 std::vector<TType> out;
152 out.reserve(in.size() * TITKVector::Dimension);
153 typename std::vector<TITKVector>::const_iterator iter = in.begin();
154 while (iter != in.end())
156 for (
unsigned int i = 0; i < TITKVector::Dimension; ++i)
158 out.push_back(
static_cast<TType
>((*iter)[i]));
169 template <
unsigned int VImageDimension>
173 std::vector<unsigned int> out(VImageDimension * 2);
174 for (
unsigned int i = 0; i < VImageDimension; ++i)
176 out[i] =
static_cast<unsigned int>(in.
GetIndex(i));
177 out[VImageDimension + i] =
static_cast<unsigned int>(in.
GetSize(i));
187 template <
typename TDirectionType>
191 TDirectionType itkDirection;
193 if (direction.empty())
195 itkDirection.SetIdentity();
197 else if (direction.size() == TDirectionType::RowDimensions * TDirectionType::ColumnDimensions)
199 std::copy(direction.begin(), direction.end(), itkDirection.GetVnlMatrix().begin());
203 sitkExceptionMacro(<<
"Length of input (" << direction.size() <<
") does not match matrix dimensions ("
204 << TDirectionType::RowDimensions <<
", " << TDirectionType::ColumnDimensions <<
").\n");
210 template <
typename TDirectionType>
214 return std::vector<double>(d.GetVnlMatrix().begin(), d.GetVnlMatrix().end());
218 template <
typename T,
typename TType>
226 <<
"Expected vector of length " << 4 <<
" but got " << in.size() <<
" elements.");
229 out.Set(in[0], in[1], in[2], in[3]);
234 template <
typename TType,
typename T>
238 std::vector<TType> out(4);
249 template <
typename F>
259 :
f_((rhs.run_ =
false, std::move(rhs.f_)))
275 template <
typename F>