

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
3 messages in net.java.dev.jna.usersImplementing Callback and problem wit...| From | Sent On | Attachments |
|---|---|---|
| Richard Otero | Dec 16, 2007 3:11 pm | |
| Timothy Wall | Dec 17, 2007 10:19 am | |
| Timothy Wall | Dec 17, 2007 10:25 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Implementing Callback and problem with setting values for defined struct | Actions... |
|---|---|---|
| From: | Richard Otero (rich...@gmail.com) | |
| Date: | Dec 16, 2007 3:11:45 pm | |
| List: | net.java.dev.jna.users | |
Hi Albert and Timothy,
Based off of your replies, this is the code that I've come up with for the callback to my java method sphereShape.
It has been generating an error: (java.exe:3776): Gts-CRITICAL **: file iso.c: line 422: assertion `g.nz > 1' failed
By placing a print statement in the C code for gts_isosurface_cartesian I see that the values it is using do not match the values I believed I had been passing to it. g.nx='0.000000' g.ny='0.000000' g.nz='0.000000' // what it sees in the gts_isosurface_cartesian C function
g.nx=100 g.ny=100 g.nz=100 // what I was hoping to pass to it from the Main function
I'm thinking that this is likely a problem with how I set the values of my structure GtsCartesianGrid in the main function.
How should one initialize a struct that they will be passing to C?
Thank you both for the guidance you've been able to give!
Richard
----------------------------------------------------------------------------------- C code from GtsCartesianGrid: typedef struct { int nx, ny, nz; double x, dx, y, dy, z, dz; } GtsCartesianGrid;
Java version for GtsCartesianGrid: public class GtsCartesianGrid extends Structure { public int nx, ny, nz; public double x, dx; public double y, dy; public double z, dz; }
------------------------------------------------------------------------------------ Entry for gts_isosurface_cartesian in the interface: public interface GTS extends Library { public GTS INSTANCE = (GTS) Native.loadLibrary("gts-0.7", GTS.class);
interface GtsIsoCartesianFunc extends Callback { // The API was: void (*GtsIsoCartesianFunc) (double **a, GtsCartesianGrid g, int i, pointer data) void callback(Pointer f, GtsCartesianGrid g, int zDirect, Pointer data); }
// The API was: void gts_isosurface_cartesian (GtsSurface *surface, GtsCartesianGrid g, GtsIsoCartesianFunc f, pointer data, double iso); public void gts_isosurface_cartesian(GtsSurfacePointer surfPointer, GtsCartesianGrid grid, GtsIsoCartesianFunc func, Pointer data, double iso);
<snip others for readability> }
------------------------------------------------------------------------------------ // Use in main function public static void sphereShape(Pointer f, GtsCartesianGrid g, int zDirect, Pointer data) { double x, y, value, z = g.z; int i, j;
for (i = 0; i < g.nx; i++) { x = g.x; for (j = 0; j < g.ny; j++) { y = g.y; value = x * x + y * y + z * z; // assumes that the double** can be treated as an array of pointers; // each a pointer to a double array // may need to treat as row-major order f.getPointer(Pointer.SIZE * i).setDouble(8 * j, value); y += g.dy; } x += g.dx; } }
public static void main(String[] args) { GTS lib = GTS.INSTANCE; // creates an initialized surface GtsSurfacePointer surface = GtsSurfacePointer.getNewSurface();
// struct that describes the grid to sample points from GtsCartesianGrid grid = new GtsCartesianGrid(); grid.x = 0; // x coordinate of the first point. grid.y = 0; grid.z = 0; grid.dx = 0.01; // Increment in direction x. grid.dy = 0.01; grid.dz = 0.01; grid.nx = 100; // Number of points in direction x. grid.ny = 100; grid.nz = 100;
lib.gts_isosurface_cartesian(surface, grid, new GtsIsoCartesianFunc() { public void callback(Pointer f, GtsCartesianGrid g, int zDirect, Pointer data) { Main.sphereShape(f, g, zDirect, data); } }, null, 1); }







