SETranslation.java
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
00003  * All rights reserved. This program is made available under the terms of the
00004  * Eclipse Public License v1.0 which accompanies this distribution, and is
00005  * available at http://www.eclipse.org/legal/epl-v10.html
00006  * Contributors:
00007  * General Robotix Inc.
00008  * National Institute of Advanced Industrial Science and Technology (AIST) 
00009  */
00017 package com.generalrobotix.ui.view.graph;
00018 
00019 import java.util.StringTokenizer;
00020 import java.text.DecimalFormat;
00021 import javax.vecmath.*;
00022 
00023 public class SETranslation implements StringExchangeable {
00024     Vector3d value_;
00025     DecimalFormat df_;
00026     boolean isNaN_;
00027 
00028     public SETranslation() {
00029         value_ = new Vector3d();
00030         df_ = new DecimalFormat("0.####");  // default format
00031     }
00032 
00033     public SETranslation(Vector3d value) {
00034         value_ = new Vector3d();
00035         setValue(value);
00036         df_ = new DecimalFormat("0.####");  // default format
00037     }
00038 
00039     public SETranslation(Double[] value) {
00040         value_ = new Vector3d();
00041         setValue(value);
00042         df_ = new DecimalFormat("0.####");  // default format
00043     }
00044 
00045     public SETranslation(double[] value) {
00046         value_ = new Vector3d();
00047         setValue(value);
00048         df_ = new DecimalFormat("0.####");  // default format
00049     }
00050 
00051     public SETranslation(float[] value) {
00052         value_ = new Vector3d();
00053         setValue(value);
00054         df_ = new DecimalFormat("0.####");  // default format
00055     }
00056 
00057     public SETranslation(double x, double y, double z) {
00058         value_ = new Vector3d();
00059         setValue(x, y, z);
00060         df_ = new DecimalFormat("0.####");  // default format
00061     }
00062 
00063     public SETranslation(String value) {
00064         value_ = new Vector3d();
00065         fromString(value);
00066         df_ = new DecimalFormat("0.####");  // default format
00067     }
00068 
00069     public SETranslation(DecimalFormat df) {
00070         df_ = df;
00071         value_ = new Vector3d();
00072     }
00073 
00074     public void setValue(Double value[]) {
00075         if (value.length != 3) throw new StringExchangeException();
00076         isNaN_ = false;
00077         for (int i = 0; i < 3; i ++) {
00078             if (value[i].isNaN()) {
00079                 isNaN_ = true;
00080             } else if (value[i].isInfinite()) {
00081                 throw new StringExchangeException();
00082             }
00083         }
00084 
00085         value_.set(
00086             value[0].doubleValue(),
00087             value[1].doubleValue(),
00088             value[2].doubleValue()
00089         );
00090     }
00091 
00092     public void setValue(double value[]) {
00093         if (value.length != 3) throw new StringExchangeException();
00094         isNaN_ = false;
00095         for (int i = 0; i < 3; i ++) {
00096             if (Double.isNaN(value[i])) {
00097                 isNaN_ = true;
00098             } else if (Double.isInfinite(value[i])) {
00099                 throw new StringExchangeException();
00100             }
00101         }
00102 
00103         value_.set(value);
00104     }
00105 
00106     public void setValue(float value[]) {
00107         if (value.length != 3) throw new StringExchangeException();
00108         isNaN_ = false;
00109         for (int i = 0; i < 3; i ++) {
00110             if (Double.isNaN(value[i])) {
00111                 isNaN_ = true;
00112             } else if (Double.isInfinite(value[i])) {
00113                 throw new StringExchangeException();
00114             }
00115         }
00116         value_.set((double)value[0], (double)value[1], (double)value[2]);
00117     }
00118 
00119     public void setValue(double x, double y, double z) {
00120         if (Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z)){
00121           isNaN_ = true;
00122         }else{
00123           isNaN_ = false;
00124         }
00125         value_.set(x, y, z);
00126     }
00127 
00128     public String toString() {
00129         if (isNaN_) { return ""; }
00130         StringBuffer strBuf = new StringBuffer();
00131 
00132         strBuf.append(df_.format(value_.x));
00133         strBuf.append(" ");
00134         strBuf.append(df_.format(value_.y));
00135         strBuf.append(" ");
00136         strBuf.append(df_.format(value_.z));
00137 
00138         return strBuf.toString();
00139     }
00140 
00141     public Object fromString(String str) {
00142         if (str.equals("")) {
00143             isNaN_ = true;
00144             return null;
00145         }
00146 
00147         StringTokenizer token = new StringTokenizer(str);
00148 
00149         Double[] doubleArray = new Double[3];
00150         isNaN_ = false;
00151 
00152         for (int i = 0; i < 3; i ++) {
00153             if (token.hasMoreTokens()) {
00154                 String value = token.nextToken();
00155                 if (value.equals("NaN")) {
00156                     isNaN_ = true;
00157                     doubleArray[i] = new Double(Double.NaN);
00158                 } else {
00159                     try {
00160                         doubleArray[i] = new Double(value);
00161                     } catch (NumberFormatException ex) {
00162                         throw new StringExchangeException();
00163                     }
00164                     if (doubleArray[i].isNaN()) {
00165                         isNaN_ = true;
00166                     } else if (doubleArray[i].isInfinite()) {
00167                         throw new StringExchangeException(); 
00168                     }
00169                 }
00170             } else {
00171                 throw new StringExchangeException();
00172             }
00173         }
00174 
00175         if (token.hasMoreTokens()) {
00176             throw new StringExchangeException();
00177         }
00178 
00179         value_.set(
00180             doubleArray[0].doubleValue(),
00181             doubleArray[1].doubleValue(),
00182             doubleArray[2].doubleValue()
00183         );
00184 
00185         return (Object)value_;
00186     }
00187 
00188     public void setValue(Object value) {
00189         value_.set((Vector3d)value);
00190     }
00191 
00192     public void setValue(Vector3d value) {
00193         value_.set(value);
00194     }
00195 
00196     public void setValue(String str) {
00197         fromString(str);
00198     }
00199 
00200     public Object getValue() {
00201         return (Object)value_;
00202     }
00203 
00204     public double getX() {
00205         return value_.x;
00206     }
00207  
00208     public double getY() {
00209         return value_.y;
00210     }
00211 
00212     public double getZ() {
00213         return value_.z;
00214     }
00215 
00216     public boolean isNaN() { return isNaN_; }
00217 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sun Apr 2 2017 03:43:57