# Java Convert int\[\] to VectorUInt32

**URL:** <https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037>\
**Category:** Beginner Questions\
**Tags:** java, simpleitk\
**Created:** [July 5, 2023, 10:07pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037 "2023-07-05T22:07:38Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 5, 2023, 10:07pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/1 "2023-07-05T22:07:38Z")

</div>

The SImpleITK.extract method requires 3 parameters:

```auto
first is org.itk.simple.Image
second is org.itk.simple.VectorUInt32
third is org.itk.simple.VectorInt32

```

i know whats are this parameters, i was able to reproduce this in python.  
But i dont know how to convert an int array to VectorUInt32 and VectorInt32, example:

```auto
int[] array = {512, 512, 0};
VectorUInt32 vectorUInt = new VectorUInt32(array[0], array[1], array[2]);
VectorInt32 vectorInt = new VectorInt32(array[0], array[1], array[2]);

```

VectorUInt32 and VectorInt32 has 3 constructors methods each.

```auto
VectorInt32(long l, boolean b) or
VectorInt32() or
VectorInt32(long l)

```

and

```auto
VectorUInt32(long l, boolean b) or
VectorUInt32() or
VectorUInt32(long l)

```

So how i’m supposed to convert this? It is very confusing.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [July 6, 2023, 2:16am UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/2 "2023-07-06T02:16:03Z")

</div>

Hello @Salu_Ramos,

I’m not too familiar with the Java version, but have you tried:

```auto
int[] array = {512,512,1}
VectorUInt32 vectorUInt = new VectorUInt32( array );
VectorInt32 vectorInt = new VectorInt32( array );

```

Note that the array size with third component of zero is usually not appropriate for image size. If in 2D size is 512\times512, if in 3D then 512\times512\times1.

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 6, 2023, 12:28pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/3 "2023-07-06T12:28:15Z")

</div>

if i try this, with array being a int or double or long:

`VectorUInt32 vectorUInt = new VectorUInt32( array );`

then:  
`java: incompatible types: int[] cannot be converted to long`  
`java: incompatible types: double[] cannot be converted to long`  
`java: incompatible types: long[] cannot be converted to long`

tried this also:

> public Image simpleSlice (long sliceSize, int sliceIndex) {  
> VectorUInt32 vectorSize = new VectorUInt32(); //like {512, 512, 0}  
> vectorSize.set(0, sliceSize[0]);  
> vectorSize.set(1, sliceSize[1]);  
> vectorSize.set(2, sliceSize[2]);  
> VectorInt32 vectorIndex = new VectorInt32(); //like {0, 0, 10}  
> vectorIndex.set(0, sliceIndex[0]);  
> vectorIndex.set(1, sliceIndex[1]);  
> vectorIndex.set(2, sliceIndex[2]);  
> Image sliceExtraction = SimpleITK.extract(this.volume, vectorSize, vectorIndex);  
> System.out.println(sliceExtraction);  
> return sliceExtraction;  
> }

then:  
`java.lang.UnsatisfiedLinkError: 'void org.itk.simple.SimpleITKJNI.VectorUInt32_set(long, org.itk.simple.VectorUInt32, int, long)'`

Nothing works

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 6, 2023, 2:14pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/4 "2023-07-06T14:14:06Z")

</div>

i find this: [Hello World — SimpleITK 2.0rc2 documentation](https://simpleitk.readthedocs.io/en/master/link_HelloWorld_docs.html)

as in example:

> long isize = {128, 128};  
> VectorUInt32 imageSize = new VectorUInt32( isize )

Documentation code does not work.

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 6, 2023, 2:57pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/5 "2023-07-06T14:57:11Z")

</div>

I just built and ran the HelloWorld example in Java on my PC, and it worked just fine. What version of Java are you using and on what platform? I’m using JDK 17.

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 6, 2023, 3:27pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/6 "2023-07-06T15:27:33Z")

</div>

i’m running java 20.0.1 2023-04-18 in windows 11, with intellij idea community.

my pom.xml:  
 ![image](https://discourse.itk.org/uploads/default/original/2X/9/941e2d3fb25e6ed072db674f7f7b35befd4b7f8b.png)

i downloaded the binaries from (last version SimpleITK-2.3.0rc1.post2-Java-win64.zip):

> **[Releases · SimpleITK/SimpleITK](https://github.com/SimpleITK/SimpleITK/releases)**
>
> SimpleITK: a layer built on top of the Insight Toolkit (ITK), intended to simplify and facilitate ITK's use in rapid prototyping, education and interpreted languages. - SimpleITK/SimpleITK

i also added the binary folder in the “project structure” \> “libraries”  
 ![image](https://discourse.itk.org/uploads/default/original/2X/6/6287cbcc83c88d325bfc888af0ff45add4119c89.png)

 ![image](https://discourse.itk.org/uploads/default/original/2X/0/02df542a4f2e775cec61a698e22eace3292faff7.png)

my VM options for binary path:

`-Djava.library.path="D:\my github repos\noah-viewer-java\SimpleITK-2.3.0rc1.post2-Java-win64"`

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 6, 2023, 6:54pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/7 "2023-07-06T18:54:09Z")

</div>

i downgraded jdk to 17 but got same error:

```auto
long[] isize = {128, 128};
VectorUInt32 imageSize = new VectorUInt32( isize );

```

`java: incompatible types: long[] cannot be converted to long`

Maybe my pom.xml is using an too old version? (0.9.0) I was unable to find another public maven repository that has newer version of simpleitk. If you can provide it to me @dchen i would be very grateful.

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 7, 2023, 4:48pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/8 "2023-07-07T16:48:46Z")

</div>

I’m not a real Java person, so I have no knowledge about Maven. Trying to read up on it. Looking at scijava maven repo, the simpleitk maven file seems to be just an XML file with a version number in it. I don’t see a jar file there, so how does that even work?

And, of course, the SimpleITK version there is very old.

---

<div class="post-metadata">

**Author:** ![Salu\_Ramos](https://discourse.itk.org/user_avatar/discourse.itk.org/salu_ramos/32/3619_2.png) [@Salu\_Ramos](https://discourse.itk.org/u/Salu_Ramos)\
**Post date:** [July 7, 2023, 5:27pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/9 "2023-07-07T17:27:38Z")

</div>

I must say that I am not a java guy either, it just so happens that Java was the best alternative for the project I am working on now.

It turns out that the only maven repository that contained simpleITK only had it in a very old version, which I must say is far from being functional. I went to the folder where maven downloads the dependencies (.m2\repository\org\itk\simple\simpleitk\0.9.0), deleted the old jar file from version 0.9.0 and put the new one from version 2.3.0 with the name of version 0.9.0. This solved all the conversion problems. But of course this is a package management problem and after talking to a java expert friend of mine, I decided to start using gradle. And since there is no up-to-date simpleitk repository I will have to ask gradle to use a local folder as a dependency.

![image](https://discourse.itk.org/uploads/default/original/2X/2/2c97e06e609f96914b68014570429db2fd6e8431.png)  
picture of simpleitk-2.3.0 undercover as simpleitk-0.9.0

But here’s a new question @dchen, how did you configure your dependencies to run?

---

<div class="post-metadata">

**Author:** ![dchen](https://discourse.itk.org/user_avatar/discourse.itk.org/dchen/32/34_2.png) [@dchen](https://discourse.itk.org/u/dchen)\
**Post date:** [July 7, 2023, 10:17pm UTC](https://discourse.itk.org/t/java-convert-int-to-vectoruint32/6037/10 "2023-07-07T22:17:55Z")

</div>

I use cmake to configure and build the SimpleITK source code. In the process it configures all the dependencies.
