CXXR (C++ R)
Rgraphics.h
1 /*CXXR $Id: Rgraphics.h 1348 2013-02-25 17:49:03Z arr $
2  *CXXR
3  *CXXR This file is part of CXXR, a project to refactor the R interpreter
4  *CXXR into C++. It may consist in whole or in part of program code and
5  *CXXR documentation taken from the R project itself, incorporated into
6  *CXXR CXXR (and possibly MODIFIED) under the terms of the GNU General Public
7  *CXXR Licence.
8  *CXXR
9  *CXXR CXXR is Copyright (C) 2008-13 Andrew R. Runnalls, subject to such other
10  *CXXR copyrights and copyright restrictions as may be stated below.
11  *CXXR
12  *CXXR CXXR is not part of the R project, and bugs and other issues should
13  *CXXR not be reported via r-bugs or other R project channels; instead refer
14  *CXXR to the CXXR website.
15  *CXXR */
16 
17 /*
18  * R : A Computer Language for Statistical Data Analysis
19  * Copyright (C) 1995, 1996 Robert Gentleman and Ross Ihaka
20  * Copyright (C) 1998--2008 R Core Team
21  *
22  * This program is free software; you can redistribute it and/or modify
23  * it under the terms of the GNU Lesser General Public License as published by
24  * the Free Software Foundation; either version 2.1 of the License, or
25  * (at your option) any later version.
26  *
27  * This program is distributed in the hope that it will be useful,
28  * but WITHOUT ANY WARRANTY; without even the implied warranty of
29  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30  * GNU Lesser General Public License for more details.
31  *
32  * You should have received a copy of the GNU Lesser General Public License
33  * along with this program; if not, a copy is available at
34  * http://www.r-project.org/Licenses/
35  */
36 
37 #ifndef RGRAPHICS_H_
38 #define RGRAPHICS_H_
39 
40 /* This was a public header in R < 2.8.0, but no longer */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46  /* possible coordinate systems (for specifying locations) */
47 typedef enum {
48  DEVICE = 0, /* native device coordinates (rasters) */
49  NDC = 1, /* normalised device coordinates x=(0,1), y=(0,1) */
50  INCHES = 13, /* inches x=(0,width), y=(0,height) */
51  NIC = 6, /* normalised inner region coordinates (0,1) */
52  OMA1 = 2, /* outer margin 1 (bottom) x=NIC, y=LINES */
53  OMA2 = 3, /* outer margin 2 (left) */
54  OMA3 = 4, /* outer margin 3 (top) */
55  OMA4 = 5, /* outer margin 4 (right) */
56  NFC = 7, /* normalised figure region coordinates (0,1) */
57  NPC = 16, /* normalised plot region coordinates (0,1) */
58  USER = 12, /* user/data/world coordinates;
59  * x,=(xmin,xmax), y=(ymin,ymax) */
60  MAR1 = 8, /* figure margin 1 (bottom) x=USER(x), y=LINES */
61  MAR2 = 9, /* figure margin 2 (left) x=USER(y), y=LINES */
62  MAR3 = 10, /* figure margin 3 (top) x=USER(x), y=LINES */
63  MAR4 = 11, /* figure margin 4 (right) x=USER(y), y=LINES */
64 
65  /* possible, units (for specifying dimensions) */
66  /* all of the above, plus ... */
67 
68  LINES = 14, /* multiples of a line in the margin (mex) */
69  CHARS = 15 /* multiples of text height (cex) */
70 } GUnit;
71 
72 #define currentFigureLocation Rf_currentFigureLocation
73 #define GArrow Rf_GArrow
74 #define GBox Rf_GBox
75 #define GCheckState Rf_GCheckState
76 #define GCircle Rf_GCircle
77 #define GClip Rf_GClip
78 #define GClipPolygon Rf_GClipPolygon
79 #define GConvert Rf_GConvert
80 #define GConvertX Rf_GConvertX
81 #define GConvertXUnits Rf_GConvertXUnits
82 #define GConvertY Rf_GConvertY
83 #define GConvertYUnits Rf_GConvertYUnits
84 #define GExpressionHeight Rf_GExpressionHeight
85 #define GExpressionWidth Rf_GExpressionWidth
86 #define GForceClip Rf_GForceClip
87 #define GLine Rf_GLine
88 #define GLocator Rf_GLocator
89 #define GLPretty Rf_GLPretty
90 #define GMapUnits Rf_GMapUnits
91 #define GMapWin2Fig Rf_GMapWin2Fig
92 #define GMathText Rf_GMathText
93 #define GMetricInfo Rf_GMetricInfo
94 #define GMMathText Rf_GMMathText
95 #define GMode Rf_GMode
96 #define GMtext Rf_GMtext
97 #define GNewPlot Rf_GNewPlot
98 #define GPath Rf_GPath
99 #define GPolygon Rf_GPolygon
100 #define GPolyline Rf_GPolyline
101 #define GPretty Rf_GPretty
102 #define GRect Rf_GRect
103 #define GRaster Rf_GRaster
104 #define GReset Rf_GReset
105 #define GRestore Rf_GRestore
106 #define GRestorePars Rf_GRestorePars
107 #define GSavePars Rf_GSavePars
108 #define GScale Rf_GScale
109 #define GSetState Rf_GSetState
110 #define GSetupAxis Rf_GSetupAxis
111 #define GStrHeight Rf_GStrHeight
112 #define GStrWidth Rf_GStrWidth
113 #define GSymbol Rf_GSymbol
114 #define GText Rf_GText
115 #define GVStrHeight Rf_GVStrHeight
116 #define GVStrWidth Rf_GVStrWidth
117 #define GVText Rf_GVText
118 
119 #define xDevtoNDC Rf_xDevtoNDC
120 #define xDevtoNFC Rf_xDevtoNFC
121 #define xDevtoNPC Rf_xDevtoNPC
122 #define xDevtoUsr Rf_xDevtoUsr
123 #define xNPCtoUsr Rf_xNPCtoUsr
124 #define yDevtoNDC Rf_yDevtoNDC
125 #define yDevtoNFC Rf_yDevtoNFC
126 #define yDevtoNPC Rf_yDevtoNPC
127 #define yDevtoUsr Rf_yDevtoUsr
128 #define yNPCtoUsr Rf_yNPCtoUsr
129 
130 
131 /*-------------------------------------------------------------------
132  *
133  * GPAR FUNCTIONS are concerned with operations on the
134  * entire set of graphics parameters for a device
135  * (e.g., initialisation, saving, and restoring)
136  *
137  * From graphics.c, used in plot.c.
138  */
139 
140 /* Reset the current graphical parameters from the default ones: */
141 void GRestore(pGEDevDesc);
142 /* Make a temporary copy of the current parameters */
143 void GSavePars(pGEDevDesc);
144 /* Restore the temporary copy saved by GSavePars */
145 void GRestorePars(pGEDevDesc);
146 
147 
148 /*-------------------------------------------------------------------
149  *
150  * DEVICE STATE FUNCTIONS are concerned with getting and setting
151  * the current state of the device; is it ready to be drawn into?
152  *
153  * From graphics.c, used in plot.c.
154  */
155 
156 /* has plot.new been called yet? */
157 void GCheckState(pGEDevDesc);
158 /* Set to 1 when plot.new succeeds
159  * Set to 0 when don't want drawing to go ahead */
160 void GSetState(int, pGEDevDesc);
161 
162 
163 
164 /*-------------------------------------------------------------------
165  *
166  * GRAPHICAL PRIMITIVES are the generic front-end for the functions
167  * that every device driver must provide.
168  *
169  * NOTE that locations supplied to these functions may be in any
170  * of the valid coordinate systems (each function takes a "coords"
171  * parameter to indicate the coordinate system); the device-specific
172  * version of the function is responsible for calling GConvert to get
173  * the location into device coordinates.
174  *
175  * From graphics.c, used in plot.c.
176  */
177 
178 
179 /* Draw a circle, centred on (x,y) with radius r (in inches). */
180 void GCircle(double, double, GUnit, double, int, int, pGEDevDesc);
181 /* Set clipping region (based on current setting of dd->gp.xpd).
182  * Only clip if new clipping region is different from the current one */
183 void GClip(pGEDevDesc);
184 /* Polygon clipping: */
185 int GClipPolygon(double *, double *, int, int, int,
186  double *, double *, pGEDevDesc);
187 /* Always clips */
188 void GForceClip(pGEDevDesc);
189 /* Draw a line from (x1,y1) to (x2,y2): */
190 void GLine(double, double, double, double, GUnit, pGEDevDesc);
191 /* Return the location of the next mouse click: */
192 Rboolean GLocator(double*, double*, GUnit, pGEDevDesc);
193 /* Return the height, depth, and width of the specified
194  * character in the specified units: */
195 void GMetricInfo(int, double*, double*, double*, GUnit, pGEDevDesc);
196 /* Set device "mode" (drawing or not drawing) here for windows and mac drivers.
197  */
198 void GMode(int, pGEDevDesc);
199 /* Draw a path using the specified lists of x and y values: */
200 void GPath(double*, double*, int, int*, Rboolean, int, int, pGEDevDesc);
201 /* Draw a polygon using the specified lists of x and y values: */
202 void GPolygon(int, double*, double*, GUnit, int, int, pGEDevDesc);
203 /* Draw series of straight lines using the specified lists of x and y values: */
204 void GPolyline(int, double*, double*, GUnit, pGEDevDesc);
205 /* Draw a rectangle given two opposite corners: */
206 void GRect(double, double, double, double, GUnit, int, int, pGEDevDesc);
207 /* Draw a raster image given two opposite corners: */
208 void GRaster(unsigned int*, int, int,
209  double, double, double, double,
210  double, Rboolean, pGEDevDesc);
211 /* Return the height of the specified string in the specified units: */
212 double GStrHeight(const char *, cetype_t, GUnit, pGEDevDesc);
213 /* Return the width of the specified string in the specified units */
214 double GStrWidth(const char *, cetype_t, GUnit, pGEDevDesc);
215 /* Draw the specified text at location (x,y) with the specified
216  * rotation and justification: */
217 void GText(double, double, GUnit, const char *, cetype_t, double, double, double,
218  pGEDevDesc);
219 
220 /* From plotmath.c, used in plot.c */
221 void GMathText(double, double, int, SEXP, double, double, double, pGEDevDesc);
222 void GMMathText(SEXP, int, double, int, double, int, double, pGEDevDesc);
223 
224 
225 /*-------------------------------------------------------------------
226  *
227  * GRAPHICAL UTILITIES are functions that produce graphical output
228  * using the graphical primitives (i.e., they are generic - NOT
229  * device-specific).
230  *
231  * From graphics.c, used in plot.c.
232  */
233 
234 /* Draw a line from (x1,y1) to (x2,y2) with an arrow head
235  * at either or both ends. */
236 void GArrow(double, double, double, double, GUnit, double, double, int, pGEDevDesc);
237 /* Draw a box around specified region:
238  * 1=plot region, 2=figure region, 3=inner region, 4=device. */
239 void GBox(int, pGEDevDesc);
240 /* Return a "nice" min, max and number of intervals for a given
241  * range on a linear or _log_ scale, respectively: */
242 void GPretty(double*, double*, int*); /* used in plot3d.c */
243 void GLPretty(double*, double*, int*);
244 /* Draw text in margins. */
245 void GMtext(const char *, cetype_t, int, double, int, double, int, double, pGEDevDesc);
246 /* Draw one of the predefined symbols (circle, square, diamond, ...) */
247 void GSymbol(double, double, GUnit, int, pGEDevDesc);
248 
249 /* From plotmath.c, used in plot.c */
250 double GExpressionHeight(SEXP, GUnit, pGEDevDesc);
251 double GExpressionWidth(SEXP, GUnit, pGEDevDesc);
252 
253 
254 
255 /*----------------------------------------------------------------------
256  *
257  * TRANSFORMATIONS are concerned with converting locations between
258  * coordinate systems and dimensions between different units.
259  *
260  * From graphics.c, used in par.c, plot.c, plot3d.c
261  */
262 
263 /* Convert an R unit (e.g., "user") into an internal unit (e.g., USER)> */
264 GUnit GMapUnits(int);
265 /* Convert a LOCATION from one coordinate system to another: */
266 void GConvert(double*, double*, GUnit, GUnit, pGEDevDesc);
267 double GConvertX(double, GUnit, GUnit, pGEDevDesc);
268 double GConvertY(double, GUnit, GUnit, pGEDevDesc);
269 /* Convert an x/y-dimension from one set of units to another: */
270 double GConvertXUnits(double, GUnit, GUnit, pGEDevDesc);
271 double GConvertYUnits(double, GUnit, GUnit, pGEDevDesc);
272 
273 /* Set up the different regions on a device (i.e., inner region,
274  * figure region, plot region) and transformations for associated
275  * coordinate systems (called whenever anything that affects the
276  * coordinate transformations changes):
277  */
278 void GReset(pGEDevDesc);
279 
280 /* Set up the user coordinate transformations: */
281 void GMapWin2Fig(pGEDevDesc);
282 /* Set up the device for a new plot by Resetting graphics parameters
283  * and Resetting the regions and coordinate Systems */
284 pGEDevDesc GNewPlot(Rboolean);
285 /* Set up the user coordinates based on the axis limits */
286 void GScale(double, double, int, pGEDevDesc);
287 /* Set up the axis limits based on the user coordinates */
288 void GSetupAxis(int, pGEDevDesc);
289 /* Return row and column of current figure in the layout matrix */
290 void currentFigureLocation(int*, int*, pGEDevDesc);
291 
292 /* which of these conversions should be public? maybe all? [NO_REMAP] */
293 double xDevtoNDC(double, pGEDevDesc);
294 double yDevtoNDC(double, pGEDevDesc);
295 double xDevtoNFC(double, pGEDevDesc);
296 double yDevtoNFC(double, pGEDevDesc);
297 double xDevtoNPC(double, pGEDevDesc);
298 double yDevtoNPC(double, pGEDevDesc);
299 double xDevtoUsr(double, pGEDevDesc);
300 double yDevtoUsr(double, pGEDevDesc);
301 double xNPCtoUsr(double, pGEDevDesc);
302 double yNPCtoUsr(double, pGEDevDesc);
303 
304 #ifdef __cplusplus
305 }
306 #endif
307 
308 #endif /* RGRAPHICS_H_ */