/* * @(#)/SliceVolumeFilter.java 1.6 96/03/31 by Andrew Barclay abb@nuccard.eushc.org * * Copyright (c) 1995 Andrew B. Barclay All Rights Reserved. * * derived from : * @(#)CropImageFilter.java 1.2 95/08/29 Jim Graham * * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved. * * Permission to use, copy, modify, and distribute this software * and its documentation for NON-COMMERCIAL purposes and without * fee is hereby granted provided that this copyright notice * appears in all copies. Please refer to the file "copyright.html" * for further important copyright and licensing information. * * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. */ import java.awt.image.ImageFilter ; import java.awt.image.ImageConsumer ; import java.awt.image.ColorModel ; import java.awt.Point ; import java.awt.Rectangle ; import java.util.Hashtable ; /** * An abstract 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 XSliceVolumeFilter * @see YSliceVolumeFilter * @see ZSliceVolumeFilter * @see CropImageFilter * @see FilteredImageSource * @see ImageFilter * * @version 1.6 96/03/31 * @author Andrew Barclay */ abstract class SliceVolumeFilter extends ImageFilter { final static int vdim = 3 ; Point srcSlices[] ; int voldims[] = new int[3] ; // Not used yet... double ul[] ; double ll[] ; double ur[] ; char type ; double slice ; int width ; int height ; boolean debug ; /** * 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 */ SliceVolumeFilter( Point srcSlices[], int volWidth, int volHeight, double slice, int width, int height ) { // info about the source volume (assuming it's arranged as zslices) this.srcSlices = srcSlices ; this.voldims[0] = volWidth ; this.voldims[1] = volHeight ; this.voldims[2] = srcSlices.length ; // info about position of slice in source volume. this.slice = slice ; this.width = width ; this.height = height ; dbg( "new SliceVolumeFilter: voldims="+voldims+", type="+type+", wh="+width+","+height ) ; dbg( "srcSlices="+srcSlices ) ; } /** * 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 ul the upper left coordinate of the slice to be extracted * @param ll the lower left coordinate of the slice to be extracted * @param ur the upper right coordinate of the slice to be extracted * @param width the width of the slice to be extracted * @param height the height of the slice to be extracted */ SliceVolumeFilter( Point srcSlices[], int volWidth, int volHeight, double ul[], double ll[], double ur[], int width, int height ) { // info about the source volume (assuming it's arranged as zslices) this.srcSlices = srcSlices ; this.voldims[0] = volWidth ; this.voldims[1] = volHeight ; this.voldims[2] = srcSlices.length ; // info about position of slice in source volume. this.ul = ul ; this.ll = ll ; this.ur = ur ; this.width = width ; this.height = height ; dbg( "new SliceVolumeFilter: voldims="+voldims ) ; } synchronized void dbg( String s ) { if( debug ) { System.out.println( s ) ; } } /** * Pass the properties from the source object along after adding a * property indicating the sliced plane. */ public void setProperties(Hashtable props) { props.put("slicevolume", this) ; super.setProperties(props); dbg( "SliceVolumeFilter.setProperties()" ) ; } /** * Override the source image's dimensions and pass the dimensions * of the slice to the ImageConsumer. * @see ImageConsumer */ public void setDimensions(int w, int h) { consumer.setDimensions(width, height) ; dbg( "SliceVolumeFilter.setDimensions() to "+width+", "+height ) ; } // Find the first slice that intersects the source region. int firstZSlice( Rectangle sr ) { int islice ; Rectangle dr = new Rectangle( voldims[0], voldims[1] ) ; for( islice = 0 ; islice < voldims[2] ; islice++ ) { // Does this slice intersect the source region? dr.move( srcSlices[islice].x, srcSlices[islice].y ) ; if( dr.intersects( sr ) ) { break ; } } return islice ; } // Find the last slice that intersects the source region. int lastZSlice( Rectangle sr ) { int islice ; Rectangle dr = new Rectangle( voldims[0], voldims[1] ) ; for( islice = voldims[2]-1 ; islice >= 0 ; islice-- ) { // Does this slice intersect the source region? dr.move( srcSlices[islice].x+1, srcSlices[islice].y+1 ) ; if( dr.intersects( sr ) ) { break ; } } return islice+1 ; } // Really want setPixels to be abstract so that derived classes must // implement, but can't because they are not abstract in the ImageFilter // superclass... }