[vtk-developers] Mac java not returning zero-initialized objects

David Gobbi david.gobbi at gmail.com
Thu Feb 24 11:42:13 EST 2011


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