3 messages in net.java.dev.jna.usersCalling a Java method from the C code...
FromSent OnAttachments
Richard OteroDec 15, 2007 1:06 pm 
Albert StrasheimDec 15, 2007 2:18 pm 
Timothy WallDec 15, 2007 2:48 pm 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Calling a Java method from the C code + pointer handling for 2D matrixActions...
From:Richard Otero (rich@gmail.com)
Date:Dec 15, 2007 1:06:36 pm
List:net.java.dev.jna.users

Hello all!

I've gotten a good section of the GTS library accessible to Java. It turned out that there were 5 required dlls that I needed in order to use the gts library; intl.dll, libglib-2.0-0.dll, libgmodule-2.0-0.dll, libgthread-2.0-0.dll and iconv.dll.

I need some help though on: gts_isosurface_cartesian. I've include the API and usage below.

It would take as an argument a pointer to a function that graphically describes a shape. For instance a sphere; f(x, y, z) = iso with f(x, y, z) = x*x + y*y + z*z.

Ideally, I would like to be able to create the function, that describes the shape, in Java and then pass the function to gts_isosurface_cartesian to have it generate the mesh for the described surface. That way later edits to the shapes or future shapes would be able to stay within the Java portion of the code.

Is this an instance where I should be using callbacks?

If I write this function in Java; how would one handle a double **a type, as appears in the GtsIsoCartesianFunc API?

thank you! Richard

---------------------------------------------------- The gts_isosurface_cartesian API is: void gts_isosurface_cartesian (GtsSurface *surface, GtsCartesianGrid g, GtsIsoCartesianFunc f, pointer data, double iso);

Where: surface : a GtsSurface. g : a GtsCartesianGrid. f : a GtsIsoCartesianFunc. data : user data to be passed to f. iso : isosurface value.

-----------------------------------------------------

GtsIsoCartesianFunc API is: void (*GtsIsoCartesianFunc) (double **a, GtsCartesianGrid g, int i, pointer data);

Where: a : the 2D array to be filled. g : a GtsCartesianGrid. i : the z direction index of the plane to be filled. data : user data to be passed to this function

-----------------------------------------------------

An example of it being used in C:

static void sphere (gdouble ** f, GtsCartesianGrid g, guint k, gpointer data) { gdouble x, y, z = g.z; guint i, j;

for (i = 0, x = g.x; i < g.nx; i++, x += g.dx) for (j = 0, y = g.y; j < g.ny; j++, y += g.dy) f[i][j] = x*x + y*y + z*z; }

/* Returns isosurface f(x, y, z) = iso with f(x, y, z) = x*x + y*y + z*z. */ int main (int argc, char * argv[]) { GtsCartesianGrid g; // A structure that I have using jna GtsSurface * surface; // Created a pointerType for this double iso; GtsIsoCartesianFunc func = sphere;

g.nx = 20; // number of points used in the x direction g.ny = 20; g.nz = 20; /* create data for the interval used, stored in g */ g.x = -10.0; g.dx = 20./(double) (g.nx - 1); g.y = -10.0; g.dy = 20./(double) (g.ny - 1); g.z = -10.0; g.dz = 20./(double) (g.nz - 1);

iso = 1; // unit sphere

// function to initialize a surface // I have this function working in jna surface = gts_surface_new (gts_surface_class (), gts_face_class (), gts_edge_class (), gts_vertex_class ());

// the function used to create the isosurface // this is the function I would like to get working with jna gts_isosurface_cartesian (surface, g, func, NULL, iso);

return 0; }