001: /*
002: * Apollo - Motion capture and animation system
003: * Copyright (c) 2005 Apollo
004: *
005: * This program is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU General Public License
007: * as published by the Free Software Foundation; either version 2
008: * of the License, or (at your option) any later version.
009: *
010: * This program is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
013: * GNU General Public License for more details.
014: *
015: * You should have received a copy of the GNU General Public License
016: * along with this program; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
018: *
019: * http://www.gnu.org/copyleft/gpl.html
020: *
021: * @author Giovane.Kuhn - brain@netuno.com.br
022: *
023: */
024: package org.apollo.datamodel;
025:
026: import java.awt.Color;
027: import java.awt.geom.Point2D;
028: import java.io.Serializable;
029:
030: import javax.vecmath.Vector2d;
031: import javax.vecmath.Vector3d;
032:
033: /**
034: * Class represent a marker in a video frame
035: * @author Giovane.Kuhn on 23/05/2005
036: */
037: public final class Marker implements Serializable {
038:
039: private static final long serialVersionUID = 1L;
040:
041: /** Marker origin from effect video */
042: public static final int ORIGIN_EFFECT = 1;
043:
044: /** Marker origin from user intervention */
045: public static final int ORIGIN_USER = 2;
046:
047: /** Marker origin from tracking */
048: public static final int ORIGIN_TRACKING = 3;
049:
050: /** Marker number */
051: private int number;
052:
053: /** Global X coordinate */
054: private Double globalX;
055:
056: /** Global Y coordinate */
057: private Double globalY;
058:
059: /** Marker color */
060: private Color color;
061:
062: /** Marker in previous frame */
063: private Marker previous;
064:
065: /** Marker in next frame */
066: private Marker next;
067:
068: /** Marker origin, see ORIGIN_XXX */
069: private int origin;
070:
071: /** Joint that this mark tracks */
072: private TrackingJoint trackingJoint;
073:
074: public TrackingJoint getTrackingJoint() {
075: return trackingJoint;
076: }
077:
078: public void setTrackingJoint(TrackingJoint joint) {
079: if (this .trackingJoint == joint) {
080: return;
081: }
082: if (this .trackingJoint != null) {
083: this .trackingJoint.removeMarker(this );
084: }
085: this .trackingJoint = joint;
086: if (joint != null) {
087: joint.addMarker(this );
088: }
089: }
090:
091: public int getOrigin() {
092: return origin;
093: }
094:
095: public void setOrigin(int origin) {
096: this .origin = origin;
097: }
098:
099: public Marker getNext() {
100: return next;
101: }
102:
103: public void setNext(Marker next) {
104: if (this .next == next) {
105: return;
106: }
107: Marker last = this .next;
108: this .next = next;
109: if (last != null) {
110: last.setPrevious(null);
111: }
112: if (next != null) {
113: next.setPrevious(this );
114: }
115: }
116:
117: public Marker getPrevious() {
118: return previous;
119: }
120:
121: public void setPrevious(Marker previous) {
122: if (this .previous == previous) {
123: return;
124: }
125: Marker last = this .previous;
126: this .previous = previous;
127: if (last != null) {
128: last.setNext(null);
129: }
130: if (previous != null) {
131: previous.setNext(this );
132: }
133: }
134:
135: public Color getColor() {
136: return color;
137: }
138:
139: public void setColor(Color color) {
140: this .color = color;
141: }
142:
143: public int getNumber() {
144: return number;
145: }
146:
147: public void setNumber(int number) {
148: this .number = number;
149: }
150:
151: public Double getGlobalX() {
152: return globalX;
153: }
154:
155: public void setGlobalX(Double x) {
156: this .globalX = x;
157: }
158:
159: public Double getGlobalY() {
160: return globalY;
161: }
162:
163: public void setGlobalY(Double y) {
164: this .globalY = y;
165: }
166:
167: public Double[] getCoordinates3d() {
168: return new Double[] { globalX, globalY, null };
169: }
170:
171: public Vector3d getVector3d() {
172: return new Vector3d( //
173: globalX == null ? Double.NaN : globalX, //
174: globalY == null ? Double.NaN : globalY, //
175: Double.NaN //
176: );
177: }
178:
179: public Vector2d getVector2d() {
180: return new Vector2d( //
181: globalX == null ? Double.NaN : globalX, //
182: globalY == null ? Double.NaN : globalY //
183: );
184: }
185:
186: public void setVector2d(Vector2d vector) {
187: this .globalX = Double.isNaN(vector.x) ? null : vector.x;
188: this .globalY = Double.isNaN(vector.y) ? null : vector.y;
189: }
190:
191: public void reset() {
192: setColor(null);
193: setPrevious(null);
194: setNext(null);
195: setTrackingJoint(null);
196: }
197:
198: public double distance(Marker other) {
199: return Point2D.distance(this.getGlobalX(), this.getGlobalY(),
200: other.getGlobalX(), other.getGlobalY());
201: }
202: }
|