Institut de Robòtica i Informàtica Industrial
KRD Group

The CuikSuite Project

cpolyhedron.c File Reference

Implementaton of the function operating on Tcpolyhedron. More...

#include "cpolyhedron.h"
#include "htransform.h"
#include "error.h"
#include <string.h>
#include <math.h>

Go to the source code of this file.

Functions

void ReadOFF (FILE *f, Tcpolyhedron *p)
 Constructor.
void GenerateCylinderOFF (unsigned int g, Tcpolyhedron *p)
 Generates an OFF that approximates a cylinder.
void ReadCylinder (FILE *f, unsigned int g, Tcpolyhedron *p)
 Constructor.
void GenerateSphereOFF (unsigned int g, Tcpolyhedron *p)
 Generates an OFF that approximates a sphere.
void ReadSphere (FILE *f, unsigned int g, Tcpolyhedron *p)
 Constructor.
void InitCPolyhedronFromFile (char *fname, Tcolor *c, unsigned int gr, Tcpolyhedron *p)
 Constructor.
void NewSphere (double r, double *center, Tcolor *c, unsigned int gr, Tcpolyhedron *p)
 Constructor.
void NewCylinder (double r, double *p1, double *p2, Tcolor *c, unsigned int gr, Tcpolyhedron *p)
 Constructor.
void CopyCPolyhedron (Tcpolyhedron *p_dst, Tcpolyhedron *p_src)
 Copy constructor.
void TransformCPolyhedron (THTransform *t, Tcpolyhedron *p)
 Applies a homogenoeus transform to a convex polyhedron.
unsigned int GetCPolyhedronType (Tcpolyhedron *p)
 Retrives the type of a convex polyhedron.
void SetCPolyhedronColor (Tcolor *c, Tcpolyhedron *p)
 Changes the color of a convex polyhedron.
void GetCPolyhedronColor (Tcolor *c, Tcpolyhedron *p)
 Gets the color of a convex polyhedron.
unsigned int GetCPolyhedronNVertex (Tcpolyhedron *p)
 Gets the number of vertexes of a convex polyhedron.
void GetCPolyhedronDefiningPoint (unsigned int i, double *point, Tcpolyhedron *p)
 Gets a point defining a a convex object.
double GetCpolyhedronRadius (Tcpolyhedron *p)
 Returns the radius used in the definition of the convex object.
void GetCPolyhedronVertex (unsigned int i, double *point, Tcpolyhedron *p)
 Gets a vertex of a convex polyhedron.
double GetCPolyhedronMaxCoordinate (Tcpolyhedron *p)
 Returns the maximum coordinate value used in a convex polyhedron.
void PlotCPolyhedron (Tplot3d *pt, Tcpolyhedron *p)
 Adds the convex polyhedron to a 3D geometry.
void MoveCPolyhedron (Tplot3d *pt, THTransform *t, Tcpolyhedron *p)
 Moves an object previously added to a 3D scene.
void SaveCPolyhedron (char *fileName, Tcpolyhedron *p)
 Stores the geometic information of a convex polyhedron into a file.
void DeleteCPolyhedron (Tcpolyhedron *p)
 Destructor.

Detailed Description

Implementaton of the function operating on Tcpolyhedron.

See also:
Tcpolyhedron, cpolyhedron.h.

Definition in file cpolyhedron.c.


Function Documentation

void ReadOFF ( FILE *  f,
Tcpolyhedron p 
)

Constructs a convex polyhedrom from a file. This function is to be used when the heading of the file is already processed and the file includes for sure the definition of an OFF.

Parameters:
f The file from where to read the information.
p The convex polyhedron to create.

Definition at line 90 of file cpolyhedron.c.

References Tcpolyhedron::center, Error(), Tcpolyhedron::fv, Tcpolyhedron::maxCoord, Tcpolyhedron::ne, NEW, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, OFF, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by InitCPolyhedronFromFile().

Here is the call graph for this function:

Here is the caller graph for this function:

void GenerateCylinderOFF ( unsigned int  g,
Tcpolyhedron p 
)

Generates and OFF that approximates a cylinder. This polyhedric approximation is the one used int collision detection.

Note that only the vertexes of the OFFS are generates (no face information is created) since for collision detection only the vertexes of the convex polyhedrons are used.

Parameters:
g The granularity to use to create the polytope that approximates the cylinder.
p The cylinder to approximate.

Definition at line 146 of file cpolyhedron.c.

References CYLINDER, Error(), Tcpolyhedron::fv, HTransformApply(), HTransformDelete(), HTransformX2Vect(), M_2PI, Tcpolyhedron::maxCoord, NEW, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by NewCylinder(), and ReadCylinder().

Here is the call graph for this function:

Here is the caller graph for this function:

void ReadCylinder ( FILE *  f,
unsigned int  g,
Tcpolyhedron p 
)

Constructs a convex polyhedrom from a file. This function is to be used when the heading of the file is already processed and the file includes for sure the definition of an CYLINDER.

Parameters:
f The file from where to read the information.
g The granularity to use to create the polytope that approximates the cylinder.
p The convex polyhedron to create.

Definition at line 199 of file cpolyhedron.c.

References Tcpolyhedron::center, CYLINDER, GenerateCylinderOFF(), Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, and Tcpolyhedron::type.

Referenced by InitCPolyhedronFromFile().

Here is the call graph for this function:

Here is the caller graph for this function:

void GenerateSphereOFF ( unsigned int  g,
Tcpolyhedron p 
)

Generates and OFF that approximates a sphere. This polyhedric approximation is the one used int collision detection.

Note that only the vertexes of the OFFS are generates (no face information is created) since for collision detection only the vertexes of the convex polyhedrons are used.

Parameters:
g The granularity to use to create the polytope that approximates the sphere.
p The sphere to approximate.

Definition at line 220 of file cpolyhedron.c.

References Tcpolyhedron::center, Error(), Tcpolyhedron::fv, HTransformApply(), HTransformDelete(), HTransformProduct(), HTransformRz(), HTransformTxyz(), M_2PI, M_PI_2, Tcpolyhedron::maxCoord, NEW, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, Tcpolyhedron::rad, SPHERE, Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by NewSphere(), and ReadSphere().

Here is the call graph for this function:

Here is the caller graph for this function:

void ReadSphere ( FILE *  f,
unsigned int  g,
Tcpolyhedron p 
)

Constructs a convex polyhedrom from a file. This function is to be used when the heading of the file is already processed and the file includes for sure the definition of an SPHERE.

Parameters:
f The file from where to read the information.
g The granularity to use to create the polytope that approximates the sphere.
p The convex polyhedron to create.

Definition at line 296 of file cpolyhedron.c.

References Tcpolyhedron::center, GenerateSphereOFF(), Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, SPHERE, and Tcpolyhedron::type.

Referenced by InitCPolyhedronFromFile().

Here is the call graph for this function:

Here is the caller graph for this function:

void InitCPolyhedronFromFile ( char *  fname,
Tcolor c,
unsigned int  gr,
Tcpolyhedron p 
)

Define a Tcpolyhedron from a file.

Parameters:
fname The name of the file from where to read the information.
c The color of the object.
gr The granularity to define polyhedrons for spheres and cylinders.
p The convex polyhedron to create.

Definition at line 314 of file cpolyhedron.c.

References Tcpolyhedron::color, CopyColor(), Error(), NEW, NO_UINT, Tcpolyhedron::obj3d, ReadCylinder(), ReadOFF(), and ReadSphere().

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void NewSphere ( double  r,
double *  center,
Tcolor c,
unsigned int  gr,
Tcpolyhedron p 
)

Defines a sphere (and its polyhedric approximation for collision detection).

Parameters:
r The radius of the sphere.
center The center of the sphere.
c The color of the sphere.
gr The granularity to define approximating polyhedrons for the sphere.
p The convex polyhedron to create.

Definition at line 353 of file cpolyhedron.c.

References Tcpolyhedron::center, Tcpolyhedron::color, CopyColor(), GenerateSphereOFF(), NO_UINT, Tcpolyhedron::obj3d, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, SPHERE, and Tcpolyhedron::type.

Here is the call graph for this function:

void NewCylinder ( double  r,
double *  p1,
double *  p2,
Tcolor c,
unsigned int  gr,
Tcpolyhedron p 
)

Defines a cylinder (and its polyhedric approximation for collision detection).

Parameters:
r The radius of the cylinder.
p1 The initial point of the cylinder axis.
p2 The final point of the cylinder axis.
c The color of the cylinder.
gr The granularity to define approximating polyhedrons for the cylinder.
p The convex polyhedron to create.

Definition at line 376 of file cpolyhedron.c.

References Tcpolyhedron::center, Tcpolyhedron::color, CopyColor(), CYLINDER, GenerateCylinderOFF(), NO_UINT, Tcpolyhedron::obj3d, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, and Tcpolyhedron::type.

Here is the call graph for this function:

void CopyCPolyhedron ( Tcpolyhedron p_dst,
Tcpolyhedron p_src 
)

Defines a polyhedron from another polyhedron.

Parameters:
p_dst The convex polyhedron to define.
p_src The convex polyhedron from where to copy.

Definition at line 403 of file cpolyhedron.c.

References Tcpolyhedron::center, Tcpolyhedron::color, CopyColor(), Tcpolyhedron::fv, Tcpolyhedron::maxCoord, Tcpolyhedron::ne, NEW, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, Tcpolyhedron::obj3d, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by AddBody2Link().

Here is the call graph for this function:

Here is the caller graph for this function:

void TransformCPolyhedron ( THTransform t,
Tcpolyhedron p 
)

Applies a homogenoeus transform to a convex polyhedron.

Parameters:
t The transform to apply.
p The polyhedron to transform.

Definition at line 451 of file cpolyhedron.c.

References Tcpolyhedron::center, HTransformApply(), Tcpolyhedron::maxCoord, Tcpolyhedron::nv, Tcpolyhedron::p1, Tcpolyhedron::p2, and Tcpolyhedron::v.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int GetCPolyhedronType ( Tcpolyhedron p  ) 

Retrives the type of a convex polyhedron.

Parameters:
p The convex polyhedron to query.
Returns:
The type of the convex polyhedron: OFF, SPHERE, CYLINDER.

Definition at line 475 of file cpolyhedron.c.

References Tcpolyhedron::type.

void SetCPolyhedronColor ( Tcolor c,
Tcpolyhedron p 
)

Changes the color of a convex polyhedron.

Parameters:
c The new color for the convex polyhedron.
p The convex polyhedron to update.

Definition at line 480 of file cpolyhedron.c.

References Tcpolyhedron::color, and CopyColor().

Here is the call graph for this function:

void GetCPolyhedronColor ( Tcolor c,
Tcpolyhedron p 
)

Gets the color of a convex polyhedron.

Parameters:
c The color of the convex polyhedron.
p The convex polyhedron to query.

Definition at line 485 of file cpolyhedron.c.

References Tcpolyhedron::color, and CopyColor().

Here is the call graph for this function:

unsigned int GetCPolyhedronNVertex ( Tcpolyhedron p  ) 

Gets the number of vertexes of a convex polyhedron.

Parameters:
p The convex polyhedron to query.
Returns:
The number of vertexes of a convex polyhedron.

Definition at line 490 of file cpolyhedron.c.

References Tcpolyhedron::nv.

void GetCPolyhedronDefiningPoint ( unsigned int  i,
double *  point,
Tcpolyhedron p 
)

Gets the coordinates of a point defining of a convex object.

A CYLINDER is defined by two points: the initial and the end points of the cylinder.

A SPHERE is defined by one point: the center of the sphere.

For OFFs, all vertexes are considered defining points.

If the convex polyhedron has less defining points than the requested number, this function triggers an error.

Parameters:
i Number of the defining point to retrive.
point Space to store the three coordinates of the requested vertex.
p The convex polyhedron to query.

Definition at line 495 of file cpolyhedron.c.

References Tcpolyhedron::center, CYLINDER, Error(), GetCPolyhedronVertex(), OFF, Tcpolyhedron::p1, Tcpolyhedron::p2, SPHERE, and Tcpolyhedron::type.

Referenced by GetMechanismDefiningPoint().

Here is the call graph for this function:

Here is the caller graph for this function:

double GetCpolyhedronRadius ( Tcpolyhedron p  ) 

Returns the radius used in the definition of the convex object. This function is only defined for SPHEREs and CYLINDERs. It triggers an error if used on a OFF.

Parameters:
p The convex polyhedron to query.
Returns:
The radius used in the convex object definition, if any.

Definition at line 535 of file cpolyhedron.c.

References Error(), OFF, Tcpolyhedron::rad, and Tcpolyhedron::type.

Here is the call graph for this function:

void GetCPolyhedronVertex ( unsigned int  i,
double *  point,
Tcpolyhedron p 
)

Gets the coordinates of the vertex of a convex polyhedron.

For cylinders and spheres point on the approximating OFF are returned.

If the convex polyhedron has less vertexes than the requested element, this function triggers an error.

Parameters:
i Number of the vertex to retrive.
point Space to store the three coordinates of the requested vertex.
p The convex polyhedron to query.

Definition at line 542 of file cpolyhedron.c.

References Error(), Tcpolyhedron::nv, and Tcpolyhedron::v.

Referenced by GetCPolyhedronDefiningPoint().

Here is the call graph for this function:

Here is the caller graph for this function:

double GetCPolyhedronMaxCoordinate ( Tcpolyhedron p  ) 

Returns the maximum coordinate value (either in X, Y, or Z) used in a convex polyhedron. This is used in higher levels to define an over-estimate bounding-box of the mechanism. This bounding box is used to define the ranges for some of the coordinate and separating planes variables.

Parameters:
p The convex polyhedron to query.
Returns:
The maximum coordinate value.

Definition at line 553 of file cpolyhedron.c.

References Tcpolyhedron::maxCoord.

Referenced by AddBody2Link().

Here is the caller graph for this function:

void PlotCPolyhedron ( Tplot3d pt,
Tcpolyhedron p 
)

Adds the convex polyhedron to a 3D geometry. Each object in a 3D scene gets an identifier that is stored in the cpolyhedron object for future reference.

Parameters:
pt The 3D geometry where to add the convex polyhedron.
p The convex polyhedron to plot.

Definition at line 558 of file cpolyhedron.c.

References Tcpolyhedron::center, Close3dObject(), Tcpolyhedron::color, CYLINDER, Tcpolyhedron::fv, Tcpolyhedron::ne, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, Tcpolyhedron::obj3d, OFF, Tcpolyhedron::p1, Tcpolyhedron::p2, Plot3dObject(), PlotCylinder(), PlotSphere(), Tcpolyhedron::rad, SPHERE, StartNew3dObject(), Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by PlotLink().

Here is the call graph for this function:

Here is the caller graph for this function:

void MoveCPolyhedron ( Tplot3d pt,
THTransform t,
Tcpolyhedron p 
)

Moves an object previously added to a 3D scene.

Parameters:
pt The 3D geometry where the convex polyhedron was added.
t The homogeneous transform to apply to the convex polyhedron.
p The convex polyhedron to move.

Definition at line 594 of file cpolyhedron.c.

References Move3dObject(), NO_UINT, and Tcpolyhedron::obj3d.

Referenced by MoveLink().

Here is the call graph for this function:

Here is the caller graph for this function:

void SaveCPolyhedron ( char *  fileName,
Tcpolyhedron p 
)

Stores the geometic information of a convex polyhedron into a file. Basically, it creates a file that can be latter read using InitCPolyhedronFromFile

Parameters:
fileName Name of the file where to store the geometric information.
p The convex polyhedron to save.

Definition at line 600 of file cpolyhedron.c.

References Tcpolyhedron::center, CYLINDER, Error(), Tcpolyhedron::fv, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, OFF, Tcpolyhedron::p1, Tcpolyhedron::p2, Tcpolyhedron::rad, SPHERE, Tcpolyhedron::type, and Tcpolyhedron::v.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void DeleteCPolyhedron ( Tcpolyhedron p  ) 

Deletes the information stored in a Tcpolyhedron and frees the allocated memory.

Parameters:
p The convex polyhedron to delete.

Definition at line 641 of file cpolyhedron.c.

References Tcpolyhedron::fv, Tcpolyhedron::nf, Tcpolyhedron::nv, Tcpolyhedron::nvf, and Tcpolyhedron::v.

Referenced by DeleteLink(), and main().

Here is the caller graph for this function: