16 #include <itkVector.h>
17 #include <vnl/vnl_vector.h>
18 #include <vnl/vnl_vector_fixed.h>
25 #include <nlohmann/json.hpp>
37 template <
class TCoordRep,
unsigned int NVectorDimension = 3>
38 class Vector :
public itk::Vector<TCoordRep, NVectorDimension>
46 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
53 itk::Vector<TCoordRep, NVectorDimension>::operator=(r);
60 Vector(
const itk::Vector<TCoordRep, NVectorDimension> &r)
61 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
70 Vector(
const TCoordRep r[NVectorDimension])
71 :
itk::
Vector<TCoordRep, NVectorDimension>(r)
83 Vector(
const vnl_vector<TCoordRep> &vnlVector)
84 :
itk::
Vector<TCoordRep, NVectorDimension>()
86 if (vnlVector.size() != NVectorDimension)
87 mitkThrow() <<
"when constructing mitk::Vector from vnl_vector: sizes didn't match: mitk::Vector "
88 << NVectorDimension <<
"; vnl_vector " << vnlVector.size();
90 for (
unsigned int var = 0; (var < NVectorDimension) && (var < vnlVector.size()); ++var)
92 this->SetElement(var, vnlVector.get(var));
99 Vector(
const vnl_vector_fixed<TCoordRep, NVectorDimension> &vnlVectorFixed)
100 :
itk::
Vector<TCoordRep, NVectorDimension>()
102 for (
unsigned int var = 0; var < NVectorDimension; ++var)
104 this->SetElement(var, vnlVectorFixed[var]);
108 template <
typename... Args,
109 typename = std::enable_if_t<(
sizeof...(Args) == NVectorDimension)>>
113 ((this->GetDataPointer()[i++] =
static_cast<TCoordRep
>(args)), ...);
123 template <
typename ArrayType>
126 itk::FixedArray<TCoordRep, NVectorDimension> *thisP =
127 dynamic_cast<itk::FixedArray<TCoordRep, NVectorDimension> *
>(
this);
128 mitk::FillArray<ArrayType, TCoordRep, NVectorDimension>(*thisP, array);
136 template <
typename ArrayType>
139 mitk::ToArray<ArrayType, TCoordRep, NVectorDimension>(array, *
this);
148 operator vnl_vector<TCoordRep>()
const {
return this->GetVnlVector(); }
152 template <
class TCoordRep,
unsigned int NVectorDimension>
155 j = nlohmann::json::array();
157 for (
size_t i = 0; i < NVectorDimension; ++i)
162 template <
class TCoordRep,
unsigned int NVectorDimension>
165 for (
size_t i = 0; i < NVectorDimension; ++i)
166 j.at(i).get_to(v[i]);
190 template <
typename TCoordRep,
unsigned int NPo
intDimension>
191 inline bool Equal(
const itk::Vector<TCoordRep, NPointDimension> &vector1,
192 const itk::Vector<TCoordRep, NPointDimension> &vector2,
194 bool verbose =
false)
197 typename itk::Vector<TCoordRep, NPointDimension>::VectorType diff = vector1 - vector2;
198 for (
unsigned int i = 0; i < NPointDimension; i++)
225 bool verbose =
false)
229 for (
unsigned int i = 0; i < diff.size(); i++)
253 template <
typename TCoordRep,
unsigned int NPo
intDimension>
254 inline bool Equal(
const vnl_vector_fixed<TCoordRep, NPointDimension> &vector1,
255 const vnl_vector_fixed<TCoordRep, NPointDimension> &vector2,
257 bool verbose =
false)
259 vnl_vector_fixed<TCoordRep, NPointDimension> diff = vector1 - vector2;
261 for (
unsigned int i = 0; i < diff.size(); i++)
MITK vector type extending itk::Vector with additional constructors and conversions.
Vector(const mitk::Vector< TCoordRep, NVectorDimension > &r)
Copy constructor.
Vector< TCoordRep, NVectorDimension > & operator=(const Vector< TCoordRep, NVectorDimension > &r)
void FillVector(const ArrayType &array)
Copy elements from an array into this vector.
Vector(const itk::Vector< TCoordRep, NVectorDimension > &r)
Constructor to convert from itk::Vector to mitk::Vector.
Vector()
Default constructor.
Vector(const TCoordRep r[NVectorDimension])
Constructor to convert an array to mitk::Vector.
void ToArray(ArrayType array) const
Copy the values stored in this vector into an array.
Vector(const vnl_vector_fixed< TCoordRep, NVectorDimension > &vnlVectorFixed)
Constructor for vnl_vector_fixed.
Vector(const vnl_vector< TCoordRep > &vnlVector)
Constructor for vnl_vectors.
Vector(const TCoordRep &v)
#define mitkThrow()
Throw a generic mitk::Exception with source location information.
Find image slices visible on a given plane.
MITKCORE_EXPORT const ScalarType eps
Epsilon value for floating point comparison (vnl_math::eps * 100).
void from_json(const nlohmann::json &, GenericLookupTable< T > &)
Deserialize a GenericLookupTable from JSON.
Vector< ScalarType, 2 > Vector2D
void ConditionalOutputOfDifference(ElementToOutput1 elem1, ElementToOutput2 elem2, mitk::ScalarType eps, bool verbose, bool isEqual)
Conditionally output the difference between two elements to the log.
Vector< ScalarType, 4 > Vector4D
Vector< ScalarType, 3 > Vector3D
void to_json(nlohmann::json &j, const GenericLookupTable< T > &t)
Serialize a GenericLookupTable to JSON.
bool DifferenceBiggerOrEqualEps(DifferenceType diff, mitk::ScalarType epsilon=mitk::eps)
Check if the absolute difference is bigger than or equal to a given epsilon.
vnl_vector< ScalarType > VnlVector
double ScalarType
Scalar type used throughout MITK for geometric computations.
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.