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.io.Serializable;
027: import java.util.ArrayList;
028: import java.util.Collections;
029: import java.util.List;
030:
031: import javax.vecmath.Vector3d;
032:
033: /**
034: * Class represents a Joint during a tracking
035: * @author Giovane.Kuhn on 27/05/2005
036: */
037: public final class TrackingJoint implements Serializable {
038:
039: private static final long serialVersionUID = 1L;
040:
041: /** Global X position */
042: private Double globalX;
043:
044: /** Global Y position */
045: private Double globalY;
046:
047: /** Global Z position */
048: private Double globalZ;
049:
050: /** Joint name */
051: private String name;
052:
053: /** List with associated markers */
054: private List<Marker> markers;
055:
056: public boolean isSimulated() {
057: return (markers == null ? true : markers.isEmpty());
058: }
059:
060: public List<Marker> getMarkers() {
061: if (markers == null) {
062: return Collections.emptyList();
063: }
064: return markers;
065: }
066:
067: public void setMarkers(List<Marker> markers) {
068: removeAllMarkers();
069: this .markers = markers;
070: if (markers != null) {
071: for (Marker m : markers) {
072: m.setTrackingJoint(this );
073: }
074: }
075: }
076:
077: public void addMarker(Marker marker) {
078: if (markers == null) {
079: markers = new ArrayList<Marker>();
080: }
081: if (!markers.contains(marker)) {
082: markers.add(marker);
083: marker.setTrackingJoint(this );
084: }
085: }
086:
087: public void removeAllMarkers() {
088: if (markers == null) {
089: return;
090: }
091: for (Marker m : new ArrayList<Marker>(markers)) {
092: m.setTrackingJoint(null);
093: }
094: }
095:
096: public void removeMarker(Marker marker) {
097: if (markers == null) {
098: return;
099: }
100: if (markers.contains(marker)) {
101: markers.remove(marker);
102: marker.setTrackingJoint(null);
103: }
104: }
105:
106: public String getName() {
107: return name;
108: }
109:
110: public void setName(String name) {
111: this .name = name;
112: }
113:
114: public Double getGlobalX() {
115: return globalX;
116: }
117:
118: public void setGlobalX(Double globalX) {
119: this .globalX = globalX;
120: }
121:
122: public Double getGlobalY() {
123: return globalY;
124: }
125:
126: public void setGlobalY(Double globalY) {
127: this .globalY = globalY;
128: }
129:
130: public Double getGlobalZ() {
131: return globalZ;
132: }
133:
134: public void setGlobalZ(Double globalZ) {
135: this .globalZ = globalZ;
136: }
137:
138: public Vector3d getVector3d() {
139: return new Vector3d( //
140: globalX == null ? Double.NaN : globalX, //
141: globalY == null ? Double.NaN : globalY, //
142: globalZ == null ? Double.NaN : globalZ //
143: );
144: }
145:
146: public void setVector3d(Vector3d v) {
147: this .globalX = Double.isNaN(v.x) ? null : v.x;
148: this .globalY = Double.isNaN(v.y) ? null : v.y;
149: this .globalZ = Double.isNaN(v.z) ? null : v.z;
150: }
151:
152: public Vector3d fillUnspecifiedCoordinates(Vector3d vector) {
153: return new Vector3d( //
154: Double.isNaN(vector.x) ? this .globalX : vector.x, //
155: Double.isNaN(vector.y) ? this .globalY : vector.y, //
156: Double.isNaN(vector.z) ? this .globalZ : vector.z //
157: );
158: }
159:
160: public String toString() {
161: return name;
162: }
163:
164: }
|