polyhedron.c File Reference

Detailed Description

Implementaton of the function operating on Tpolyhedron.

See Also
Tpolyhedron, polyhedron.h.

Definition in file polyhedron.c.

Functions

boolean ReadGeneralMesh (char *fn, Tpolyhedron *p)
 Constructor. More...
 
void ReadSTL (char *fn, Tpolyhedron *p)
 Constructor. More...
 
void ReadOFF (FILE *f, Tpolyhedron *p)
 Constructor. More...
 
void GenerateCylinderOFF (unsigned int g, Tpolyhedron *p)
 Generates an OFF that approximates a cylinder. More...
 
void ReadLine (FILE *f, Tpolyhedron *p)
 Constructor. More...
 
void ReadSegments (FILE *f, Tpolyhedron *p)
 Constructor. More...
 
void ReadCylinder (FILE *f, unsigned int g, Tpolyhedron *p)
 Constructor. More...
 
void GenerateSphereOFF (unsigned int g, Tpolyhedron *p)
 Generates an OFF that approximates a sphere. More...
 
void ReadSphere (FILE *f, unsigned int g, Tpolyhedron *p)
 Constructor. More...
 
void InitPolyhedronFromFile (Tfilename *fname, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void InitPolyhedronFromTriangles (unsigned int nv, double **v, unsigned int nt, unsigned int **t, Tcolor *c, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void NewBox (double xl, double yl, double zl, double xu, double yu, double zu, Tcolor *c, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void NewSphere (double r, double *center, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void NewCylinder (double r, double *p1, double *p2, Tcolor *c, unsigned int gr, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void NewLine (double *p1, double *p2, Tcolor *c, unsigned int bs, Tpolyhedron *p)
 Constructor. More...
 
void NewSegments (unsigned int n, double *x, double *y, double *z, Tcolor *c, Tpolyhedron *p)
 Constructor. More...
 
void CopyPolyhedron (Tpolyhedron *p_dst, Tpolyhedron *p_src)
 Copy constructor. More...
 
void TransformPolyhedron (THTransform *t, Tpolyhedron *p)
 Applies a homogenoeus transform to a polyhedron. More...
 
void GetPolyhedronCenter (double *c, Tpolyhedron *p)
 Gets the center of the spheres. More...
 
unsigned int GetPolyhedronType (Tpolyhedron *p)
 Retrives the type of a polyhedron. More...
 
void SetPolyhedronColor (Tcolor *c, Tpolyhedron *p)
 Changes the color of a polyhedron. More...
 
void GetPolyhedronColor (Tcolor *c, Tpolyhedron *p)
 Gets the color of a polyhedron. More...
 
unsigned int GetPolyhedronStatus (Tpolyhedron *p)
 Gets the status of a polyhedron (NORMAL, HIDDEN, DECOR). More...
 
void GetOFFInfo (unsigned int *nv, double ***v, unsigned int *nf, unsigned int **nvf, unsigned int ***fv, Tpolyhedron *p)
 Gets the OFF information. More...
 
unsigned int GetPolyhedronNVertex (Tpolyhedron *p)
 Gets the number of vertexes of a polyhedron. More...
 
void GetPolyhedronDefiningPoint (unsigned int i, double *point, Tpolyhedron *p)
 Gets a point defining a a object. More...
 
double GetPolyhedronRadius (Tpolyhedron *p)
 Returns the radius used in the definition of the object. More...
 
void GetPolyhedronVertex (unsigned int i, double *point, Tpolyhedron *p)
 Gets a vertex of a polyhedron. More...
 
double GetPolyhedronMaxCoordinate (Tpolyhedron *p)
 Returns the maximum coordinate value used in a polyhedron. More...
 
void PlotPolyhedron (Tplot3d *pt, Tpolyhedron *p)
 Adds the polyhedron to a 3D geometry. More...
 
void PolyhedronPrintCenter (FILE *f, THTransform *t, Tpolyhedron *p)
 Prints the center of a sphere to a file. More...
 
void PolyhedronPrintCenterAndCenter (FILE *f, THTransform *t, Tpolyhedron *p)
 Prints the center and the radius of a sphere to a file. More...
 
void MovePolyhedron (Tplot3d *pt, THTransform *t, Tpolyhedron *p)
 Moves an object previously added to a 3D scene. More...
 
void SavePolyhedron (char *fileName, Tpolyhedron *p)
 Stores the geometic information of a polyhedron into a file. More...
 
void PrintPolyhedron (FILE *f, char *path, char *label, unsigned int n, Tpolyhedron *p)
 Stores the polyhedron information into a file. More...
 
void DeletePolyhedron (Tpolyhedron *p)
 Destructor. More...
 

Function Documentation

boolean ReadGeneralMesh ( char *  fn,
Tpolyhedron p 
)

Constructs a convex polyhedrom from a general mesh file via the assimp library.

Parameters
fnThe file name from where to read the information.
pThe convex polyhedron to create.
Returns
TRUE if the file can be read successfully.

Definition at line 231 of file polyhedron.c.

References Error(), FALSE, Tpolyhedron::fv, Tpolyhedron::ne, NEW, Tpolyhedron::nf, Tpolyhedron::nv, Tpolyhedron::nvf, OFF, TRUE, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by InitPolyhedronFromFile().

void ReadSTL ( char *  fn,
Tpolyhedron p 
)

Constructs a convex polyhedrom from a binary STL file.

The parsing of the STL file is done following the instructions given here.

Parameters
fnThe file name from where to read the information.
pThe convex polyhedron to create.

Definition at line 287 of file polyhedron.c.

References Distance(), Error(), FALSE, Tpolyhedron::fv, Tpolyhedron::ne, NEW, Tpolyhedron::nf, Tpolyhedron::nv, Tpolyhedron::nvf, OFF, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by InitPolyhedronFromFile().

void ReadOFF ( FILE *  f,
Tpolyhedron 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
fThe file from where to read the information.
pThe convex polyhedron to create.

Definition at line 366 of file polyhedron.c.

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

Referenced by InitPolyhedronFromFile().

void GenerateCylinderOFF ( unsigned int  g,
Tpolyhedron 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
gThe granularity to use to create the polytope that approximates the cylinder.
pThe cylinder to approximate.

Definition at line 422 of file polyhedron.c.

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

Referenced by NewCylinder(), NewLine(), ReadCylinder(), and ReadLine().

void ReadLine ( FILE *  f,
Tpolyhedron 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 LINE.

Parameters
fThe file from where to read the information.
pThe convex polyhedron to create.

Definition at line 508 of file polyhedron.c.

References Tpolyhedron::center, GenerateCylinderOFF(), LINE, Tpolyhedron::p1, Tpolyhedron::p2, Tpolyhedron::rad, and Tpolyhedron::type.

Referenced by InitPolyhedronFromFile().

void ReadSegments ( FILE *  f,
Tpolyhedron 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 SEGMENT.

Parameters
fThe file from where to read the information.
pThe convex polyhedron to create.

Definition at line 529 of file polyhedron.c.

References Tpolyhedron::center, Tpolyhedron::maxCoord, Tpolyhedron::ne, NEW, Tpolyhedron::nf, Tpolyhedron::nv, Tpolyhedron::nvf, Tpolyhedron::p1, Tpolyhedron::p2, Tpolyhedron::rad, SEGMENTS, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by InitPolyhedronFromFile().

void ReadCylinder ( FILE *  f,
unsigned int  g,
Tpolyhedron 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
fThe file from where to read the information.
gThe granularity to use to create the polytope that approximates the cylinder.
pThe convex polyhedron to create.

Definition at line 572 of file polyhedron.c.

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

Referenced by InitPolyhedronFromFile().

void GenerateSphereOFF ( unsigned int  g,
Tpolyhedron 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
gThe granularity to use to create the polytope that approximates the sphere.
pThe sphere to approximate.

Definition at line 593 of file polyhedron.c.

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

Referenced by NewSphere(), and ReadSphere().

void ReadSphere ( FILE *  f,
unsigned int  g,
Tpolyhedron 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
fThe file from where to read the information.
gThe granularity to use to create the polytope that approximates the sphere.
pThe convex polyhedron to create.

Definition at line 709 of file polyhedron.c.

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

Referenced by InitPolyhedronFromFile().

void InitPolyhedronFromFile ( Tfilename fname,
Tcolor c,
unsigned int  gr,
unsigned int  bs,
Tpolyhedron p 
)

Define a Tpolyhedron from a file.

The default geometry file used in the CuikSuite are an variant of the geomview OFF files. Originally, the OFF files only include polygonal geometry (vertices and faces). We extended it to include also spheres, cylinders, lines and sets of 3D segments.

Additionally, the CuikSuite can natively read binary STL files.

Finally, if the Assimp libary is available we can read any of the file types supported by this libary. This includes, for instance, collada or blender files. The full list of supported file types is here. All those file formats are converted to a general OFF structure (vertices and faces).

Parameters
fnameThe name of the file from where to read the information.
cThe color of the object.
grThe granularity to define polyhedrons for spheres and cylinders.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 727 of file polyhedron.c.

References Tpolyhedron::color, CopyColor(), Error(), GetFileExtension(), GetFileFullName(), HIDDEN_SHAPE, NEW, NewColor(), NO_UINT, Tpolyhedron::obj3d, ReadCylinder(), ReadGeneralMesh(), ReadLine(), ReadOFF(), ReadSegments(), ReadSphere(), ReadSTL(), and Tpolyhedron::status.

Referenced by main().

void InitPolyhedronFromTriangles ( unsigned int  nv,
double **  v,
unsigned int  nt,
unsigned int **  t,
Tcolor c,
unsigned int  bs,
Tpolyhedron p 
)

Defines an OFF object from a set of triangles.

Parameters
nvNumber of vertexes defining the triangulated surface.
vThe 3D vertexes defining the surface.
ntNumber of triangles.
tThe triangle vertexes (indices of the vertexes defining the triangles).
cThe color of the sphere.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 801 of file polyhedron.c.

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

void NewBox ( double  xl,
double  yl,
double  zl,
double  xu,
double  yu,
double  zu,
Tcolor c,
unsigned int  bs,
Tpolyhedron p 
)

Defines an axis aligned box. The box is actually defined as an OFF. So, this function is just a convenient way to define OFFs for this simple shape.

Parameters
xlThe lower coordinate along the X axis.
ylThe lower coordinate along the Y axis.
zlThe lower coordinate along the Z axis.
xuThe upper coordinate along the X axis.
yuThe upper coordinate along the Y axis.
zuThe upper coordinate along the Z axis.
cThe color of the sphere.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 857 of file polyhedron.c.

References Tpolyhedron::center, Tpolyhedron::color, CopyColor(), Error(), Tpolyhedron::fv, Tpolyhedron::maxCoord, Tpolyhedron::ne, NEW, Tpolyhedron::nf, NO_UINT, Tpolyhedron::nv, Tpolyhedron::nvf, Tpolyhedron::obj3d, OFF, Tpolyhedron::p1, Tpolyhedron::p2, Tpolyhedron::rad, Tpolyhedron::status, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by main().

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

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

Parameters
rThe radius of the sphere.
centerThe center of the sphere.
cThe color of the sphere.
grThe granularity to define approximating polyhedrons for the sphere.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 926 of file polyhedron.c.

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

Referenced by InitWorldFromMolecule(), and main().

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

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

Parameters
rThe radius of the cylinder.
p1The initial point of the cylinder axis.
p2The final point of the cylinder axis.
cThe color of the cylinder.
grThe granularity to define approximating polyhedrons for the cylinder.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 950 of file polyhedron.c.

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

Referenced by InitWorldFromMolecule(), and main().

void NewLine ( double *  p1,
double *  p2,
Tcolor c,
unsigned int  bs,
Tpolyhedron p 
)

Defines a line.

Parameters
p1The initial point of the line.
p2The final point of the line.
cThe color of the line.
bsStatus of the body: NORMAL, HIDDEN, DECOR.
pThe polyhedron to create.

Definition at line 977 of file polyhedron.c.

References Tpolyhedron::center, Tpolyhedron::color, CopyColor(), GenerateCylinderOFF(), LINE, NO_UINT, Tpolyhedron::obj3d, Tpolyhedron::p1, Tpolyhedron::p2, Tpolyhedron::rad, Tpolyhedron::status, and Tpolyhedron::type.

void NewSegments ( unsigned int  n,
double *  x,
double *  y,
double *  z,
Tcolor c,
Tpolyhedron p 
)

Defines a set of segments.

Parameters
nThe number of points defining the segmetns
xThe x components of the segmets (2 entries per segment).
yThe x components of the segmets (2 entries per segment).
zThe x components of the segmets (2 entries per segment).
cThe color of the set of segments.
pThe polyhedron to create.

Definition at line 1004 of file polyhedron.c.

References Tpolyhedron::center, Tpolyhedron::color, CopyColor(), DECOR_SHAPE, Tpolyhedron::maxCoord, Tpolyhedron::ne, NEW, Tpolyhedron::nf, NO_UINT, Tpolyhedron::nv, Tpolyhedron::nvf, Tpolyhedron::obj3d, Tpolyhedron::p1, Tpolyhedron::p2, Tpolyhedron::rad, SEGMENTS, Tpolyhedron::status, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by InitWorldFromMolecule().

void CopyPolyhedron ( Tpolyhedron p_dst,
Tpolyhedron p_src 
)

Defines a polyhedron from another polyhedron.

Parameters
p_dstThe polyhedron to define.
p_srcThe polyhedron from where to copy.

Definition at line 1051 of file polyhedron.c.

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

Referenced by AddBody2Link(), and AddShape2Environment().

void TransformPolyhedron ( THTransform t,
Tpolyhedron p 
)

Applies a homogenoeus transform to a polyhedron.

Parameters
tThe transform to apply.
pThe polyhedron to transform.

Definition at line 1113 of file polyhedron.c.

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

Referenced by main().

void GetPolyhedronCenter ( double *  c,
Tpolyhedron p 
)

Gets the center of the spheres. When applied to other type of polyhedrons an error is triggered.

Parameters
c3D vector where to return the center.
pThe (sphere) polyhedron.

Definition at line 1145 of file polyhedron.c.

References Tpolyhedron::center, Error(), SPHERE, and Tpolyhedron::type.

Referenced by SolidCorrection(), and WorldAtomJacobian().

unsigned int GetPolyhedronType ( Tpolyhedron p)

Retrives the type of a polyhedron.

Parameters
pThe polyhedron to query.
Returns
The type of the polyhedron: OFF, SPHERE, CYLINDER, LINE, SEGMENTS.

Definition at line 1155 of file polyhedron.c.

References Tpolyhedron::type.

Referenced by AddBody2Link(), AddShape2Solid(), LinkNAtoms(), SolidCorrection(), and WorldAtomJacobian().

void SetPolyhedronColor ( Tcolor c,
Tpolyhedron p 
)

Changes the color of a polyhedron.

Parameters
cThe new color for the polyhedron.
pThe polyhedron to update.

Definition at line 1160 of file polyhedron.c.

References Tpolyhedron::color, and CopyColor().

void GetPolyhedronColor ( Tcolor c,
Tpolyhedron p 
)

Gets the color of a polyhedron.

Parameters
cThe color of the polyhedron.
pThe polyhedron to query.

Definition at line 1165 of file polyhedron.c.

References Tpolyhedron::color, and CopyColor().

Referenced by GetObstacleColor().

unsigned int GetPolyhedronStatus ( Tpolyhedron p)

Gets the status of a polyhedron (NORMAL, HIDDEN, DECOR).

Parameters
pThe polyhedron to query.
Returns
The status of a polyhedron.

Definition at line 1170 of file polyhedron.c.

References Tpolyhedron::status.

Referenced by AddBody2Link(), AddShape2Solid(), GetLinkBodyStatus(), GetObstacleShapeStatus(), SolidCorrection(), and VisibleLink().

void GetOFFInfo ( unsigned int *  nv,
double ***  v,
unsigned int *  nf,
unsigned int **  nvf,
unsigned int ***  fv,
Tpolyhedron p 
)

Returns the OFF information defining a shape (an OFF is the format for polyhedrons used in Geomview). Note that this can also be used for spheres and cylinders since they also have an OFF defined (a polygon approximating them).

This function returns pointers to the internal structures in the polyhedron. Use them with care (for query but without modifying them)

Parameters
nvNumber of vertexes in the OFF.
vVertexes defining the OFF.
nfNumber of faces in the OFF.
nvfNumber of vertexes for each face.
fvThe index of the vertexes for each face.
pThe polyhedron.

Definition at line 1175 of file polyhedron.c.

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

Referenced by AddShape2Solid(), InitPQPCD(), and InitVcollideCD().

unsigned int GetPolyhedronNVertex ( Tpolyhedron p)

Gets the number of vertexes of a polyhedron.

Parameters
pThe polyhedron to query.
Returns
The number of vertexes of a polyhedron.

Definition at line 1185 of file polyhedron.c.

References Tpolyhedron::nv.

void GetPolyhedronDefiningPoint ( unsigned int  i,
double *  point,
Tpolyhedron p 
)

Gets the coordinates of a point defining of a object.

A SEGMENTS is a set of segments defined by pairs of points. In this case one of the points defining the segment is returned.

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

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 polyhedron has less defining points than the requested number, this function triggers an error.

Parameters
iNumber of the defining point to retrive.
pointSpace to store the three coordinates of the requested vertex.
pThe polyhedron to query.

Definition at line 1190 of file polyhedron.c.

References Tpolyhedron::center, CYLINDER, Error(), GetPolyhedronVertex(), LINE, OFF, Tpolyhedron::p1, Tpolyhedron::p2, SEGMENTS, SPHERE, and Tpolyhedron::type.

Referenced by GetMechanismDefiningPoint(), and SolidCorrection().

double GetPolyhedronRadius ( Tpolyhedron p)

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

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

Definition at line 1232 of file polyhedron.c.

References Error(), LINE, OFF, Tpolyhedron::rad, SEGMENTS, and Tpolyhedron::type.

Referenced by AddShape2Solid().

void GetPolyhedronVertex ( unsigned int  i,
double *  point,
Tpolyhedron p 
)

Gets the coordinates of the vertex of a polyhedron.

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

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

Parameters
iNumber of the vertex to retrive.
pointSpace to store the three coordinates of the requested vertex.
pThe polyhedron to query.

Definition at line 1239 of file polyhedron.c.

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

Referenced by GetPolyhedronDefiningPoint().

double GetPolyhedronMaxCoordinate ( Tpolyhedron p)

Returns the maximum coordinate value (either in X, Y, or Z) used in a 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
pThe polyhedron to query.
Returns
The maximum coordinate value.

Definition at line 1250 of file polyhedron.c.

References Tpolyhedron::maxCoord.

Referenced by AddBody2Link(), and AddShape2Environment().

void PlotPolyhedron ( Tplot3d pt,
Tpolyhedron p 
)

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

Parameters
ptThe 3D geometry where to add the polyhedron.
pThe polyhedron to plot.

Definition at line 1255 of file polyhedron.c.

References Tpolyhedron::center, Close3dObject(), Tpolyhedron::color, CYLINDER, Tpolyhedron::fv, HIDDEN_SHAPE, LINE, Tpolyhedron::ne, Tpolyhedron::nf, Tpolyhedron::nv, Tpolyhedron::nvf, Tpolyhedron::obj3d, OFF, Tpolyhedron::p1, Tpolyhedron::p2, Plot3dObject(), PlotLine(), PlotSegments(), PlotSphere(), Tpolyhedron::rad, SEGMENTS, SPHERE, StartNew3dObject(), Tpolyhedron::status, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by PlotEnvironment(), and PlotLink().

void PolyhedronPrintCenter ( FILE *  f,
THTransform t,
Tpolyhedron p 
)

Prints the center of spheres to a file. Other types of polyhedrons are non considered (they are just skiped).

This is used only whent the world represents a molecule and we want to store the atom (i.e., the sphere) positions into a file.

This is also useful to get particular points from configurations of mechanisms (we just put a sphere on the point and then use cuiksamples2atoms to convert configurations to samples.

Note that the sphere centers are translated to gobal coordinates before printing them.

Parameters
fThe file where to store the sphere center.
tThe transform to get the global coordinates of the center.
pThe polyhedron to process.

Definition at line 1285 of file polyhedron.c.

References Tpolyhedron::center, HTransformApply(), SPHERE, and Tpolyhedron::type.

Referenced by LinkPrintAtoms().

void PolyhedronPrintCenterAndCenter ( FILE *  f,
THTransform t,
Tpolyhedron p 
)

Prints the center of spheres and the radius to a file. Other types of polyhedrons are non considered (they are just skiped).

This is an auxiliary function of LinkStoreAtoms.

Parameters
fThe file where to store the sphere center.
tThe transform to get the global coordinates of the center.
pThe polyhedron to process.

Definition at line 1297 of file polyhedron.c.

References Tpolyhedron::center, HTransformApply(), Tpolyhedron::rad, SPHERE, and Tpolyhedron::type.

Referenced by LinkStoreAtoms().

void MovePolyhedron ( Tplot3d pt,
THTransform t,
Tpolyhedron p 
)

Moves an object previously added to a 3D scene.

Parameters
ptThe 3D geometry where the polyhedron was added.
tThe homogeneous transform to apply to the polyhedron.
pThe polyhedron to move.

Definition at line 1309 of file polyhedron.c.

References HIDDEN_SHAPE, Move3dObject(), NO_UINT, Tpolyhedron::obj3d, and Tpolyhedron::status.

Referenced by MoveLinkFromTransform().

void SavePolyhedron ( char *  fileName,
Tpolyhedron p 
)

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

Parameters
fileNameName of the file where to store the geometric information.
pThe polyhedron to save.

Definition at line 1315 of file polyhedron.c.

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

Referenced by main(), and PrintPolyhedron().

void PrintPolyhedron ( FILE *  f,
char *  path,
char *  label,
unsigned int  n,
Tpolyhedron p 
)

Stores the polyhedron information into a file in the format valid to be read by InitWorldFromFile.

Spheres and cylinders are directly written, but OFFs are stored in a separate file.

Parameters
fThe file where to store the information.
pathThe working folder.
labelSting identifying the entity containing the polyhedron.
nIdentifier of the polyhedron in the link.
pThe polyhedron to save.

Definition at line 1366 of file polyhedron.c.

References Tpolyhedron::center, Tpolyhedron::color, CreateFileName(), CYLINDER, DECOR_SHAPE, DeleteFileName(), Error(), FALSE, GetBlue(), GetFileFullName(), GetGreen(), GetRed(), HIDDEN_SHAPE, LINE, NEW, NORMAL_SHAPE, Tpolyhedron::nv, OFF, OFF_EXT, Tpolyhedron::p1, Tpolyhedron::p2, Print3Reals(), Tpolyhedron::rad, SavePolyhedron(), SEGMENTS, SPHERE, Tpolyhedron::status, TRUE, Tpolyhedron::type, and Tpolyhedron::v.

Referenced by PrintEnvironment(), and PrintLink().

void DeletePolyhedron ( Tpolyhedron p)

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

Parameters
pThe polyhedron to delete.

Definition at line 1484 of file polyhedron.c.

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

Referenced by DeleteEnvironment(), DeleteLink(), InitWorldFromMolecule(), and main().