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

Bill Lorensen bill.lorensen at gmail.com
Thu Feb 24 11:42:06 EST 2011


I think it just seems to be filled with zeroes on the PC. I believe
that you must fill it explicitly with whatever you feel is the right
value. The Allocate method just does a malloc, not a calloc. The data
array associated with images is dynamically allocated. I do not know
if Java requires that dynamically allocated data must be initialized
to 0.

Bill


On Thu, Feb 24, 2011 at 11: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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
>



More information about the vtk-developers mailing list