File: index.html

package info (click to toggle)
g2 0.61-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,828 kB
  • ctags: 1,037
  • sloc: ansic: 8,262; sh: 2,708; makefile: 222; perl: 186; fortran: 183; cpp: 34
file content (150 lines) | stat: -rw-r--r-- 13,446 bytes parent folder | download
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
<!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">
</head><body>
<!-- Generated by Doxygen 1.3.6 -->
<div class="qindex"><a class="qindexHL" href="index.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
<h1>g2 Documentation</h1>
<p>
<h3 align="center">0.6x </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 &amp; 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 graphic library</li><li>Simple to use</li><li>Supports several types of output devices (currently X11, PostScript, devices supported by gd <a href="http://www.boutell.com/gd/">http://www.boutell.com/gd/</a> (PNG, JPEG), FIG (<a href="http://www.xfig.org">http://www.xfig.org</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>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. This library provides a comprehensive set of functions for simultaneous generation of graphical output on different types of devices. Presently, following devices are currently supported by g2: X11, gd (PNG and JPEG), PostScript and FIG (xfig). 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 devices will 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>
<pre class="fragment"><div>                                   /-------&gt; PNG:   <a class="code" href="group__vd.html#ga7">g2_attach</a>(id_PNG,..
            ----------------------- 
g2_plot---&gt; | Virtual device: <span class="keywordtype">id</span>  |--------&gt; X11:   <a class="code" href="group__vd.html#ga7">g2_attach</a>(id_X11,...
            -----------------------
                                   \-------&gt; PS:    <a class="code" href="group__vd.html#ga7">g2_attach</a>(id_PS,...
</div></pre><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 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 mirrorsite. 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>
LINUX<p>
<ol>
<li>Either install RPM packet with binaries, or compile as described in the UNIX section</li></ol>
<p>
UNIX<p>
<ol>
<li>Extract package with gzip -dc g2-xxxx.tar.gz | tar xvf -</li><li>Run './configure'</li><li>Optionally run 'make depend'</li><li>Run 'make'</li><li>Run 'make install' or copy libg2.a and <a class="el" href="g2_8h.html">g2.h</a>, <a class="el" href="g2__X11_8h.html">g2_X11.h</a>, <a class="el" href="g2__gd_8h.html">g2_gd.h</a>, anf <a class="el" href="g2__PS_8h.html">g2_PS.h</a> to the default locations for library and include files.</li><li>Optional: cd to demo directory and run 'make demo' to compile demo applications</li></ol>
<p>
WINDOWS NT<p>
<ol>
<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 Unix 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>
<p>
PERL (old instructions)<p>
<ol>
<li>Change to directory g2_perl</li><li>Perform following steps<ol>
<li>perl Makefile.PL</li><li>make</li><li>make test</li><li>make install</li></ol>
</li><li>See the <a class="el" href="index.html#perl">Perl interface</a> section for more information</li><li>swig is also supported, more details are comming ...</li></ol>
<p>
VMS<p>
<ol>
<li>Try to extract either the tar.gz or the zip distribution (whatever is easier for you)</li><li>type mms to compile library (descrip.mms file is suplied)</li><li>run mms 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>
<pre class="fragment"><div><span class="preprocessor">#include &lt;g2.h&gt;</span>
<span class="preprocessor">#include &lt;g2_PS.h&gt;</span>

main()
{
    <span class="keywordtype">int</span> <span class="keywordtype">id</span>;
    <span class="keywordtype">id</span> = <a class="code" href="group__PS.html#ga0">g2_open_PS</a>(<span class="stringliteral">"rect.ps"</span>, g2_A4, g2_PS_land); 
    <a class="code" href="group__graphic.html#ga36">g2_rectangle</a>(<span class="keywordtype">id</span>, 20, 20, 150, 150); 
    <a class="code" href="group__device.html#ga9">g2_close</a>(<span class="keywordtype">id</span>);
}
</div></pre><p>
<ul>
<li>Always include &lt;<a class="el" href="g2_8h.html">g2.h</a>&gt;. Additionally include header files for all types of devices you want to use.</li><li>Open devices using g2_open_XY functions. 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#ga9">g2_close()</a> to close device.</li><li>Consider turning off auto flush (<a class="el" href="group__device.html#ga10">g2_set_auto_flush()</a>) for improved performance.</li></ul>
<p>
You want to draw a PNG file instead of a PostScript file ?<p>
replace the PS header file with<p>
<pre class="fragment"><div><span class="preprocessor">#include &lt;g2_gd.h&gt;</span>
</div></pre><p>
and replace the g2_open_PS function call with<p>
<pre class="fragment"><div><span class="keywordtype">id</span> = <a class="code" href="group__GD.html#ga0">g2_open_gd</a>(<span class="stringliteral">"rect.png"</span>, 300, 200, g2_gd_png);
</div></pre><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 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 PNG and PostScript device. You can attach and detatch further devices at any time.<p>
<pre class="fragment"><div><span class="preprocessor">#include &lt;g2.h&gt;</span>
<span class="preprocessor">#include &lt;g2_PS.h&gt;</span>
<span class="preprocessor">#include &lt;g2_gd.h&gt;</span>

main()
{
    <span class="keywordtype">int</span> id_PS,id_PNG,<span class="keywordtype">id</span>;

    id_PS  = <a class="code" href="group__PS.html#ga0">g2_open_PS</a>(<span class="stringliteral">"rect.ps"</span>, g2_A4, g2_PS_land);
    id_PNG = <a class="code" href="group__GD.html#ga0">g2_open_gd</a>(<span class="stringliteral">"rect.png"</span>, 300, 200, g2_gd_png);
    <span class="keywordtype">id</span>     = <a class="code" href="group__vd.html#ga6">g2_open_vd</a>();

    <a class="code" href="group__vd.html#ga7">g2_attach</a>(<span class="keywordtype">id</span>, id_PS);
    <a class="code" href="group__vd.html#ga7">g2_attach</a>(<span class="keywordtype">id</span>, id_PNG);

    <a class="code" href="group__graphic.html#ga36">g2_rectangle</a>(<span class="keywordtype">id</span>, 20, 20, 150, 150);
    <a class="code" href="group__graphic.html#ga40">g2_circle</a>(<span class="keywordtype">id</span>, 50, 60, 100);

    <a class="code" href="group__device.html#ga9">g2_close</a>(<span class="keywordtype">id</span>);
}
</div></pre><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, etc. can be found in the distribution (demo directory).<h3><a class="anchor" name="fortran">
Fortran interface</a></h3>
The Fortran interface for g2 is currently tested for Linux and Digital Unix/OSF. Function names for Fortran are the same as in C, however following differences exist:<p>
all variables including device IDs are of type REAL void functions are implemented as subroutines and must be called with CALL constants defined by #define in C (e.g. g2_A4) do not work. Get corresponding values from the apropriate header files.<p>
A short Fortran example:<p>
<pre class="fragment"><div>        program demo
        real d,color
        d=<a class="code" href="group__PS.html#ga0">g2_open_PS</a>('demo_f.ps', 4.0, 1.0)
        call <a class="code" href="group__graphic.html#ga28">g2_plot</a>(d, 50.0, 50.0)
        call <a class="code" href="group__graphic.html#ga46">g2_string</a>(d, 25.0, 75.0, 'TEST ')
        color=<a class="code" href="group__color.html#ga16">g2_ink</a>(d, 1.0, 0.0, 0.0)
        write (6,*) color
        call <a class="code" href="group__color.html#ga17">g2_pen</a>(d, color)
        call <a class="code" href="group__graphic.html#ga40">g2_circle</a>(d, 20.0, 20.0, 10.0)
        call <a class="code" href="group__control.html#ga11">g2_flush</a>(d)
        call <a class="code" href="group__device.html#ga9">g2_close</a>(d)
        stop
        end
</div></pre><h3><a class="anchor" name="perl">
Perl interface (old info)</a></h3>
The perl interface for g2 is currently tested for Linux and Digital Unix/OSF. Function names in perl are the same as in C, however the device itself is implemented object orientated, i.e. the device argument is ommited in all functions. E.g., following simple perl script:<p>
<pre class="fragment"><div>use G2;

$d = newX11 G2::Device(100,100);
$d-&gt;circle(10, 10, 20);
$d-&gt;string(20, 40, <span class="stringliteral">"Hello World"</span>);

print <span class="stringliteral">"\nDone.\n[Enter]\n"</span>;
getc(STDIN);

$d-&gt;close()
</div></pre><p>
The creator functions are newX11, newGIF, newPS, etc. and accept the same arguments as the open functions in the C version. See the perl documentation (perldoc G2) for more details and the test.pl script for a more extensive example.<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 (spline implementation): tijs/vimec-nl</li></ul>
<p>
or visit 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 Thu Apr 8 23:32:49 2004 for g2 by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 > 
</a>1.3.6 </small></address>
</body>
</html>