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 using itkPointVectorType = TITKPointVector;
69 itkPointVectorType out;
71 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
75 typename itkPointVectorType::value_type pt(&in[i]);
88 template<
typename TITKVector,
typename TType>
91 using itkVectorType = TITKVector;
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 using ITKVectorType =
typename TVectorOfITKVector::ValueType;
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.empty() )
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);
235 template <
typename F>
252 template <
typename F>