>>>>> "TH" == Ted Hill <[EMAIL PROTECTED]> writes:
TH> I have tried your 'simplest' case, i.e. [14][x][x]
TH> where I want to display slice number 14. My code snippet is
TH> below. What happens is that no matter what offset I give the
TH> DataBufferUShort constructor, I still get slice 0, same as
TH> specifying an offset of 0.
Well I looked at the code and I can't see anything wrong with it.
I would suggest moving the offset from DataBufferUShort, to the
bandoffset array in the PixelInterleaved Sample Model. I suspect (no
proof yet) that some of the processing loops are erroneously ignoring
the databuffer offset, it isn't used that often in general (but the
band offset is). For this case which you use shouldn't matter (see
below I've updated your example code).
TH> Two things that I am not sure about:
TH> 1. what should the 'size' param to the DataBufferUShort
TH> constructor be?
The size (in elements) of the section of the DataBuffer that you
are interested in. You used the correct value for this case
(512*512). Be aware that in the other axial cuts this number will be
much larger (~ 512*512*512-512) - or just specify the rest of the
array (or the array.length now since you will be using an offset of
'0').
TH> 2. what should the 'Point' param to createWritableRaster be?
It is the x/y coord of the upper left hand corner of the Raster.
If you are going to build a BufferedImage from it, it must be 0,0
(well it can be anything but it will be ignored, so don't fool
yourself).
----
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);
// CHANGE: ^^^^^^^^^^^^^^^^^^
// 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[ ] {sliceNumber*512*512});
// CHANGE: ^^^^^^^^^^^^^^^^^^^
// 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);
--
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".