fw4spl
fwMath Namespace Reference

The namespace fwMath contains classes which provide the implementation of several mathematic functions and objects (plane, line, point). More...

Functions

template<typename TYPE >
bool isEqual (TYPE a, TYPE b, const float epsilon=0.00001F)
 Returns true iff a and b are equal with 'epsilon' error margin. More...
 
template<typename CONTAINER >
bool isContainerEqual (CONTAINER &containerA, CONTAINER &containerB, const float epsilon=0.00001F)
 Returns true iff container a and b are equal with 'epsilon' error margin. More...
 
FWMATH_API bool getClosestPoints (const fwLine &_ray1, const fwLine &_ray2, fwVec3d &_pointOnThis, fwVec3d &_pointOnfwLine)
 Compute the closest points between two rays. More...
 
FWMATH_API fwVec3d getClosestPoint (const fwLine &_ray, const fwVec3d &_point)
 Compute the projection of a point in a given direction. More...
 
FWMATH_API bool intersect (const fwLine &_ray, double _radius, const fwVec3d &_point)
 Compute the projection of a point in a given direction and test if this intersection is inside a given radius. More...
 
FWMATH_API bool intersect (const fwLine &_line, double _radius, const fwVec3d &_origin, const fwVec3d &_direction, fwVec3d &_point)
 Compute the closest points between two rays and test these points lie inside a sphere of a given radius. More...
 
FWMATH_API bool intersect (const fwLine &_line, const fwVec3d &_v1, const fwVec3d &_v2, const fwVec3d &_v3, fwVec3d &_point, fwVec3d &_barycentric, bool &_front)
 Give the intersection between a plane and a line. The result is returned in a point (_point). More...
 
FWMATH_API void multVecMatrix (const fwMatrix4x4 &_matrix, const fwVec3d &_source, fwVec3d &_dest)
 Multiply a matrix by a vector. More...
 
FWMATH_API fwMatrix4x4 getRotationMatrix (const fwVec3d &_vecNorm)
 Compute a matrix rotation. More...
 
FWMATH_API fwMatrix4x4 getInverse (const fwMatrix4x4 &matrix)
 Computes the inverse of a matrix. More...
 
FWMATH_API bool IsInclosedVolume (const fwVertexPosition &_vertex, const fwVertexIndex &_vertexIndex, const fwVec3d &_p)
 
FWMATH_API bool intersect_triangle (fwVec3d _orig, fwVec3d _dir, fwVec3d _vert0, fwVec3d _vert1, fwVec3d _vert2, double &_t, double &_u, double &_v)
 Compute the intersection between triangle(define by threes vertex vert1, vert2, vert3) and the Oz parallel line and cross by the point P. The function return true if intersection is found (false otherwise). t is the oriented distance of P to the intersection point. u and v is the coordinate of the intersection point in the (O, u, v) triangle coordinate system with : O = vert1. u = vert2 - O. v = vert3 - O. "Fast, Minimum Storage Ray/Triangle Intersection", Tomas Muller, Ben Trumbore.
 
FWMATH_API bool isBorderlessSurface (const fwVertexIndex &_vertexIndex)
 test whatever a vertex is duplicated or not
 
FWMATH_API void findBorderEdges (const fwVertexIndex &_vertexIndex, std::vector< std::vector< std::pair< int, int > > > &contours)
 
FWMATH_API bool closeSurface (fwVertexPosition &_vertex, fwVertexIndex &_vertexIndex)
 Closes the surface if necessary. More...
 
FWMATH_API bool removeOrphanVertices (fwVertexPosition &_vertex, fwVertexIndex &_vertexIndex)
 
template<typename T , typename U >
std::pair< T, U > makeOrderedPair (const T first, const U second)
 
template<typename T , typename U , typename V >
bool isBorderlessSurface (T *cellDataBegin, T *cellDataEnd, U *cellDataOffsetsBegin, U *cellDataOffsetsEnd, V *cellTypesBegin)
 
FWMATH_API fwPlane getPlane (const fwVec3d &_point1, const fwVec3d &_point2, const fwVec3d &_point3)
 
FWMATH_API fwPlane getPlane (const fwVec3d &_normal, const fwVec3d &_point)
 compute a plane from a normal and a point which must be in the plane. More...
 
FWMATH_API void setValues (fwPlane &_plane, const fwVec3d &_point1, const fwVec3d &_point2, const fwVec3d &_point3)
 Initialize a plane _plane with three points (_point1, _point2, _point3). It computes the plane's normal and the distance from the origin. More...
 
FWMATH_API fwVec3d getNormal (const fwPlane &_plane)
 Return the normal of the given plane _plane. More...
 
FWMATH_API void setNormal (fwPlane &_plane, const fwVec3d &_normal)
 Set the normal of the given plane _plane. More...
 
FWMATH_API double getDistance (const fwPlane &_plane)
 Get the distance from origin for the given plan (_plane). More...
 
FWMATH_API void setDistance (fwPlane &_plane, const double _distance)
 Set the distance from origin (_distance) for the given plan (_plane). More...
 
FWMATH_API bool intersect (const fwPlane &_fwPlane, const fwLine &_line, fwVec3d &_point)
 Give the intersection between a plane and a line. The result is returned in a point (_point) More...
 
FWMATH_API bool isInHalfSpace (const fwPlane &_plane, const fwVec3d &_point)
 Compute if a point is in a half plane. More...
 
FWMATH_API void transform (fwPlane &_plane, const fwMatrix4x4 &_matrix)
 Apply a transformation to a plane. The transformation is defined by a matrix 4x4. More...
 
FWMATH_API void offset (fwPlane &_plane, double _offset)
 Add an offset at the distance of origin which define the plane (_plane). More...
 
FWMATH_API double normalize (fwVec3d &vec)
 Normalize a vector.
 
FWMATH_API fwVec3d normalized (const fwVec3d &vec)
 Return a normalized vector. More...
 
FWMATH_API double dot (const fwVec3d &v1, const fwVec3d &v2)
 Compute the Dot product between two vectors. More...
 
FWMATH_API fwVec3d cross (const fwVec3d &v1, const fwVec3d &v2)
 Compute the Cross product between two vectors. More...
 
FWMATH_API double vecLength (const fwVec3d &_vec)
 Compute the length of the vector. More...
 
FWMATH_API void negate (fwVec3d &_vec)
 Compute the negate of the vector. More...
 

Detailed Description

The namespace fwMath contains classes which provide the implementation of several mathematic functions and objects (plane, line, point).

Function Documentation

bool fwMath::closeSurface ( fwVertexPosition &  _vertex,
fwVertexIndex &  _vertexIndex 
)

Closes the surface if necessary.

Returns
True if container mesh is changed

Definition at line 239 of file MeshFunctions.cpp.

fwVec3d fwMath::cross ( const fwVec3d &  v1,
const fwVec3d &  v2 
)

Compute the Cross product between two vectors.

Parameters
[in]v1
[in]v2
Returns
the cross product.

Definition at line 47 of file VectorFunctions.cpp.

Referenced by intersect().

+ Here is the caller graph for this function:

double fwMath::dot ( const fwVec3d &  v1,
const fwVec3d &  v2 
)

Compute the Dot product between two vectors.

Parameters
[in]v1
[in]v2
Returns
the dot product.

Definition at line 39 of file VectorFunctions.cpp.

Referenced by intersect().

+ Here is the caller graph for this function:

fwVec3d fwMath::getClosestPoint ( const fwLine &  _ray,
const fwVec3d &  _point 
)

Compute the projection of a point in a given direction.

Parameters
[in]_rayray (origin,direction). Direction vector is assumed be normalized.
[in]_pointpoint to be projected
Returns
closest point of the line if an intersection is found.

Definition at line 56 of file LineFunctions.cpp.

Referenced by intersect().

+ Here is the caller graph for this function:

bool fwMath::getClosestPoints ( const fwLine &  _ray1,
const fwLine &  _ray2,
fwVec3d &  _pointOnThis,
fwVec3d &  _pointOnfwLine 
)

Compute the closest points between two rays.

Parameters
[in]_ray1ray (origin,direction). Direction vector is assumed be normalized.
[in]_ray2ray (origin,direction). Direction vector is assumed be normalized.
[out]_pointOnThisintersection point.
[out]_pointOnfwLinebarycenter of the triangle defined by the three points of the place. Return FALSE if the lines are parallel, TRUE otherwise.
p1 + t1 * d1
p2 + t2 * d2
(p2 - p1 + t2 * d2 - t1 * d1) * d1 = 0
(p2 - p1 + t2 * d2 - t1 * d1) * d2 = 0
t2 * (d2.d1) - t1 = (p1 - p2).d1
t2 - t1 * (d1.d2) = (p1 - p2).d2

delta = 1 - (d1.d2)**2

t2 = [ d2.(p1-p2) - d1.(p1-p2) * (d1.d2)]/delta
t1 = [-d1.(p1-p2) + d2.(p1-p2) * (d1.d2)]/delta

Definition at line 21 of file LineFunctions.cpp.

Referenced by intersect().

+ Here is the caller graph for this function:

double fwMath::getDistance ( const fwPlane &  _plane)

Get the distance from origin for the given plan (_plane).

Parameters
[in]_plane
Returns
the distance of origin of the plane.

Definition at line 73 of file PlaneFunctions.cpp.

Referenced by offset().

+ Here is the caller graph for this function:

fwMatrix4x4 fwMath::getInverse ( const fwMatrix4x4 &  matrix)

Computes the inverse of a matrix.

Parameters
[in]matrix
Returns
inverted matrix

Definition at line 39 of file MatrixFunctions.cpp.

fwVec3d fwMath::getNormal ( const fwPlane &  _plane)

Return the normal of the given plane _plane.

Parameters
[in]_plane
Returns
the normalize normal of the plane.

Definition at line 54 of file PlaneFunctions.cpp.

Referenced by intersect().

+ Here is the caller graph for this function:

fwPlane fwMath::getPlane ( const fwVec3d &  _normal,
const fwVec3d &  _point 
)

compute a plane from a normal and a point which must be in the plane.

Parameters
[in]_pointa point of the plan/
[in]_normalthe normal of the new plane.
Returns
the new plane.

Definition at line 171 of file PlaneFunctions.cpp.

fwMatrix4x4 fwMath::getRotationMatrix ( const fwVec3d &  _vecNorm)

Compute a matrix rotation.

Deprecated:
The function implementation seems very dodgy, prefer ::glm::yawPitchRoll() or ::glm::orientate4()
Parameters
[in]_vecNorm
Returns
rotation matrix

Definition at line 60 of file MatrixFunctions.cpp.

bool fwMath::intersect ( const fwLine &  _ray,
double  _radius,
const fwVec3d &  _point 
)

Compute the projection of a point in a given direction and test if this intersection is inside a given radius.

Parameters
[in]_rayray (origin,direction). Direction vector is assumed be normalized.
[in]_radiusmaximum distance of the point
[in]_pointpoint to be projected
Returns
closest point of the line if an intersection is found.

Definition at line 75 of file LineFunctions.cpp.

References getClosestPoint().

Referenced by intersect().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool fwMath::intersect ( const fwLine &  _line,
double  _radius,
const fwVec3d &  _origin,
const fwVec3d &  _direction,
fwVec3d &  _point 
)

Compute the closest points between two rays and test these points lie inside a sphere of a given radius.

Parameters
[in]_lineray (origin,direction). Direction vector is assumed be normalized.
[in]_radiusmaximum distance of the point
[in]_originorigin of the second ray
[in]_directiondirection of the second ray
[in]_pointpoint to be projected
Returns
closest point of the line if an intersection is found.

Definition at line 87 of file LineFunctions.cpp.

References getClosestPoints().

+ Here is the call graph for this function:

bool fwMath::intersect ( const fwPlane &  _fwPlane,
const fwLine &  _line,
fwVec3d &  _point 
)

Give the intersection between a plane and a line. The result is returned in a point (_point)

Parameters
[in]_fwPlane
[in]_line
[out]_pointintersection point.
Returns
true if an intersection is found.

Definition at line 87 of file PlaneFunctions.cpp.

bool fwMath::intersect ( const fwLine &  _line,
const fwVec3d &  _v1,
const fwVec3d &  _v2,
const fwVec3d &  _v3,
fwVec3d &  _point,
fwVec3d &  _barycentric,
bool &  _front 
)

Give the intersection between a plane and a line. The result is returned in a point (_point).

Deprecated:
This function was added for a specific purpose and will be removed in a future release.
Parameters
[in]_lineinput line (2 positions)
[in]_v1first point of the plane
[in]_v2second point of the plane
[in]_v3third point of the plane
[out]_pointintersection point.
[out]_barycentricbarycenter of the triangle defined by the three points of the plane.
[out]_fronttrue if the dot product of the plane normal and ths positive Z axis (0,0,1) is positive.
Returns
true if an intersection is found.

Definition at line 106 of file LineFunctions.cpp.

References cross(), dot(), getNormal(), and intersect().

+ Here is the call graph for this function:

template<typename CONTAINER >
bool fwMath::isContainerEqual ( CONTAINER &  containerA,
CONTAINER &  containerB,
const float  epsilon = 0.00001F 
)

Returns true iff container a and b are equal with 'epsilon' error margin.

Parameters
containerAcontainer to compare
containerBcontainer to compare
epsilon: error margin
Returns
true iff container a and b are equal with 'epsilon' error margin

Definition at line 36 of file Compare.hpp.

References isEqual().

Referenced by fwDataTools::Image::mergeMask().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename TYPE >
bool fwMath::isEqual ( TYPE  a,
TYPE  b,
const float  epsilon = 0.00001F 
)

Returns true iff a and b are equal with 'epsilon' error margin.

Parameters
avalue to compare
bvalue to compare
epsilon: error margin
Returns
true iff a and b are equal with 'epsilon' error margin

Definition at line 23 of file Compare.hpp.

Referenced by isContainerEqual().

+ Here is the caller graph for this function:

bool fwMath::isInHalfSpace ( const fwPlane &  _plane,
const fwVec3d &  _point 
)

Compute if a point is in a half plane.

Parameters
[in]_plane
[in]_point
Returns
true if point is in a half plane.

Definition at line 117 of file PlaneFunctions.cpp.

void fwMath::multVecMatrix ( const fwMatrix4x4 &  _matrix,
const fwVec3d &  _source,
fwVec3d &  _dest 
)

Multiply a matrix by a vector.

Parameters
[in]_matrix
[in]_source
[out]_dest

Definition at line 19 of file MatrixFunctions.cpp.

void fwMath::negate ( fwVec3d &  _vec)

Compute the negate of the vector.

Parameters
[in]_vec
[out]_vec

Definition at line 67 of file VectorFunctions.cpp.

fwVec3d fwMath::normalized ( const fwVec3d &  vec)

Return a normalized vector.

Parameters
[in]vecvector to normalize
Returns
normalized vector

Definition at line 30 of file VectorFunctions.cpp.

References normalize().

+ Here is the call graph for this function:

void fwMath::offset ( fwPlane &  _plane,
double  _offset 
)

Add an offset at the distance of origin which define the plane (_plane).

Parameters
[in]_plane
[in]_offset
[out]_plane

Definition at line 162 of file PlaneFunctions.cpp.

References getDistance(), and setDistance().

+ Here is the call graph for this function:

bool fwMath::removeOrphanVertices ( fwVertexPosition &  _vertex,
fwVertexIndex &  _vertexIndex 
)

remove orphan vertices (i.e not used in _vertexIndex), _vertexIndex is reordered according to vertex suppressions

Definition at line 280 of file MeshFunctions.cpp.

void fwMath::setDistance ( fwPlane &  _plane,
const double  _distance 
)

Set the distance from origin (_distance) for the given plan (_plane).

Parameters
[in]_distance
[in]_plane
Returns
[out] _plane

Definition at line 80 of file PlaneFunctions.cpp.

Referenced by offset().

+ Here is the caller graph for this function:

void fwMath::setNormal ( fwPlane &  _plane,
const fwVec3d &  _normal 
)

Set the normal of the given plane _plane.

Parameters
[in]_plane
[in]_normal

Definition at line 61 of file PlaneFunctions.cpp.

void fwMath::setValues ( fwPlane &  _plane,
const fwVec3d &  _point1,
const fwVec3d &  _point2,
const fwVec3d &  _point3 
)

Initialize a plane _plane with three points (_point1, _point2, _point3). It computes the plane's normal and the distance from the origin.

Parameters
[out]_planethe new plane.
[in]_point1a point of the plan.
[in]_point2a point of the plan.
[in]_point3a point of the plan.

Definition at line 30 of file PlaneFunctions.cpp.

void fwMath::transform ( fwPlane &  _plane,
const fwMatrix4x4 &  _matrix 
)

Apply a transformation to a plane. The transformation is defined by a matrix 4x4.

Parameters
[in]_plane
[in]_matrix
[out]_plane

Definition at line 128 of file PlaneFunctions.cpp.

double fwMath::vecLength ( const fwVec3d &  _vec)

Compute the length of the vector.

Parameters
[in]_vec
Returns
the vector's length

Definition at line 59 of file VectorFunctions.cpp.

Referenced by normalize().

+ Here is the caller graph for this function: