18#ifndef sitkTemplateFunctions_h
19#define sitkTemplateFunctions_h
32template <
unsigned int VImageDimension>
58 operator<<(std::ostream & os,
const std::vector<T> & v)
66 std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(os,
", "));
67 return os << v.back() <<
" ]";
70template <
typename TITKPo
intVector,
typename TType>
75 using itkPointVectorType = TITKPointVector;
76 itkPointVectorType out;
78 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
80 for (
unsigned int i = 0; i + Dimension <= in.size(); i += Dimension)
82 typename itkPointVectorType::value_type pt(&in[i]);
94template <
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)
115template <
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]);
131template <
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)
141 out.insert(out.end(), temp.begin(), temp.end());
147template <
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]));
169template <
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));
187template <
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");
210template <
typename TDirectionType>
214 return std::vector<double>(d.GetVnlMatrix().begin(), d.GetVnlMatrix().end());
218template <
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]);
234template <
typename TType,
typename T>
238 std::vector<TType> out(4);
259 :
f_((rhs.run_ =
false, std::move(rhs.f_)))
const IndexType & GetIndex() const
const SizeType & GetSize() const
void Set(const MatrixType &mat)
std::vector< TType > SITKCommon_HIDDEN sitkVectorOfITKVectorToSTL(const TVectorOfITKVector &in)
Convert an ITK style array of ITK fixed width vector to std::vector.
std::vector< TType > SITKCommon_HIDDEN sitkITKVectorToSTL(const TITKVector &in)
Convert an ITK fixed width vector to a std::vector.
SITKCommon_EXPORT std::ostream & operator<<(std::ostream &os, const EventEnum k)
TITKVector SITKCommon_HIDDEN sitkSTLVectorToITK(const std::vector< TType > &in)
Copy the elements of an std::vector into an ITK fixed width vector.
scope_exit< F > make_scope_exit(F &&f) noexcept
std::vector< unsigned int > SITKCommon_HIDDEN sitkITKImageRegionToSTL(const ImageRegion< VImageDimension > &in)
Convert an ITK ImageRegion to and std::vector with the first part being the start index followed by t...
std::vector< TType > SITKCommon_HIDDEN sitkITKVersorToSTL(const itk::Versor< T > &in)
void SITKCommon_HIDDEN Unused(const T &)
A function which does nothing.
std::vector< double > SITKCommon_HIDDEN sitkITKDirectionToSTL(const TDirectionType &d)
TDirectionType SITKCommon_HIDDEN sitkSTLToITKDirection(const std::vector< double > &direction)
itk::Versor< T > SITKCommon_HIDDEN sitkSTLVectorToITKVersor(const std::vector< TType > &in)
TITKPointVector SITKCommon_HIDDEN sitkSTLVectorToITKPointVector(const std::vector< TType > &in)
#define SITKCommon_HIDDEN
#define sitkExceptionMacro(x)
scope_exit & operator=(scope_exit &&rhs)=delete
scope_exit(const scope_exit &)=delete
scope_exit & operator=(const scope_exit &)=delete
scope_exit(scope_exit &&rhs) noexcept