[vtkusers] How to prevent out-of-memory crash with vtkImageReader from Java

Marco Sambin m.sambin at gmail.com
Wed Oct 15 05:04:59 EDT 2014


Hi all.
In my VTK-based Java application, I am reading a "raw volume file"
(containing a set of CT slices) through some Java code looking like this:

[...]
vtkImageReader imageReaderVTK =  new vtkImageReader();
imageReaderVTK.FileLowerLeftOn();
imageReaderVTK.SetFileDimensionality(3);
imageReaderVTK.SetFileName(curRawVolFile.getAbsolutePath());
imageReaderVTK.SetDataExtent(0, sliceCols - 1,
                      0, sliceRows - 1,
                      0, numOfUsedImages - 1);
imageReaderVTK.SetDataSpacing(xSpacing, ySpacing, zSpacing);
imageReaderVTK.SetDataOrigin(0.0, 0.0, 0.0);
imageReaderVTK.SetDataScalarTypeToUnsignedShort();
imageReaderVTK.SetDataByteOrderToBigEndian();

// The following call may cause a process crash due to out-of-memory
imageReaderVTK.UpdateWholeExtent();
[...]

I am then passing this volume to a vtkImagePlaneWidget for some reslicing.

As the last comment (in the code fragment above) suggests, in some cases I
get a crash of the JVM process, due to the fact the reader goes out of
memory while actually reading and allocating the whole volume in memory.
This especially happens when using a 32-bit JRE.
I understand that I cannot read a huge volume in memory if just a small
amount of memory is available to the process, but my question is:
is there a way to manage "more gracefully" this out-of-memory from Java
code, in such a way to be able to inform the user that "Not enough memory
is available to read this volume", instead of causing a JVM crash?

I am using VTK 6.1.0.

Thanks for any hint/suggestion about this topic.

Best regards,

Marco
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20141015/10945f50/attachment.html>


More information about the vtkusers mailing list