Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00017 package com.generalrobotix.ui.view.graph;
00018
00019 import com.generalrobotix.ui.util.AxisAngle4d;
00020 import java.util.StringTokenizer;
00021 import java.text.DecimalFormat;
00022 import javax.vecmath.*;
00023
00024 public class SEAxisAngle implements StringExchangeable {
00025 AxisAngle4d value_;
00026 DecimalFormat df_;
00027 boolean isNaN_;
00028
00029 public SEAxisAngle() {
00030 value_ = new AxisAngle4d();
00031 df_ = new DecimalFormat("0.####");
00032 }
00033
00034 public SEAxisAngle(AxisAngle4d value) {
00035 value_ = new AxisAngle4d();
00036 setValue(value);
00037 df_ = new DecimalFormat("0.####");
00038 }
00039
00040 public SEAxisAngle(Double[] value) {
00041 value_ = new AxisAngle4d();
00042 setValue(value);
00043 df_ = new DecimalFormat("0.####");
00044 }
00045
00046 public SEAxisAngle(double[] value) {
00047 value_ = new AxisAngle4d();
00048 setValue(value);
00049 df_ = new DecimalFormat("0.####");
00050 }
00051
00052 public SEAxisAngle(float[] value) {
00053 value_ = new AxisAngle4d();
00054 setValue(value);
00055 df_ = new DecimalFormat("0.####");
00056 }
00057
00058 public SEAxisAngle(double x, double y, double z, double angle) {
00059 value_ = new AxisAngle4d();
00060 setValue(x, y, z, angle);
00061 df_ = new DecimalFormat("0.####");
00062 }
00063
00064 public SEAxisAngle(Quat4d value) {
00065 value_ = new AxisAngle4d();
00066 value_.set(value);
00067 df_ = new DecimalFormat("0.####");
00068 }
00069
00070 public SEAxisAngle(String value) {
00071 value_ = new AxisAngle4d();
00072 fromString(value);
00073 df_ = new DecimalFormat("0.####");
00074 }
00075
00076 public SEAxisAngle(DecimalFormat df) {
00077 df_ = df;
00078 value_ = new AxisAngle4d();
00079 }
00080
00081 public void setValue(Double value[]) {
00082 if (value.length != 4) throw new StringExchangeException();
00083 isNaN_ = false;
00084 for (int i = 0; i < 4; i ++) {
00085 if (value[i].isNaN()) {
00086 isNaN_ = true;
00087 } else if (value[i].isInfinite()) {
00088 throw new StringExchangeException();
00089 }
00090 }
00091
00092 value_.set(
00093 value[0].doubleValue(),
00094 value[1].doubleValue(),
00095 value[2].doubleValue(),
00096 value[3].doubleValue()
00097 );
00098
00099 Quat4d quat = new Quat4d();
00100 quat.set(value_);
00101 value_.set(quat);
00102 }
00103
00104 public void setValue(double value[]) {
00105 if (value.length != 4) throw new StringExchangeException();
00106 isNaN_ = false;
00107 for (int i = 0; i < 4; i ++) {
00108 if (Double.isNaN(value[i])) {
00109 isNaN_ = true;
00110 } else if (Double.isInfinite(value[i])) {
00111 throw new StringExchangeException();
00112 }
00113 }
00114
00115 value_.set(value);
00116
00117 Quat4d quat = new Quat4d();
00118 quat.set(value_);
00119 value_.set(quat);
00120 }
00121
00122 public void setValue(float value[]) {
00123 if (value.length != 4) throw new StringExchangeException();
00124 isNaN_ = false;
00125 for (int i = 0; i < 4; i ++) {
00126 if (Double.isNaN(value[i])) {
00127 isNaN_ = true;
00128 } else if (Double.isInfinite(value[i])) {
00129 throw new StringExchangeException();
00130 }
00131 }
00132 value_.set(
00133 (double)value[0],
00134 (double)value[1],
00135 (double)value[2],
00136 (double)value[3]
00137 );
00138
00139 Quat4d quat = new Quat4d();
00140 quat.set(value_);
00141 value_.set(quat);
00142 }
00143
00144 public void setValue(Quat4d value) {
00145 isNaN_ = false;
00146 value_.set(value);
00147 }
00148
00149 public String toString() {
00150 if (isNaN_) { return ""; }
00151
00152 StringBuffer strBuf = new StringBuffer();
00153
00154 strBuf.append(df_.format(value_.x));
00155 strBuf.append(" ");
00156 strBuf.append(df_.format(value_.y));
00157 strBuf.append(" ");
00158 strBuf.append(df_.format(value_.z));
00159 strBuf.append(" ");
00160 strBuf.append(df_.format(value_.angle));
00161
00162 return strBuf.toString();
00163 }
00164
00165 public Object fromString(String str) {
00166 if (str.equals("")) {
00167 isNaN_ = true;
00168 return null;
00169 }
00170
00171 StringTokenizer token = new StringTokenizer(str);
00172
00173 Double[] doubleArray = new Double[4];
00174
00175 isNaN_ = false;
00176
00177 for (int i = 0; i < 4; i ++) {
00178 if (token.hasMoreTokens()) {
00179 String value = token.nextToken();
00180 if (value.equals("NaN")) {
00181 isNaN_ = true;
00182 doubleArray[i] = new Double(Double.NaN);
00183 } else {
00184 try {
00185 doubleArray[i] = new Double(value);
00186 } catch (NumberFormatException ex) {
00187 throw new StringExchangeException();
00188 }
00189
00190 if (doubleArray[i].isNaN()) {
00191 isNaN_ = true;
00192 } else if (doubleArray[i].isInfinite()) {
00193 throw new StringExchangeException();
00194 }
00195 }
00196 } else {
00197 throw new StringExchangeException();
00198 }
00199 }
00200
00201 if (token.hasMoreTokens()) {
00202 throw new StringExchangeException();
00203 }
00204
00205 value_.set(
00206 doubleArray[0].doubleValue(),
00207 doubleArray[1].doubleValue(),
00208 doubleArray[2].doubleValue(),
00209 doubleArray[3].doubleValue()
00210 );
00211
00212 Quat4d quat = new Quat4d();
00213 quat.set(value_);
00214 value_.set(quat);
00215
00216 return (Object)value_;
00217 }
00218
00219 public void setValue(Object value) {
00220 Quat4d quat = new Quat4d();
00221 quat.set((AxisAngle4d)value);
00222 value_.set(quat);
00223 }
00224
00225 public void setValue(double x, double y, double z, double angle) {
00226 value_.set(x, y, z, angle);
00227 Quat4d quat = new Quat4d();
00228 quat.set(value_);
00229 value_.set(quat);
00230 }
00231
00232 public void setValue(String str) {
00233 fromString(str);
00234 }
00235
00236 public Object getValue() {
00237 return (Object)value_;
00238 }
00239
00240 public double getX() {
00241 return value_.x;
00242 }
00243
00244 public double getY() {
00245 return value_.y;
00246 }
00247
00248 public double getZ() {
00249 return value_.z;
00250 }
00251
00252 public double getAngle() {
00253 return value_.angle;
00254 }
00255
00256 public boolean isNaN() {
00257 return isNaN_;
00258 }
00259 }