[vtkusers] VTK and Java - JNI issue

Monnier, Gilles Gilles.Monnier at oce.com
Tue Aug 21 04:22:47 EDT 2012


Oups, the code I posted is not axacly right, here it is:
 
 
JNIEXPORT jlong JNICALL Java_nativePCL_1triangulation
  (JNIEnv * env, jobject obj, jobject polyDataJava)
{
 
 // Get the pointer on the input polyData object
 vtkSmartPointer<vtkPolyData> inPolyDataSmartPtr = (vtkPolyData*)(vtkJavaGetPointerFromObject(env,polyDataJava));
 
 if(inPolyDataSmartPtr != NULL) {
    // Triangulate the input vtk point cloud 
    vtkSmartPointer<vtkPolyData> outPolyDataSmartPtr = Triangulation::triangulate(inPolyDataSmartPtr);
 
    return (jlong)(size_t) outPolyDataSmartPtr.GetPointer();
  
 } else {
    // No input data was retrieved
    return 0;
 }
 return 0;
}
 
________________________________

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Monnier, Gilles
Sent: mardi 21 août 2012 10:18
To: A A; vtkusers at vtk.org
Subject: Re: [vtkusers] VTK and Java - JNI issue


Hi,
 
Thanks for the response. Actually, I succeeded to do what I want with the following method :
 
vtkJavaGetPointerFromObject
 
This method is defined into vtkJavaUtil.h (exported in vtkCommonJava.dll). So finally my code is the following to perform a quite fast triangulation with PCL :
 
JNIEXPORT jobject JNICALL Java_nativePCL_1triangulation
  (JNIEnv * env, jobject obj, jobject polyDataJava)
{
 
 // Get the pointer on the input polyData object
 vtkSmartPointer<vtkPolyData> inPolyDataSmartPtr = (vtkPolyData*)(vtkJavaGetPointerFromObject(env,polyDataJava));
 
 if(inPolyDataSmartPtr != NULL) {
    // Triangulate the input vtk point cloud 
    vtkSmartPointer<vtkPolyData> outPolyDataSmartPtr = Triangulation::triangulate(inPolyDataSmartPtr);
 
    vtkPolyData* polydatatest = (vtkPolyData*) out2PolyDataSmartPtr.GetPointer();
    return (jlong)(size_t) outPolyDataSmartPtr.GetPointer();
  
 } else {
    // No input data was retrieved
    return NULL;
 }
 return NULL;
}
 
I didn't know about the auto-generating of JNI from vtk, but I think this will produce quite the same result, and I will make use of that next time, so thanks for the tip.
 
Regards,
Gilles Monnier.
 
________________________________

From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of A A
Sent: mardi 21 août 2012 04:26
To: vtkusers at vtk.org
Subject: Re: [vtkusers] VTK and Java - JNI issue


Personally, I would try to avoid hand coding JNI glue code myself. Since VTK already provided facilities for auto-generating JNI code, I would make use of that. You can simply create a subclasses of vtkObject which consists of a static function, say, 

void triangulation(vtkPolyData* inputCloud)

In the implementation of this function, you now have a pointer the vtkPolyData object which you instantiated in the java side. You could compile this class with Java wrapping turned on (See the Examples/Build folder in the VTK source for examples) and link in the PCL library, and all the JNI code will be generated for you. At the beginning of the java program, you will need to make sure to load (with the loadLibrary function) the 2 generated shared libaries plus the PCL library.



On Thu, Aug 16, 2012 at 11:06 AM, Monnier, Gilles <Gilles.Monnier at oce.com> wrote:


	
	Hi,

	 

	I'm currently facing an issue using VTK with java.

	 

	Actually, I'm trying to integrate a C++ library into my software. This library is PCL (Point Cloud Library), which offer some interesting features concerning triangulation and registration. Here is below how my application is designed:

	 

	 

	

	 

	Kitware already provide the JNI interface for VTK, but PCL does not. What I would like to do is to be able to request PCL to perform a triangulation on the vtkPolyData I instanciated into my java code.

	 

	Therefore, I started to create the PCL JNI interface by creating a simple method on the java side:

	 

	public native int nativePCL_triangulation(vtkPolyData inputCloud);

	 

	Then after having generated the header file, I need to implement the C++ code of the interface:

	 

	#include <vtkPolyData.h>

	

	JNIEXPORT jint JNICALL nativePCL_triangulation(JNIEnv * env, jobject obj, jobject polyDataJava)

	{

	       //vtkPolyData* vp = dynamic_cast<vtkPolyData*>(polyDataJava);

	       return 0;

	}

	 

	And here is my issue : How can I retrieve the pointer on the polyData I instanciated into my java code? 

	To be clear, I would like to access the C++ object instanciated by VTK from the C++ part of the interface I want to implement (the best would be a stuff like a dynamic_cast as in the comment above...). I have absolutely no idea how to achieve that.

	 

	Thanks much,

	Gilles Monnier


	This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law. If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message. Thank you for your co-operation. 

	_______________________________________________
	Powered by www.kitware.com
	
	Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
	
	Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
	
	Follow this link to subscribe/unsubscribe:
	http://www.vtk.org/mailman/listinfo/vtkusers
	
	



This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law. If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message. Thank you for your co-operation. 


This message and attachment(s) are intended solely for use by the addressee and may contain information that is privileged, confidential or otherwise exempt from disclosure under applicable law.

If you are not the intended recipient or agent thereof responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited.

If you have received this communication in error, please notify the sender immediately by telephone and with a 'reply' message.

Thank you for your co-operation.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120821/d35fb5fe/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/png
Size: 9362 bytes
Desc: pic2.png
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120821/d35fb5fe/attachment.png>


More information about the vtkusers mailing list