GrxTransformItem.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  */
10 
11 
12 package com.generalrobotix.ui.item;
13 
14 import java.util.List;
15 import java.util.Vector;
16 
17 import org.eclipse.jface.dialogs.MessageDialog;
18 
19 import javax.media.j3d.BadTransformException;
20 import javax.media.j3d.BranchGroup;
21 import javax.media.j3d.Geometry;
22 import javax.media.j3d.QuadArray;
23 import javax.media.j3d.Shape3D;
24 import javax.media.j3d.Switch;
25 import javax.media.j3d.Transform3D;
26 import javax.media.j3d.TransformGroup;
28 
29 import javax.vecmath.Color3f;
30 import javax.vecmath.Matrix3d;
31 import javax.vecmath.Matrix4d;
32 import javax.vecmath.Point3f;
33 import javax.vecmath.Vector3d;
34 
35 import jp.go.aist.hrp.simulator.ModelLoader;
36 import jp.go.aist.hrp.simulator.ModelLoaderHelper;
37 import jp.go.aist.hrp.simulator.ModelLoaderPackage.ModelLoaderException;
38 import jp.go.aist.hrp.simulator.SceneInfo;
39 import jp.go.aist.hrp.simulator.ShapePrimitiveType;
40 
48 
52 @SuppressWarnings("serial")
53 public class GrxTransformItem extends GrxBaseItem {
54  public TransformGroup tg_;
55  public BranchGroup bg_;
56 
58  public Vector<GrxTransformItem> children_;
59 
60  private Switch switchAxes_;
61  private Switch switchBb_;
62  protected GrxModelItem model_;
63 
69  public GrxTransformItem(String name, GrxPluginManager manager, GrxModelItem model) {
70  super(name, manager);
71  model_ = model;
72 
73  tg_ = new TransformGroup();
74  tg_.setCapability(TransformGroup.ALLOW_CHILDREN_READ);
75  tg_.setCapability(TransformGroup.ALLOW_CHILDREN_EXTEND);
76  tg_.setCapability(TransformGroup.ALLOW_CHILDREN_WRITE);
77  tg_.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
78  tg_.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
79 
80  switchAxes_ = GrxShapeUtil.createAxes();
81  tg_.addChild(switchAxes_);
82 
83  bg_ = new BranchGroup();
84  bg_.setCapability(BranchGroup.ALLOW_DETACH);
85  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
86  bg_.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
87 
88  bg_.addChild(tg_);
89 
90  createBoundingBox();
91 
92  children_ = new Vector<GrxTransformItem>();
93 
94  }
95 
100  public void addChild(GrxTransformItem child){
101  children_.add(child);
102  child.parent_ = this;
103  tg_.addChild(child.bg_);
104  resizeBoundingBox();
105  }
106 
111  public void removeChild(GrxTransformItem child){
112  children_.remove(child);
113  child.bg_.detach();
114  resizeBoundingBox();
115  }
116 
120  public void delete() {
121  try{
122  // delete children first
123  while (children_.size() > 0){
124  children_.get(0).delete();
125  }
126 
127  if (parent_ != null){
128  parent_.removeChild(this);
129  // I don't know why the following line is required.
130  // But without the line, this transform is moved to the origin.
131  model_.calcForwardKinematics();
132  }
133  }catch(Exception ex){
134  ex.printStackTrace();
135  }
136  manager_.itemChange(this, GrxPluginManager.REMOVE_ITEM);
137  }
138 
143  public GrxModelItem model() {
144  return model_;
145  }
146 
147  public void setFocused(boolean b){
148  super.setFocused(b);
149  switchAxes_.setWhichChild(b? Switch.CHILD_ALL:Switch.CHILD_NONE);
150  switchBb_.setWhichChild(b? Switch.CHILD_ALL:Switch.CHILD_NONE);
151  }
152 
153  private void createBoundingBox(){
155  modifier.init_ = true;
157  Color3f color = new Color3f(1.0f, 0.0f, 0.0f);
158  switchBb_ = SceneGraphModifier._makeSwitchNode(modifier._makeBoundingBox(color));
159  tg_.addChild(switchBb_);
160  }
161 
162  protected void resizeBoundingBox(){
163  Transform3D trorg = new Transform3D();
164  tg_.getTransform(trorg);
165  try{
166  Transform3D tr = new Transform3D();
167  tg_.setTransform(tr);
168 
170 
171  modifier.init_ = true;
173  modifier._calcUpperLower(tg_, tr);
174 
175  Shape3D shapeNode = (Shape3D)switchBb_.getChild(0);
176  Geometry gm = (Geometry)shapeNode.getGeometry(0);
177 
178  Point3f[] p3fW = modifier._makePoints();
179  if (gm instanceof QuadArray) {
180  QuadArray qa = (QuadArray) gm;
181  qa.setCoordinates(0, p3fW);
182  }
183 
184  }catch(Exception ex){
185  ex.printStackTrace();
186 
187  }
188  tg_.setTransform(trorg);
189  }
190 
191  public void gatherSensors(String type, List<GrxSensorItem> sensors){
192  if (this instanceof GrxSensorItem){
193  GrxSensorItem sensor = (GrxSensorItem)this;
194  if (sensor.type_.equals(type)){
195  sensors.add(sensor);
196  }
197  }
198  for (int i=0; i<children_.size(); i++){
199  children_.get(i).gatherSensors(type, sensors);
200  }
201  }
202 
203  // (Vector3)v = (Matrix4d)tg_*(Vector3d)v
204  public Vector3d transformV3 (Vector3d v){
205  Transform3D t3d = new Transform3D();
206  Vector3d p = new Vector3d();
207  Vector3d _v = new Vector3d(v);
208  tg_.getTransform(t3d);
209  t3d.transform(v, _v);
210  t3d.get(p);
211  _v.add(p);
212  return _v;
213  }
214 
215  public Switch getBBSwitch(){
216  resizeBoundingBox();
217  return switchBb_;
218  }
219 }
png_infop png_charp png_int_32 png_int_32 int * type
Definition: png.h:2332
#define null
our own NULL pointer
Definition: IceTypes.h:57
GrxTransformItem(String name, GrxPluginManager manager, GrxModelItem model)
png_infop png_charpp name
Definition: png.h:2382
item corresponds to a robot model
png_uint_32 i
Definition: png.h:2735
long b
Definition: jpegint.h:371
item which have a transformation
void removeChild(GrxTransformItem child)
remove a child from children
void addChild(GrxTransformItem child)
add a child
void calcForwardKinematics()
compute forward kinematics
プラグイン管理クラス GrxUIの核になるクラス。プラグインのロード等の、初期化を実行する。 プラグインとそ...
functions to make various basic shapes
GrxModelItem model()
get model item to which this item belongs
org
static Switch createAxes()
create X(red),Y(green) and Z(blue) axes
void _calcUpperLower(Node node, Transform3D t3dParent)
void gatherSensors(String type, List< GrxSensorItem > sensors)


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Sat Apr 13 2019 02:14:22