16 #include <itkVector.h>
17 #include <vnl/vnl_vector.h>
18 #include <vnl/vnl_vector_fixed.h>
25 #include <nlohmann/json.hpp>
29 template <
class TCoordRep,
unsigned int NVectorDimension = 3>
30 class Vector :
public itk::Vector<TCoordRep, NVectorDimension>
41 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
48 itk::Vector<TCoordRep, NVectorDimension>::operator=(r);
56 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
66 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
79 :
itk::
Vector<TCoordRep, NVectorDimension>()
81 if (vnlVector.size() != NVectorDimension)
82 mitkThrow() <<
"when constructing mitk::Vector from vnl_vector: sizes didn't match: mitk::Vector "
83 << NVectorDimension <<
"; vnl_vector " << vnlVector.size();
85 for (
unsigned int var = 0; (var < NVectorDimension) && (var < vnlVector.size()); ++var)
87 this->SetElement(var, vnlVector.get(var));
95 :
itk::
Vector<TCoordRep, NVectorDimension>()
97 for (
unsigned int var = 0; var < NVectorDimension; ++var)
99 this->SetElement(var, vnlVectorFixed[var]);
103 template <
typename... Args,
104 typename = std::enable_if_t<(
sizeof...(Args) == NVectorDimension)>>
108 ((this->GetDataPointer()[i++] =
static_cast<TCoordRep
>(args)), ...);
117 template <
typename ArrayType>
120 itk::FixedArray<TCoordRep, NVectorDimension> *thisP =
121 dynamic_cast<itk::FixedArray<TCoordRep, NVectorDimension> *
>(
this);
122 mitk::FillArray<ArrayType, TCoordRep, NVectorDimension>(*thisP, array);
130 template <
typename ArrayType>
133 mitk::ToArray<ArrayType, TCoordRep, NVectorDimension>(array, *
this);
141 operator vnl_vector<TCoordRep>()
const {
return this->GetVnlVector(); }
144 template <
class TCoordRep,
unsigned int NVectorDimension>
147 j = nlohmann::json::array();
149 for (
size_t i = 0; i < NVectorDimension; ++i)
153 template <
class TCoordRep,
unsigned int NVectorDimension>
156 for (
size_t i = 0; i < NVectorDimension; ++i)
157 j.at(i).get_to(v[i]);
180 template <
typename TCoordRep,
unsigned int NPo
intDimension>
181 inline bool Equal(
const itk::Vector<TCoordRep, NPointDimension> &vector1,
182 const itk::Vector<TCoordRep, NPointDimension> &vector2,
184 bool verbose =
false)
187 typename itk::Vector<TCoordRep, NPointDimension>::VectorType diff = vector1 - vector2;
188 for (
unsigned int i = 0; i < NPointDimension; i++)
214 bool verbose =
false)
218 for (
unsigned int i = 0; i < diff.size(); i++)
241 template <
typename TCoordRep,
unsigned int NPo
intDimension>
242 inline bool Equal(
const vnl_vector_fixed<TCoordRep, NPointDimension> &vector1,
243 const vnl_vector_fixed<TCoordRep, NPointDimension> &vector2,
245 bool verbose =
false)
247 vnl_vector_fixed<TCoordRep, NPointDimension> diff = vector1 - vector2;
249 for (
unsigned int i = 0; i < diff.size(); i++)