7 #include "fwMath/VectorFunctions.hpp" 10 #include <glm/gtc/type_ptr.hpp> 19 const ::glm::dvec3 vecGlm = ::glm::make_vec3<double>(vec.data());
21 const ::glm::dvec3 normalizedVec = ::glm::normalize(vecGlm);
22 vec[0] = normalizedVec[0];
23 vec[1] = normalizedVec[1];
24 vec[2] = normalizedVec[2];
39 double dot(
const fwVec3d& v1,
const fwVec3d& v2)
42 return v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2];
47 fwVec3d
cross(
const fwVec3d& v1,
const fwVec3d& v2)
49 const ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(v1.data());
50 const ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(v2.data());
52 ::glm::dvec3 res = ::glm::cross(vecGlm1, vecGlm2);
54 return {{res[0], res[1], res[2]}};
61 ::glm::dvec3 vecGLM (vec[0], vec[1], vec[2]);
62 return ::glm::length(vecGLM);
77 fwVec3d& operator*=(fwVec3d& vec1,
double val)
79 ::glm::dvec3 vecGlm1(vec1[0], vec1[1], vec1[2]);
81 vec1 = {{vecGlm1[0], vecGlm1[1], vecGlm1[2]}};
88 fwVec3d& operator/=(fwVec3d& vec,
double val )
90 FW_RAISE_IF(
"Division by 0 not possible.", val == 0.0);
92 ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec.data());
94 vec = {{vecGlm1[0], vecGlm1[1], vecGlm1[2]}};
101 fwVec3d& operator+=(fwVec3d& vec1,
const fwVec3d& vec2)
103 ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec1.data());
104 ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(vec2.data());
106 vec1 = {{vecGlm1[0], vecGlm1[1], vecGlm1[2]}};
113 fwVec3d& operator-=(fwVec3d& vec1,
const fwVec3d& vec2)
115 ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec1.data());
116 ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(vec2.data());
118 vec1 = {{vecGlm1[0], vecGlm1[1], vecGlm1[2]}};
125 fwVec3d operator*(
const fwVec3d& vec,
double val)
127 ::glm::dvec3 vecGlm1(vec[0], vec[1], vec[2]);
128 ::glm::dvec3 vecGlm = vecGlm1 * val;
130 return {{vecGlm[0], vecGlm[1], vecGlm[2]}};
135 fwVec3d operator*(
const double val,
const fwVec3d& vec)
142 fwVec3d operator/(
const fwVec3d& vec,
double val)
144 FW_RAISE_IF(
"Division by 0 not possible.", val == 0.0);
146 ::glm::dvec3 vecGlm1(vec[0], vec[1], vec[2]);
147 ::glm::dvec3 vecGlm = vecGlm1 / val;
149 return {{vecGlm[0], vecGlm[1], vecGlm[2]}};
154 fwVec3d operator+(
const fwVec3d& vec1,
const fwVec3d& vec2)
156 const ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec1.data());
157 const ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(vec2.data());
158 ::glm::dvec3 vecGlm = vecGlm1 + vecGlm2;
160 return {{vecGlm[0], vecGlm[1], vecGlm[2]}};
165 fwVec3d operator-(
const fwVec3d& vec1,
const fwVec3d& vec2)
167 const ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec1.data());
168 const ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(vec2.data());
169 ::glm::dvec3 vecGlm = vecGlm1 - vecGlm2;
171 return {{vecGlm[0], vecGlm[1], vecGlm[2]}};
176 int operator==(
const fwVec3d& vec1,
const fwVec3d& vec2)
178 const ::glm::dvec3 vecGlm1 = ::glm::make_vec3<double>(vec1.data());
179 const ::glm::dvec3 vecGlm2 = ::glm::make_vec3<double>(vec2.data());
180 ::glm::bvec3 res = ::glm::equal(vecGlm1, vecGlm2);
182 return res[0] && res[1] && res[2];
187 int operator!=(
const fwVec3d& vec1,
const fwVec3d& vec2)
189 return !(vec1 == vec2);
FWMATH_API double vecLength(const fwVec3d &_vec)
Compute the length of the vector.
FWMATH_API fwVec3d normalized(const fwVec3d &vec)
Return a normalized vector.
FWMATH_API fwVec3d cross(const fwVec3d &v1, const fwVec3d &v2)
Compute the Cross product between two vectors.
The namespace fwMath contains classes which provide the implementation of several mathematic function...
FWMATH_API void negate(fwVec3d &_vec)
Compute the negate of the vector.
FWMATH_API double dot(const fwVec3d &v1, const fwVec3d &v2)
Compute the Dot product between two vectors.
FWMATH_API double normalize(fwVec3d &vec)
Normalize a vector.