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

The CuikSuite Project

cpolyhedron.h File Reference

Definition of the Tcpolyhedron type and the associated functions. More...

#include "plot3d.h"
#include "htransform.h"
#include "color.h"
#include <stdlib.h>

Go to the source code of this file.

Data Structures

struct  Tcpolyhedron
 A convex polyhedron. More...

Defines

#define NORMAL_SHAPE   0
 One of the possible type of shapes.
#define HIDDEN_SHAPE   1
 One of the possible type of shapes.
#define DECOR_SHAPE   2
 One of the possible type of shapes.
#define OFF   0
 One of the possible type of convex polyhedrons.
#define SPHERE   1
 One of the possible type of convex polyhedrons.
#define CYLINDER   2
 One of the possible type of convex polyhedrons.

Functions

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

Definition of the Tcpolyhedron type and the associated functions.

See also:
Tcpolyhedron, cpolyhedron.c.

Definition in file cpolyhedron.h.


Define Documentation

#define NORMAL_SHAPE   0

One of the possible type of shapes. A normal shape is show and considered for collisions.

See also:
Tcpolyhedron

Definition at line 27 of file cpolyhedron.h.

#define HIDDEN_SHAPE   1

One of the possible type of shapes. A hiden shape is not show but it is considered for collisions.

See also:
Tcpolyhedron

Definition at line 36 of file cpolyhedron.h.

#define DECOR_SHAPE   2

One of the possible type of shapes. A decor(ation) shape is show but it is not considered for collisions.

See also:
Tcpolyhedron

Definition at line 45 of file cpolyhedron.h.

#define OFF   0

One of the possible type of convex polyhedrons. An OFF is a general polyhedron defined by its vertices and its faces. This is a standard geomview construction.

See also:
Tcpolyhedron

Definition at line 57 of file cpolyhedron.h.

Referenced by GetCPolyhedronDefiningPoint(), GetCpolyhedronRadius(), PlotCPolyhedron(), ReadOFF(), and SaveCPolyhedron().

#define SPHERE   1

One of the possible type of convex polyhedrons. An SPHERE is defined by a center (x,y,z) and a radius. This is a standard geomview construction.

See also:
Tcpolyhedron

Definition at line 68 of file cpolyhedron.h.

Referenced by GenerateSphereOFF(), GetCPolyhedronDefiningPoint(), NewSphere(), PlotCPolyhedron(), ReadSphere(), and SaveCPolyhedron().

#define CYLINDER   2

One of the possible type of convex polyhedrons. An CYLINDER is defined by two 3d points. This is not standard in geomview.

See also:
Tcpolyhedron

Definition at line 78 of file cpolyhedron.h.

Referenced by GenerateCylinderOFF(), GetCPolyhedronDefiningPoint(), NewCylinder(), PlotCPolyhedron(), ReadCylinder(), and SaveCPolyhedron().


Function Documentation

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: