GrxSegmentItem.java
Go to the documentation of this file.
1 package com.generalrobotix.ui.item;
2 
3 import javax.media.j3d.BadTransformException;
4 import javax.media.j3d.Switch;
5 import javax.media.j3d.Transform3D;
6 import javax.media.j3d.TransformGroup;
7 import javax.vecmath.Color3f;
8 import javax.vecmath.Matrix3d;
9 import javax.vecmath.Vector3d;
10 
11 import jp.go.aist.hrp.simulator.LinkInfo;
12 import jp.go.aist.hrp.simulator.SegmentInfo;
13 
17 
18 @SuppressWarnings("serial")
19 public class GrxSegmentItem extends GrxShapeTransformItem {
20  public double mass_;
21  public double[] centerOfMass_;
22  public double[] momentOfInertia_;
23  // display
24  private Switch switchCom_;
25  private TransformGroup tgCom_;
26 
27  public GrxSegmentItem(String name, GrxPluginManager manager_, GrxModelItem model_, LinkInfo linkInfo, SegmentInfo segmentInfo) {
28  super(name, manager_, model_);
29  setIcon("segment1.png");
30  switchCom_ = GrxShapeUtil.createBall(0.01, new Color3f(1.0f, 0.5f, 0.25f), 0.5f);
31  tgCom_ = (TransformGroup)switchCom_.getChild(0);
32  tg_.addChild(switchCom_);
33 
34  if(segmentInfo != null){
35  transform(segmentInfo.transformMatrix);
36  centerOfMass(segmentInfo.centerOfMass);
37  momentOfInertia(segmentInfo.inertia);
38  mass(segmentInfo.mass);
39  if(linkInfo != null){
40  int n = segmentInfo.shapeIndices.length;
41  for(int i=0; i<n; i++)
42  addTransformedShapeIndex(linkInfo.shapeIndices[segmentInfo.shapeIndices[i]]);
43  buildShapeTransforms(linkInfo.inlinedShapeTransformMatrices);
44  }
45  }else{
46  transform( new double[]{ 1.0, 0.0, 0.0, 0.0,
47  0.0, 1.0, 0.0, 0.0,
48  0.0, 0.0, 1.0, 0.0 });
49  centerOfMass(new double[]{0.0, 0.0, 0.0});
50  momentOfInertia(new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
51  mass(0.0);
52  }
53  initMenu();
54  }
55 
56  private void mass(double mass){
57  mass_ = mass;
58  setDbl("mass", mass);
59  _updateScaleOfBall();
60  if (model_ != null) model_.notifyModified();
61  }
62 
63  private void momentOfInertia(double[] inertia){
64  if(inertia == null || inertia.length != 9) return;
65  momentOfInertia_ = inertia;
66  setDblAry("momentsOfInertia", inertia);
67  _updateScaleOfBall();
68  if (model_ != null) model_.notifyModified();
69  }
70 
71  private void centerOfMass(double[] centerOfMass){
72  if (centerOfMass == null || centerOfMass.length != 3) return;
73  centerOfMass_ = centerOfMass;
74  setDblAry("centerOfMass", centerOfMass);
75  Transform3D t3d = new Transform3D();
76  tgCom_.getTransform(t3d);
77  t3d.setTranslation(new Vector3d(centerOfMass_));
78  tgCom_.setTransform(t3d);
79  if (model_ != null) model_.notifyModified();
80  }
81 
82  public boolean propertyChanged(String property, String value) {
83  if (property.equals("name")){ //$NON-NLS-1$
84  rename(value);
85  }else if(property.equals("translation")){ //$NON-NLS-1$
86  translation(value);
87  ((GrxLinkItem)parent_).modifyCenterOfMass();
88  }else if(property.equals("rotation")){ //$NON-NLS-1$
89  rotation(value);
90  ((GrxLinkItem)parent_).modifyCenterOfMass();
91  }else if(property.equals("centerOfMass")){ //$NON-NLS-1$
92  centerOfMass(getDblAry(value));
93  ((GrxLinkItem)parent_).modifyCenterOfMass();
94  }else if(property.equals("momentsOfInertia")){ //$NON-NLS-1$
95  momentOfInertia(getDblAry(value));
96  ((GrxLinkItem)parent_).modifyInertia();
97  }else if(property.equals("mass")){ //$NON-NLS-1$
98  mass(getDbl(value));
99  ((GrxLinkItem)parent_).modifyMass();
100  }else{
101  return false;
102  }
103  return true;
104  }
105 
106  public void setFocused(boolean b){
107  if (b)
108  resizeBoundingBox();
109  super.setFocused(b);
110  switchCom_.setWhichChild(b? Switch.CHILD_ALL:Switch.CHILD_NONE);
111  }
112 
113  private void _updateScaleOfBall(){
114  Matrix3d I = new Matrix3d(momentOfInertia_);
115  Vector3d scale = CalcInertiaUtil.calcScale(I, mass_);
116  Transform3D t3d = new Transform3D();
117  tgCom_.getTransform(t3d);
118  t3d.setScale(scale);
119  try{
120  tgCom_.setTransform(t3d);
121  }catch(BadTransformException ex){
122  System.out.println("BadTransformException in _updateScaleOfBall"); //$NON-NLS-1$
123  }
124  }
125 }
void centerOfMass(double[] centerOfMass)
#define null
our own NULL pointer
Definition: IceTypes.h:57
png_infop png_charpp name
Definition: png.h:2382
png_voidp int value
Definition: png.h:2113
item corresponds to a robot model
png_uint_32 i
Definition: png.h:2735
long b
Definition: jpegint.h:371
boolean propertyChanged(String property, String value)
static Vector3d calcScale(Matrix3d I, double m)
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
functions to make various basic shapes
GrxSegmentItem(String name, GrxPluginManager manager_, GrxModelItem model_, LinkInfo linkInfo, SegmentInfo segmentInfo)
static Switch createBall(double radius, Color3f c)
create ball with switch node


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat May 8 2021 02:42:38