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 }
i
png_uint_32 i
Definition: png.h:2732
com.generalrobotix.ui.item.GrxSegmentItem.momentOfInertia_
double[] momentOfInertia_
Definition: GrxSegmentItem.java:22
com.generalrobotix.ui.item.GrxSegmentItem
Definition: GrxSegmentItem.java:19
com.generalrobotix.ui.item.GrxSegmentItem.mass_
double mass_
Definition: GrxSegmentItem.java:20
com.generalrobotix.ui.item.GrxSegmentItem.mass
void mass(double mass)
Definition: GrxSegmentItem.java:56
com.generalrobotix.ui.item.GrxSegmentItem.centerOfMass
void centerOfMass(double[] centerOfMass)
Definition: GrxSegmentItem.java:71
com.generalrobotix.ui.util.CalcInertiaUtil
Definition: CalcInertiaUtil.java:6
jp.go
autoplay.n
n
Definition: autoplay.py:12
com.generalrobotix.ui.item.GrxSegmentItem.GrxSegmentItem
GrxSegmentItem(String name, GrxPluginManager manager_, GrxModelItem model_, LinkInfo linkInfo, SegmentInfo segmentInfo)
Definition: GrxSegmentItem.java:27
jp
com.generalrobotix.ui.item.GrxShapeTransformItem
Definition: GrxShapeTransformItem.java:33
com.generalrobotix.ui.item.GrxSegmentItem.setFocused
void setFocused(boolean b)
set/unset focus on this plugin
Definition: GrxSegmentItem.java:106
swingTest.f
f
Definition: swingTest.py:6
com.generalrobotix.ui.item.GrxSegmentItem.propertyChanged
boolean propertyChanged(String property, String value)
check validity of new value of property and update if valid
Definition: GrxSegmentItem.java:82
jp.go.aist
com.generalrobotix.ui.util.CalcInertiaUtil.calcScale
static Vector3d calcScale(Matrix3d I, double m)
Definition: CalcInertiaUtil.java:8
b
long b
Definition: jpegint.h:371
value
png_voidp int value
Definition: png.h:2110
com.generalrobotix.ui.item.GrxSegmentItem.momentOfInertia
void momentOfInertia(double[] inertia)
Definition: GrxSegmentItem.java:63
jp.go.aist.hrp
com.generalrobotix.ui.item.GrxSegmentItem.switchCom_
Switch switchCom_
Definition: GrxSegmentItem.java:24
name
png_infop png_charpp name
Definition: png.h:2379
com.generalrobotix.ui.item.GrxLinkItem
Definition: GrxLinkItem.java:68
com.generalrobotix
com.generalrobotix.ui.GrxPluginManager
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそのアイテムのマップ(::pluginMap_)、プラグインとその情報のマップ(::pinfoM...
Definition: GrxPluginManager.java:79
com.generalrobotix.ui.util.GrxShapeUtil
functions to make various basic shapes
Definition: GrxShapeUtil.java:30
com
com.generalrobotix.ui.item.GrxModelItem
item corresponds to a robot model
Definition: GrxModelItem.java:52
com.generalrobotix.ui.util
Definition: AlertBox.java:17
jp.go.aist.hrp.simulator
Definition: PathConsumer.java:8
com.generalrobotix.ui
com.generalrobotix.ui.item.GrxSegmentItem.centerOfMass_
double[] centerOfMass_
Definition: GrxSegmentItem.java:21
com.generalrobotix.ui.item.GrxSegmentItem.tgCom_
TransformGroup tgCom_
Definition: GrxSegmentItem.java:25
com.generalrobotix.ui.util.GrxShapeUtil.createBall
static Switch createBall(double radius, Color3f c)
create ball with switch node
Definition: GrxShapeUtil.java:86
com.generalrobotix.ui.item.GrxSegmentItem._updateScaleOfBall
void _updateScaleOfBall()
Definition: GrxSegmentItem.java:113


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Wed Sep 7 2022 02:51:03