/* * @(#)/YSliceVolumeFilter.java 1.3 96/03/31 by Andrew Barclay abb@nuccard.eushc.org * * Copyright (c) 1995 Andrew B. Barclay All Rights Reserved. */ import java.awt.image.ColorModel ; import java.awt.Point ; import java.awt.Rectangle ; import SliceVolumeFilter ; /** * An ImageFilter class for sliceing volume images. * This class extends the basic ImageFilter Class to extract a given * slice of an existing Volume and provide a source for a * new image containing just the extracted slice. It is meant to * be used in conjunction with a FilteredImageSource object to produce * sliced versions of existing volumes. * * @see CropImageFilter * @see FilteredImageSource * @see ImageFilter * @see SliceVolumeFilter * * @version 1.1 95/12/06 * @author Andrew Barclay */ public class YSliceVolumeFilter extends SliceVolumeFilter { byte outpixelsB[] ; int outpixelsI[] ; double szincr ; boolean debug = false ; /** * Construct a SliceVolumeFilter that extracts a slice of the source * Volume specified by the ul, ll and ur parameters. * @param srcSlices[] the array of x,y positions of the source image slices * @param volWidth the width of the source volume * @param volHeight the height of the source volume * @param slice the slice number to be extracted * @param width the width of the slice to be extracted * @param height the height of the slice to be extracted */ public YSliceVolumeFilter( Point srcSlices[], int volWidth, int volHeight, double slice, int width, int height ) { super( srcSlices, volWidth, volHeight, slice, width, height ) ; type = 'Y' ; szincr = (double)voldims[2] / (double)height ; } /** * Determine if the delivered pixels intersect the slice to * be extracted and pass through only that subset of pixels that * appear in the output slice. */ public void setPixels(int x, int y, int w, int h, ColorModel model, byte pixels[], int off, int scansize) { long ct = System.currentTimeMillis() ; Rectangle sr = new Rectangle( x, y, w, h ) ; int sz1 = firstZSlice( sr ) ; int sz2 = lastZSlice( sr ) ; /* dbg( "sr="+sr+" sz1="+sz1+" sz2="+sz2 ) ; dbg( "off="+off+" scansize="+scansize+" type="+type+" slice="+slice ) ; */ // implement this properly later -- for now, just take orthogonal // slices. int islice = (int)( 0.5 + slice ) ; if( islice >= 0 && islice < voldims[1] ) { double sz = -0.5*szincr + sz1 ; int ystart = (int)( 0.5 + sz/szincr ) ; int iyp = 0, nlines = 0 ; if( outpixelsB == null ) outpixelsB = new byte[width*height] ; byte outpixels[] = outpixelsB ; for( ; sz < (-0.5 + sz2) ; sz += szincr ) { int isz = (int)( 0.5 + sz ) ; int x1 = srcSlices[isz].x ; int y1 = srcSlices[isz].y + islice ; if( y <= y1 && (y+h) > y1 && x <= x1 && (x+w) > x1 ) { int dx = (x1>x) ? x1-x : 0 ; int dy = (y1>y) ? y1-y : 0 ; int is = off + dx + dy*scansize ; System.arraycopy( pixels, is, outpixels, iyp, width ) ; iyp += width ; nlines++ ; } else if( nlines == 0 ) { ystart++ ; } } if( nlines > 0 ) { dbg( "yslice="+islice ) ; dbg( "sr="+sr+" sz1="+sz1+" sz2="+sz2 ) ; dbg( "ystart="+ystart+" nlines="+nlines ) ; consumer.setPixels( 0, ystart, width, nlines, model, outpixels, 0, width ) ; dbg( "byte time= "+(System.currentTimeMillis()-ct)+" ms.\n" ) ; } } } public void setPixels(int x, int y, int w, int h, ColorModel model, int pixels[], int off, int scansize) { long ct = System.currentTimeMillis() ; Rectangle sr = new Rectangle( x, y, w, h ) ; int sz1 = firstZSlice( sr ) ; int sz2 = lastZSlice( sr ) ; /* dbg( "sr="+sr+" sz1="+sz1+" sz2="+sz2 ) ; dbg( "off="+off+" scansize="+scansize+" type="+type+" slice="+slice ) ; */ // implement this properly later -- for now, just take orthogonal // slices. int islice = (int)( 0.5 + slice ) ; if( islice >= 0 && islice < voldims[1] ) { double sz = -0.5*szincr + sz1 ; int ystart = (int)( 0.5 + sz/szincr ) ; int iyp = 0, nlines = 0 ; if( outpixelsI == null ) outpixelsI = new int[width*height] ; int outpixels[] = outpixelsI ; for( ; sz < (-0.5 + sz2) ; sz += szincr ) { int isz = (int)( 0.5 + sz ) ; int x1 = srcSlices[isz].x ; int y1 = srcSlices[isz].y + islice ; if( y <= y1 && (y+h) > y1 && x <= x1 && (x+w) > x1 ) { int dx = (x1>x) ? x1-x : 0 ; int dy = (y1>y) ? y1-y : 0 ; int is = off + dx + dy*scansize ; System.arraycopy( pixels, is, outpixels, iyp, width ) ; iyp += width ; nlines++ ; } else if( nlines == 0 ) { ystart++ ; } } if( nlines > 0 ) { dbg( "yslice="+islice ) ; dbg( "sr="+sr+" sz1="+sz1+" sz2="+sz2 ) ; dbg( "ystart="+ystart+" nlines="+nlines ) ; consumer.setPixels( 0, ystart, width, nlines, model, outpixels, 0, width ) ; dbg( "int time= "+(System.currentTimeMillis()-ct)+" ms.\n" ) ; } } } }