001: /*
002: * $RCSfile: ImageSequence.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:09 $
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 sequence of images, each associated with a
019: * time stamp and a camera position. The images are of the type
020: * <code>javax.media.jai.PlanarImage</code>; the time stamps are of the
021: * type <code>float</code>; the camera positions are of the type
022: * <code>java.lang.Object</code>. The tuple (image, time stamp, camera
023: * position) is represented by class
024: * <code>javax.media.jai.SequentialImage</code>.
025: *
026: * <p> This class can be used to represent video or time-lapse photography.
027: *
028: * @see PlanarImage
029: * @see SequentialImage
030: *
031: * @deprecated as of JAI 1.1. Use
032: * <code>AttributedImageCollection</code> instead.
033: */
034:
035: public class ImageSequence extends CollectionImage {
036:
037: /** The default constrctor. */
038: protected ImageSequence() {
039: }
040:
041: /**
042: * Constructs a class that represents a sequence of images.
043: *
044: * @param images A collection of <code>SequentialImage</code>.
045: *
046: * @throws IllegalArgumentException if <code>images</code> is <code>null</code>.
047: */
048: public ImageSequence(Collection images) {
049: super (images);
050: }
051:
052: /**
053: * Returns the image associated with the specified time stamp,
054: * or <code>null</code> if no match is found.
055: */
056: public PlanarImage getImage(float ts) {
057: Iterator iter = iterator();
058:
059: while (iter.hasNext()) {
060: SequentialImage si = (SequentialImage) iter.next();
061: if (si.timeStamp == ts) {
062: return si.image;
063: }
064: }
065:
066: return null;
067: }
068:
069: /**
070: * Returns the image associated with the specified camera position,
071: * or <code>null</code> if <code>cp</code> is <code>null</code> or
072: * if no match is found.
073: */
074: public PlanarImage getImage(Object cp) {
075: if (cp != null) {
076: Iterator iter = iterator();
077:
078: while (iter.hasNext()) {
079: SequentialImage si = (SequentialImage) iter.next();
080: if (si.cameraPosition.equals(cp)) {
081: return si.image;
082: }
083: }
084: }
085:
086: return null;
087: }
088:
089: /**
090: * Returns the time stamp associated with the specified image, or
091: * <code>-Float.MAX_VALUE</code> if <code>pi</code> is <code>null</code>
092: * or if no match is found.
093: */
094: public float getTimeStamp(PlanarImage pi) {
095: if (pi != null) {
096: Iterator iter = iterator();
097:
098: while (iter.hasNext()) {
099: SequentialImage si = (SequentialImage) iter.next();
100: if (si.image.equals(pi)) {
101: return si.timeStamp;
102: }
103: }
104: }
105:
106: return -Float.MAX_VALUE;
107: }
108:
109: /**
110: * Returns the camera position associated with the specified image,
111: * or <code>null</code> if <code>pi</code> is <code>null</code> or
112: * if no match is found.
113: */
114: public Object getCameraPosition(PlanarImage pi) {
115: if (pi != null) {
116: Iterator iter = iterator();
117:
118: while (iter.hasNext()) {
119: SequentialImage si = (SequentialImage) iter.next();
120: if (si.image.equals(pi)) {
121: return si.cameraPosition;
122: }
123: }
124: }
125:
126: return null;
127: }
128:
129: /**
130: * Adds a <code>SequentialImage</code> to this collection. If the
131: * specified image is <code>null</code>, it is not added to the
132: * collection.
133: *
134: * @return <code>true</code> if and only if the
135: * <code>SequentialImage</code> is added to the collection.
136: */
137: public boolean add(Object o) {
138: if (o != null && o instanceof SequentialImage) {
139: return super .add(o);
140: } else {
141: return false;
142: }
143: }
144:
145: /**
146: * Removes the <code>SequentialImage</code> that contains the
147: * specified image from this collection.
148: *
149: * @return <code>true</code> if and only if a
150: * <code>SequentialImage</code> with the
151: * specified image is removed from the collection.
152: */
153: public boolean remove(PlanarImage pi) {
154: if (pi != null) {
155: Iterator iter = iterator();
156:
157: while (iter.hasNext()) {
158: SequentialImage si = (SequentialImage) iter.next();
159: if (si.image.equals(pi)) {
160: return super .remove(si);
161: }
162: }
163: }
164:
165: return false;
166: }
167:
168: /**
169: * Removes the <code>SequentialImage</code> that contains the
170: * specified time stamp from this collection.
171: *
172: * @return <code>true</code> if and only if a
173: * <code>SequentialImage</code> with the
174: * specified time stamp is removed from the collection.
175: */
176: public boolean remove(float ts) {
177: Iterator iter = iterator();
178:
179: while (iter.hasNext()) {
180: SequentialImage si = (SequentialImage) iter.next();
181: if (si.timeStamp == ts) {
182: return super .remove(si);
183: }
184: }
185:
186: return false;
187: }
188:
189: /**
190: * Removes the <code>SequentialImage</code> that contains the
191: * specified camera position from this collection.
192: *
193: * @return <code>true</code> if and only if a
194: * <code>SequentialImage</code> with the
195: * specified camera position is removed from the collection.
196: */
197: public boolean remove(Object cp) {
198: if (cp != null) {
199: Iterator iter = iterator();
200:
201: while (iter.hasNext()) {
202: SequentialImage si = (SequentialImage) iter.next();
203: if (si.cameraPosition.equals(cp)) {
204: return super .remove(si);
205: }
206: }
207: }
208:
209: return false;
210: }
211: }
|