~ubuntu-branches/ubuntu/maverick/swig1.3/maverick

« back to all changes in this revision

Viewing changes to Examples/GIFPlot/Interface/gifplot.i

  • Committer: Bazaar Package Importer
  • Author(s): Torsten Landschoff
  • Date: 2002-03-29 01:56:07 UTC
  • Revision ID: james.westby@ubuntu.com-20020329015607-c0wt03xu8oy9ioj7
Tags: upstream-1.3.11
ImportĀ upstreamĀ versionĀ 1.3.11

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Graphics module
 
3
//
 
4
%module gifplot
 
5
%{
 
6
#include "gifplot.h"
 
7
%}
 
8
 
 
9
/* Pixel is 8-bits */
 
10
 
 
11
typedef unsigned char Pixel;
 
12
typedef float Zvalue;
 
13
 
 
14
/* ------------------------------------------------------------------------
 
15
   ColorMap
 
16
 
 
17
   Definition and methods for colormaps
 
18
   ------------------------------------------------------------------------ */
 
19
 
 
20
typedef struct ColorMap {
 
21
  char          *name;
 
22
 
 
23
//
 
24
// %addmethods adds some C methods to this structure to make it
 
25
// look like a C++ class in Python.
 
26
// These are really named things like ColorMap_default, ColorMap_assign, etc...
 
27
 
 
28
  %addmethods {
 
29
    ColorMap(char *filename);
 
30
    ~ColorMap();
 
31
#if defined(SWIGJAVA ) || defined(SWIGPHP4)
 
32
    %name(make_default) void        default();
 
33
#else
 
34
    void        default();
 
35
#endif
 
36
    void        assign(int index,int r, int g, int b);
 
37
    %name(__getitem__)  int getitem(int index);
 
38
    %name(__setitem__)  void setitem(int index, int value);
 
39
    int         write(char *filename);
 
40
  }
 
41
} ColorMap;
 
42
 
 
43
/* Some default colors */
 
44
 
 
45
#define BLACK   0
 
46
#define WHITE   1
 
47
#define RED     2
 
48
#define GREEN   3
 
49
#define BLUE    4
 
50
#define YELLOW  5
 
51
#define CYAN    6
 
52
#define MAGENTA 7
 
53
 
 
54
/*-------------------------------------------------------------------------
 
55
  FrameBuffer
 
56
 
 
57
  This structure defines a simple 8 bit framebuffer.  
 
58
  ------------------------------------------------------------------------- */
 
59
 
 
60
typedef struct FrameBuffer {
 
61
  unsigned int    height;
 
62
  unsigned int    width;
 
63
  int             xmin;      /* These are used for clipping */
 
64
  int             ymin;
 
65
  int             xmax;
 
66
  int             ymax;
 
67
  %addmethods {
 
68
    FrameBuffer(unsigned int width, unsigned int height);
 
69
    ~FrameBuffer();
 
70
    void resize(int width, int height);
 
71
    void clear(Pixel color);
 
72
    void plot(int x, int y, Pixel color);
 
73
    void horizontal(int xmin, int xmax, int y, Pixel color);
 
74
    void horizontalinterp(int xmin, int xmax, int y,  Pixel c1, Pixel c2);
 
75
    void vertical(int ymin, int ymax, int x, Pixel color);
 
76
    void box(int x1, int y1,  int x2, int y2, Pixel color);
 
77
    void solidbox(int x1, int y1, int x2, int y2, Pixel color);
 
78
    void interpbox(int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
 
79
    void circle(int x1, int y1, int radius, Pixel color);
 
80
    void solidcircle(int x1, int y1, int radius, Pixel color);
 
81
    void line(int x1, int y1, int x2, int y2, Pixel color);
 
82
    void setclip(int xmin, int ymin, int xmax, int ymax);
 
83
    void noclip();
 
84
    int  makeGIF(ColorMap *cmap, void *buffer, unsigned int maxsize);
 
85
    void zresize(int width, int height);
 
86
    void zclear();
 
87
    void drawchar(int x, int y, int fgcolor, int bgcolor, char chr, int orientation);
 
88
    void drawstring(int x, int y, int fgcolor, int bgcolor, char *text, int orientation);
 
89
    void drawpixmap(PixMap *pm, int x, int y, int fgcolor, int bgcolor);
 
90
    int  writeGIF(ColorMap *cmap, char *filename);      
 
91
  }
 
92
} FrameBuffer;
 
93
 
 
94
#define  HORIZONTAL  1
 
95
#define  VERTICAL    2
 
96
 
 
97
/* --------------------------------------------------------------------------
 
98
   PixMap
 
99
 
 
100
   The equivalent of "bit-maps".
 
101
   -------------------------------------------------------------------------- */
 
102
 
 
103
/* PIXMAP methods */
 
104
 
 
105
extern PixMap   *new_PixMap(int width, int height, int centerx, int centery);
 
106
extern void      delete_PixMap(PixMap *pm);
 
107
extern void      PixMap_set(PixMap *pm, int x, int y, int pix);
 
108
 
 
109
#define   GIFPLOT_TRANSPARENT  0
 
110
#define   GIFPLOT_FOREGROUND   1
 
111
#define   GIFPLOT_BACKGROUND   2
 
112
 
 
113
/* --------------------------------------------------------------------------
 
114
   Plot2D
 
115
 
 
116
   Definition and methods for 2D plots.
 
117
   --------------------------------------------------------------------------- */
 
118
 
 
119
typedef struct Plot2D {
 
120
  FrameBuffer     *frame;
 
121
  int             view_xmin;    /* Minimum coordinates of view region */
 
122
  int             view_ymin;    
 
123
  int             view_xmax;    /* Maximum coordinates of view region */
 
124
  int             view_ymax;    
 
125
  double          xmin;         /* Minimum coordinates of plot region */
 
126
  double          ymin;
 
127
  double          xmax;         /* Maximum coordinates of plot region */
 
128
  double          ymax;
 
129
  int             xscale;       /* Type of scaling (LINEAR, LOG, etc..) */
 
130
  int             yscale;       
 
131
  %addmethods {
 
132
       Plot2D(FrameBuffer *frame,double xmin,double ymin,  double xmax, double ymax);
 
133
       ~Plot2D();
 
134
       Plot2D  *copy();
 
135
       void     clear(Pixel c);
 
136
       void     setview(int vxmin, int vymin, int vxmax, int vymax);
 
137
       void     setrange(double xmin, double ymin, double xmax, double ymax);
 
138
       void     setscale(int xscale, int yscale);
 
139
       void     plot(double x, double y, Pixel color);
 
140
       void     box(double x1, double y1, double x2, double y2, Pixel color);
 
141
       void     solidbox(double x1, double y1,  double x2, double y2, Pixel color);
 
142
       void     interpbox(double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
 
143
 
 
144
       void     circle(double x, double y, double radius, Pixel color);
 
145
       void     solidcircle(double x, double y,  double radius, Pixel color);
 
146
       void     line(double x1, double y1,  double x2, double y2, Pixel color);
 
147
       void     start();
 
148
       void     drawpixmap(PixMap *pm, double x, double y, Pixel color, Pixel bgcolor);
 
149
       void     xaxis(double x, double y, double xtick, int ticklength, Pixel color);
 
150
       void     yaxis(double x, double y, double ytick, int ticklength, Pixel color);
 
151
       void     triangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
 
152
 
 
153
       void     solidtriangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
 
154
 
 
155
       void     interptriangle(double x1, double y1, Pixel c1,
 
156
                           double x2, double y2, Pixel c2,
 
157
                           double x3, double y3, Pixel c3);
 
158
 
 
159
  }
 
160
} Plot2D;
 
161
 
 
162
#define LINEAR     10
 
163
#define LOG        11
 
164
 
 
165
/* ------------------------------------------------------------------------------
 
166
   Plot3D
 
167
 
 
168
   Data Structure for 3-D plots
 
169
   ------------------------------------------------------------------------------ */
 
170
 
 
171
typedef struct Plot3D {
 
172
  FrameBuffer    *frame;
 
173
  int            view_xmin;  /* Viewing region */
 
174
  int            view_ymin;
 
175
  int            view_xmax;
 
176
  int            view_ymax;
 
177
  double         xmin;       /* Bounding box */
 
178
  double         ymin;
 
179
  double         zmin;
 
180
  double         xmax;
 
181
  double         ymax;
 
182
  double         zmax;
 
183
  double         xcenter;    /* Center point */
 
184
  double         ycenter;
 
185
  double         zcenter;
 
186
  double         fovy;       /* Field of view */
 
187
  double         aspect;     /* Aspect ratio  */
 
188
  double         znear;      /* near "clipping" plane */
 
189
  double         zfar;       /* far "clipping" plane */
 
190
  double         lookatz;    /* Where is the z-lookat point */
 
191
  double         xshift;     /* Used for translation and stuff */
 
192
  double         yshift;
 
193
  %addmethods {
 
194
    Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax);
 
195
    ~Plot3D();
 
196
    Plot3D *copy();
 
197
    void   clear(Pixel bgcolor);
 
198
    void   perspective( double fovy, double znear, double zfar);
 
199
    void   lookat( double z);
 
200
    void   autoperspective( double fovy);
 
201
    void   ortho(double left, double right, double bottom, double top);
 
202
    void   autoortho();
 
203
    void   rotx( double deg);
 
204
    void   roty( double deg);
 
205
    void   rotz( double deg);
 
206
    void   rotl( double deg);
 
207
    void   rotr( double deg);
 
208
    void   rotd( double deg);
 
209
    void   rotu( double deg);
 
210
    void   rotc( double deg);
 
211
    void   zoom( double percent);
 
212
    void   left( double percent);
 
213
    void   right( double percent);
 
214
    void   down( double percent);
 
215
    void   up( double percent);
 
216
    void   center( double cx, double cy);
 
217
    void   plot( double x, double y, double z, Pixel Color);
 
218
    void   setview( int vxmin, int vymin, int vxmax, int vymax);
 
219
    void   start();
 
220
    void   line( double x1, double y1, double z1,
 
221
                 double x2, double y2, double z2, Pixel color);
 
222
    void   triangle( double x1, double y1, double z1,
 
223
                     double x2, double y2, double z2,
 
224
                     double x3, double y3, double z3, Pixel color);
 
225
    void   solidtriangle( double x1, double y1, double z1,
 
226
                          double x2, double y2, double z2,
 
227
                          double x3, double y3, double z3, Pixel color);
 
228
    void interptriangle(double x1, double y1, double z1, Pixel c1,
 
229
                        double x2, double y2, double z2, Pixel c2,
 
230
                        double x3, double y3, double z3, Pixel c3);
 
231
    void   quad( double x1, double y1, double z1,
 
232
                 double x2, double y2, double z2,
 
233
                 double x3, double y3, double z3,
 
234
                 double x4, double y4, double z4,
 
235
                 Pixel color);
 
236
    void   solidquad( double x1, double y1, double z1,
 
237
                      double x2, double y2, double z2,
 
238
                      double x3, double y3, double z3,
 
239
                      double x4, double y4, double z4,
 
240
                      Pixel color);
 
241
    void   interpquad( double x1, double y1, double z1, Pixel c1,
 
242
                       double x2, double y2, double z2, Pixel c2,
 
243
                       double x3, double y3, double z3, Pixel c3,
 
244
                       double x4, double y4, double z4, Pixel c4);
 
245
    void   solidsphere( double x, double y, double z, double radius,Pixel c);
 
246
    void   outlinesphere( double x, double y, double z, double radius,Pixel c, Pixel bc);
 
247
  }
 
248
} Plot3D;
 
249
 
 
250
#ifndef SWIGJAVA
 
251
/* These directives create constants of a specific type.  They
 
252
   do not correspond to any C variable or declared constant in the
 
253
   header file */
 
254
%constant PixMap * SQUARE = &PixMap_SQUARE;
 
255
%constant PixMap * TRIANGLE = &PixMap_TRIANGLE;
 
256
%constant PixMap * CROSS = &PixMap_CROSS;
 
257
#endif
 
258
 
 
259
 
 
260
 
 
261