1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>g2: Main Page</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.4.6 -->
<div class="tabs">
<ul>
<li id="current"><a href="index.html"><span>Main Page</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li><a href="pages.html"><span>Related Pages</span></a></li>
</ul></div>
<h1>g2 Documentation</h1>
<p>
<h3 align="center">0.7x </h3><h2><a class="anchor" name="licence">
License Notice</a></h2>
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *<p>
Copyright (C) 1998-2004 Ljubomir Milanovic & Horst Wagner.<h2><a class="anchor" name="introduction">
Introduction</a></h2>
<h3><a class="anchor" name="what">
What is g2 ?</a></h3>
<h4><a class="anchor" name="short">
Short version (if you are in hurry)</a></h4>
<ul>
<li>2D graphics library</li><li>Simple to use</li><li>Supports several types of output devices (currently X11, PostScript, devices supported by <a href="http://www.boutell.com/gd">gd</a> (PNG, JPEG), <a href="http://www.xfig.org">FIG</a> and MS Windows windows)</li><li>Concept allows easy implementation of new device types</li><li>Virtual devices allow to send output simultaneously to several devices</li><li>User definable coordinate system</li><li>Written in ANSI-C</li><li>Tested under Digital Unix, AIX, Linux, VMS and Windows NT</li><li>Perl support</li><li>Python support</li><li>Fortran interface</li></ul>
<h4><a class="anchor" name="long">
Long version</a></h4>
g2 is a simple to use graphics library for 2D graphical applications written in Ansi-C. It provides a comprehensive set of functions for simultaneous generation of graphical output on different types of devices. Currently, the following devices are supported by g2: X11, PostScript, <a href="http://www.boutell.com/gd">gd</a> (PNG and JPEG), <a href="http://www.xfig.org">FIG</a> and MSWindows. One major feature of the g2 library is the concept of virtual devices. An arbitrary number of physical devices (such as PostScript or X11) can be grouped to create a so-called virtual device. Commands sent to such a virtual device are automatically issued to all attached physical devices. This allows for example simultaneous output to a PNG file and a PostScript file. A virtual device in turn can be attached to another virtual device, allowing to construct trees of devices. Virtual devices can also be useful when using different user-coordinate systems. E.g. one X11 window showing an overview of a graphical output, and a second window showing a zoom of a more detailed area of the graphic. Drawing in both windows is performed by one single command to the virtual device.<p>
<div class="fragment"><pre class="fragment"> /-------> PNG: <a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(id_PNG,..
-----------------------
<a class="code" href="group__graphic.html#g72fe3325f5927565723b8bb655d6f9aa">g2_plot</a>---> | Virtual device: <span class="keywordtype">id</span> |--------> X11: <a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(id_X11,...
-----------------------
\-------> PS: <a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(id_PS,...
</pre></div><p>
If you don't need or like the concept of virtual devices, simply ignore it.<h2><a class="anchor" name="getting">
Getting Started</a></h2>
<h3><a class="anchor" name="preinstallation">
Preinstallation tasks:</a></h3>
PNG and JPEG support<p>
g2 uses the gd library by Thomas Boutell to generate PNG and JPEG files. This package is freeware (however, not GPL) and can be downloaded at <a href="http://www.boutell.com/gd/.">http://www.boutell.com/gd/.</a> Linux users might prefer to install a pre-compiled gd rpm package which should be available at your local RedHat mirror site. NT users should install the gd source package in a subdirectory named "gd" which should be located in the same directory as the g2 subdirectory (but not in the g2 directory itself). Otherwise, file locations for gd must be modified in the g2 project workspace. Unix and VMS users will have to build and install gd according to the instructions found in the gd distribution.<h3><a class="anchor" name="installation">
Installation</a></h3>
<h4><a class="anchor" name="Linux">
Linux</a></h4>
<ol type=1>
<li>Either install RPM packet with binaries, or compile as described in the <a class="el" href="index.html#Unix">Unix</a> section</li></ol>
<h4><a class="anchor" name="Unix">
Unix</a></h4>
<ol type=1>
<li>Extract package with <code>gzip -dc g2-xxxx.tar.gz | tar xvf -</code></li><li>Run <code>./configure</code></li><li>Optionally run <code>make depend</code></li><li>Run <code>make</code> </li><li>Run <code>make install</code>, or copy libg2.a/so and <a class="el" href="g2_8h-source.html">g2.h</a>, <a class="el" href="g2__X11_8h-source.html">g2_X11.h</a>, <a class="el" href="g2__PS_8h-source.html">g2_PS.h</a>, <a class="el" href="g2__gd_8h-source.html">g2_gd.h</a> and <a class="el" href="g2__FIG_8h-source.html">g2_FIG.h</a> to the default locations for library and include files</li><li>Optionally <code>cd</code> to demo directory and run <code>make</code> </li></ol>
<h4><a class="anchor" name="Windows">
Windows NT</a></h4>
<ol type=1>
<li>Extract package using either the .tar.gz or the .zip distribution</li><li>MS Visual C++ users can build both library and demos with the supplied project file: g2.dsw (to obtain an icon and use menu functions, you must also build the g2res project in g2.dsw)</li><li>Users of gcc or other commandline based compilers with make support continue as in <a class="el" href="index.html#Unix">Unix</a> example</li><li>It is also possible to compile g2 on winNT/95 using the free cygwin32 library and a X-windows library for Windows. Theoretically it should be possible to support both X-windows and native NT/95 windows at the same time.</li></ol>
<h4><a class="anchor" name="Perl">
Perl (old instructions)</a></h4>
<ol type=1>
<li>Change to directory g2_perl</li><li>Perform following steps<ul>
<li><code>perl Makefile.PL</code></li><li><code>make</code></li><li><code>make test</code></li><li><code>make install</code></li></ul>
</li><li>See the <a class="el" href="index.html#perl">Perl interface</a> section for more information</li></ol>
<h4><a class="anchor" name="Python">
Python</a></h4>
<ol type=1>
<li>Make sure you have Python installed (note: SWIG is <b>not</b> needed)</li><li>Build g2 as described above (see <a class="el" href="index.html#installation">Installation</a>)</li><li>Change to directory g2_python</li><li>Type<ul>
<li>on Linux:<ul>
<li><code>make</code> to build g2 Python module</li><li><code>make demo</code> to test g2 Python module</li><li><code>make install</code> to install g2 Python module (you must be <b>root</b>)</li></ul>
</li><li>on Windows (you need Visual Studio when using the standard Python release for Windows):<ul>
<li><code>setup.py "compile options" "link options" install</code></li></ul>
</li></ul>
</li><li>If you link your g2 Python module against <code>libg2.so</code>, and you are unwilling or unable to do an install, you need to tell the g2 Python module where to look for it, either with <code>ldconfig</code>, or with the <code>LD_LIBRARY_PATH</code> environment variable</li><li>See the <a class="el" href="index.html#python">Python interface</a> section for more information</li></ol>
<h4><a class="anchor" name="VMS">
VMS</a></h4>
<ol type=1>
<li>Try to extract either the .tar.gz or the .zip distribution (whatever is easier for you)</li><li>Type <code>mms</code> to compile library (descrip.mms file is supplied)</li><li>Run <code>mms</code> in demo directory to compile demo applications</li></ol>
<h3><a class="anchor" name="simple">
A simple example</a></h3>
The following example is a minimal application. It draws a rectangle in a PostScript file.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <g2.h></span>
<span class="preprocessor">#include <g2_PS.h></span>
main()
{
<span class="keywordtype">int</span> id;
<span class="keywordtype">id</span> = <a class="code" href="group__PS.html#gda2bc748f9389d18e321bb128dde870d">g2_open_PS</a>(<span class="stringliteral">"rect.ps"</span>, <a class="code" href="group__PS.html#gg147a33ff8f46822ca27813fe0ac690aac5411ceeb3a7af0a92163d20b52dfa15">g2_A4</a>, <a class="code" href="group__PS.html#ggb9b3e4d201b82db4770d6f2ec3f2ba8eac4814a6ad4c6afff7c3f0c27a753f41">g2_PS_land</a>);
<a class="code" href="group__graphic.html#gc3f4b85588f4386c38e9921204cab604">g2_rectangle</a>(<span class="keywordtype">id</span>, 20, 20, 150, 150);
<a class="code" href="group__device.html#g178c2872b2fdaca92980a3b8bd6141b5">g2_close</a>(<span class="keywordtype">id</span>);
}
</pre></div><p>
<ul>
<li>Always include <<a class="el" href="g2_8h-source.html">g2.h</a>>. Additionally include header files for all types of devices you want to use.</li><li>Open devices using g2_open_XY functions.<br>
The open function returns a device id of type int, which you need to refer to the device.</li><li>Call <a class="el" href="group__device.html#g178c2872b2fdaca92980a3b8bd6141b5">g2_close()</a> to close device.</li><li>Consider turning off auto flush (<a class="el" href="group__device.html#g63b5d9b2ba3a0280c225e79a6be2e901">g2_set_auto_flush()</a>) for improved performance.</li></ul>
<p>
You want to draw a PNG file instead of a PostScript file ? Replace the PS header file with<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <g2_gd.h></span>
</pre></div><p>
and replace the call to <a class="el" href="group__PS.html#gda2bc748f9389d18e321bb128dde870d">g2_open_PS()</a> with<p>
<div class="fragment"><pre class="fragment"><span class="keywordtype">id</span> = <a class="code" href="group__GD.html#gff0703f99796214de86e90476a623329">g2_open_gd</a>(<span class="stringliteral">"rect.png"</span>, 300, 200, <a class="code" href="group__GD.html#ggfeeff2ea4a0b345e44279ce12a64224237389d17d24315c869b266b21e8eefda">g2_gd_png</a>);
</pre></div><p>
You want to draw to a PNG file and a PostScript file with one plot command ?<p>
Here we use the concept of virtual devices. Open a PNG and a PostScript device, then open a virtual device and attach both the PNG and PostScript device to the virtual device. Plot commands to the virtual device will be issued to both the PNG and the PostScript device. You can attach and detach further devices at any time.<p>
<div class="fragment"><pre class="fragment"><span class="preprocessor">#include <g2.h></span>
<span class="preprocessor">#include <g2_PS.h></span>
<span class="preprocessor">#include <g2_gd.h></span>
main()
{
<span class="keywordtype">int</span> id_PS,id_PNG,id;
id_PS = <a class="code" href="group__PS.html#gda2bc748f9389d18e321bb128dde870d">g2_open_PS</a>(<span class="stringliteral">"rect.ps"</span>, <a class="code" href="group__PS.html#gg147a33ff8f46822ca27813fe0ac690aac5411ceeb3a7af0a92163d20b52dfa15">g2_A4</a>, <a class="code" href="group__PS.html#ggb9b3e4d201b82db4770d6f2ec3f2ba8eac4814a6ad4c6afff7c3f0c27a753f41">g2_PS_land</a>);
id_PNG = <a class="code" href="group__GD.html#gff0703f99796214de86e90476a623329">g2_open_gd</a>(<span class="stringliteral">"rect.png"</span>, 300, 200, <a class="code" href="group__GD.html#ggfeeff2ea4a0b345e44279ce12a64224237389d17d24315c869b266b21e8eefda">g2_gd_png</a>);
<span class="keywordtype">id</span> = <a class="code" href="group__vd.html#g140fb10e1c95834e3f2380bb4103ce4b">g2_open_vd</a>();
<a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(<span class="keywordtype">id</span>, id_PS);
<a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(<span class="keywordtype">id</span>, id_PNG);
<a class="code" href="group__graphic.html#gc3f4b85588f4386c38e9921204cab604">g2_rectangle</a>(<span class="keywordtype">id</span>, 20, 20, 150, 150);
<a class="code" href="group__graphic.html#g674df70a144d3fd3e421d3a0dd40734e">g2_circle</a>(<span class="keywordtype">id</span>, 50, 60, 100);
<a class="code" href="group__device.html#g178c2872b2fdaca92980a3b8bd6141b5">g2_close</a>(<span class="keywordtype">id</span>);
}
</pre></div><p>
Note: closing a virtual device automatically closes all attached devices.<h4><a class="anchor" name="more">
More examples</a></h4>
More examples showing the usage of different user coordinate systems, multiple virtual devices, splines, etc. can be found in the distribution (demo directory).<h3><a class="anchor" name="fortran">
Fortran interface</a></h3>
The Fortran interface for g2 has currently been tested on Linux and Digital Unix/OSF. Function names for Fortran are the same as in C, however the following differences exist:<p>
<ul>
<li>All variables, including device IDs, are of type <code>REAL</code> </li><li>Void functions are implemented as subroutines and must be called with <code>CALL</code> </li><li>Constants defined by <code>#define</code> in C (e.g. <a class="el" href="group__PS.html#gg147a33ff8f46822ca27813fe0ac690aac5411ceeb3a7af0a92163d20b52dfa15">g2_A4</a>) do not work. Get corresponding values from the appropriate header files.</li></ul>
<p>
A short Fortran example:<p>
<div class="fragment"><pre class="fragment"> program demo
real d,color
d=<a class="code" href="group__PS.html#gda2bc748f9389d18e321bb128dde870d">g2_open_PS</a>('demo_f.ps', 4.0, 1.0)
call <a class="code" href="group__graphic.html#g72fe3325f5927565723b8bb655d6f9aa">g2_plot</a>(d, 50.0, 50.0)
call <a class="code" href="group__graphic.html#g08987c8a1ffa556d8bf917f2a9dd6b2a">g2_string</a>(d, 25.0, 75.0, 'TEST ')
color=<a class="code" href="group__color.html#g85f53048c6eb057e1ebdaeed53e3e5d9">g2_ink</a>(d, 1.0, 0.0, 0.0)
write (6,*) color
call <a class="code" href="group__color.html#g23fb2c58c675c566a16f8e9f738f102e">g2_pen</a>(d, color)
call <a class="code" href="group__graphic.html#g674df70a144d3fd3e421d3a0dd40734e">g2_circle</a>(d, 20.0, 20.0, 10.0)
call <a class="code" href="group__control.html#gc7db6077da6b358b4b67f08f4b5b093e">g2_flush</a>(d)
call <a class="code" href="group__device.html#g178c2872b2fdaca92980a3b8bd6141b5">g2_close</a>(d)
stop
end
</pre></div><h3><a class="anchor" name="perl">
Perl interface (old info)</a></h3>
The Perl interface for g2 has currently been tested on Linux and Digital Unix/OSF. Function names in Perl are the same as in C, however the device itself is implemented object oriented, i.e. the device argument is omitted in all functions. Cf. the following simple Perl script:<p>
<div class="fragment"><pre class="fragment">use G2;
$d = newX11 G2::Device(100,100);
$d->circle(10, 10, 20);
$d->string(20, 40, <span class="stringliteral">"Hello World"</span>);
print <span class="stringliteral">"\nDone.\n[Enter]\n"</span>;
getc(STDIN);
$d->close()
</pre></div><p>
The creator functions are <code>newX11</code>, <code>newGIF</code>, <code>newPS</code>, etc. and accept the same arguments as the open functions in the C version. See the Perl documentation (<code>perldoc G2</code>) for more details and the test.pl script for a more extensive example.<h3><a class="anchor" name="python">
Python interface</a></h3>
Function names in Python are the same as in C, however the device itself is implemented object oriented, i.e. the device argument is omitted in all methods. An object is instantiated with one of the <code>g2_open_</code> functions. Here is a simple Python script:<p>
<div class="fragment"><pre class="fragment"><span class="keyword">import</span> sys
from g2 <span class="keyword">import</span> *
X11 = <a class="code" href="group__X11.html#gb36e635122fa975ef0f4c646a15314bb">g2_open_X11</a>(822, 575)
PS = <a class="code" href="group__PS.html#gda2bc748f9389d18e321bb128dde870d">g2_open_PS</a>('foo.ps', <a class="code" href="group__PS.html#gg147a33ff8f46822ca27813fe0ac690aac5411ceeb3a7af0a92163d20b52dfa15">g2_A4</a>, <a class="code" href="group__PS.html#ggb9b3e4d201b82db4770d6f2ec3f2ba8eac4814a6ad4c6afff7c3f0c27a753f41">g2_PS_land</a>)
graph = <a class="code" href="group__vd.html#g140fb10e1c95834e3f2380bb4103ce4b">g2_open_vd</a>()
graph.<a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(X11)
graph.<a class="code" href="group__vd.html#g7b455ab14d94ad12443c7f3e7520607b">g2_attach</a>(PS)
graph.<a class="code" href="group__graphic.html#gb875f61c7378088b09cd17e687f90fc2">g2_line</a>(30, 30, 90, 90)
graph.<a class="code" href="group__graphic.html#g674df70a144d3fd3e421d3a0dd40734e">g2_circle</a>(60, 60, 30)
X11.<a class="code" href="group__color.html#g23fb2c58c675c566a16f8e9f738f102e">g2_pen</a>(X11.<a class="code" href="group__color.html#g85f53048c6eb057e1ebdaeed53e3e5d9">g2_ink</a>(.75, .2, 0))
graph.<a class="code" href="group__graphic.html#g7176a055b45bcdf718eced277e9c3469">g2_polygon</a>([60, 30, 30, 60, 60, 90, 90, 60])
graph.<a class="code" href="group__control.html#gc9b97c37c7d9d6328e2778ddff86fb95">g2_set_dash</a>([20, 12])
sqrts = [100, 100, 225, 150, 400, 200, 625, 250]
graph.<a class="code" href="group__graphic.html#gdafb426bd26b996c0ef4bb6cb74e3b7f">g2_poly_line</a>(sqrts)
graph.<a class="code" href="group__graphic.html#gca2cdab23b7f4544b2766920af126bc6">g2_image</a>(640, 252, [[2, 4, 6],[3, 6, 9],[4, 8, 12]])
graph.<a class="code" href="group__control.html#gc7db6077da6b358b4b67f08f4b5b093e">g2_flush</a>()
print 'Done.\n[Enter]'
sys.stdin.read(1)
graph.<a class="code" href="group__device.html#g178c2872b2fdaca92980a3b8bd6141b5">g2_close</a>()
</pre></div><p>
In C, many functions expect a pointer to a buffer of <code>double</code>'s and an <code>int</code> stating the number of points in this buffer. In Python, these functions are passed just a list of <code>float</code>s. You need not specify the number of points: Python knows the length of the list.<p>
Full documentation, including sample code, is available from the interactive Python prompt:<p>
<div class="fragment"><pre class="fragment">$ python
>>> <span class="keyword">import</span> g2
>>> help(g2)
</pre></div><p>
Here functions with a Python specific form (e.g. <a class="el" href="group__control.html#g4a8930f7774ed7e4b1598b0b8072039e">g2_query_pointer()</a>) are marked as such.<h2><a class="anchor" name="Contact">
Contact</a></h2>
You can contact the authors and contributors by e-mail (/ is @ and - is .):<p>
<ul>
<li>Ljubomir Milanovic: ljubo/users-sourceforge-net</li><li>Horst Wagner: wagner/users-sourceforge-net</li><li>Tijs Michels (<a class="el" href="group__splines.html">spline</a> implementation and <a class="el" href="index.html#python">Python</a> wrapper): tijs/users-sourceforge-net</li></ul>
<p>
or visit the g2 home page on: <a href="http://g2.sourceforge.net/">http://g2.sourceforge.net/</a> <hr size="1"><address style="align: right;"><small>Generated on Tue Oct 17 21:27:48 2006 for g2 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.6 </small></address>
</body>
</html>
|