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

The CuikSuite Project

plot3d.c File Reference

Implementation of the functions operating on Tplot3d. More...

#include "plot3d.h"
#include "error.h"
#include <stdlib.h>
#include <string.h>
#include <math.h>

Go to the source code of this file.

Functions

void InitPlot3d (char *name, boolean axes, int argc, char **arg, Tplot3d *p)
 Constructor.
void Start3dBlock (Tplot3d *p)
 Starts a block of commands.
void Close3dBlock (Tplot3d *p)
 Ends a block of commands.
void Delete3dObject (unsigned int nobj, Tplot3d *p)
 Deletes a previously created geometric object.
unsigned int StartNew3dObject (Tcolor *c, Tplot3d *p)
 Start a composed object.
void Close3dObject (Tplot3d *p)
 Closes a composed object.
void SetColor3dObject (unsigned int nobj, Tcolor *c, Tplot3d *p)
 Changes the color of an object.
void Delay3dObject (double t, Tplot3d *p)
 Introduces a delay in the generation of the geometry.
void Move3dObject (unsigned int nobj, THTransform *t, Tplot3d *p)
 Moves a 3d object.
void PlotBox3d (double min_x, double max_x, double min_y, double max_y, double min_z, double max_z, Tplot3d *p)
 Adds an axis aligned box to the current object.
void PlotTriangle3d (double x1, double y1, double z1, double x2, double y2, double z2, double x3, double y3, double z3, Tplot3d *p)
 Adds a triangle to the current object.
void Plot3dObject (unsigned int nv, unsigned int nf, unsigned int ne, double **v, unsigned int *nvf, unsigned int **fv, Tplot3d *p)
 Adds a polytope to the current object.
void PlotSphere (double r, double x, double y, double z, Tplot3d *p)
 Adds a sphere to the current object.
void PlotCylinder (double r, double *p1, double *p2, Tplot3d *p)
 Adds a cylinder to the current object.
void PlotVect3d (unsigned int n, double *x, double *y, double *z, Tplot3d *p)
 Adds a polyline to the current object.
void Take3dSnapshot (char *name, Tplot3d *p)
 Takes a screenshot of the geometry.
void ClosePlot3d (boolean quit, double average_x, double average_y, double average_z, Tplot3d *p)
 Destructor.

Detailed Description

Implementation of the functions to generate 3d plots.

See also:
Tplot3d, plot3d.h.

Definition in file plot3d.c.


Function Documentation

void InitPlot3d ( char *  name,
boolean  axes,
int  argc,
char **  arg,
Tplot3d p 
)

Definition at line 34 of file plot3d.c.

References Tplot3d::color, DCP3D_G, DCP3D_R, Error(), Tplot3d::f, FALSE, Tplot3d::fileName, Tplot3d::inObject, NEW, NewColor(), and Tplot3d::nobj.

Referenced by AnimateWorld(), and main().

Here is the call graph for this function:

Here is the caller graph for this function:

void Start3dBlock ( Tplot3d p  ) 

Starts a block of commands that have to be executed simultaneously. Commands are, for instance, the generation of new geometry of the transformation/deletion of existing objects.

Parameters:
p The plot to update.

Definition at line 117 of file plot3d.c.

References Tplot3d::f.

Referenced by AnimateWorld(), MoveMechanism(), and PlotMechanism().

Here is the caller graph for this function:

void Close3dBlock ( Tplot3d p  ) 

Ends a block of commands that have to be executed simultaneously.

Parameters:
p The plot to update.

Definition at line 122 of file plot3d.c.

References Tplot3d::f.

Referenced by AnimateWorld(), MoveMechanism(), and PlotMechanism().

Here is the caller graph for this function:

void Delete3dObject ( unsigned int  nobj,
Tplot3d p 
)

Deletes a previously created geometric object. This is used when creating animations.

Parameters:
nobj The identifier of the object to be deleted (i.e., the return of StartNew3dObject when the object was created).
p The plot to update.

Definition at line 128 of file plot3d.c.

References Tplot3d::f, and Tplot3d::fileName.

unsigned int StartNew3dObject ( Tcolor c,
Tplot3d p 
)

Start the definition of a geometric object composed by one or more basic geometric elements.

Parameters:
c Color for the object.
p The plot to update.
Returns:
The identifier of the started object.

Definition at line 133 of file plot3d.c.

References Close3dObject(), Tplot3d::color, CopyColor(), Tplot3d::f, Tplot3d::fileName, Tplot3d::inObject, Tplot3d::nobj, and TRUE.

Referenced by main(), PlotCPolyhedron(), PlotJoint(), and PlotLink().

Here is the call graph for this function:

Here is the caller graph for this function:

void Close3dObject ( Tplot3d p  ) 

Ends the definition of a geometric object composed by many basic geometric elements.

Parameters:
p The plot to update.

Definition at line 147 of file plot3d.c.

References Tplot3d::color, Tplot3d::f, FALSE, Tplot3d::fileName, Tplot3d::inObject, Tplot3d::nobj, and SetColor3dObject().

Referenced by ClosePlot3d(), PlotCPolyhedron(), PlotJoint(), PlotLink(), and StartNew3dObject().

Here is the call graph for this function:

Here is the caller graph for this function:

void SetColor3dObject ( unsigned int  nobj,
Tcolor c,
Tplot3d p 
)

Changes the color of an object.

Parameters:
nobj The object identifier as returned by StartNew3dObject.
c Color for the object.
p The plot to update.

Definition at line 160 of file plot3d.c.

References Tplot3d::f, Tplot3d::fileName, Tplot3d::inObject, and PrintColor().

Referenced by Close3dObject().

Here is the call graph for this function:

Here is the caller graph for this function:

void Delay3dObject ( double  t,
Tplot3d p 
)

Introduces a delay in the generation of the geometry. Used for animations.

Parameters:
t Length in seconds of the delay.
p The plot to update.

Definition at line 172 of file plot3d.c.

References Tplot3d::f.

Referenced by AnimateWorld().

Here is the caller graph for this function:

void Move3dObject ( unsigned int  nobj,
THTransform t,
Tplot3d p 
)

Moves a 3d object.

Parameters:
nobj The identifier of the object to move, as returned by StartNew3dObject.
t The homogenous transoform to apply to the object.
p The plot to update.

Definition at line 178 of file plot3d.c.

References Tplot3d::f, Tplot3d::fileName, and HTransformPrintT().

Referenced by MoveCPolyhedron(), MoveJoint(), and MoveLink().

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotBox3d ( double  min_x,
double  max_x,
double  min_y,
double  max_y,
double  min_z,
double  max_z,
Tplot3d p 
)

Adds an axis aligned box to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

Parameters:
min_x Lower limit for the box along the X axis.
max_x Upper limit for the box along the X axis.
min_y Lower limit for the box along the Y axis.
max_y Upper limit for the box along the Y axis.
min_z Lower limit for the box along the Z axis.
max_z Upper limit for the box along the Z axis.
p The plot to update.

Definition at line 185 of file plot3d.c.

References Error(), Tplot3d::f, and Tplot3d::inObject.

Referenced by main().

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotTriangle3d ( double  x1,
double  y1,
double  z1,
double  x2,
double  y2,
double  z2,
double  x3,
double  y3,
double  z3,
Tplot3d p 
)

Adds triangle to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

Parameters:
x1 X coordinate for the first point of the triangle.
y1 Y coordinate for the first point of the triangle.
z1 Z coordinate for the first point of the triangle.
x2 X coordinate for the second point of the triangle.
y2 Y coordinate for the second point of the triangle.
z2 Z coordinate for the second point of the triangle.
x3 X coordinate for the third point of the triangle.
y3 Y coordinate for the third point of the triangle.
z3 Z coordinate for the third point of the triangle.
p The plot to update.

Definition at line 217 of file plot3d.c.

References Error(), Tplot3d::f, and Tplot3d::inObject.

Here is the call graph for this function:

void Plot3dObject ( unsigned int  nv,
unsigned int  nf,
unsigned int  ne,
double **  v,
unsigned int *  nvf,
unsigned int **  fv,
Tplot3d p 
)

Adds polytope to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

What we denote as polytope are geomview OFFs.

Parameters:
nv Number of vertexes of the polytope.
nf Number of faces of the polytope.
ne Number of edges of the polytope (not used).
v Pointer to 3d array with the (x,y,z) coordinates of the vertexes.
nvf Pointer to an array with the number of vertexes for each face.
fv Pointer to an array with the vertexes for each face.
p The plot to update.

Definition at line 237 of file plot3d.c.

References Error(), Tplot3d::f, and Tplot3d::inObject.

Referenced by PlotCPolyhedron().

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotSphere ( double  r,
double  x,
double  y,
double  z,
Tplot3d p 
)

Adds sphere to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

Parameters:
r The radius of the sphere.
x The X component of the center of the sphere.
y The Y component of the center of the sphere.
z The Z component of the center of the sphere.
p The plot to update.

Definition at line 265 of file plot3d.c.

References Error(), Tplot3d::f, and Tplot3d::inObject.

Referenced by PlotCPolyhedron(), and PlotJoint().

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotCylinder ( double  r,
double *  p1,
double *  p2,
Tplot3d p 
)

Adds cylinder to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

Parameters:
r The radius of the cylinder.
p1 Array with the (x,y,z) point where the cylinder has to start.
p2 Array with the (x,y,z) point where the cylinder has to end.
p The plot to update.

Definition at line 273 of file plot3d.c.

References Error(), Tplot3d::f, HTransformDelete(), HTransformPrintT(), HTransformX2Vect(), and Tplot3d::inObject.

Referenced by PlotCPolyhedron(), and PlotJoint().

Here is the call graph for this function:

Here is the caller graph for this function:

void PlotVect3d ( unsigned int  n,
double *  x,
double *  y,
double *  z,
Tplot3d p 
)

Adds polyline (i.e., a collection of concatenated lines) to the current object. This command can only be used in between a call to StartNew3dObject and the corresponding call to Close3dObject.

Parameters:
n Number of points defining the polyline.
x Array with the x component for the points in the polyline.
y Array with the y component for the points in the polyline.
z Array with the z component for the points in the polyline.
p The plot to update.

Definition at line 291 of file plot3d.c.

References Tplot3d::color, Error(), Tplot3d::f, Tplot3d::inObject, and PrintColor().

Referenced by PlotLink().

Here is the call graph for this function:

Here is the caller graph for this function:

void Take3dSnapshot ( char *  file,
Tplot3d p 
)

Takes a screenshot of the geometry. Used to create videos from animations.

The screenshot format are .ppm files that can be browsed/manipulated easily.

Parameters:
file Name of the file where to store the snapshot.
p The plot to update.

Definition at line 312 of file plot3d.c.

References Tplot3d::f.

void ClosePlot3d ( boolean  quit,
double  average_x,
double  average_y,
double  average_z,
Tplot3d p 
)

Closes a 3d plot. Before closing the file, all geometric objects are offset by (average_x,average_y,average_z). This is used to center the scene in the (0,0,0) and facilitates the on-line manipulation (rotations, translations,...) using geomview.

Parameters:
quit TRUE if we want to quit geomview right after displaying the geometry. Used to quit after an animation.
average_x X translation to apply to all objects in the scene before closing the plot.
average_y Y translation to apply to all objects in the scene before closing the plot.
average_z Z translation to apply to all objects in the scene before closing the plot.
p The plot to update.

Definition at line 318 of file plot3d.c.

References Close3dObject(), Tplot3d::f, Tplot3d::fileName, and Tplot3d::nobj.

Referenced by AnimateWorld(), and main().

Here is the call graph for this function:

Here is the caller graph for this function: