> From: "Casteel, Don" <[EMAIL PROTECTED]>
> Subject: [JAVA3D] Out Of Memory Exception !!!
> To: [EMAIL PROTECTED]
>
> I've written a working Isosurface Generator using the "marching cubes"
> algorithm. It takes a dataset of voxels like the data you can find on the
> web from MRI scans, and wraps a surface around the data based on a threshold
> variable. The program has worked fine with datasets up to 50x50x50 voxels.
> (I'm generating my own datasets with another J3D program, same format as the
> MRI data)
>
> I've sized a temporary Point3d[] array to 50x50x50x5x3, (the maximum number
> of vertices possible, 5 triangles per cube 3 vertices each). As each cube is
> parsed I fill the temp array with the vertices until all cubes have been
> parsed, keeping count of the number of actual vertices used. Then initialize
> a public array to the size required and extract the points from the temp
> array into it, and dispose of the temp array.
>
> (the above step wouldn't be required if I could append Arrays)

This approach uses many more points than the data set could ever use.  Think
about it, how many cubes out of the volume actually have the surface passing
through them?  Certainly less than 10%.  Only allocating memory for the cubes
that have a surface would save alot of memory.

Also, as you are generating the surface, you only need to have one "layer" of
cubes in memory at a time (where a "layer" is the set of cubes between two
slices).  The cubes from all the layers can be joined together once the surfaces
are generated.

> Again this all works fine with a dataset of that size. However when I
> attempt to go to a 100x100x100 dataset, I'm getting an out of memory
> exception.

This makes sense, even without knowing the sizes for internal Java entities we
know that you are using:

        342MB of doubles (100x100x100x5x3x (3 doubles/P3D) x sizeof(double))
        15 million Point3d objects
        5 million double[] arrays  (100x100x100x5)
        1 million double[][] arrays (100x100x100)
        10,000 double[][][] arrays (100x100)
        100 double[][][][] arrays

Using a single layer of cubes at generation time will reduce this by 100x,
filling in the cubes as necessary could save another 10-100x.

You may also want to consider using floats for your internal data.  Unless the
MRI has more than 24 bits of resolution in any direction a float should be able
to handle the data (float == 24 bit mantissa, 8 bit exponent).

> I've re-written the code using a PointArray() hoping this would
> be a more efficient use of memory, but again I run out of memory.

The real data usage is still in the doubles in the PointArray.
>
> I'm working on an Integraph TZD 2000 GL2 450MHz workstation with 384Mb of
> RAM, so memory shouldn't be a problem.

384 MB will be enough to generate the isosurface, but you are going to need to
filter (decimate) and stripify the surface to get good display performace.

Doug Gehringer
Sun Microsystems

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to