Login  Register

Re: Copy volume from within stack to new stack

Posted by dscho on Jan 19, 2009; 6:25pm
URL: http://imagej.273.s1.nabble.com/Copy-volume-from-within-stack-to-new-stack-tp3693965p3693988.html

Hi,

On Mon, 19 Jan 2009, Michael Doube wrote:

> OK. To answer my own question, I had to move a line
>
>   short[] roiPixels = new short[roiWidth*roiHeight];
>
> From outside to inside the
>
> for (int z = startZ; z <= startZ+roiDepth; z++)
>
> loop.
>
> Can anyone tell me why this makes a difference?

Java objects -- and arrays are very much an object, not a primitive -- are
always passed by reference, that is if you do pass an array to a
constructor which keeps a reference around, and you change the array
later, the newly created class will get the changes, too.

This is very much what is happening here: ShortProcessor does not make a
copy, but uses the pixels directly.  But in the next loop iteration you
changed the pixels array.

Ciao,
Dscho