Thomas,
Thank you very much for your response, it was very
enlightening. I was
thinking that the important part of the
PixelInterleavedSampleModel
was in the constructor but didn't really understand the pixel
stride or
scanline stride concepts well enough. Also I had forgotten
about the
DataBuffer constructor that takes an offset into the supplied
array.
I have tried your 'simplest' case, i.e. [14][x][x] where I
want to display
slice number 14. My code snippet is below. What happens is
that no matter what
offset I give the DataBufferUShort constructor, I still get
slice 0, same
as specifying an offset of 0.
Two things that I am not sure about:
1. what should the 'size' param to the DataBufferUShort
constructor be?
2. what should the 'Point' param to createWritableRaster be?
For number 1. I'm assuming that in the 'simple' case it should
just be
the size of the image (w x h).
For number 2. I'm not sure, I've never seen an example where
the Point
is not 0,0.
Perhaps one of these two is causing my problem.
Thank you for your help Thomas, I really appreciate it,
Ted Hill
======================================================
int sliceNumber = 14;
final int transferType = DataBuffer.TYPE_USHORT;
// 0. Read the data file for all slices into a one dimensional
short array
short [ ] allSliceDataArray = get3DDataArray( );
// 1. Create a DataBufferUShort( ) from existing short[ ]
DataBuffer allSliceDataBuffer = new
DataBufferUShort(allSliceDataArray, // raw array
512 * 512,
// size
sliceNumber
* 512 * 512); // offset
// 2. Create a compatible SampleModel, I think this sample model
may work for the first axial view
SampleModel sm = new PixelInterleavedSampleModel(transferType,
512, 512, 1, 512, new int[ ] {0});
// 3. Use the DataBuffer from 1. above to create a Raster
WritableRaster allSliceRaster = Raster.createWritableRaster(sm,
allSliceDataBuffer, new Point(0, 0));
// 4. Create a compatible ColorModel
ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_GRAY);
ColorModel cm = new ComponentColorModel(cs, new int[ ] {16},
false, false, Transparency.OPAQUE, transferType);
// 5. Finally create the BufferedImage using the Raster from 3.
above.
BufferedImage bi = new BufferedImage(cm, allSliceRaster, false,
null);
----- Original Message -----
From: "Thomas E Deweese" <[EMAIL PROTECTED]>
To: "Ted Hill" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, August 17, 2000 8:17 AM
Subject: Re: [JAVA2D] BufferedImage Internals Puzzler
> >>>>> "TH" == Ted Hill <[EMAIL PROTECTED]> writes:
>
> TH> Dmitri, Thanks for the response.
>
> TH> If none of the following methods:
>
> >> > getDataElement [...]
>
> TH> are responsible for associating data array values with pixels, do
> TH> you know how this association is made?
>
> With PixelInterleavedSampleModel (it is different for different sample
> models) the association is made in the constructor:
>
> public PixelInterleavedSampleModel(int dataType, int w, int h,
> int pixelStride,
> int scanlineStride,
> int[] bandOffsets)
>
> The fields of interest for us are:
> pixelStride, scanlineStride, and bandOffsets.
>
> You will also probably need to make use of the DataBuffer offset
> (in addition to the bandOffsets):
>
> public DataBufferByte(byte[] dataArray, int size, int offset)
>
> This uses the array you give it, it doesn't copy the data.
>
> ---
>
> So let's say we wanted to select plane 15 of a 512x512x512 block, I'm
> assuming 1 band data.
>
> I'll do this for the three major axis:
>
> Simplest case: [14][x][x]
>
> DataBuffer.offset = 14*512*512; // select 14th slice
>
> pixelStride = 1; // going across row order
> scanlineStride = 512; // going down through the slice
> bandOffsets = [0]; // Just one band here.
>
>
> [x][14][x]
>
> DataBuffer.offset = 14*512; // Start in first slice but at 14th
> // line (we read across slices now).
>
> pixelStride = 1; // We are still reading pixels in a row
> scanlineStride = 512*512; // Every scan line comes from a different
> // slice.
> bandOffsets = [0]; // Just one band here.
>
> [x][x][14]
> DataBuffer.offset = [14]; // 14th pixel of first line of first slice.
>
> pixelStride = 512; // We now read down a slice for pixels
> scanlineStride = 512*512; // Still pull each scanline from a different
> // slice.
> bandOffsets = [0]; // Just one band here.
>
>
> TH> I would like to find some method to override in the
> TH> PixelInterleavedSampleModel, so that I can select multiple planes
> TH> out of my 3D data array.
>
> You will need to construct a new PixelInterleavedSampleModel &
> DataBuffer for each plane but you won't need to copy any data.
>
> Depending on the flexibility you need in selecting slices you may
> need to go up to ComponentSampleModel (or over to BandedSampleModel,
> which has a different set of constraints. It's likely that by
> switching between Banded and PixelInterleaved you can cover all the
> cases you need to).
>
> In general there aren't as many optimized loops for
> ComponentSampleModel but it usually doesn't need to call a method at
> every pixel.
>
> TH> By the way, before trying PixelInterleavedSampleModel, I had
> TH> extended ComponentSampleModel, this was very slow, approx 30 sec
> TH> to draw a 512 X 512 image. In that case, getDataElement was being
> TH> called for each pixel of the image.
>
> I am surprised to hear that it was this slow (hotspot's dynamic
> inlining may help this), although in general a system that relies on a
> method call per pixel will not give very good results.
>
> --
> Thomas DeWeese
> [EMAIL PROTECTED]
> "The only difference between theory and practice is
> that in theory there isn't any." -- unknown
>
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".