Discussion:
[ITK-users] Generating compatible Java wrappings of SimpleITK between Windows and Linux (x86-64)
Kosma Dunikowski
2017-09-13 10:45:48 UTC
Permalink
Hi,

I'm having a problem with swig-generated Java wrappings on both Windows
and Linux. I'm getting different method signatures all over the place, e.g:

Windows:
public void add(long x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}

Linux:
public void add(int x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}

Windows:
public java.math.BigInteger getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}

Linux:
public long getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}

(full diff @
https://drive.google.com/a/pixel.com.pl/file/d/0Bzm8rPONV4SJOTA4R0tHTXFPWms/view?usp=sharing)

As you can see there are some differences in data sizes. So far I've
tried building it with swig 3.0.8, 3.0.9, 3.0.12 and a patched fork
mentioned at https://github.com/swig/swig/pull/649 with similar results.
I'm using ITK v4.10.0 and SimpleITK v0.10.0 but I've also tried the
latest releases. As for the compilers, I used multiple versions of gcc
on Linux and mingw-w64 and Visual Studio on Windows.

I've tried manually undefining SWIGWORDSIZE64 on Linux (which is enabled
if SITK_ULONG_SAME_AS_UINT64 test passes), which resulted in matching
wrappings but also immediate segfaults after I tried using it.

If anyone knows how to tackle this problem, I would greatly appreciate
it, since I'm unable to maintain separate Java codebases for different
platforms.

Best regards,

Kosma Dunikowski

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
Lowekamp, Bradley (NIH/NLM/LHC) [C]
2017-09-13 17:14:11 UTC
Permalink
Hello,

That you for posting the issue.

Can you please create an issue for this problem in SimpleITK’s Github issue tracker:
https://github.com/SimpleITK/SimpleITK/issues

I recall looking into this problem some time ago and not being happy with this inconsistent interface for Java that SWIG generated. It should be consistent. There is not much to how we specify the interface for Java, so this is really SWIG will need to be fixed to get our interface proper.

Unfortunately, the mixture of type long and BinInteger is complicated since the long type cannot be implicitly converted to a BigInteger. In our generated code for testing we added a class to help with this conversion. Depending on your usage this may be a useful approach.

Thanks,
Brad

On 9/13/17, 6:46 AM, "Kosma Dunikowski" <***@pixel.com.pl> wrote:

Hi,

I'm having a problem with swig-generated Java wrappings on both Windows
and Linux. I'm getting different method signatures all over the place, e.g:

Windows:
public void add(long x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}

Linux:
public void add(int x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}

Windows:
public java.math.BigInteger getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}

Linux:
public long getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}

(full diff @
https://drive.google.com/a/pixel.com.pl/file/d/0Bzm8rPONV4SJOTA4R0tHTXFPWms/view?usp=sharing)

As you can see there are some differences in data sizes. So far I've
tried building it with swig 3.0.8, 3.0.9, 3.0.12 and a patched fork
mentioned at https://github.com/swig/swig/pull/649 with similar results.
I'm using ITK v4.10.0 and SimpleITK v0.10.0 but I've also tried the
latest releases. As for the compilers, I used multiple versions of gcc
on Linux and mingw-w64 and Visual Studio on Windows.

I've tried manually undefining SWIGWORDSIZE64 on Linux (which is enabled
if SITK_ULONG_SAME_AS_UINT64 test passes), which resulted in matching
wrappings but also immediate segfaults after I tried using it.

If anyone knows how to tackle this problem, I would greatly appreciate
it, since I'm unable to maintain separate Java codebases for different
platforms.

Best regards,

Kosma Dunikowski

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
***@itk.org
http://public.kitware.com/mailman/listinfo/community


_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/ma
Kosma Dunikowski
2017-09-14 15:14:57 UTC
Permalink
Hi again,

Thanks for the response. In the end I got to work properly with the
forked swig I mentioned (https://github.com/johnwason/swig/tree/java64),
after adding

#if defined(SWIGWORDSIZE64)
%apply unsigned int { size_t };
%apply const unsigned int & { const size_t & };
#endif

as recommended by the patch's author. I asked the swig maintainers to
consider pulling these changes in.

Kosma
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Hello,
That you for posting the issue.
https://github.com/SimpleITK/SimpleITK/issues
I recall looking into this problem some time ago and not being happy with this inconsistent interface for Java that SWIG generated. It should be consistent. There is not much to how we specify the interface for Java, so this is really SWIG will need to be fixed to get our interface proper.
Unfortunately, the mixture of type long and BinInteger is complicated since the long type cannot be implicitly converted to a BigInteger. In our generated code for testing we added a class to help with this conversion. Depending on your usage this may be a useful approach.
Thanks,
Brad
Hi,
I'm having a problem with swig-generated Java wrappings on both Windows
public void add(long x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public void add(int x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public java.math.BigInteger getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
public long getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
https://drive.google.com/a/pixel.com.pl/file/d/0Bzm8rPONV4SJOTA4R0tHTXFPWms/view?usp=sharing)
As you can see there are some differences in data sizes. So far I've
tried building it with swig 3.0.8, 3.0.9, 3.0.12 and a patched fork
mentioned at https://github.com/swig/swig/pull/649 with similar results.
I'm using ITK v4.10.0 and SimpleITK v0.10.0 but I've also tried the
latest releases. As for the compilers, I used multiple versions of gcc
on Linux and mingw-w64 and Visual Studio on Windows.
I've tried manually undefining SWIGWORDSIZE64 on Linux (which is enabled
if SITK_ULONG_SAME_AS_UINT64 test passes), which resulted in matching
wrappings but also immediate segfaults after I tried using it.
If anyone knows how to tackle this problem, I would greatly appreciate
it, since I'm unable to maintain separate Java codebases for different
platforms.
Best regards,
Kosma Dunikowski
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
http://public.kitware.com/mailman/listinfo/community
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
ht
Lowekamp, Bradley (NIH/NLM/LHC) [C]
2017-09-14 15:19:04 UTC
Permalink
Can you please create an issue on SimpleITK github issue tracker?

Where did you add that SWIG code too?

Thanks,
Brad

On 9/14/17, 11:16 AM, "Kosma Dunikowski" <***@pixel.com.pl> wrote:

Hi again,

Thanks for the response. In the end I got to work properly with the
forked swig I mentioned (https://github.com/johnwason/swig/tree/java64),
after adding

#if defined(SWIGWORDSIZE64)
%apply unsigned int { size_t };
%apply const unsigned int & { const size_t & };
#endif

as recommended by the patch's author. I asked the swig maintainers to
consider pulling these changes in.

Kosma
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Hello,
That you for posting the issue.
https://github.com/SimpleITK/SimpleITK/issues
I recall looking into this problem some time ago and not being happy with this inconsistent interface for Java that SWIG generated. It should be consistent. There is not much to how we specify the interface for Java, so this is really SWIG will need to be fixed to get our interface proper.
Unfortunately, the mixture of type long and BinInteger is complicated since the long type cannot be implicitly converted to a BigInteger. In our generated code for testing we added a class to help with this conversion. Depending on your usage this may be a useful approach.
Thanks,
Brad
Hi,
I'm having a problem with swig-generated Java wrappings on both Windows
public void add(long x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public void add(int x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public java.math.BigInteger getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
public long getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
https://drive.google.com/a/pixel.com.pl/file/d/0Bzm8rPONV4SJOTA4R0tHTXFPWms/view?usp=sharing)
As you can see there are some differences in data sizes. So far I've
tried building it with swig 3.0.8, 3.0.9, 3.0.12 and a patched fork
mentioned at https://github.com/swig/swig/pull/649 with similar results.
I'm using ITK v4.10.0 and SimpleITK v0.10.0 but I've also tried the
latest releases. As for the compilers, I used multiple versions of gcc
on Linux and mingw-w64 and Visual Studio on Windows.
I've tried manually undefining SWIGWORDSIZE64 on Linux (which is enabled
if SITK_ULONG_SAME_AS_UINT64 test passes), which resulted in matching
wrappings but also immediate segfaults after I tried using it.
If anyone knows how to tackle this problem, I would greatly appreciate
it, since I'm unable to maintain separate Java codebases for different
platforms.
Best regards,
Kosma Dunikowski
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
http://public.kitware.com/mailman/listinfo/community
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://pu
Kosma Dunikowski
2017-09-14 15:39:24 UTC
Permalink
I added it to Wrapping/Java/Java.i

GitHub issue: https://github.com/SimpleITK/SimpleITK/issues/295
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Can you please create an issue on SimpleITK github issue tracker?
Where did you add that SWIG code too?
Thanks,
Brad
Hi again,
Thanks for the response. In the end I got to work properly with the
forked swig I mentioned (https://github.com/johnwason/swig/tree/java64),
after adding
#if defined(SWIGWORDSIZE64)
%apply unsigned int { size_t };
%apply const unsigned int & { const size_t & };
#endif
as recommended by the patch's author. I asked the swig maintainers to
consider pulling these changes in.
Kosma
Post by Lowekamp, Bradley (NIH/NLM/LHC) [C]
Hello,
That you for posting the issue.
https://github.com/SimpleITK/SimpleITK/issues
I recall looking into this problem some time ago and not being happy with this inconsistent interface for Java that SWIG generated. It should be consistent. There is not much to how we specify the interface for Java, so this is really SWIG will need to be fixed to get our interface proper.
Unfortunately, the mixture of type long and BinInteger is complicated since the long type cannot be implicitly converted to a BigInteger. In our generated code for testing we added a class to help with this conversion. Depending on your usage this may be a useful approach.
Thanks,
Brad
Hi,
I'm having a problem with swig-generated Java wrappings on both Windows
public void add(long x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public void add(int x) {
SimpleITKJNI.VectorInt64_add(swigCPtr, this, x);
}
public java.math.BigInteger getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
public long getPixelAsUInt64(VectorUInt32 idx) {
return SimpleITKJNI.Image_getPixelAsUInt64(swigCPtr, this,
VectorUInt32.getCPtr(idx), idx);
}
https://drive.google.com/a/pixel.com.pl/file/d/0Bzm8rPONV4SJOTA4R0tHTXFPWms/view?usp=sharing)
As you can see there are some differences in data sizes. So far I've
tried building it with swig 3.0.8, 3.0.9, 3.0.12 and a patched fork
mentioned at https://github.com/swig/swig/pull/649 with similar results.
I'm using ITK v4.10.0 and SimpleITK v0.10.0 but I've also tried the
latest releases. As for the compilers, I used multiple versions of gcc
on Linux and mingw-w64 and Visual Studio on Windows.
I've tried manually undefining SWIGWORDSIZE64 on Linux (which is enabled
if SITK_ULONG_SAME_AS_UINT64 test passes), which resulted in matching
wrappings but also immediate segfaults after I tried using it.
If anyone knows how to tackle this problem, I would greatly appreciate
it, since I'm unable to maintain separate Java codebases for different
platforms.
Best regards,
Kosma Dunikowski
_____________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
_______________________________________________
Community mailing list
http://public.kitware.com/mailman/listinfo/community
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitw

Loading...