The great merge
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@4141 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
6fcc22a1f8
commit
516036631c
1508 changed files with 125983 additions and 44037 deletions
|
|
@ -1,18 +0,0 @@
|
|||
TOP = ../..
|
||||
SWIG = $(TOP)/../swig -shadow
|
||||
SWIGOPT = -I../Include
|
||||
SRCS =
|
||||
TARGET = libjgifplot
|
||||
INTERFACE = gifplot.i
|
||||
LIBS = -L.. -lgifplot -lm
|
||||
INCLUDE = -I../Include
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDE='$(INCLUDE)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
|
||||
|
||||
clean::
|
||||
rm -f *_wrap* *.o *~ *.so .~* core *.gif *.class ColorMap.java FrameBuffer.java Plot2D.java Plot3D.java gifplot.java
|
||||
|
||||
check: all
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
The gifplot example does not work straight out of the box,
|
||||
I had to change ../Interface/gifplot.i slightly for java.
|
||||
|
||||
a)
|
||||
The colors (e.g. BLACK) where defined as:
|
||||
|
||||
#define BLACK 0
|
||||
|
||||
and the functions expect 'Pixel color' where Pixel is a unsigned char.
|
||||
#define constants contain no type information and are translated to integer
|
||||
constants. Because of that, you have to cast every Pixel to a byte in java.
|
||||
|
||||
Changing the definition to:
|
||||
const Pixel BLACK = 0;
|
||||
fixes this.
|
||||
|
||||
b)
|
||||
The definitions:
|
||||
|
||||
const PixMap *SQUARE = &PixMap_SQUARE;
|
||||
const PixMap *TRIANGLE = &PixMap_TRIANGLE;
|
||||
const PixMap *CROSS = &PixMap_CROSS;
|
||||
|
||||
don't work.
|
||||
The wrapper code expects actual variables SQUARE, etc. and they are not
|
||||
defined in gifplot.h.
|
||||
|
||||
c)
|
||||
In shadow mode the method ColorMap::default() clashes with the reserved name
|
||||
default.
|
||||
4
SWIG/Examples/GIFPlot/Java/check.list
Normal file
4
SWIG/Examples/GIFPlot/Java/check.list
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
# see top-level Makefile.in
|
||||
full
|
||||
shadow
|
||||
simple
|
||||
Binary file not shown.
7
SWIG/Examples/GIFPlot/Java/full/.cvsignore
Normal file
7
SWIG/Examples/GIFPlot/Java/full/.cvsignore
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.so
|
||||
*.dll
|
||||
*.gif
|
||||
20
SWIG/Examples/GIFPlot/Java/full/Makefile
Normal file
20
SWIG/Examples/GIFPlot/Java/full/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -I../../Include -noproxy
|
||||
SRCS =
|
||||
TARGET = gifplot
|
||||
INTERFACE = gifplot.i
|
||||
LIBS = -L../.. -lgifplot
|
||||
INCLUDES = -I../../Include
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
|
||||
javac *.java
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile java_clean
|
||||
rm -f *.gif
|
||||
|
||||
check: all
|
||||
8
SWIG/Examples/GIFPlot/Java/full/README
Normal file
8
SWIG/Examples/GIFPlot/Java/full/README
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
This example runs the entire gifplot.h header file through SWIG without
|
||||
any changes. The program 'main.java' does something a little more
|
||||
interesting. After doing a make, run it using 'java main'. You'll have to go
|
||||
look at the header file to get a complete listing of the functions.
|
||||
|
||||
Note the differences in the main.java files between this example and the
|
||||
'full' example. This example does not use shadow classes.
|
||||
|
||||
15
SWIG/Examples/GIFPlot/Java/full/gifplot.i
Normal file
15
SWIG/Examples/GIFPlot/Java/full/gifplot.i
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
/* Oh what the heck, let's just grab the whole darn header file
|
||||
and see what happens. */
|
||||
|
||||
%module gifplot
|
||||
%{
|
||||
|
||||
/* Note: You still need this part because the %include directive
|
||||
merely causes SWIG to interpret the contents of a file. It doesn't
|
||||
include the right include headers for the resulting C code */
|
||||
|
||||
#include "gifplot.h"
|
||||
|
||||
%}
|
||||
|
||||
%include gifplot.h
|
||||
75
SWIG/Examples/GIFPlot/Java/full/main.java
Normal file
75
SWIG/Examples/GIFPlot/Java/full/main.java
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
// Plot a 3D function
|
||||
import java.lang.Math;
|
||||
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("gifplot");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
// Here are some plotting parameters
|
||||
double xmin = -5.0;
|
||||
double xmax = 5.0;
|
||||
double ymin = -5.0;
|
||||
double ymax = 5.0;
|
||||
double zmin = -5.0;
|
||||
double zmax = 5.0;
|
||||
|
||||
// Grid resolution
|
||||
int nxpoints = 60;
|
||||
int nypoints = 60;
|
||||
|
||||
SWIGTYPE_p_ColorMap cmap = gifplot.new_ColorMap("cmap");
|
||||
SWIGTYPE_p_FrameBuffer frame = gifplot.new_FrameBuffer(500,500);
|
||||
gifplot.FrameBuffer_clear(frame,(short)gifplot.BLACK);
|
||||
|
||||
SWIGTYPE_p_Plot3D p3 = gifplot.new_Plot3D(frame,xmin,ymin,zmin,xmax,ymax,zmax);
|
||||
gifplot.Plot3D_lookat(p3,2*(zmax-zmin));
|
||||
gifplot.Plot3D_autoperspective(p3,40);
|
||||
gifplot.Plot3D_rotu(p3,60);
|
||||
gifplot.Plot3D_rotr(p3,30);
|
||||
gifplot.Plot3D_rotd(p3,10);
|
||||
|
||||
System.out.println( "Making a nice 3D plot..." );
|
||||
gifplot.Plot3D_clear(p3,(short)gifplot.BLACK);
|
||||
gifplot.Plot3D_start(p3);
|
||||
double dx = 1.0*(xmax-xmin)/nxpoints;
|
||||
double dy = 1.0*(ymax-ymin)/nypoints;
|
||||
double cscale = 240.0/(zmax-zmin);
|
||||
double x = xmin;
|
||||
for (int i = 0; i < nxpoints; i++) {
|
||||
double y = ymin;
|
||||
for (int j = 0; j < nypoints; j++) {
|
||||
double z1 = func(x,y);
|
||||
double z2 = func(x+dx,y);
|
||||
double z3 = func(x+dx,y+dy);
|
||||
double z4 = func(x,y+dy);
|
||||
double c1 = cscale*(z1-zmin);
|
||||
double c2 = cscale*(z2-zmin);
|
||||
double c3 = cscale*(z3-zmin);
|
||||
double c4 = cscale*(z4-zmin);
|
||||
double c = (c1+c2+c3+c4)/4;
|
||||
if (c < 0) c = 0;
|
||||
if (c > 239) c = 239;
|
||||
gifplot.Plot3D_solidquad(p3,x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,(short)(c+16));
|
||||
y = y + dy;
|
||||
}
|
||||
x = x + dx;
|
||||
}
|
||||
|
||||
gifplot.FrameBuffer_writeGIF(frame,cmap,"image.gif");
|
||||
System.out.println( "Wrote image.gif" );
|
||||
}
|
||||
|
||||
// Here is the function to plot
|
||||
public static double func(double x, double y) {
|
||||
return 5*java.lang.Math.cos(2*java.lang.Math.sqrt(x*x+y*y))*java.lang.Math.exp(-0.3*java.lang.Math.sqrt(x*x+y*y));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,273 +0,0 @@
|
|||
//
|
||||
// Graphics module
|
||||
//
|
||||
%module gifplot
|
||||
%{
|
||||
#include "gifplot.h"
|
||||
%}
|
||||
|
||||
/* Pixel is 8-bits */
|
||||
|
||||
typedef unsigned char Pixel;
|
||||
typedef float Zvalue;
|
||||
|
||||
%disabledoc
|
||||
|
||||
/* ------------------------------------------------------------------------
|
||||
ColorMap
|
||||
|
||||
Definition and methods for colormaps
|
||||
------------------------------------------------------------------------ */
|
||||
|
||||
typedef struct ColorMap {
|
||||
char *name;
|
||||
|
||||
//
|
||||
// %addmethods adds some C methods to this structure to make it
|
||||
// look like a C++ class in Python.
|
||||
// These are really named things like ColorMap_default, ColorMap_assign, etc...
|
||||
|
||||
%addmethods {
|
||||
ColorMap(char *filename);
|
||||
~ColorMap();
|
||||
#ifdef SWIGJAVA
|
||||
%name(make_default) void default();
|
||||
#else
|
||||
void default();
|
||||
#endif
|
||||
void assign(int index,int r, int g, int b);
|
||||
%name(__getitem__) int getitem(int index);
|
||||
%name(__setitem__) void setitem(int index, int value);
|
||||
int write(char *filename);
|
||||
}
|
||||
} ColorMap;
|
||||
|
||||
/* Some default colors */
|
||||
|
||||
#ifdef SWIGJAVA
|
||||
const Pixel BLACK = 0;
|
||||
const Pixel WHITE = 1;
|
||||
const Pixel RED = 2;
|
||||
const Pixel GREEN = 3;
|
||||
const Pixel BLUE = 4;
|
||||
const Pixel YELLOW = 5;
|
||||
const Pixel CYAN = 6;
|
||||
const Pixel MAGENTA = 7;
|
||||
#else
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
#define RED 2
|
||||
#define GREEN 3
|
||||
#define BLUE 4
|
||||
#define YELLOW 5
|
||||
#define CYAN 6
|
||||
#define MAGENTA 7
|
||||
#endif
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
FrameBuffer
|
||||
|
||||
This structure defines a simple 8 bit framebuffer.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct FrameBuffer {
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
int xmin; /* These are used for clipping */
|
||||
int ymin;
|
||||
int xmax;
|
||||
int ymax;
|
||||
%addmethods {
|
||||
FrameBuffer(unsigned int width, unsigned int height);
|
||||
~FrameBuffer();
|
||||
void resize(int width, int height);
|
||||
void clear(Pixel color);
|
||||
void plot(int x, int y, Pixel color);
|
||||
void horizontal(int xmin, int xmax, int y, Pixel color);
|
||||
void horizontalinterp(int xmin, int xmax, int y, Pixel c1, Pixel c2);
|
||||
void vertical(int ymin, int ymax, int x, Pixel color);
|
||||
void box(int x1, int y1, int x2, int y2, Pixel color);
|
||||
void solidbox(int x1, int y1, int x2, int y2, Pixel color);
|
||||
void interpbox(int x1, int y1, int x2, int y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
|
||||
void circle(int x1, int y1, int radius, Pixel color);
|
||||
void solidcircle(int x1, int y1, int radius, Pixel color);
|
||||
void line(int x1, int y1, int x2, int y2, Pixel color);
|
||||
void setclip(int xmin, int ymin, int xmax, int ymax);
|
||||
void noclip();
|
||||
int makeGIF(ColorMap *cmap, void *buffer, unsigned int maxsize);
|
||||
void zresize(int width, int height);
|
||||
void zclear();
|
||||
void drawchar(int x, int y, int fgcolor, int bgcolor, char chr, int orientation);
|
||||
void drawstring(int x, int y, int fgcolor, int bgcolor, char *text, int orientation);
|
||||
void drawpixmap(PixMap *pm, int x, int y, int fgcolor, int bgcolor);
|
||||
int writeGIF(ColorMap *cmap, char *filename);
|
||||
}
|
||||
} FrameBuffer;
|
||||
|
||||
#define HORIZONTAL 1
|
||||
#define VERTICAL 2
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
PixMap
|
||||
|
||||
The equivalent of "bit-maps".
|
||||
-------------------------------------------------------------------------- */
|
||||
|
||||
/* PIXMAP methods */
|
||||
|
||||
extern PixMap *new_PixMap(int width, int height, int centerx, int centery);
|
||||
extern void delete_PixMap(PixMap *pm);
|
||||
extern void PixMap_set(PixMap *pm, int x, int y, int pix);
|
||||
|
||||
#define TRANSPARENT 0
|
||||
#define FOREGROUND 1
|
||||
#define BACKGROUND 2
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
Plot2D
|
||||
|
||||
Definition and methods for 2D plots.
|
||||
--------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct Plot2D {
|
||||
FrameBuffer *frame;
|
||||
int view_xmin; /* Minimum coordinates of view region */
|
||||
int view_ymin;
|
||||
int view_xmax; /* Maximum coordinates of view region */
|
||||
int view_ymax;
|
||||
double xmin; /* Minimum coordinates of plot region */
|
||||
double ymin;
|
||||
double xmax; /* Maximum coordinates of plot region */
|
||||
double ymax;
|
||||
int xscale; /* Type of scaling (LINEAR, LOG, etc..) */
|
||||
int yscale;
|
||||
%addmethods {
|
||||
Plot2D(FrameBuffer *frame,double xmin,double ymin, double xmax, double ymax);
|
||||
~Plot2D();
|
||||
Plot2D *copy();
|
||||
void clear(Pixel c);
|
||||
void setview(int vxmin, int vymin, int vxmax, int vymax);
|
||||
void setrange(double xmin, double ymin, double xmax, double ymax);
|
||||
void setscale(int xscale, int yscale);
|
||||
void plot(double x, double y, Pixel color);
|
||||
void box(double x1, double y1, double x2, double y2, Pixel color);
|
||||
void solidbox(double x1, double y1, double x2, double y2, Pixel color);
|
||||
void interpbox(double x1, double y1, double x2, double y2, Pixel c1, Pixel c2, Pixel c3, Pixel c4);
|
||||
|
||||
void circle(double x, double y, double radius, Pixel color);
|
||||
void solidcircle(double x, double y, double radius, Pixel color);
|
||||
void line(double x1, double y1, double x2, double y2, Pixel color);
|
||||
void start();
|
||||
void drawpixmap(PixMap *pm, double x, double y, Pixel color, Pixel bgcolor);
|
||||
void xaxis(double x, double y, double xtick, int ticklength, Pixel color);
|
||||
void yaxis(double x, double y, double ytick, int ticklength, Pixel color);
|
||||
void triangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
|
||||
|
||||
void solidtriangle(double x1, double y1, double x2, double y2, double x3, double y3, Pixel c);
|
||||
|
||||
void interptriangle(double x1, double y1, Pixel c1,
|
||||
double x2, double y2, Pixel c2,
|
||||
double x3, double y3, Pixel c3);
|
||||
|
||||
}
|
||||
} Plot2D;
|
||||
|
||||
#define LINEAR 10
|
||||
#define LOG 11
|
||||
|
||||
/* ------------------------------------------------------------------------------
|
||||
Plot3D
|
||||
|
||||
Data Structure for 3-D plots
|
||||
------------------------------------------------------------------------------ */
|
||||
|
||||
typedef struct Plot3D {
|
||||
FrameBuffer *frame;
|
||||
int view_xmin; /* Viewing region */
|
||||
int view_ymin;
|
||||
int view_xmax;
|
||||
int view_ymax;
|
||||
double xmin; /* Bounding box */
|
||||
double ymin;
|
||||
double zmin;
|
||||
double xmax;
|
||||
double ymax;
|
||||
double zmax;
|
||||
double xcenter; /* Center point */
|
||||
double ycenter;
|
||||
double zcenter;
|
||||
double fovy; /* Field of view */
|
||||
double aspect; /* Aspect ratio */
|
||||
double znear; /* near "clipping" plane */
|
||||
double zfar; /* far "clipping" plane */
|
||||
double lookatz; /* Where is the z-lookat point */
|
||||
double xshift; /* Used for translation and stuff */
|
||||
double yshift;
|
||||
%addmethods {
|
||||
Plot3D(FrameBuffer *frame, double xmin, double ymin, double zmin, double xmax, double ymax, double zmax);
|
||||
~Plot3D();
|
||||
Plot3D *copy();
|
||||
void clear(Pixel bgcolor);
|
||||
void perspective( double fovy, double znear, double zfar);
|
||||
void lookat( double z);
|
||||
void autoperspective( double fovy);
|
||||
void ortho(double left, double right, double bottom, double top);
|
||||
void autoortho();
|
||||
void rotx( double deg);
|
||||
void roty( double deg);
|
||||
void rotz( double deg);
|
||||
void rotl( double deg);
|
||||
void rotr( double deg);
|
||||
void rotd( double deg);
|
||||
void rotu( double deg);
|
||||
void rotc( double deg);
|
||||
void zoom( double percent);
|
||||
void left( double percent);
|
||||
void right( double percent);
|
||||
void down( double percent);
|
||||
void up( double percent);
|
||||
void center( double cx, double cy);
|
||||
void plot( double x, double y, double z, Pixel Color);
|
||||
void setview( int vxmin, int vymin, int vxmax, int vymax);
|
||||
void start();
|
||||
void line( double x1, double y1, double z1,
|
||||
double x2, double y2, double z2, Pixel color);
|
||||
void triangle( double x1, double y1, double z1,
|
||||
double x2, double y2, double z2,
|
||||
double x3, double y3, double z3, Pixel color);
|
||||
void solidtriangle( double x1, double y1, double z1,
|
||||
double x2, double y2, double z2,
|
||||
double x3, double y3, double z3, Pixel color);
|
||||
void interptriangle(double x1, double y1, double z1, Pixel c1,
|
||||
double x2, double y2, double z2, Pixel c2,
|
||||
double x3, double y3, double z3, Pixel c3);
|
||||
void quad( double x1, double y1, double z1,
|
||||
double x2, double y2, double z2,
|
||||
double x3, double y3, double z3,
|
||||
double x4, double y4, double z4,
|
||||
Pixel color);
|
||||
void solidquad( double x1, double y1, double z1,
|
||||
double x2, double y2, double z2,
|
||||
double x3, double y3, double z3,
|
||||
double x4, double y4, double z4,
|
||||
Pixel color);
|
||||
void interpquad( double x1, double y1, double z1, Pixel c1,
|
||||
double x2, double y2, double z2, Pixel c2,
|
||||
double x3, double y3, double z3, Pixel c3,
|
||||
double x4, double y4, double z4, Pixel c4);
|
||||
void solidsphere( double x, double y, double z, double radius,Pixel c);
|
||||
void outlinesphere( double x, double y, double z, double radius,Pixel c, Pixel bc);
|
||||
}
|
||||
} Plot3D;
|
||||
|
||||
#ifndef SWIGJAVA
|
||||
const PixMap *SQUARE = &PixMap_SQUARE;
|
||||
const PixMap *TRIANGLE = &PixMap_TRIANGLE;
|
||||
const PixMap *CROSS = &PixMap_CROSS;
|
||||
#endif
|
||||
|
||||
%enabledoc
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,107 +0,0 @@
|
|||
import gifplot;
|
||||
|
||||
public class ortho {
|
||||
|
||||
static {
|
||||
System.loadLibrary("jgifplot");
|
||||
};
|
||||
|
||||
public static double func(double x, double y) {
|
||||
double r;
|
||||
double f;
|
||||
r = Math.sqrt(x*x + y*y);
|
||||
|
||||
f = (Math.sin(0.30*r*x)+Math.cos(0.30*r*y))/(1.0+r);
|
||||
return f;
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
FrameBuffer f;
|
||||
Plot3D p3;
|
||||
ColorMap cm;
|
||||
|
||||
double x,y;
|
||||
double dx,dy;
|
||||
double z1,z2,z3,z4;
|
||||
int c1,c2,c3,c4;
|
||||
|
||||
/* Create a framebuffer */
|
||||
|
||||
f = new FrameBuffer(700,400);
|
||||
|
||||
/* Load a colormap */
|
||||
|
||||
cm = new ColorMap("cm15");
|
||||
|
||||
/* Create a new 2D image */
|
||||
|
||||
f.clear(gifplot.BLACK);
|
||||
p3 = new Plot3D(f,-6.3,-6.3,-1.5,6.3,6.3,1.5);
|
||||
|
||||
/* Set viewing region in 2D plot */
|
||||
|
||||
p3.setview(50,50,650,350);
|
||||
|
||||
/* Set how far away from the image we are */
|
||||
p3.lookat(20);
|
||||
|
||||
/* Set the field of view for the perspective */
|
||||
|
||||
|
||||
// Plot3D_autoperspective(p3,40);
|
||||
|
||||
p3.autoortho();
|
||||
|
||||
/* Now make a plot of a 3D function */
|
||||
|
||||
/* Make a frame */
|
||||
|
||||
f.noclip();
|
||||
f.box(49,49,650,350,gifplot.WHITE);
|
||||
p3.start(); /* Always call this prior to making an image */
|
||||
p3.clear(gifplot.BLACK);
|
||||
p3.rotu(60);
|
||||
p3.rotz(40);
|
||||
x = -6.3;
|
||||
dx = 0.25;
|
||||
while (x < 6.3) {
|
||||
y = -6.3;
|
||||
dy = 0.25;
|
||||
while (y < 6.3) {
|
||||
z1 = func(x,y);
|
||||
z2 = func(x+dx,y);
|
||||
z3 = func(x+dx,y+dy);
|
||||
z4 = func(x,y+dy);
|
||||
c1 = (int) ((z1 + 1.0)*120) + 16;
|
||||
if (c1 < 16) c1 = 16;
|
||||
if (c1 > 254) c1 = 254;
|
||||
|
||||
c2 = (int) ((z2 + 1.0)*120) + 16;
|
||||
if (c2 < 16) c2 = 16;
|
||||
if (c2 > 254) c2 = 254;
|
||||
|
||||
c3 = (int) ((z3 + 1.0)*120) + 16;
|
||||
if (c3 < 16) c3 = 16;
|
||||
if (c3 > 254) c3 = 254;
|
||||
|
||||
c4 = (int) ((z4 + 1.0)*120) + 16;
|
||||
if (c4 < 16) c4 = 16;
|
||||
if (c4 > 254) c4= 254;
|
||||
|
||||
p3.interpquad(x,y,z1,(byte) c1,
|
||||
x+dx,y,z2,(byte) c2,
|
||||
x+dx,y+dy,z3,(byte) c3,
|
||||
x,y+dy,z4,(byte) c4);
|
||||
y = y + dy;
|
||||
}
|
||||
x = x + dx;
|
||||
}
|
||||
|
||||
/* Make a GIF file */
|
||||
|
||||
f.writeGIF(cm,"plot.gif");
|
||||
|
||||
System.out.println("Image written to 'plot.gif'");
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import gifplot;
|
||||
|
||||
public class shadow {
|
||||
|
||||
static {
|
||||
System.loadLibrary("jgifplot");
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
FrameBuffer fb = new FrameBuffer(300, 300);
|
||||
ColorMap cm = new ColorMap("cmap");
|
||||
|
||||
fb.clear(gifplot.BLACK);
|
||||
fb.drawstring(50, 50, gifplot.WHITE, gifplot.BLACK, "Hello world", gifplot.VERTICAL);
|
||||
fb.solidbox(200, 200, 220, 240, gifplot.BLUE);
|
||||
fb.line(0, 290, 293, 50, gifplot.RED);
|
||||
fb.circle(100, 100, 10, gifplot.YELLOW);
|
||||
fb.writeGIF(cm, "plot.gif");
|
||||
|
||||
System.out.println("Image written to 'plot.gif'");
|
||||
}
|
||||
}
|
||||
7
SWIG/Examples/GIFPlot/Java/shadow/.cvsignore
Normal file
7
SWIG/Examples/GIFPlot/Java/shadow/.cvsignore
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.so
|
||||
*.dll
|
||||
*.gif
|
||||
20
SWIG/Examples/GIFPlot/Java/shadow/Makefile
Normal file
20
SWIG/Examples/GIFPlot/Java/shadow/Makefile
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -I../../Interface
|
||||
SRCS =
|
||||
TARGET = gifplot
|
||||
INTERFACE = gifplot.i
|
||||
LIBS = -L../.. -lgifplot
|
||||
INCLUDES = -I../../Include
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
|
||||
javac *.java
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile java_clean
|
||||
rm -f *.gif
|
||||
|
||||
check: all
|
||||
5
SWIG/Examples/GIFPlot/Java/shadow/README
Normal file
5
SWIG/Examples/GIFPlot/Java/shadow/README
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
This example uses the file in ../../Interface/gifplot.i to build
|
||||
an interface with shadow classes. After doing a make, run the program main, ie: 'java main'.
|
||||
|
||||
Note the differences in the main.java files between this example and the
|
||||
'full' example. This example uses the shadow classes.
|
||||
BIN
SWIG/Examples/GIFPlot/Java/shadow/cmap
Normal file
BIN
SWIG/Examples/GIFPlot/Java/shadow/cmap
Normal file
Binary file not shown.
76
SWIG/Examples/GIFPlot/Java/shadow/main.java
Normal file
76
SWIG/Examples/GIFPlot/Java/shadow/main.java
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Plot a 3D function
|
||||
|
||||
import java.lang.Math;
|
||||
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("gifplot");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
// Here are some plotting parameters
|
||||
double xmin = -5.0;
|
||||
double xmax = 5.0;
|
||||
double ymin = -5.0;
|
||||
double ymax = 5.0;
|
||||
double zmin = -5.0;
|
||||
double zmax = 5.0;
|
||||
|
||||
// Grid resolution
|
||||
int nxpoints = 60;
|
||||
int nypoints = 60;
|
||||
|
||||
ColorMap cmap = new ColorMap("cmap");
|
||||
FrameBuffer frame = new FrameBuffer(500,500);
|
||||
frame.clear((short)gifplot.BLACK);
|
||||
|
||||
Plot3D p3 = new Plot3D(frame,xmin,ymin,zmin,xmax,ymax,zmax);
|
||||
p3.lookat(2*(zmax-zmin));
|
||||
p3.autoperspective(40);
|
||||
p3.rotu(60);
|
||||
p3.rotr(30);
|
||||
p3.rotd(10);
|
||||
|
||||
System.out.println( "Making a nice 3D plot..." );
|
||||
p3.clear((short)gifplot.BLACK);
|
||||
p3.start();
|
||||
double dx = 1.0*(xmax-xmin)/nxpoints;
|
||||
double dy = 1.0*(ymax-ymin)/nypoints;
|
||||
double cscale = 240.0/(zmax-zmin);
|
||||
double x = xmin;
|
||||
for (int i = 0; i < nxpoints; i++) {
|
||||
double y = ymin;
|
||||
for (int j = 0; j < nypoints; j++) {
|
||||
double z1 = func(x,y);
|
||||
double z2 = func(x+dx,y);
|
||||
double z3 = func(x+dx,y+dy);
|
||||
double z4 = func(x,y+dy);
|
||||
double c1 = cscale*(z1-zmin);
|
||||
double c2 = cscale*(z2-zmin);
|
||||
double c3 = cscale*(z3-zmin);
|
||||
double c4 = cscale*(z4-zmin);
|
||||
double c = (c1+c2+c3+c4)/4;
|
||||
if (c < 0) c = 0;
|
||||
if (c > 239) c = 239;
|
||||
p3.solidquad(x,y,z1,x+dx,y,z2,x+dx,y+dy,z3,x,y+dy,z4,(short)(c+16));
|
||||
y = y + dy;
|
||||
}
|
||||
x = x + dx;
|
||||
}
|
||||
|
||||
frame.writeGIF(cmap,"image.gif");
|
||||
System.out.println( "Wrote image.gif" );
|
||||
}
|
||||
|
||||
// Here is the function to plot
|
||||
public static double func(double x, double y) {
|
||||
return 5*java.lang.Math.cos(2*java.lang.Math.sqrt(x*x+y*y))*java.lang.Math.exp(-0.3*java.lang.Math.sqrt(x*x+y*y));
|
||||
}
|
||||
}
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import gifplot;
|
||||
|
||||
public class simple {
|
||||
|
||||
static {
|
||||
System.loadLibrary("jgifplot");
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
long f = gifplot.new_FrameBuffer(300, 300);
|
||||
long c = gifplot.new_ColorMap("cmap");
|
||||
|
||||
gifplot.FrameBuffer_clear(f, gifplot.BLACK);
|
||||
gifplot.FrameBuffer_drawstring(f, 50, 50, gifplot.WHITE, gifplot.BLACK, "Hello world", gifplot.HORIZONTAL);
|
||||
gifplot.FrameBuffer_solidbox(f, 200, 200, 220, 240, gifplot.BLUE);
|
||||
gifplot.FrameBuffer_line(f, 0, 290, 293, 50, gifplot.RED);
|
||||
gifplot.FrameBuffer_circle(f, 100, 100, 10, gifplot.YELLOW);
|
||||
gifplot.FrameBuffer_writeGIF(f, c, "plot.gif");
|
||||
|
||||
System.out.println("Image written to 'plot.gif'");
|
||||
}
|
||||
}
|
||||
7
SWIG/Examples/GIFPlot/Java/simple/.cvsignore
Normal file
7
SWIG/Examples/GIFPlot/Java/simple/.cvsignore
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
*.class
|
||||
*.java
|
||||
*_wrap.c
|
||||
*_wrap.cxx
|
||||
*.so
|
||||
*.dll
|
||||
*.gif
|
||||
21
SWIG/Examples/GIFPlot/Java/simple/Makefile
Normal file
21
SWIG/Examples/GIFPlot/Java/simple/Makefile
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
TOP = ../../..
|
||||
SWIG = $(TOP)/../swig
|
||||
SWIGOPT = -noproxy
|
||||
SRCS =
|
||||
TARGET = simple
|
||||
INTERFACE = simple.i
|
||||
LIBS = -L../.. -lgifplot
|
||||
INCLUDES = -I../../Include
|
||||
|
||||
all::
|
||||
$(MAKE) -f $(TOP)/Makefile SRCS='$(SRCS)' SWIG='$(SWIG)' \
|
||||
INCLUDES='$(INCLUDES)' LIBS='$(LIBS)' SWIGOPT='$(SWIGOPT)' \
|
||||
TARGET='$(TARGET)' INTERFACE='$(INTERFACE)' java
|
||||
javac *.java
|
||||
|
||||
|
||||
clean::
|
||||
$(MAKE) -f $(TOP)/Makefile java_clean
|
||||
rm -f *.gif
|
||||
|
||||
check: all
|
||||
5
SWIG/Examples/GIFPlot/Java/simple/README
Normal file
5
SWIG/Examples/GIFPlot/Java/simple/README
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
This is a very minimalistic example in which just a few functions
|
||||
and constants from library are wrapped and used to draw some simple
|
||||
shapes. After doing a make, run the java program, ie 'java main'.
|
||||
|
||||
|
||||
41
SWIG/Examples/GIFPlot/Java/simple/main.java
Normal file
41
SWIG/Examples/GIFPlot/Java/simple/main.java
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
public class main {
|
||||
|
||||
static {
|
||||
try {
|
||||
System.loadLibrary("simple");
|
||||
} catch (UnsatisfiedLinkError e) {
|
||||
System.err.println("Native code library failed to load. See the chapter on Dynamic Linking Problems in the SWIG Java documentation for help.\n" + e);
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String argv[]) {
|
||||
|
||||
// Draw some simple shapes
|
||||
System.out.println( "Drawing some basic shapes" );
|
||||
|
||||
SWIGTYPE_p_ColorMap cmap = simple.new_ColorMap(null);
|
||||
SWIGTYPE_p_FrameBuffer f = simple.new_FrameBuffer(400,400);
|
||||
|
||||
// Clear the picture
|
||||
simple.FrameBuffer_clear(f,(short)simple.BLACK);
|
||||
|
||||
// Make a red box
|
||||
simple.FrameBuffer_box(f,40,40,200,200,(short)simple.RED);
|
||||
|
||||
// Make a blue circle
|
||||
simple.FrameBuffer_circle(f,200,200,40,(short)simple.BLUE);
|
||||
|
||||
// Make green line
|
||||
simple.FrameBuffer_line(f,10,390,390,200, (short)simple.GREEN);
|
||||
|
||||
// Write an image out to disk
|
||||
|
||||
simple.FrameBuffer_writeGIF(f,cmap,"image.gif");
|
||||
System.out.println( "Wrote image.gif" );
|
||||
|
||||
simple.delete_FrameBuffer(f);
|
||||
simple.delete_ColorMap(cmap);
|
||||
}
|
||||
}
|
||||
38
SWIG/Examples/GIFPlot/Java/simple/simple.i
Normal file
38
SWIG/Examples/GIFPlot/Java/simple/simple.i
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/* This example shows a very simple interface wrapping a few
|
||||
primitive declarations */
|
||||
|
||||
%module simple
|
||||
%{
|
||||
#include "gifplot.h"
|
||||
%}
|
||||
|
||||
typedef unsigned char Pixel;
|
||||
|
||||
/* Here are a few useful functions */
|
||||
|
||||
ColorMap *new_ColorMap(char *filename = 0);
|
||||
void delete_ColorMap(ColorMap *cmap);
|
||||
|
||||
FrameBuffer *new_FrameBuffer(unsigned int width, unsigned int height);
|
||||
void delete_FrameBuffer(FrameBuffer *frame);
|
||||
void FrameBuffer_clear(FrameBuffer *frame, Pixel color);
|
||||
void FrameBuffer_line(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
|
||||
void FrameBuffer_box(FrameBuffer *frame, int x1, int y1, int x2, int y2, Pixel color);
|
||||
void FrameBuffer_circle(FrameBuffer *frame, int x1, int y1, int radius, Pixel color);
|
||||
int FrameBuffer_writeGIF(FrameBuffer *f, ColorMap *c, char *filename);
|
||||
|
||||
/* And some useful constants */
|
||||
|
||||
#define BLACK 0
|
||||
#define WHITE 1
|
||||
#define RED 2
|
||||
#define GREEN 3
|
||||
#define BLUE 4
|
||||
#define YELLOW 5
|
||||
#define CYAN 6
|
||||
#define MAGENTA 7
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue