18 #ifndef sitkTemplateFunctions_h
19 #define sitkTemplateFunctions_h
31 template<
unsigned int VImageDimension>
class ImageRegion;
32 template<
typename T>
class Versor;
60 std::copy( v.begin(), v.end()-1, std::ostream_iterator<T>(os,
", ") );
61 return os << v.back() <<
" ]";
64 template<
typename TITKPo
intVector,
typename TType>
68 typedef TITKPointVector itkPointVectorType;
69 itkPointVectorType out;
71 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
73 for(
unsigned int i = 0; i + Dimension <= in.size(); i += Dimension )
75 typename itkPointVectorType::value_type pt(&in[i]);
88 template<
typename TITKVector,
typename TType>
91 typedef TITKVector itkVectorType;
92 if ( in.size() < itkVectorType::Dimension )
95 <<
"Expected vector of length " << itkVectorType::Dimension
96 <<
" but only got " << in.size() <<
" elements." );
99 for(
unsigned int i = 0; i < itkVectorType::Dimension; ++i )
108 template<
typename TType,
typename TITKVector>
111 std::vector<TType> out( TITKVector::Dimension );
112 for(
unsigned int i = 0; i < TITKVector::Dimension; ++i )
114 out[i] =
static_cast<TType
>(in[i]);
123 template<
typename TType,
typename TVectorOfITKVector>
126 typedef typename TVectorOfITKVector::ValueType ITKVectorType;
127 std::vector<TType> out;
128 out.reserve( in.Size()*ITKVectorType::Dimension );
129 for(
unsigned int i = 0; i < in.Size(); ++i )
131 const std::vector<TType> &temp = sitkITKVectorToSTL<TType>(in[i]);
132 out.insert(out.end(), temp.begin(), temp.end());
138 template<
typename TType,
typename TITKVector>
141 std::vector<TType> out;
142 out.reserve( in.size()*TITKVector::Dimension );
143 typename std::vector<TITKVector>::const_iterator iter = in.begin();
144 while(iter!=in.end())
146 for(
unsigned int i = 0; i < TITKVector::Dimension; ++i )
148 out.push_back(static_cast<TType>((*iter)[i]));
159 template<
unsigned int VImageDimension>
162 std::vector<unsigned int> out( VImageDimension*2 );
163 for(
unsigned int i = 0; i < VImageDimension; ++i )
165 out[i] =
static_cast<unsigned int>(in.
GetIndex(i));
166 out[VImageDimension+i] =
static_cast<unsigned int>(in.
GetSize(i));
176 template<
typename TDirectionType >
179 TDirectionType itkDirection;
181 if ( direction.size() == 0 )
183 itkDirection.SetIdentity();
185 else if( direction.size() == TDirectionType::RowDimensions*TDirectionType::ColumnDimensions )
187 std::copy( direction.begin(), direction.end(), itkDirection.GetVnlMatrix().begin() );
191 sitkExceptionMacro(<<
"Length of input ("<<direction.size()<<
") does not match matrix dimensions ("
192 <<TDirectionType::RowDimensions<<
", "<<TDirectionType::ColumnDimensions<<
").\n");
198 template<
typename TDirectionType >
201 return std::vector<double>( d.GetVnlMatrix().begin(), d.GetVnlMatrix().end() );
205 template<
typename T,
typename TType>
209 if ( in.size() != 4 )
212 <<
"Expected vector of length " << 4
213 <<
" but got " << in.size() <<
" elements." );
216 out.Set(in[0],in[1],in[2],in[3]);
221 template<
typename TType,
typename T>
224 std::vector<TType> out(4);
TITKVector SITKCommon_HIDDEN sitkSTLVectorToITK(const std::vector< TType > &in)
Copy the elements of an std::vector into an ITK fixed width vector.
constexpr unsigned int Dimension
std::vector< TType > SITKCommon_HIDDEN sitkVectorOfITKVectorToSTL(const TVectorOfITKVector &in)
Convert an ITK style array of ITK fixed witdth vector to std::vector.
TDirectionType SITKCommon_HIDDEN sitkSTLToITKDirection(const std::vector< double > &direction)
itk::Versor< T > SITKCommon_HIDDEN sitkSTLVectorToITKVersor(const std::vector< TType > &in)
const SizeType & GetSize() const
std::vector< TType > SITKCommon_HIDDEN sitkITKVectorToSTL(const TITKVector &in)
Convert an ITK fixed width vector to a std::vector.
TITKPointVector SITKCommon_HIDDEN sitkSTLVectorToITKPointVector(const std::vector< TType > &in)
void SITKCommon_HIDDEN Unused(const T &)
A function which does nothing.
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...
#define sitkExceptionMacro(x)
std::vector< double > SITKCommon_HIDDEN sitkITKDirectionToSTL(const TDirectionType &d)
const IndexType & GetIndex() const
std::vector< TType > SITKCommon_HIDDEN sitkITKVersorToSTL(const itk::Versor< T > &in)
#define SITKCommon_HIDDEN