SETranslation.java
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, AIST, the University of Tokyo and General Robotix Inc.
3  * All rights reserved. This program is made available under the terms of the
4  * Eclipse Public License v1.0 which accompanies this distribution, and is
5  * available at http://www.eclipse.org/legal/epl-v10.html
6  * Contributors:
7  * General Robotix Inc.
8  * National Institute of Advanced Industrial Science and Technology (AIST)
9  */
17 package com.generalrobotix.ui.view.graph;
18 
19 import java.util.StringTokenizer;
20 import java.text.DecimalFormat;
21 import javax.vecmath.*;
22 
23 public class SETranslation implements StringExchangeable {
24  Vector3d value_;
25  DecimalFormat df_;
26  boolean isNaN_;
27 
28  public SETranslation() {
29  value_ = new Vector3d();
30  df_ = new DecimalFormat("0.####"); // default format
31  }
32 
33  public SETranslation(Vector3d value) {
34  value_ = new Vector3d();
35  setValue(value);
36  df_ = new DecimalFormat("0.####"); // default format
37  }
38 
39  public SETranslation(Double[] value) {
40  value_ = new Vector3d();
41  setValue(value);
42  df_ = new DecimalFormat("0.####"); // default format
43  }
44 
45  public SETranslation(double[] value) {
46  value_ = new Vector3d();
47  setValue(value);
48  df_ = new DecimalFormat("0.####"); // default format
49  }
50 
51  public SETranslation(float[] value) {
52  value_ = new Vector3d();
53  setValue(value);
54  df_ = new DecimalFormat("0.####"); // default format
55  }
56 
57  public SETranslation(double x, double y, double z) {
58  value_ = new Vector3d();
59  setValue(x, y, z);
60  df_ = new DecimalFormat("0.####"); // default format
61  }
62 
63  public SETranslation(String value) {
64  value_ = new Vector3d();
65  fromString(value);
66  df_ = new DecimalFormat("0.####"); // default format
67  }
68 
69  public SETranslation(DecimalFormat df) {
70  df_ = df;
71  value_ = new Vector3d();
72  }
73 
74  public void setValue(Double value[]) {
75  if (value.length != 3) throw new StringExchangeException();
76  isNaN_ = false;
77  for (int i = 0; i < 3; i ++) {
78  if (value[i].isNaN()) {
79  isNaN_ = true;
80  } else if (value[i].isInfinite()) {
81  throw new StringExchangeException();
82  }
83  }
84 
85  value_.set(
86  value[0].doubleValue(),
87  value[1].doubleValue(),
88  value[2].doubleValue()
89  );
90  }
91 
92  public void setValue(double value[]) {
93  if (value.length != 3) throw new StringExchangeException();
94  isNaN_ = false;
95  for (int i = 0; i < 3; i ++) {
96  if (Double.isNaN(value[i])) {
97  isNaN_ = true;
98  } else if (Double.isInfinite(value[i])) {
99  throw new StringExchangeException();
100  }
101  }
102 
103  value_.set(value);
104  }
105 
106  public void setValue(float value[]) {
107  if (value.length != 3) throw new StringExchangeException();
108  isNaN_ = false;
109  for (int i = 0; i < 3; i ++) {
110  if (Double.isNaN(value[i])) {
111  isNaN_ = true;
112  } else if (Double.isInfinite(value[i])) {
113  throw new StringExchangeException();
114  }
115  }
116  value_.set((double)value[0], (double)value[1], (double)value[2]);
117  }
118 
119  public void setValue(double x, double y, double z) {
120  if (Double.isNaN(x) || Double.isNaN(y) || Double.isNaN(z)){
121  isNaN_ = true;
122  }else{
123  isNaN_ = false;
124  }
125  value_.set(x, y, z);
126  }
127 
128  public String toString() {
129  if (isNaN_) { return ""; }
130  StringBuffer strBuf = new StringBuffer();
131 
132  strBuf.append(df_.format(value_.x));
133  strBuf.append(" ");
134  strBuf.append(df_.format(value_.y));
135  strBuf.append(" ");
136  strBuf.append(df_.format(value_.z));
137 
138  return strBuf.toString();
139  }
140 
141  public Object fromString(String str) {
142  if (str.equals("")) {
143  isNaN_ = true;
144  return null;
145  }
146 
147  StringTokenizer token = new StringTokenizer(str);
148 
149  Double[] doubleArray = new Double[3];
150  isNaN_ = false;
151 
152  for (int i = 0; i < 3; i ++) {
153  if (token.hasMoreTokens()) {
154  String value = token.nextToken();
155  if (value.equals("NaN")) {
156  isNaN_ = true;
157  doubleArray[i] = new Double(Double.NaN);
158  } else {
159  try {
160  doubleArray[i] = new Double(value);
161  } catch (NumberFormatException ex) {
162  throw new StringExchangeException();
163  }
164  if (doubleArray[i].isNaN()) {
165  isNaN_ = true;
166  } else if (doubleArray[i].isInfinite()) {
167  throw new StringExchangeException();
168  }
169  }
170  } else {
171  throw new StringExchangeException();
172  }
173  }
174 
175  if (token.hasMoreTokens()) {
176  throw new StringExchangeException();
177  }
178 
179  value_.set(
180  doubleArray[0].doubleValue(),
181  doubleArray[1].doubleValue(),
182  doubleArray[2].doubleValue()
183  );
184 
185  return (Object)value_;
186  }
187 
188  public void setValue(Object value) {
189  value_.set((Vector3d)value);
190  }
191 
192  public void setValue(Vector3d value) {
193  value_.set(value);
194  }
195 
196  public void setValue(String str) {
197  fromString(str);
198  }
199 
200  public Object getValue() {
201  return (Object)value_;
202  }
203 
204  public double getX() {
205  return value_.x;
206  }
207 
208  public double getY() {
209  return value_.y;
210  }
211 
212  public double getZ() {
213  return value_.z;
214  }
215 
216  public boolean isNaN() { return isNaN_; }
217 }
SETranslation(double x, double y, double z)
* x
Definition: IceUtils.h:98
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_voidp int value
Definition: png.h:2113
png_uint_32 i
Definition: png.h:2735
void setValue(double x, double y, double z)
* y
Definition: IceUtils.h:97


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:05