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)
65 Vector<TCoordRep, NVectorDimension>(
const TCoordRep r[NVectorDimension])
66 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
73 Vector<TCoordRep, NVectorDimension>(
const TCoordRep &v) :
itk::
Vector<TCoordRep, NVectorDimension>(v) {}
78 Vector<TCoordRep, NVectorDimension>(
const vnl_vector<TCoordRep> &vnlVector)
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));
94 Vector<TCoordRep, NVectorDimension>(
const vnl_vector_fixed<TCoordRep, NVectorDimension> &vnlVectorFixed)
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++)
Vector< TCoordRep, NVectorDimension > & operator=(const Vector< TCoordRep, NVectorDimension > &r)
void FillVector(const ArrayType &array)
Vector()
Default constructor has nothing to do.
void ToArray(ArrayType array) const
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Vector< ScalarType, 2 > Vector2D
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Vector< ScalarType, 4 > Vector4D
Vector< ScalarType, 3 > Vector3D
void to_json(nlohmann::json &j, const GenericLookupTable< T > &t)
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
vnl_vector< ScalarType > VnlVector
MITKNEWMODULE_EXPORT bool Equal(mitk::ExampleDataStructure *leftHandSide, mitk::ExampleDataStructure *rightHandSide, mitk::ScalarType eps, bool verbose)
Returns true if the example data structures are considered equal.
void from_json(const nlohmann::json &, GenericLookupTable< T > &)