EMAN2
Public Types | Public Member Functions | Private Attributes | List of all members
EMAN::Vec3< Type > Class Template Reference

The Vec3 object is a templated object, intended to instantiated with basic types such as int, float, double etc. More...

#include <vec3.h>

Inheritance diagram for EMAN::Vec3< Type >:
Inheritance graph
[legend]

Public Types

typedef Type type
 One can always cast to the type of a Vec3 by accessing Vec3<Type>::type. More...
 

Public Member Functions

 Vec3 ()
 contruct a Vec3 object with all elements equal to 0. More...
 
template<typename Type2 , typename Type3 , typename Type4 >
 Vec3 (const Type2 &x, const Type3 &y, const Type4 &z=0)
 contruct a Vec3 object given (x,y) or (x,y,z) values. More...
 
template<typename Type2 >
 Vec3 (const vector< Type2 > &v)
 Construct a Vec3 object given a std::vector object. More...
 
template<typename Type2 >
 Vec3 (const Vec3< Type2 > &v)
 Copy constructor copies vector elements. More...
 
 ~Vec3 ()
 Destructor. More...
 
float normalize ()
 Normalize the vector and return its length before the normalization. More...
 
float length () const
 Calculate its length. More...
 
Type squared_length () const
 Calculate its squared length. More...
 
template<typename Type2 >
Type dot (const Vec3< Type2 > &v) const
 Calculate the dot product of 'this' vector with a second vector. More...
 
template<typename Type2 >
Vec3< Type > cross (const Vec3< Type2 > &v) const
 Calculate the cross product of 'this' vector with a second vector. More...
 
vector< Type > as_list () const
 Return the values of this vector as a std::vector. More...
 
template<typename Type2 >
void set_value (const vector< Type2 > &v)
 Set new values using a std::vector object. More...
 
template<typename Type2 >
void set_value_at (int index, const Type2 &value)
 Set values at a particular index. More...
 
void set_value (const Type &x, const Type &y, const Type &z)
 Set new values to this vector object. More...
 
Type operator[] (int i) const
 Get the ith item of the vector. More...
 
Type & operator[] (int i)
 Get the ith item of the vector. More...
 
Type at (int i)
 Get the ith item of the vector. More...
 
int number_of_element ()
 For python len More...
 
Type * begin ()
 Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple. More...
 
Type * end ()
 Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple. More...
 
template<typename Type2 >
Vec3< Type > & operator+= (const Vec3< Type2 > &v)
 'this' += v; Add the 2 vectors by adding item by item. More...
 
template<typename Type2 >
Vec3< Type > & operator+= (const Type2 &d)
 'this' += d. More...
 
template<typename Type2 >
Vec3< Type > & operator-= (const Vec3< Type2 > &v)
 'this' -= v; Minus the 2 vectors item by item. More...
 
template<typename Type2 >
Vec3< Type > & operator-= (const Type2 &d)
 'this' -= d; Minus a number from each item of 'this' vector. More...
 
template<typename Type2 >
Vec3< Type > & operator*= (const Type2 &d)
 'this' *= d; Multiply a number on each item of 'this' vector. More...
 
template<typename Type2 >
Vec3< Type > & operator/= (const Type2 &d)
 'this' /= d; Divide a number on each item of 'this' vector. More...
 
template<typename Type2 >
 operator vector< Type2 > () const
 

Private Attributes

Type vec [3]
 

Detailed Description

template<typename Type>
class EMAN::Vec3< Type >

The Vec3 object is a templated object, intended to instantiated with basic types such as int, float, double etc.

You may try to use other more generic types such as classes but you may get bad results. Note that the normalize and length operations are precise only to 32 bits Note there are convenient typedef so one needn't bother about using template terminology typedef Vec3<float> Vec3f; typedef Vec3<int> Vec3i; typedef Vec3<double> Vec3d; // Not recommended for use unless precision is addressed in this class

Author
David Woolford (based on the work of who ever wrote the original Vec3f and Vec3i classes - extracted into a template)
Date
August 2008 ?

Definition at line 271 of file vec3.h.

Member Typedef Documentation

◆ type

template<typename Type >
typedef Type EMAN::Vec3< Type >::type

One can always cast to the type of a Vec3 by accessing Vec3<Type>::type.

Definition at line 276 of file vec3.h.

Constructor & Destructor Documentation

◆ Vec3() [1/4]

template<typename Type >
EMAN::Vec3< Type >::Vec3 ( )
inline

contruct a Vec3 object with all elements equal to 0.

Definition at line 280 of file vec3.h.

280 {
281
282 vec[0] = static_cast<Type>(0);
283 vec[1] = static_cast<Type>(0);
284 vec[2] = static_cast<Type>(0);
285 }
Type vec[3]
Definition: vec3.h:582

References EMAN::Vec3< Type >::vec.

◆ Vec3() [2/4]

template<typename Type >
template<typename Type2 , typename Type3 , typename Type4 >
EMAN::Vec3< Type >::Vec3 ( const Type2 &  x,
const Type3 &  y,
const Type4 &  z = 0 
)
inline

contruct a Vec3 object given (x,y) or (x,y,z) values.

Parameters
xValue of the first item.
yValue of the second item.
zValue of the third item. If not specified, default to 0.

Definition at line 294 of file vec3.h.

295 {
296 vec[0] = static_cast<Type>(x);
297 vec[1] = static_cast<Type>(y);
298 vec[2] = static_cast<Type>(z);
299 }
#define y(i, j)
Definition: projector.cpp:1516
#define x(i)
Definition: projector.cpp:1517

References EMAN::Vec3< Type >::vec, x, and y.

◆ Vec3() [3/4]

template<typename Type >
template<typename Type2 >
EMAN::Vec3< Type >::Vec3 ( const vector< Type2 > &  v)
inline

Construct a Vec3 object given a std::vector object.

The std::vector object should have at least 3 items.

Parameters
vThe std::vector object. It should have at least 3 items.

Definition at line 306 of file vec3.h.

307 {
308 vec[0] = static_cast<Type>(v[0]);
309 vec[1] = static_cast<Type>(v[1]);
310 vec[2] = static_cast<Type>(v[2]);
311 }

References EMAN::Vec3< Type >::vec.

◆ Vec3() [4/4]

template<typename Type >
template<typename Type2 >
EMAN::Vec3< Type >::Vec3 ( const Vec3< Type2 > &  v)
inline

Copy constructor copies vector elements.

Definition at line 316 of file vec3.h.

317 {
318 vec[0] = v[0];
319 vec[1] = v[1];
320 vec[2] = v[2];
321 }

References EMAN::Vec3< Type >::vec.

◆ ~Vec3()

template<typename Type >
EMAN::Vec3< Type >::~Vec3 ( )
inline

Destructor.

Definition at line 325 of file vec3.h.

325{}

Member Function Documentation

◆ as_list()

template<typename Type >
vector< Type > EMAN::Vec3< Type >::as_list ( ) const
inline

Return the values of this vector as a std::vector.

Returns
The std::vector version of this vector.

Definition at line 394 of file vec3.h.

395 {
396 vector < Type > v(3);
397 v[0] = vec[0];
398 v[1] = vec[1];
399 v[2] = vec[2];
400 return v;
401 }

References EMAN::Vec3< Type >::vec.

◆ at()

template<typename Type >
Type EMAN::Vec3< Type >::at ( int  i)
inline

Get the ith item of the vector.

Used in the left side of the assignment.

Parameters
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 468 of file vec3.h.

469 {
470 return vec[i];
471 }

References EMAN::Vec3< Type >::vec.

◆ begin()

template<typename Type >
Type * EMAN::Vec3< Type >::begin ( void  )
inline

Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.

Returns
the iterator (here is the pointer) of the first element

Definition at line 487 of file vec3.h.

488 {
489 return &vec[0];
490 }

References EMAN::Vec3< Type >::vec.

◆ cross()

template<typename Type >
template<typename Type2 >
Vec3< Type > EMAN::Vec3< Type >::cross ( const Vec3< Type2 > &  v) const
inline

Calculate the cross product of 'this' vector with a second vector.

Parameters
vThe second vector to do the cross product.
Returns
The cross product.

Definition at line 384 of file vec3.h.

385 {
386 return Vec3<Type>((vec[1] * v[2] - vec[2] * v[1]),
387 (vec[2] * v[0] - vec[0] * v[2]),
388 (vec[0] * v[1] - vec[1] * v[0]));
389 }

References EMAN::Vec3< Type >::vec.

Referenced by EMAN::PointArray::calc_transform(), EMAN::Quaternion::rotate(), EMAN::PointArray::sim_potentiald(), and EMAN::PointArray::sim_updategeom().

◆ dot()

template<typename Type >
template<typename Type2 >
Type EMAN::Vec3< Type >::dot ( const Vec3< Type2 > &  v) const
inline

Calculate the dot product of 'this' vector with a second vector.

Parameters
vThe second vector to do the dot product.
Returns
The dot product.

Definition at line 373 of file vec3.h.

374 {
375 return static_cast<Type>((vec[0] * v[0] + vec[1] * v[1] + vec[2] * v[2]));
376 }

References EMAN::Vec3< Type >::vec.

Referenced by EMAN::PointArray::calc_helicity(), EMAN::PointArray::calc_transform(), EMAN::operator*(), EMAN::Symmetry3D::point_in_which_asym_unit(), EMAN::PointArray::sim_potentiald(), and EMAN::PointArray::sim_updategeom().

◆ end()

template<typename Type >
Type * EMAN::Vec3< Type >::end ( void  )
inline

Add this function to make it iterable in Python, so we can call list() or tuple() to convert Vec3f in python to a list or tuple.

Returns
the iterator (here is the pointer) of the one beyond the last element.

Definition at line 497 of file vec3.h.

498 {
499 return &vec[3];
500 }

References EMAN::Vec3< Type >::vec.

◆ length()

template<typename Type >
float EMAN::Vec3< Type >::length ( ) const
inline

Calculate its length.

Returns
The vector's length Warning - float precision

Definition at line 352 of file vec3.h.

353 {
354 float t = (float)(vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]);
355 return (float)sqrt(t);
356 }
EMData * sqrt() const
return square root of current image

References sqrt(), and EMAN::Vec3< Type >::vec.

Referenced by EMAN::PointArray::calc_transform(), EMAN::PointArray::construct_helix(), EMAN::PointArray::merge_to(), EMAN::Vec3< Type >::normalize(), EMAN::PointArray::remove_helix_from_map(), EMAN::PointArray::sim_minstep_seq(), EMAN::PointArray::sim_potentiald(), EMAN::PointArray::sim_rescale(), EMAN::PointArray::sim_updategeom(), EMAN::Quaternion::to_angle(), and EMAN::Quaternion::to_axis().

◆ normalize()

template<typename Type >
float EMAN::Vec3< Type >::normalize ( )
inline

Normalize the vector and return its length before the normalization.

Returns
The length of the Vec before normalization.

Definition at line 332 of file vec3.h.

333 {
334 // Warning - float precision
335 float len = length();
336 if (len != 0) {
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);
340 }
341 else {
342 set_value(0, 0, 0);
343 }
344 return len;
345 }
void set_value(const vector< Type2 > &v)
Set new values using a std::vector object.
Definition: vec3.h:408
float length() const
Calculate its length.
Definition: vec3.h:352

References EMAN::Vec3< Type >::length(), EMAN::Vec3< Type >::set_value(), and EMAN::Vec3< Type >::vec.

Referenced by EMAN::PointArray::calc_transform(), EMAN::PlatonicSym::get_asym_unit_points(), EMAN::TetrahedralSym::get_asym_unit_points(), EMAN::OptimumOrientationGenerator::optimize_distances(), refalin3d_perturbquat(), and EMAN::Transform::set_rotation().

◆ number_of_element()

template<typename Type >
int EMAN::Vec3< Type >::number_of_element ( )
inline

For python len

Returns
the number of elements in this container. it's always 3.

Definition at line 477 of file vec3.h.

478 {
479 return 3;
480 }

◆ operator vector< Type2 >()

template<typename Type >
template<typename Type2 >
EMAN::Vec3< Type >::operator vector< Type2 > ( ) const
inline

Definition at line 575 of file vec3.h.

575 {
576 vector<Type2> v(vec,vec+3);
577 return v;
578 }

References EMAN::Vec3< Type >::vec.

◆ operator*=()

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator*= ( const Type2 &  d)
inline

'this' *= d; Multiply a number on each item of 'this' vector.

Parameters
dThe number to multiply.
Returns
The new 'this' as a result of multiplication.

Definition at line 555 of file vec3.h.

555 {
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);
559 return *this;
560 }

References EMAN::Vec3< Type >::vec.

◆ operator+=() [1/2]

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator+= ( const Type2 &  d)
inline

'this' += d.

Add d to each item of this vector.

Parameters
dThe number used to be added to this vector.
Returns
The new 'this' as a result of add.

Definition at line 519 of file vec3.h.

519 {
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);
523 return *this;
524 }

References EMAN::Vec3< Type >::vec.

◆ operator+=() [2/2]

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator+= ( const Vec3< Type2 > &  v)
inline

'this' += v; Add the 2 vectors by adding item by item.

Parameters
vThe vector used to be added to 'this' vector.
Returns
The new 'this' as a result of add.

Definition at line 507 of file vec3.h.

507 {
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]);
511 return *this;
512 }

References EMAN::Vec3< Type >::vec.

◆ operator-=() [1/2]

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator-= ( const Type2 &  d)
inline

'this' -= d; Minus a number from each item of 'this' vector.

Parameters
dThe number used to be substracted from 'this' vector.
Returns
The new 'this' as a result of substraction.

Definition at line 543 of file vec3.h.

543 {
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);
547 return *this;
548 }

References EMAN::Vec3< Type >::vec.

◆ operator-=() [2/2]

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator-= ( const Vec3< Type2 > &  v)
inline

'this' -= v; Minus the 2 vectors item by item.

Parameters
vThe vector used to be substracted from 'this' vector.
Returns
The new 'this' as a result of substraction.

Definition at line 531 of file vec3.h.

531 {
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]);
535 return *this;
536 }

References EMAN::Vec3< Type >::vec.

◆ operator/=()

template<typename Type >
template<typename Type2 >
Vec3< Type > & EMAN::Vec3< Type >::operator/= ( const Type2 &  d)
inline

'this' /= d; Divide a number on each item of 'this' vector.

Parameters
dThe number to divide.
Returns
The new 'this' as a result of division.

Definition at line 567 of file vec3.h.

567 {
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);
571 return *this;
572 }

References EMAN::Vec3< Type >::vec.

◆ operator[]() [1/2]

template<typename Type >
Type & EMAN::Vec3< Type >::operator[] ( int  i)
inline

Get the ith item of the vector.

Used in the left side of the assignment.

Parameters
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 456 of file vec3.h.

457 {
458 return vec[i];
459 }

References EMAN::Vec3< Type >::vec.

◆ operator[]() [2/2]

template<typename Type >
Type EMAN::Vec3< Type >::operator[] ( int  i) const
inline

Get the ith item of the vector.

Used in the right side of the assignment.

Parameters
iThe index of the item to get. Its validality is not checked.
Returns
The ith item of the vector.

Definition at line 444 of file vec3.h.

445 {
446 return vec[i];
447 }

References EMAN::Vec3< Type >::vec.

◆ set_value() [1/2]

template<typename Type >
void EMAN::Vec3< Type >::set_value ( const Type &  x,
const Type &  y,
const Type &  z 
)
inline

Set new values to this vector object.

Parameters
xValue of the first item.
yValue of the second item.
zValue of the third item.

Definition at line 430 of file vec3.h.

431 {
432 vec[0] = x;
433 vec[1] = y;
434 vec[2] = z;
435 }

References EMAN::Vec3< Type >::vec, x, and y.

◆ set_value() [2/2]

template<typename Type >
template<typename Type2 >
void EMAN::Vec3< Type >::set_value ( const vector< Type2 > &  v)
inline

Set new values using a std::vector object.

Parameters
vA std::vector object used to set 'this' vector's value. It should have at least 3 items.

Definition at line 408 of file vec3.h.

409 {
410 vec[0] = static_cast<Type>(v[0]);
411 vec[1] = static_cast<Type>(v[1]);
412 vec[2] = static_cast<Type>(v[2]);
413 }

References EMAN::Vec3< Type >::vec.

Referenced by wustl_mm::GraySkeletonCPP::VolumeSkeletonizer::CleanUpSkeleton(), EMAN::Vec3< Type >::normalize(), and EMAN::Quaternion::to_axis().

◆ set_value_at()

template<typename Type >
template<typename Type2 >
void EMAN::Vec3< Type >::set_value_at ( int  index,
const Type2 &  value 
)
inline

Set values at a particular index.

Parameters
indexThe index to be set
valueThe value to be set

Definition at line 420 of file vec3.h.

421 {
422 vec[index] = static_cast<Type>(value);
423 }

References EMAN::Vec3< Type >::vec.

◆ squared_length()

template<typename Type >
Type EMAN::Vec3< Type >::squared_length ( ) const
inline

Calculate its squared length.

no sqrt called

Returns
The vector's length squared.

Definition at line 362 of file vec3.h.

363 {
364 return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] ;
365 }

References EMAN::Vec3< Type >::vec.

Referenced by EMAN::Symmetry3D::get_touching_au_transforms().

Member Data Documentation

◆ vec

template<typename Type >
Type EMAN::Vec3< Type >::vec[3]
private

The documentation for this class was generated from the following file: