33#define eman__vec3_h__ 1
64 template<
typename Type>
74 vec[0] =
static_cast<Type
>(0);
75 vec[1] =
static_cast<Type
>(0);
76 vec[2] =
static_cast<Type
>(0);
77 vec[3] =
static_cast<Type
>(0);
80 template<
typename Type2,
typename Type3,
typename Type4,
typename Type5>
81 Vec4(
const Type2& a,
const Type3& b,
const Type4& c,
const Type5& d)
83 vec[0] =
static_cast<Type
>(a);
84 vec[1] =
static_cast<Type
>(b);
85 vec[2] =
static_cast<Type
>(c);
86 vec[3] =
static_cast<Type
>(d);
93 template<
typename Type2>
94 Vec4(
const vector < Type2 > &v)
96 vec[0] =
static_cast<Type
>(v[0]);
97 vec[1] =
static_cast<Type
>(v[1]);
98 vec[2] =
static_cast<Type
>(v[2]);
99 vec[3] =
static_cast<Type
>(v[3]);
104 template<
typename Type2>
124 return (
float)
sqrt(t);
136 vec[0] =
static_cast<Type
> (
vec[0] / len);
137 vec[1] =
static_cast<Type
> (
vec[1] / len);
138 vec[2] =
static_cast<Type
> (
vec[2] / len);
139 vec[3] =
static_cast<Type
> (
vec[3] / len);
151 template<
typename Type2>
154 vec[0] =
static_cast<Type
>(v[0]);
155 vec[1] =
static_cast<Type
>(v[1]);
156 vec[2] =
static_cast<Type
>(v[2]);
157 vec[3] =
static_cast<Type
>(v[3]);
164 template<
typename Type2>
167 vec[index] =
static_cast<Type
>(value);
175 void set_value(
const Type& a,
const Type& b,
const Type& c,
const Type& d)
190 inline Type
at(
int i)
270 template<
typename Type>
282 vec[0] =
static_cast<Type
>(0);
283 vec[1] =
static_cast<Type
>(0);
284 vec[2] =
static_cast<Type
>(0);
293 template<
typename Type2,
typename Type3,
typename Type4>
294 Vec3(
const Type2&
x,
const Type3&
y,
const Type4& z = 0)
296 vec[0] =
static_cast<Type
>(
x);
297 vec[1] =
static_cast<Type
>(
y);
298 vec[2] =
static_cast<Type
>(z);
305 template<
typename Type2>
306 Vec3(
const vector < Type2 > &v)
308 vec[0] =
static_cast<Type
>(v[0]);
309 vec[1] =
static_cast<Type
>(v[1]);
310 vec[2] =
static_cast<Type
>(v[2]);
315 template<
typename Type2>
337 vec[0] =
static_cast<Type
> (
vec[0] / len);
338 vec[1] =
static_cast<Type
> (
vec[1] / len);
339 vec[2] =
static_cast<Type
> (
vec[2] / len);
355 return (
float)
sqrt(t);
372 template<
typename Type2>
375 return static_cast<Type
>((
vec[0] * v[0] +
vec[1] * v[1] +
vec[2] * v[2]));
383 template<
typename Type2>
387 (
vec[2] * v[0] -
vec[0] * v[2]),
388 (
vec[0] * v[1] -
vec[1] * v[0]));
396 vector < Type > v(3);
407 template<
typename Type2>
410 vec[0] =
static_cast<Type
>(v[0]);
411 vec[1] =
static_cast<Type
>(v[1]);
412 vec[2] =
static_cast<Type
>(v[2]);
419 template<
typename Type2>
422 vec[index] =
static_cast<Type
>(value);
468 inline Type
at(
int i)
506 template<
typename Type2>
508 vec[0] =
static_cast<Type
>(
vec[0]+v[0]);
509 vec[1] =
static_cast<Type
>(
vec[1]+v[1]);
510 vec[2] =
static_cast<Type
>(
vec[2]+v[2]);
518 template<
typename Type2>
520 vec[0] =
static_cast<Type
>(
vec[0]+d);
521 vec[1] =
static_cast<Type
>(
vec[1]+d);
522 vec[2] =
static_cast<Type
>(
vec[2]+d);
530 template<
typename Type2>
532 vec[0] =
static_cast<Type
>(
vec[0]-v[0]);
533 vec[1] =
static_cast<Type
>(
vec[1]-v[1]);
534 vec[2] =
static_cast<Type
>(
vec[2]-v[2]);
542 template<
typename Type2>
544 vec[0] =
static_cast<Type
>(
vec[0]-d);
545 vec[1] =
static_cast<Type
>(
vec[1]-d);
546 vec[2] =
static_cast<Type
>(
vec[2]-d);
554 template<
typename Type2>
556 vec[0] =
static_cast<Type
>(
vec[0]*d);
557 vec[1] =
static_cast<Type
>(
vec[1]*d);
558 vec[2] =
static_cast<Type
>(
vec[2]*d);
566 template<
typename Type2>
568 vec[0] =
static_cast<Type
>(
vec[0]/d);
569 vec[1] =
static_cast<Type
>(
vec[1]/d);
570 vec[2] =
static_cast<Type
>(
vec[2]/d);
574 template<
typename Type2>
575 operator vector<Type2>()
const {
576 vector<Type2> v(
vec,
vec+3);
585 template<
typename Type,
typename Type2>
589 return Vec3<Type>(
static_cast<Type
>(v1[0] + v2[0]),
static_cast<Type
>(v1[1] + v2[1]),
static_cast<Type
>(v1[2] + v2[2]));;
592 template<
typename Type,
typename Type2>
608 template<
typename Type,
typename Type2>
611 return Vec3<Type>(
static_cast<Type
>(v1[0] - v2[0]),
612 static_cast<Type
>(v1[1] - v2[1]),
613 static_cast<Type
>(v1[2] - v2[2]));
616 template<
typename Type,
typename Type2>
623 template<
typename Type>
637 template<
typename Type,
typename Type2>
643 template<
typename Type,
typename Type2>
652 template<
typename Type,
typename Type2>
660 template<
typename Type,
typename Type2>
669 template<
typename Type,
typename Type2>
677 template<
typename Type,
typename Type2>
679 if (v1[0] == v2[0] && v1[1] == v2[1] && v1[2] == v2[2]) {
685 template<
typename Type,
typename Type2>
687 if (v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2]) {
708 template<
typename Type>
719 vec[0] =
static_cast<Type
>(0);
720 vec[1] =
static_cast<Type
>(0);
728 template<
typename Type2,
typename Type3>
731 vec[0] =
static_cast<Type
>(
x);
732 vec[1] =
static_cast<Type
>(
y);
739 template<
typename Type2>
740 Vec2(
const vector < Type2 > &v)
742 vec[0] =
static_cast<Type
>(v[0]);
743 vec[1] =
static_cast<Type
>(v[1]);
748 template<
typename Type2>
751 vec[0] =
static_cast<Type
>(v[0]);
752 vec[1] =
static_cast<Type
>(v[1]);
769 vec[0] =
static_cast<Type
> (
vec[0] / len);
770 vec[1] =
static_cast<Type
> (
vec[1] / len);
786 return (
float)
sqrt(t);
803 template<
typename Type2>
806 return static_cast<Type
>((
vec[0] * v[0] +
vec[1] * v[1]));
814 vector < Type > v(2);
824 template<
typename Type2>
827 vec[0] =
static_cast<Type
>(v[0]);
828 vec[1] =
static_cast<Type
>(v[1]);;
835 template<
typename Type2>
838 vec[index] =
static_cast<Type
>(value);
876 inline Type
at(
int i) {
return vec[i]; }
913 template<
typename Type2>
915 vec[0] =
static_cast<Type
>(
vec[0]+v[0]);
916 vec[1] =
static_cast<Type
>(
vec[1]+v[1]);
924 template<
typename Type2>
926 vec[0] =
static_cast<Type
>(
vec[0]+d);
927 vec[1] =
static_cast<Type
>(
vec[1]+d);
935 template<
typename Type2>
937 vec[0] =
static_cast<Type
>(
vec[0]-v[0]);
938 vec[1] =
static_cast<Type
>(
vec[1]-v[1]);
946 template<
typename Type2>
948 vec[0] =
static_cast<Type
>(
vec[0]-d);
949 vec[1] =
static_cast<Type
>(
vec[1]-d);
957 template<
typename Type2>
959 vec[0] =
static_cast<Type
>(
vec[0]*d);
960 vec[1] =
static_cast<Type
>(
vec[1]*d);
968 template<
typename Type2>
970 vec[0] =
static_cast<Type
>(
vec[0]/d);
971 vec[1] =
static_cast<Type
>(
vec[1]/d);
980 template<
typename Type,
typename Type2>
983 return Vec2<Type>(
static_cast<Type
>(v1[0] + v2[0]),
static_cast<Type
>(v1[1] + v2[1]));;
986 template<
typename Type,
typename Type2>
994 template<
typename Type,
typename Type2>
997 return Vec2<Type>(
static_cast<Type
>(v1[0] - v2[0]),
static_cast<Type
>(v1[1] - v2[1]));
1000 template<
typename Type,
typename Type2>
1008 template<
typename Type>
1015 template<
typename Type,
typename Type2>
1021 template<
typename Type,
typename Type2>
1030 template<
typename Type,
typename Type2>
1038 template<
typename Type,
typename Type2>
1047 template<
typename Type,
typename Type2>
1055 template<
typename Type,
typename Type2>
1057 if (v1[0] == v2[0] && v1[1] == v2[1] ) {
1063 template<
typename Type,
typename Type2>
1065 if (v1[0] != v2[0] || v1[1] != v2[1] ) {
The Vec2 is precisely the same as Vec3 except it works exclusively in 2D Note there are convenient ty...
vector< Type > as_list() const
Return the values of this vector as a std::vector.
Type squared_length() const
Calculate its squared length.
Vec2(const Vec2< Type2 > &v)
Copy constructor copies vector elements.
Type at(int i)
Get the ith item of the vector.
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Type type
One can always cast to the type of a Vec2 by accessing Vec2<Type>::type.
float length() const
Calculate its length.
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Type dot(const Vec2< Type2 > &v) const
Calculate the dot product of 'this' vector with a second vector.
Vec2()
contruct a Vec2 object with all elements equal to 0.
float normalize()
Normalize the vector and return its length before the normalization.
int number_of_element()
For python len
Vec2< Type > & operator+=(const Vec2< Type2 > &v)
'this' += v; Add the 2 vectors by adding item by item.
void set_value(const Type &x, const Type &y)
Set new values to this vector object.
Type operator[](int i) const
Get the ith item of the vector.
Vec2< Type > & operator/=(const Type2 &d)
'this' /= d; Divide a number on each item of 'this' vector.
Vec2< Type > & operator*=(const Type2 &d)
'this' *= d; Multiply a number on each item of 'this' vector.
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Vec2(const Type2 &x, const Type3 &y)
contruct a Vec2 object given (x,y) or (x,y,z) values.
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
Vec2< Type > & operator-=(const Vec2< Type2 > &v)
'this' -= v; Minus the 2 vectors item by item.
Vec2(const vector< Type2 > &v)
Construct a Vec2 object given a std::vector object.
The Vec3 object is a templated object, intended to instantiated with basic types such as int,...
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Type type
One can always cast to the type of a Vec3 by accessing Vec3<Type>::type.
Vec3< Type > & operator*=(const Type2 &d)
'this' *= d; Multiply a number on each item of 'this' vector.
Vec3< Type > & operator-=(const Vec3< Type2 > &v)
'this' -= v; Minus the 2 vectors item by item.
Vec3< Type > cross(const Vec3< Type2 > &v) const
Calculate the cross product of 'this' vector with a second vector.
Vec3< Type > & operator/=(const Type2 &d)
'this' /= d; Divide a number on each item of 'this' vector.
vector< Type > as_list() const
Return the values of this vector as a std::vector.
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Vec3(const Vec3< Type2 > &v)
Copy constructor copies vector elements.
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Type squared_length() const
Calculate its squared length.
Type dot(const Vec3< Type2 > &v) const
Calculate the dot product of 'this' vector with a second vector.
Type operator[](int i) const
Get the ith item of the vector.
Type at(int i)
Get the ith item of the vector.
float normalize()
Normalize the vector and return its length before the normalization.
void set_value(const Type &x, const Type &y, const Type &z)
Set new values to this vector object.
float length() const
Calculate its length.
int number_of_element()
For python len
Vec3(const vector< Type2 > &v)
Construct a Vec3 object given a std::vector object.
Vec3(const Type2 &x, const Type3 &y, const Type4 &z=0)
contruct a Vec3 object given (x,y) or (x,y,z) values.
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
Vec3< Type > & operator+=(const Vec3< Type2 > &v)
'this' += v; Add the 2 vectors by adding item by item.
Vec3()
contruct a Vec3 object with all elements equal to 0.
The Vec4 object is a templated object, intended to instantiated with basic types such as int,...
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Vec4(const Vec4< Type2 > &v)
Copy constructor copies vector elements.
Type operator[](int i) const
Get the ith item of the vector.
void set_value(const Type &a, const Type &b, const Type &c, const Type &d)
Set new values to this vector object.
Type * begin()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
Type * end()
Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in...
float length() const
Calculate its length.
void set_value_at(int index, const Type2 &value)
Set values at a particular index.
float normalize()
Normalize the vector and return its length before the normalization.
Type type
One can always cast to the type of a Vec4 by accessing Vec4<Type>::type.
Vec4(const vector< Type2 > &v)
Construct a Vec3 object given a std::vector object.
Type at(int i)
Get the ith item of the vector.
Vec4(const Type2 &a, const Type3 &b, const Type4 &c, const Type5 &d)
int number_of_element()
For python len
EMData * sqrt() const
return square root of current image
EMData * operator+(const EMData &em, float n)
bool operator!=(const EMObject &e1, const EMObject &e2)
EMData * operator-(const EMData &em, float n)
EMData * operator/(const EMData &em, float n)
EMData * operator*(const EMData &em, float n)
bool operator==(const EMObject &e1, const EMObject &e2)