- Main Page
- Namespaces
- Classes
- Files
- Related Pages

- File List
- File Members

# ColUtils.cpp File Reference

Utility functions for the CollDet library. Some of them are (hopefully) temporary only, untilthey become available in OpenSG. More...

Include dependency graph for ColUtils.cpp:

## Namespaces
namespace | col
## Classes
struct | col::lessByAngle
| Compare points by angle. More...
struct | col::sBF
| contains some state across different invocations of addFace() More...
## Random numbers
#define | mod_diff(x, y) ( (x) - (y) & (M_MM-1) )
#define | is_odd(x) ( (x) & 1 )
#define | evenize(x) ( (x) & (M_MM-2) )
double | col::my_drand48 (void)
| Substitute for the drand48() function under Unix (needed under Windoze).
unsigned int | col::pseudo_random (void)
| Pseudo random number generator.
float | col::pseudo_randomf (void)
| Pseudo random number generator.
## Defines
#define | COL_EXPORT
#define | sqr(x) ((x)*(x))
#define | COL_EDGE_EDGE(__V0, __U0, __U1)
#define | COL_EDGE_AGAINST_TRI(_V0, _V1, _U0, _U1, _U2)
#define | COL_RAY_EDGE_2(succaction)
## Functions
Vector, Matrix, and Transformation Math
float | col::operator * (const Vec3f &vec3, const Vec4f &vec4)
| Several 'vector * vector' and 'vector * point' products.
float | col::operator * (const Pnt3f &pnt, const float vec[3])
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
float | col::operator * (const osg::Vec4f &vec4, const Pnt3f &pnt3)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
float | col::operator * (const Pnt3f &pnt3, const Vec3f &vec3)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void | col::operator+= (Vec4f &vec4, const Vec3f &vec3)
| Vec4f += Vec3f.
Pnt3f | col::lincomb (float c1, const Pnt3f &pnt1, float c2, const Pnt3f &pnt2)
| Affine combination of two points.
void | col::getTransfomUpto (const osg::NodePtr &cur, const osg::NodePtr &upto, osg::Matrix &result)
| Combine all transformation matrices between two nodes in the graph.
void | col::iterFaces (const osg::NodePtr &node, void(*callback)(const osg::NodePtr &, const osg::GeometryPtr &, const osg::FaceIterator &, void *), void *data)
| Calls a function for every face in the scenegraph.
void | col::countFaces (const osg::NodePtr &, const osg::GeometryPtr &, const osg::FaceIterator &, void *data)
| Count the number of faces in a scenegraph.
float | col::dist2 (const Pnt3f &pnt1, const Pnt3f &pnt2)
| Square distance between 2 points.
float | col::dist (const Pnt3f &pnt1, const Pnt3f &pnt2)
| Distance between 2 points.
Pnt3f | col::barycenter (const Pnt3f *points, const unsigned int npoints)
| Average of an array of points.
Pnt3f | col::barycenter (const vector< Pnt3f > &points)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Pnt3f | col::barycenter (const Pnt3f *points, const unsigned int index[], const unsigned int nindices)
| Average of an array of indexed points.
Pnt3f | col::barycenter (const osg::MFPnt3f *points, const unsigned int index[], const unsigned int nindices)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Pnt3f | col::barycenter (const vector< Pnt3f > &points, const TopoFace &face)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
bool | col::collinear (const Vec3f &a, const Vec3f &b)
| Test if two vectors are collinear.
bool | col::coplanar (const Pnt3f &p0, const Pnt3f &p1, const Pnt3f &p2, const Pnt3f &q0, const Pnt3f &q1, const Pnt3f &q2)
| Test if two triangles (planes / polygons) are coplanar.
Vec3f | col::operator * (const osg::Matrix &m, const Vec3f &v)
| Matrix * Vec3f.
Pnt3f | col::mulM3Pnt (const osg::Matrix &m, const Pnt3f &p)
| Matrix * Pnt3f.
Pnt3f | col::operator * (const osg::Matrix &m, const Pnt3f &p)
| Matrix * vector.
osg::Matrix | col::operator * (const osg::Matrix &m1, const osg::Matrix &m2)
| Matrix * matrix.
Vec3f | col::mulMTVec (const osg::Matrix &m, const Vec3f &v)
| Transposed matrix * Vec3f.
void | col::printMat (const osg::Matrix &m, FILE *file)
| Print a matrix.
void | col::printPnt (const osg::Pnt3f &p, FILE *file)
| Print a point.
void | col::dominantIndices (const Vec3f &v, unsigned int *x, unsigned int *y)
| Dominant coord plane which v is "most orthogonal" to.
void | col::dominantIndices (const Vec3f &v, unsigned int *x, unsigned int *y, unsigned int *z)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
unsigned int | col::dominantIndex (const Vec3f &v)
| Dominant coord axis which v is "most parallel" to.
Vec3f | col::triangleNormal (const Pnt3f &p0, const Pnt3f &p1, const Pnt3f &p2)
| Normal of a triangle defined by 3 points.
osg::Matrix | col::axisToMat (const Vec3f &a, float d)
| Convert a rotation given by axis & angle to a matrix.
unsigned int | col::discretizeOri (osg::Quaternion q, unsigned int r)
| Convert an orientation (quarternion) into an integer (e.g., index).
void | col::mlerp (OSG::Matrix *intermat, const OSG::Matrix &m1, const OSG::Matrix &m2, float t)
| Matrix linear interpolation.
Geometry
void | col::sortVerticesCounterClockwise (const vector< Pnt3f > &vertex, const Vec3f &normal, TopoFace &face)
| Sort vertices of a face such that they occur counter clockwise.
osg::NodePtr | col::geomFromPoints (const vector< Pnt3f > &vertex, vector< TopoFace > &face, int gl_type, bool skip_redundant, const Vec3f normals[])
| Create a polyhedron from simple vertex and face arrays.
osg::NodePtr | col::geomFromPoints (const Pnt3f vertex[], unsigned int nvertices, unsigned int face[], const unsigned int face_nv[], unsigned int nfaces, int gl_type, bool skip_redundant, const Vec3f normals[])
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
osg::NodePtr | col::makeCube (float radius, int gl_type)
| Create a cube as OpenSG object.
void | col::getNodeBBox (osg::NodePtr node, float min[3], float max[3])
| Get BoundingBox of an osg-node.
osg::GeometryPtr | col::getGeom (const osg::NodePtr node)
| Return the pointer to the geometry core of the node.
osg::MFPnt3f * | col::getPoints (const osg::NodePtr node)
| Return the pointer to the multi-field of the points.
osg::MFPnt3f * | col::getPoints (const osg::GeometryPtr geo)
| This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
osg::GeoPositions3fPtr | col::getPositions (const osg::NodePtr node)
| Return the GeoPositionsPtr of a node.
void | col::calcVertexNormals (const osg::NodePtr node, const float creaseAngle)
| Calculate vertex normals for all geometries in a subtree.
osg::NodePtr | col::findGeomNode (const osg::NodePtr node)
| Find the first node that has a geometry.
osg::MaterialPtr | col::findMaterial (const osg::NodePtr node)
| Return the material a geometry node is being drawn with.
void | col::addFace (const osg::NodePtr &node, const osg::GeometryPtr &geo, const osg::FaceIterator &face, sBF *bf)
| Add one face to a geometry/node; used by addAllFaces.
void | col::addAllFaces (const osg::NodePtr &root, sBF *bf)
| Copy all faces in the subtree into one geometry; used by mergeGeom().
void | col::mergeGeom (const osg::NodePtr &subtree, osg::NodePtr *geonode)
| Merge all geometries in a subtree into a node.
Timers, timing, sleeping, etc.
void | col::sleep (unsigned int microseconds)
| Sleep n microseconds.
float | col::time (void)
| Get the user time in milliseconds.
Floating-Point Tricks
unsigned int | col::sign (float &x)
| Returns 0 if x < 0, 0x80000000 otherwise.
Misc
bool | col::lockToProcessor (unsigned int processor)
| Lock the calling process to a certain processor.
Intersection Tests
bool | col::isectCoplanarTriangles (const Vec3f &normalV, const Pnt3f &polyVv0, const Pnt3f &polyVv1, const Pnt3f &polyVv2, const Pnt3f &polyUv0, const Pnt3f &polyUv1, const Pnt3f &polyUv2)
| Checks whether two coplanar triangles intersect.
bool | col::isectCoplanarEdges (const Pnt3f &v0V, const Pnt3f &v1V, const Pnt3f &u0V, const Pnt3f &u1V, unsigned int x, unsigned int y)
| Checks if the edges intersect in 2D.
void | col::isectEdgePolygon (const Pnt3f &v1, const Pnt3f &v2, const Pnt3f *poly, unsigned int plSize, const Vec3f &normalV, unsigned int x, unsigned int y, bool *isect, bool *oneside)
| Checks, if edge intersects polygon in 2D.
void | col::isectEdgeTriangle (const Pnt3f &v1, const Pnt3f &v2, const Pnt3f *poly, const Vec3f &normalV, unsigned int x, unsigned int y, bool *isect, bool *oneside)
bool | col::pointInPolygon (const Pnt3f &pt, const Pnt3f *poly, unsigned int plSize, unsigned int x, unsigned int y)
| Check if point is inside polygon.
bool | col::pointInTriangle (const Pnt3f &pt, const Pnt3f &v0, const Pnt3f &v1, const Pnt3f &v2, unsigned int x, unsigned int y)
| Check whether point is inside triangle.

## Detailed Description

Utility functions for the CollDet library. Some of them are (hopefully) temporary only, untilthey become available in OpenSG.

Author:
  Gabriel Zachmann

## Define Documentation

#define COL_EDGE_AGAINST_TRI | ( | _V0,
|  | _V1,
|  | _U0,
|  | _U1,
|  | _U2 |  | ) |

Value:

    {                                                                   \
                                        /* temporary variables, also for    */  \
                                        /* interaction with COL_EDGE_EDGE   */  \
                float _Ax, _Ay, _Bx, _By, _Cx, _Cy, _EE, _DD, _FF;              \
                _Ax = _V1 [i] - _V0 [i];                                        \
                _Ay = _V1 [j] - _V0 [j];                                        \
                                        /* test edge U0,U1 against V0,V1    */  \
                COL_EDGE_EDGE(_V0, _U0, _U1);                                   \
                                        /* test edge U1,U2 against V0,V1    */  \
                COL_EDGE_EDGE(_V0, _U1, _U2);                                   \
                                        /* test edge U2,U1 against V0,V1    */  \
                COL_EDGE_EDGE(_V0, _U2, _U0);                                   \
            }

#define COL_EDGE_EDGE | ( | __V0,
|  | __U0,
|  | __U1 |  | ) |

Value:

    _Bx = __U0 [i] - __U1 [i];                                          \
            _By = __U0 [j] - __U1 [j];                                          \
            _Cx = __V0 [i] - __U0 [i];                                          \
            _Cy = __V0 [j] - __U0 [j];                                          \
            _FF = _Ay * _Bx - _Ax * _By;                                        \
            _DD = _By * _Cx - _Bx * _Cy;                                        \
            if((_FF > 0 && _DD >= 0 && _DD <= _FF) ||                           \
               (_FF < 0 && _DD <= 0 && _DD >= _FF))                             \
            {                                                                   \
                _EE = _Ax * _Cy - _Ay * _Cx;                                    \
                if(_FF > 0)                                                     \
                {                                                               \
                    if(_EE >= 0 && _EE <= _FF) return true;                     \
                }                                                               \
                else                                                            \
                {                                                               \
                    if(_EE <= 0 && _EE >= _FF) return true;                     \
                }                                                               \
            }

#define COL_RAY_EDGE_2 | ( | succaction |  | ) |

Value:

    {                                                               \
            if ( v1x < px && v2x < px )                                 \
                succaction;                                             \
            v1y = v1[y];                                                \
            v2y = v2[y];                                                \
            if ( v1y > py && v2y > py )                                 \
                succaction;                                             \
            if ( v1y <= py && v2y <= py )                               \
                succaction;                                             \
            if ( v1x >= px && v2x >= px )                               \
            {                                                           \
                in ++ ;                                                 \
                succaction;                                             \
            }                                                           \
            y1py = v1y - py;                                            \
            x1px = v1x - px;                                            \
            y2py = v2y - py;                                            \
            x2px = v2x - px;                                            \
            if ( y1py >= x1px && y2py >= x2px )                         \
                succaction;                                             \
            if ( (-y1py) >= x1px && (-y2py) >= x2px )                   \
                succaction;                                             \
                                                                        \
            y1y2 = v1y - v2y;                                           \
            t = y1py*(v2x - v1x) + x1px*y1y2;                           \
            if ( (t>0.0f && y1y2 > 0.0f) || (t<0.0f && y1y2 < 0.0f) )   \
                in ++ ;                                                 \
        }