18 #ifndef sitkTemplateFunctions_h
19 #define sitkTemplateFunctions_h
31 template<
unsigned int VImageDimension>
class ImageRegion;
59 std::copy( v.begin(), v.end()-1, std::ostream_iterator<T>(os,
", ") );
60 return os << v.back() <<
" ]";
63 template<
typename TITKPo
intVector,
typename TType>
67 typedef TITKPointVector itkPointVectorType;
68 itkPointVectorType out;
70 unsigned int Dimension = itkPointVectorType::value_type::GetPointDimension();
72 for(
unsigned int i = 0; i <= in.size()- Dimension; i += Dimension )
74 typename itkPointVectorType::value_type pt(&in[i]);
87 template<
typename TITKVector,
typename TType>
90 typedef TITKVector itkVectorType;
91 if ( in.size() < itkVectorType::Dimension )
94 <<
"Expected vector of length " << itkVectorType::Dimension
95 <<
" but only got " << in.size() <<
" elements." );
98 for(
unsigned int i = 0; i < itkVectorType::Dimension; ++i )
107 template<
typename TType,
typename TITKVector>
110 std::vector<TType> out( TITKVector::Dimension );
111 for(
unsigned int i = 0; i < TITKVector::Dimension; ++i )
113 out[i] =
static_cast<TType
>(in[i]);
119 template<
typename TType,
typename TITKVector>
122 std::vector<TType> out;
123 out.reserve( in.size()*TITKVector::Dimension );
124 typename std::vector<TITKVector>::const_iterator iter = in.begin();
125 while(iter!=in.end())
127 for(
unsigned int i = 0; i < TITKVector::Dimension; ++i )
129 out.push_back(static_cast<TType>((*iter)[i]));
140 template<
unsigned int VImageDimension>
143 std::vector<unsigned int> out( VImageDimension*2 );
144 for(
unsigned int i = 0; i < VImageDimension; ++i )
146 out[i] =
static_cast<unsigned int>(in.
GetIndex(i));
147 out[VImageDimension+i] =
static_cast<unsigned int>(in.
GetSize(i));
157 template<
typename TDirectionType >
160 TDirectionType itkDirection;
162 if ( direction.size() == 0 )
164 itkDirection.SetIdentity();
166 else if( direction.size() == TDirectionType::RowDimensions*TDirectionType::ColumnDimensions )
168 std::copy( direction.begin(), direction.end(), itkDirection.GetVnlMatrix().begin() );
172 sitkExceptionMacro(<<
"Length of input ("<<direction.size()<<
") does not match matrix dimensions ("
173 <<TDirectionType::RowDimensions<<
", "<<TDirectionType::ColumnDimensions<<
").\n");
179 template<
typename TDirectionType >
182 return std::vector<double>( d.GetVnlMatrix().begin(), d.GetVnlMatrix().end() );
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
TDirectionType SITKCommon_HIDDEN sitkSTLToITKDirection(const std::vector< double > &direction)
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
#define SITKCommon_HIDDEN