plot.c File Reference

Detailed Description

Implementation of the functions to generate 2d plots.

See Also
Tplot, plot.h.

Definition in file plot.c.

Macros

#define CM2POINTS   450.0 /*number of points of each cm in Xfig*/
 Scale factor between centimiters and xfig units. More...
 
#define POINTS2CM   (1.0/CM2POINTS)
 Scale factor between xfig units and centimiters. More...
 
#define USER2XFIG(x, y, p)
 Converts a x-y point in R^2 into a xfig point. More...
 
#define PRINTXFIGPREAMBLE(p)
 Writes a preamble common to all xfig elements. More...
 

Functions

void InitPlot (const char *name, Tplot *p)
 Constructor. More...
 
void SetLineWidth (unsigned int width, Tplot *p)
 Changes the current line width. More...
 
void SetLineStyle (unsigned int style, Tplot *p)
 Changes the current line stype. More...
 
void SetOrigin (double offset_x, double offset_y, Tplot *p)
 Changes the current origin of the plot. More...
 
void SetPenColor (int color, Tplot *p)
 Changes the current pen color. More...
 
void SetFillColor (int color, Tplot *p)
 Changes the current fill color. More...
 
void SetFillIntensity (unsigned int intensity, Tplot *p)
 Changes the current fill intensity. More...
 
void SetDepth (unsigned int depth, Tplot *p)
 Changes the current plot depth. More...
 
void PlotCircle (double cx, double cy, double r, Tplot *p)
 Plots a circle. More...
 
void PlotRectangle (double x_left, double y_sup, double x_right, double y_inf, Tplot *p)
 Plots a rectangle. More...
 
void PlotTriangle (double x1, double y1, double x2, double y2, double x3, double y3, Tplot *p)
 Plots a triangle. More...
 
void PlotLine (double x0, double y0, double x1, double y1, Tplot *p)
 Plots a segment. More...
 
void PlotArrow (double x0, double y0, double x1, double y1, Tplot *p)
 Plots a segment with an arrow. More...
 
void PlotText (double x, double y, const char *text, Tplot *p)
 Plots a text. More...
 
void PlotAxis (const char *nx, double min_x, double max_x, const char *ny, double min_y, double max_y, double step, Tplot *p)
 Plots a X-Y axis. More...
 
void ClosePlot (Tplot *p)
 Destructor. More...
 

Macro Definition Documentation

#define CM2POINTS   450.0 /*number of points of each cm in Xfig*/

Scale factor between centimiters and xfig units.

Definition at line 23 of file plot.c.

Referenced by PlotCircle().

#define POINTS2CM   (1.0/CM2POINTS)

Scale factor between xfig units and centimiters.

Definition at line 30 of file plot.c.

Referenced by PlotRectangle().

#define USER2XFIG (   x,
  y,
 
)
Value:
(signed int)(((p)->offset_x+(x))*CM2POINTS),\
(signed int)(((p)->offset_y-(y))*CM2POINTS)
#define CM2POINTS
Scale factor between centimiters and xfig units.
Definition: plot.c:23

Converts a x-y point in R^2 into a xfig point.

Parameters
xX-coordinate for the R^2 point.
yY-coordinate for the R^2 point.
pThe plot.

Definition at line 41 of file plot.c.

Referenced by PlotArrow(), PlotCircle(), PlotLine(), PlotRectangle(), PlotText(), and PlotTriangle().

#define PRINTXFIGPREAMBLE (   p)
Value:
fprintf((p)->f," %d %d %d %d %d -1 %d %f ",\
(p)->line_style,(p)->line_width,(p)->pen_color,\
(p)->fill_color,(p)->depth,(p)->fill_intensity,\
(((p)->line_style==SOLID_LINE)?0.0:4.0))
#define SOLID_LINE
Solid line in 2d.
Definition: plot.h:27

Writes a preamble common to all xfig elements with the line style, line width,....

Parameters
pThe plot.

Definition at line 52 of file plot.c.

Referenced by PlotArrow(), PlotCircle(), PlotLine(), PlotRectangle(), and PlotTriangle().

Function Documentation

void InitPlot ( const char *  name,
Tplot p 
)

Initilizes a plot with

Parameters
nameName for the file where to store the plot.
pThe plot to initialize.

Definition at line 60 of file plot.c.

References Tplot::depth, Tplot::f, Tplot::fill_color, Tplot::fill_intensity, Tplot::line_style, Tplot::line_width, Tplot::offset_x, Tplot::offset_y, Tplot::pen_color, and SOLID_LINE.

Referenced by main().

void SetLineWidth ( unsigned int  width,
Tplot p 
)

Changes the current line width. It will be used to plot elements from this point on.

Parameters
widthNew line width.
pThe plot to update.

Definition at line 97 of file plot.c.

References Tplot::line_width.

void SetLineStyle ( unsigned int  style,
Tplot p 
)

Changes the current line style. It will be used to plot elements from this point on.

Parameters
styleNew line style. Possible styles are SOLID_LINE, DASHED_LINE, DOTTED_LINE
pThe plot to update.
See Also
defines.h

Definition at line 105 of file plot.c.

References Tplot::line_style.

Referenced by PlotAxis().

void SetOrigin ( double  offset_x,
double  offset_y,
Tplot p 
)

Changes the current origin of the plot. Elements from now on will be refered to this new origin.

Parameters
offset_xNew offset in x for the origin.
offset_yNew offset in y for the origin.
pThe plot to update.

Definition at line 116 of file plot.c.

References Tplot::offset_x, and Tplot::offset_y.

Referenced by main().

void SetPenColor ( int  color,
Tplot p 
)

Changes the current pen color. Elements from now on will be plotted with this color. Possible colors are:

  • -1:default 0:black 1:blue 2:green 3:cyan 4:red 5 magenta 6 yellow 7 white 8 blue4 9 blue3 10 blue2 11 ltblue 12 green4 12 green3 14 green2 15 cyan4 16 cyan3 17 cyan2 18 read4 19 read3 20 read2 21 magenta4 22 magenta3 23 magenta2 24 brown4 25 brown3 26 brown2 27 pink4 28 pink3 29 pink2 30 pink 31 gold.
Parameters
colorThe new pen color.
pThe plot to update.

Definition at line 122 of file plot.c.

References Tplot::pen_color.

void SetFillColor ( int  color,
Tplot p 
)

Changes the current fill color. Elements from now on will be filled with this color. Possible colors are:

  • -1:default 0:black 1:blue 2:green 3:cyan 4:red 5 magenta 6 yellow 7 white 8 blue4 9 blue3 10 blue2 11 ltblue 12 green4 12 green3 14 green2 15 cyan4 16 cyan3 17 cyan2 18 read4 19 read3 20 read2 21 magenta4 22 magenta3 23 magenta2 24 brown4 25 brown3 26 brown2 27 pink4 28 pink3 29 pink2 30 pink 31 gold.
Parameters
colorThe new fill color.
pThe plot to update.

Definition at line 128 of file plot.c.

References Tplot::fill_color.

void SetFillIntensity ( unsigned int  intensity,
Tplot p 
)

Changes the current fill intensity. Elements from now on will be filled with this intensity. The valid ranges for intensities are [0,20] with 0 no-fill and 20 full_fill.

Parameters
intensityThe new fill intensity.
pThe plot to update.

Definition at line 134 of file plot.c.

References Tplot::fill_intensity.

void SetDepth ( unsigned int  depth,
Tplot p 
)

Changes the current plot depth. Elements from now on will be plotted at this depth.

Parameters
depthThe new depth.
pThe plot to update.

Definition at line 141 of file plot.c.

References Tplot::depth.

void PlotCircle ( double  cx,
double  cy,
double  r,
Tplot p 
)

Adds a circle to a plot.

Parameters
cxX coordinate for the center of the circle.
cyY coordinate for the center of the circle.
rRadius for the circle.
pThe plot to update.

Definition at line 149 of file plot.c.

References CM2POINTS, Tplot::f, PRINTXFIGPREAMBLE, and USER2XFIG.

void PlotRectangle ( double  x_left,
double  y_sup,
double  x_right,
double  y_inf,
Tplot p 
)

Adds a rectangle to a plot.

Parameters
x_leftX-lower coordinate.
y_supY-upper coordinate.
x_rightX-upper coordinate.
y_infY-lower coordinate.
pThe plot to update.

Definition at line 165 of file plot.c.

References Tplot::f, POINTS2CM, PRINTXFIGPREAMBLE, and USER2XFIG.

Referenced by main().

void PlotTriangle ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3,
Tplot p 
)

Adds a triangle to a plot.

Parameters
x1X coordinate for the first point of the triangle.
y1Y coordinate for the first point of the triangle.
x2X coordinate for the second point of the triangle.
y2Y coordinate for the second point of the triangle.
x3X coordinate for the third point of the triangle.
y3Y coordinate for the third point of the triangle.
pThe plot to update.

Definition at line 194 of file plot.c.

References Tplot::f, PRINTXFIGPREAMBLE, and USER2XFIG.

void PlotLine ( double  x0,
double  y0,
double  x1,
double  y1,
Tplot p 
)

Adds a segment to a plot.

Parameters
x0X coordinate for the origin of the segment.
y0Y coordinate for the origin of the segment.
x1X coordinate for the end of the segment.
y1Y coordinate for the end of the segment.
pThe plot to update.

Definition at line 215 of file plot.c.

References Tplot::f, PRINTXFIGPREAMBLE, and USER2XFIG.

Referenced by PlotAxis(), and PlotPolyhedron().

void PlotArrow ( double  x0,
double  y0,
double  x1,
double  y1,
Tplot p 
)

Adds a segment with an arrow at the end to a plot.

Parameters
x0X coordinate for the origin of the arrow.
y0Y coordinate for the origin of the arrow.
x1X coordinate for the end of the arrow.
y1Y coordinate for the end of the arrow.
pThe plot to update.

Definition at line 227 of file plot.c.

References Tplot::f, PRINTXFIGPREAMBLE, and USER2XFIG.

Referenced by PlotAxis().

void PlotText ( double  x,
double  y,
const char *  text,
Tplot p 
)

Adds a text with to a plot.

Parameters
xX coordinate for the text.
yY coordinate for the text.
textThe text to plot.
pThe plot to update.

Definition at line 239 of file plot.c.

References Tplot::f, and USER2XFIG.

Referenced by PlotAxis().

void PlotAxis ( const char *  nx,
double  min_x,
double  max_x,
const char *  ny,
double  min_y,
double  max_y,
double  step,
Tplot p 
)

Adds X-Y axis to the plot.

Parameters
nxLabel for the X axis.
min_xValue at which the X axis have to start.
max_xValue at which the X axis have to end.
nyLabel for the Y axis.
min_yValue at which the Y axis have to start.
max_yValue at which the Y axis have to end.
stepSeparation between ticks along the axis.
pThe plot to update.

Definition at line 247 of file plot.c.

References PlotArrow(), PlotLine(), PlotText(), SetLineStyle(), and SOLID_LINE.

Referenced by main().

void ClosePlot ( Tplot p)

Flushes the information to the output file, closes the file, and frees all the allocated memory for the plot structure.

Parameters
pThe plot to close.

Definition at line 275 of file plot.c.

References Tplot::f.

Referenced by main().