# Java wrapper code changes

**URL:** https://discourse.vtk.org/t/java-wrapper-code-changes/5834
**Category:** Announcements
**Created:** [May 21, 2021, 1:07am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834 "2021-05-21T01:07:22Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [May 21, 2021, 1:07am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/1 "2021-05-21T01:07:22Z")

</div>

Recently some significant changes have been merged to the VTK master branch for the Java wrapper code generation. The number of exported data types has been extended to include _byte_, _short_, _long_ and _float_ types, so that the generated methods closely match those in the VTK API. Overloaded function declarations are also now output. Array marshalling has been improved and the javac deprecation warnings have been eliminated.

It would be helpful if any developers building the Java wrappers from the master branch could try out the new code and give some feedback about any issues they run into.

---

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [October 11, 2021, 10:09am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/2 "2021-10-11T10:09:00Z")

</div>

Hi,

I am currently using VTK 9.0.3 with the Java Wrapper that I built few weeks ago. I have VTU files containing `<DataArray type="Float64" NumberOfComponents="3" format="binary">` and I have no problem loading them.

However I don’t see any method for retrieving `vtkDataArray` as Java float directly, only as `double` or `double[]`, so I do the cast by myself. Do you expect I find new Java methods for retrieving byte, short, long and float types?

 ![Capture d’écran 2021-10-11 à 12.03.08](https://discourse.vtk.org/uploads/default/original/2X/a/a8119098ee77b4c19e37f3c20fe74975f66b5aee.jpeg)

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [October 11, 2021, 1:13pm UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/3 "2021-10-11T13:13:53Z")

</div>

`float[] output = ((vtkFloatArray) array).GetJavaArray();`

---

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [October 12, 2021, 4:15pm UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/4 "2021-10-12T16:15:59Z")

</div>

Thanks Todd. The file I have declare Float64 data type, but data is parsed as java double (seams correct). The method you suggest works but if you are looking for feedback on float loading, may I ask you pointers toward files that lead to java float when loaded?

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [October 12, 2021, 9:30pm UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/5 "2021-10-12T21:30:04Z")

</div>

> [@Martin3d](#):
>
> may I ask you pointers toward files that lead to java float when loaded?

Sorry I don’t understand the question.

What do you mean when you say Float64 is parsed as double? What C++ code is being called?

---

<div class="post-metadata">

### Author: ![Sebastien\_Jourdain](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sebastien_jourdain/32/100_2.png) [@Sebastien\_Jourdain](https://discourse.vtk.org/u/Sebastien_Jourdain)
#### Post date: [October 12, 2021, 11:26pm UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/6 "2021-10-12T23:26:05Z")

</div>

By definition we have

```auto
float32 => float
float64 => double

```

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [October 13, 2021, 12:03am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/7 "2021-10-13T00:03:29Z")

</div>

In that case a _vtkDoubleArray_ is created by the reader rather than a _vtkFloatArray_ so

```auto

double[] output = ((vtkDoubleArray) array).GetJavaArray();

```

---

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [October 13, 2021, 7:25am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/8 "2021-10-13T07:25:10Z")

</div>

Yes, I understood vtk Float64 are parsed as java double. My point is that you asked for feedbacks on _byte_ , _short_ , _long_ and _float_ types (which I understood to be java types), but I only have files containing vtk Float64. If you provide me a file containing Float32, I can give a try and let you know if this works correctly.

---

<div class="post-metadata">

### Author: ![toddy](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/t/edb3f5/32.png) [@toddy](https://discourse.vtk.org/u/toddy)
#### Post date: [October 13, 2021, 7:44am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/9 "2021-10-13T07:44:07Z")

</div>

Ah. Sorry. I don’t have any data files for that.

I was mainly referring to methods which now pass parameters of those types like  
`vtkBrush.SetColor(byte r,byte g,byte b)` which previously used integers.

---

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [October 13, 2021, 9:39am UTC](https://discourse.vtk.org/t/java-wrapper-code-changes/5834/10 "2021-10-13T09:39:20Z")

</div>

I unfortunately can’t test this : I am on MacOS, where [vtk renderers crash in Java](https://discourse.vtk.org/t/simplevtk-java-example-crashing-on-macos/6472/6), so I use [another rendering framework](https://github.com/jzy3d/jzy3d-api). I mainly use vtk in Java for IO and filtering so far.
