001: /*
002: * $RCSfile: ImageStack.java,v $
003: *
004: * Copyright (c) 2005 Sun Microsystems, Inc. All rights reserved.
005: *
006: * Use is subject to license terms.
007: *
008: * $Revision: 1.1 $
009: * $Date: 2005/02/11 04:57:10 $
010: * $State: Exp $
011: */
012: package javax.media.jai;
013:
014: import java.util.Collection;
015: import java.util.Iterator;
016:
017: /**
018: * A class representing a stack of images, each associated with a
019: * spatial position/orientation defined in a common coordinate system.
020: * The images are of the type <code>javax.media.jai.PlanarImage</code>;
021: * the coordinates are of the type <code>java.lang.Object</code>.
022: * The tuple (image, coordinate) is represented by class
023: * <code>javax.media.jai.CoordinateImage</code>.
024: *
025: * <p> This class can be used to represent medical or geophysical images.
026: *
027: * @see PlanarImage
028: *
029: * @deprecated as of JAI 1.1. Use
030: * <code>AttributedImageCollection</code> instead.
031: */
032: public abstract class ImageStack extends CollectionImage {
033:
034: /** The default constructor. */
035: protected ImageStack() {
036: }
037:
038: /**
039: * Constructor.
040: *
041: * @param images A collection of <code>CoordinateImage</code>.
042: *
043: * @throws IllegalArgumentException if <code>images</code> is <code>null</code>.
044: */
045: public ImageStack(Collection images) {
046: super (images);
047: }
048:
049: /**
050: * Returns the image associated with the specified coordinate,
051: * or <code>null</code> if <code>c</code> is <code>null</code> or
052: * if no match is found.
053: *
054: * @param c The specified coordinate object.
055: */
056: public PlanarImage getImage(Object c) {
057: if (c != null) {
058: Iterator iter = iterator();
059:
060: while (iter.hasNext()) {
061: CoordinateImage ci = (CoordinateImage) iter.next();
062: if (ci.coordinate.equals(c)) {
063: return ci.image;
064: }
065: }
066: }
067:
068: return null;
069: }
070:
071: /**
072: * Returns the coordinate associated with the specified image,
073: * or <code>null</code> if <code>pi</code> is <code>null</code> or
074: * if no match is found.
075: *
076: * @param pi The specified planar image.
077: */
078: public Object getCoordinate(PlanarImage pi) {
079: if (pi != null) {
080: Iterator iter = iterator();
081:
082: while (iter.hasNext()) {
083: CoordinateImage ci = (CoordinateImage) iter.next();
084: if (ci.image.equals(pi)) {
085: return ci.coordinate;
086: }
087: }
088: }
089:
090: return null;
091: }
092:
093: /**
094: * Adds a <code>CoordinateImage</code> to this collection. If the
095: * specified image is <code>null</code>, it is not added to the
096: * collection.
097: *
098: * @return true if and only if the <code>CoordinateImage</code> is added
099: * to the collection.
100: */
101: public boolean add(Object o) {
102: if (o != null && o instanceof CoordinateImage) {
103: return super .add(o);
104: } else {
105: return false;
106: }
107: }
108:
109: /**
110: * Removes the <code>CoordinateImage</code> that contains the
111: * specified image from this collection.
112: *
113: * @param pi The specified planar image.
114: * @return true if and only if a <code>CoordinateImage</code> containing
115: * the specified image is removed from the collection.
116: */
117: public boolean remove(PlanarImage pi) {
118: if (pi != null) {
119: Iterator iter = iterator();
120:
121: while (iter.hasNext()) {
122: CoordinateImage ci = (CoordinateImage) iter.next();
123: if (ci.image.equals(pi)) {
124: return super .remove(ci);
125: }
126: }
127: }
128:
129: return false;
130: }
131:
132: /**
133: * Removes the <code>CoordinateImage</code> that contains the
134: * specified coordinate from this collection.
135: *
136: * @param c The specified coordinate object.
137: * @return true if and only if a <code>CoordinateImage</code> containing
138: * the specified coordinate is removed from the collection.
139: */
140: public boolean remove(Object c) {
141: if (c != null) {
142: Iterator iter = iterator();
143:
144: while (iter.hasNext()) {
145: CoordinateImage ci = (CoordinateImage) iter.next();
146: if (ci.coordinate.equals(c)) {
147: return super .remove(ci);
148: }
149: }
150: }
151:
152: return false;
153: }
154: }
|