[vtk-developers] Mac java not returning zero-initialized objects
Mark Roden
mmroden at gmail.com
Fri Feb 25 01:11:02 EST 2011
Thanks to everyone on this.
The solution by Dean fixed the issue.
I do want to stress, though, that this is a big difference between
C/C++ and Java-- Java's guarantee of default initial values means that
many programmers rely on those defaults. I think quite a few people
(myself included) will see stability problems because they will (and I
have) use that guarantee to assume that objects are initialized to
zeros, and therefore don't perform a secondary memory-wiping step once
an object has been allocated. I don't pretend to know how hard it
would be to fix the wrapping, but it does mean that vtk's java
libraries do not conform to a basic portion of the java standard.
Just raising the issue.
Thanks for the help,
Mark
On Thu, Feb 24, 2011 at 8:42 AM, David Gobbi <david.gobbi at gmail.com> wrote:
> Hi Mark,
>
> In VTK, when vtkDataArrays are allocated they are not initialized.
> Since VTK data array allocation occurs everywhere in VTK, often
> several layers deep, it would be impossible for the Java wrappers
> to know when a vtkDataArray is allocated. Someone could add an
> exception specifically for vtkImageData::AllocateScalars(), but that
> would just be scratching an itch.
>
> You'll have to find some way to clear the scalars. Try Dean's suggestion
> to see if it works for you.
>
> - David
>
>
> On Thu, Feb 24, 2011 at 9:17 AM, Mark Roden <mmroden at gmail.com> wrote:
>> I've found what I think is an interesting bug in the Java wrapping.
>>
>> According to the spec
>> (http://java.sun.com/docs/books/jls/third_edition/html/typesValues.html#4.12.5),
>> values in java should be initialized to zero. However, when I create
>> a new vtkImageData object, the contents are not zero.
>>
>> For instance, this method, used to make a mask on top of an existing
>> vtkImageData object:
>>
>> public vtkImageData getBlankBinaryData(vtkImageData inImage){
>> vtkImageData blankImage = new vtkImageData();
>> int [] extent = inImage.GetWholeExtent();
>> double[] origin = inImage.GetOrigin();
>> double[] spacing = inimage.GetSpacing();
>> blankImage.SetExtent(extent);
>> blankImage.SetOrigin(origin);
>> blankImage.SetSpacing(spacing);
>> blankImage.SetScalarTypeToUnsignedChar();
>> blankImage.AllocateScalars();
>> return blankImage;
>> }
>>
>> That above code returns an image that is set to zero on the PC, but
>> contains a wide variety of values on the mac.
>>
>> This seems like an oversight in the wrapper. What should I do to
>> guarantee that a new vtkImageData contains only zeros?
>>
>> Thanks,
>> Mark
>
More information about the vtk-developers
mailing list