SEAxisAngle.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 
20 import java.util.StringTokenizer;
21 import java.text.DecimalFormat;
22 import javax.vecmath.*;
23 
24 public class SEAxisAngle implements StringExchangeable {
25  AxisAngle4d value_;
26  DecimalFormat df_;
27  boolean isNaN_;
28 
29  public SEAxisAngle() {
30  value_ = new AxisAngle4d();
31  df_ = new DecimalFormat("0.####"); // default format
32  }
33 
35  value_ = new AxisAngle4d();
36  setValue(value);
37  df_ = new DecimalFormat("0.####"); // default format
38  }
39 
40  public SEAxisAngle(Double[] value) {
41  value_ = new AxisAngle4d();
42  setValue(value);
43  df_ = new DecimalFormat("0.####"); // default format
44  }
45 
46  public SEAxisAngle(double[] value) {
47  value_ = new AxisAngle4d();
48  setValue(value);
49  df_ = new DecimalFormat("0.####"); // default format
50  }
51 
52  public SEAxisAngle(float[] value) {
53  value_ = new AxisAngle4d();
54  setValue(value);
55  df_ = new DecimalFormat("0.####"); // default format
56  }
57 
58  public SEAxisAngle(double x, double y, double z, double angle) {
59  value_ = new AxisAngle4d();
60  setValue(x, y, z, angle);
61  df_ = new DecimalFormat("0.####"); // default format
62  }
63 
64  public SEAxisAngle(Quat4d value) {
65  value_ = new AxisAngle4d();
66  value_.set(value);
67  df_ = new DecimalFormat("0.####"); // default format
68  }
69 
70  public SEAxisAngle(String value) {
71  value_ = new AxisAngle4d();
72  fromString(value);
73  df_ = new DecimalFormat("0.####"); // default format
74  }
75 
76  public SEAxisAngle(DecimalFormat df) {
77  df_ = df;
78  value_ = new AxisAngle4d();
79  }
80 
81  public void setValue(Double value[]) {
82  if (value.length != 4) throw new StringExchangeException();
83  isNaN_ = false;
84  for (int i = 0; i < 4; i ++) {
85  if (value[i].isNaN()) {
86  isNaN_ = true;
87  } else if (value[i].isInfinite()) {
88  throw new StringExchangeException();
89  }
90  }
91 
92  value_.set(
93  value[0].doubleValue(),
94  value[1].doubleValue(),
95  value[2].doubleValue(),
96  value[3].doubleValue()
97  );
98 
99  Quat4d quat = new Quat4d();
100  quat.set(value_);
101  value_.set(quat);
102  }
103 
104  public void setValue(double value[]) {
105  if (value.length != 4) throw new StringExchangeException();
106  isNaN_ = false;
107  for (int i = 0; i < 4; i ++) {
108  if (Double.isNaN(value[i])) {
109  isNaN_ = true;
110  } else if (Double.isInfinite(value[i])) {
111  throw new StringExchangeException();
112  }
113  }
114 
115  value_.set(value);
116 
117  Quat4d quat = new Quat4d();
118  quat.set(value_);
119  value_.set(quat);
120  }
121 
122  public void setValue(float value[]) {
123  if (value.length != 4) throw new StringExchangeException();
124  isNaN_ = false;
125  for (int i = 0; i < 4; i ++) {
126  if (Double.isNaN(value[i])) {
127  isNaN_ = true;
128  } else if (Double.isInfinite(value[i])) {
129  throw new StringExchangeException();
130  }
131  }
132  value_.set(
133  (double)value[0],
134  (double)value[1],
135  (double)value[2],
136  (double)value[3]
137  );
138 
139  Quat4d quat = new Quat4d();
140  quat.set(value_);
141  value_.set(quat);
142  }
143 
144  public void setValue(Quat4d value) {
145  isNaN_ = false;
146  value_.set(value);
147  }
148 
149  public String toString() {
150  if (isNaN_) { return ""; }
151 
152  StringBuffer strBuf = new StringBuffer();
153 
154  strBuf.append(df_.format(value_.x));
155  strBuf.append(" ");
156  strBuf.append(df_.format(value_.y));
157  strBuf.append(" ");
158  strBuf.append(df_.format(value_.z));
159  strBuf.append(" ");
160  strBuf.append(df_.format(value_.angle));
161 
162  return strBuf.toString();
163  }
164 
165  public Object fromString(String str) {
166  if (str.equals("")) {
167  isNaN_ = true;
168  return null;
169  }
170 
171  StringTokenizer token = new StringTokenizer(str);
172 
173  Double[] doubleArray = new Double[4];
174 
175  isNaN_ = false;
176 
177  for (int i = 0; i < 4; i ++) {
178  if (token.hasMoreTokens()) {
179  String value = token.nextToken();
180  if (value.equals("NaN")) {
181  isNaN_ = true;
182  doubleArray[i] = new Double(Double.NaN);
183  } else {
184  try {
185  doubleArray[i] = new Double(value);
186  } catch (NumberFormatException ex) {
187  throw new StringExchangeException();
188  }
189 
190  if (doubleArray[i].isNaN()) {
191  isNaN_ = true;
192  } else if (doubleArray[i].isInfinite()) {
193  throw new StringExchangeException();
194  }
195  }
196  } else {
197  throw new StringExchangeException();
198  }
199  }
200 
201  if (token.hasMoreTokens()) {
202  throw new StringExchangeException();
203  }
204 
205  value_.set(
206  doubleArray[0].doubleValue(),
207  doubleArray[1].doubleValue(),
208  doubleArray[2].doubleValue(),
209  doubleArray[3].doubleValue()
210  );
211 
212  Quat4d quat = new Quat4d();
213  quat.set(value_);
214  value_.set(quat);
215 
216  return (Object)value_;
217  }
218 
219  public void setValue(Object value) {
220  Quat4d quat = new Quat4d();
221  quat.set((AxisAngle4d)value);
222  value_.set(quat);
223  }
224 
225  public void setValue(double x, double y, double z, double angle) {
226  value_.set(x, y, z, angle);
227  Quat4d quat = new Quat4d();
228  quat.set(value_);
229  value_.set(quat);
230  }
231 
232  public void setValue(String str) {
233  fromString(str);
234  }
235 
236  public Object getValue() {
237  return (Object)value_;
238  }
239 
240  public double getX() {
241  return value_.x;
242  }
243 
244  public double getY() {
245  return value_.y;
246  }
247 
248  public double getZ() {
249  return value_.z;
250  }
251 
252  public double getAngle() {
253  return value_.angle;
254  }
255 
256  public boolean isNaN() {
257  return isNaN_;
258  }
259 }
* 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
SEAxisAngle(double x, double y, double z, double angle)
void setValue(double x, double y, double z, double angle)
* 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