[Insight-users] About pipeline in Java
William A. Hoffman
billlist at nycap.rr.com
Wed, 10 Mar 2004 10:53:57 -0500
OK, here is how you can access the data in an image from java:
ImageFileReaderF2 reader;
reader.Update();
itkImageF2_Pointer image = reader.GetOutput();
SWIGTYPE_p_float fp = image.GetBufferPointer();
long numPix = image.GetBufferedRegion().GetNumberOfPixels();
// to set data in the image
for(long i = 0; i < numPix; ++i)
{
SwigExtras.FArray_setitem(fp, i, 1.0);
}
// to get data from the image
for(long i = 0; i < numPix; ++i)
{
float pixel = SwigExtras.FArray_getitem(fp, i);
// do something with pixel
}
This should allow import/export of image data from itk to java.
This will not be the fastest code around, see my posting:
"Re: [Insight-users] Java wrappers import/export data" on the 8th for
details of how you might make it faster. However, it should get
the job done, and if you minimize the import/export it should
work well enough.
So, I can see two uses for this:
1. you load the data using a java class, then process the
data with itk. In this case:
create a new itkImageF2 and allocate the buffer, then write
the data using the FArray_setitem.
2. you load the data and process it in itk, then you use
java to display the image after processing. For this use
the reader example above.
-Bill
At 05:16 PM 3/9/2004, Pablo D. Burstein wrote:
>Hi Bill,
>
> Thanks for the new version. Indeed it returns an itkImageUS2 now. The problem is that GetBufferPointer() (in fact I wouldn't know how to use this in Java), GetPixelContainer(), etc., still return SWIGTypes (aren't these intended to be internal?), so I am stuck again.
>
>Any solution in view?
>Thanks,
>Pablo
>
>
>William A. Hoffman wrote:
>
>>I have checked in the fix for CableSwig.cxx.
>>
>>I now get this:
>>
>>public class itkImageFileReaderUC2_Pointer {
>>....
>> public itkImageUC2 GetOutput() {
>>
>>
>>-Bill
>>
>>At 11:22 AM 3/9/2004, Pablo D. Burstein wrote:
>>
>>
>>>That's very encouraging news. Please, let me (us) know as soon as it's checked in.
>>>
>>>Thanks a lot,
>>>Pablo
>>>
>>>William A. Hoffman wrote:
>>>
>>>
>>>
>>>>This is a bug in the wrapping. It should not return a SWIGTYPE_p class, it should
>>>>return the image class. I checked in a fix, but had to back it out because
>>>>it broke the tcl wrapping. I will post when I have checked in the new fix.
>>>>
>>>>-Bill
>>>>
>>>>
>>>>At 10:54 AM 3/9/2004, Pablo D. Burstein wrote:
>>>>
>>>>
>>>>
>>>>
>>>>>Hi,
>>>>>
>>>>> I have a problem understanding how the pipeline, used from Java-wrapped ITK, works. Specifically, when I used my own wrapping (and wrote a C++ pipeline), I could have an ImageFileReader connecting to an Image::Pointer and then access the Image's methods. Opposedly, when I use ImageFileReader from java, GetOutput() returns a SWIGTYPE_p_itk_ImageTunsigned_short_2_t (for example). How does this relates to ITK's Image now? What should I do if I want to call, for instance, GetBufferPointer() or have any similar access to the data?
>>>>>And in general, is there any doc explaining the Java-wrapped ITK architecture?
>>>>>
>>>>>Thanks,
>>>>>Pablo
>>>>>
>>>>>
>>>>>Brad King wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>>Pablo D. Burstein wrote:
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>Hi Brad,
>>>>>>>
>>>>>>>I caanot find itkbase.java anywhere (I wanted to take a look).
>>>>>>>
>>>>>>>
>>>>>>It is in the ITK build tree under Wrapping/CSwig/Java/{Debug,Release}/InsightToolkit, and is configured by the build process from a source tree file under Wrapping/CSwig/Java called itkbase.java.in.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I put InsigtToolkit.jar in the classpath but it didn't help. From my JNI
>>>>>>>
>>>>>>>
>>>>>>>experience, the Java class accessing native methods should load the dlls using the name of the library, no path or extensions allowed.
>>>>>>>
>>>>>>>
>>>>>>The jar that is created by ITK now is designed to run from the build tree only. No installable version has been created. The idea of encoding the paths to the libraries is that one may use the jar by simply adding it to the classpath (right from the build tree, not copying it to somewhere else). There is no need for adding the DLL locations to the PATH environment variable.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>>I tried to look for System.loadLibrary in the wrapped code; haven't found anything of the kind. How do libs get loaded then?
>>>>>>>
>>>>>>>
>>>>>>If you find the code in itkbase.java, it should be clear how it works. All the wrapper code in java starts by calling a method in itkbase.java to find and load the native DLLs. The whole idea is to work around what seems to be an inherent Java/Windows design flaw. No one should ever have to add entries to both the CLASSPATH and the PATH variables just to load a package. What if a user points the PATH to the wrong DLL versions for the jar to which they pointed the CLASSPATH?
>>>>>>
>>>>>>-Brad
>>>>>>
>>>>>>
>>>>>______________________________________________________________________
>>>>>This email has been scanned by the MessageLabs Email Security System.
>>>>>For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
>>>>>_______________________________________________
>>>>>Insight-users mailing list
>>>>>Insight-users at itk.org
>>>>>http://www.itk.org/mailman/listinfo/insight-users
>>>>>
>>>>>
>>>______________________________________________________________________
>>>This email has been scanned by the MessageLabs Email Security System.
>>>For more information please visit http://www.messagelabs.com/email ______________________________________________________________________
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users at itk.org
>>>http://www.itk.org/mailman/listinfo/insight-users
>>>
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>>
>
>______________________________________________________________________
>This email has been scanned by the MessageLabs Email Security System.
>For more information please visit http://www.messagelabs.com/email ______________________________________________________________________