18#ifndef sitkTemplateFunctions_h
19#define sitkTemplateFunctions_h
33template <
unsigned int VImageDimension>
59 operator<<(std::ostream & os,
const std::vector<T> & v)
67 std::copy(v.begin(), v.end() - 1, std::ostream_iterator<T>(os,
", "));
68 return os << v.back() <<
" ]";
71template <
typename TITKPo
intVector,
typename TType>
76 using itkPointVectorType = TITKPointVector;
77 itkPointVectorType out;
79 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
81 for (
unsigned int i = 0; i + Dimension <= in.size(); i += Dimension)
83 typename itkPointVectorType::value_type pt(&in[i]);
95template <
typename TITKVector,
typename TType>
99 using itkVectorType = TITKVector;
100 if (in.size() < itkVectorType::Dimension)
103 <<
"Expected vector of length " << itkVectorType::Dimension <<
" but only got " << in.size()
107 for (
unsigned int i = 0; i < itkVectorType::Dimension; ++i)
116template <
typename TType,
typename TITKVector>
120 std::vector<TType> out(TITKVector::Dimension);
121 for (
unsigned int i = 0; i < TITKVector::Dimension; ++i)
123 out[i] =
static_cast<TType
>(in[i]);
132template <
typename TType,
typename TVectorOfITKVector>
136 using ITKVectorType =
typename std::iterator_traits<
decltype(std::begin(in))>::value_type;
137 std::vector<TType> out;
138 out.reserve(in.Size() * ITKVectorType::Dimension);
139 for (
const auto & v : in)
141 out.insert(out.end(), v.begin(), v.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_)))
285template <
typename T, T
Offset, T... Is>
292template <
unsigned int Start,
unsigned int Stop>
296 std::make_integer_sequence<
unsigned int, Stop - Start + 1>::type>;
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.
detail::make_offset_integer_sequence_helper< unsigned int, Start, std::make_integer_sequence< unsigned int, Stop - Start+1 >::type > make_dimension_sequence
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)
std::integer_sequence< T, Offset+Is... > type
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