GrxSegmentItem.java
Go to the documentation of this file.
00001 package com.generalrobotix.ui.item;
00002 
00003 import javax.media.j3d.BadTransformException;
00004 import javax.media.j3d.Switch;
00005 import javax.media.j3d.Transform3D;
00006 import javax.media.j3d.TransformGroup;
00007 import javax.vecmath.Color3f;
00008 import javax.vecmath.Matrix3d;
00009 import javax.vecmath.Vector3d;
00010 
00011 import jp.go.aist.hrp.simulator.LinkInfo;
00012 import jp.go.aist.hrp.simulator.SegmentInfo;
00013 
00014 import com.generalrobotix.ui.GrxPluginManager;
00015 import com.generalrobotix.ui.util.CalcInertiaUtil;
00016 import com.generalrobotix.ui.util.GrxShapeUtil;
00017 
00018 @SuppressWarnings("serial")
00019 public class GrxSegmentItem extends GrxShapeTransformItem {
00020         public double mass_;
00021         public double[] centerOfMass_;
00022         public double[] momentOfInertia_;
00023         // display
00024     private Switch switchCom_;
00025     private TransformGroup tgCom_;
00026         
00027         public GrxSegmentItem(String name, GrxPluginManager manager_, GrxModelItem model_, LinkInfo linkInfo, SegmentInfo segmentInfo) {
00028                 super(name, manager_, model_);
00029                 setIcon("segment1.png");
00030                 switchCom_ = GrxShapeUtil.createBall(0.01, new Color3f(1.0f, 0.5f, 0.25f), 0.5f);
00031             tgCom_ = (TransformGroup)switchCom_.getChild(0);
00032             tg_.addChild(switchCom_);
00033             
00034             if(segmentInfo != null){
00035                         transform(segmentInfo.transformMatrix);
00036                 centerOfMass(segmentInfo.centerOfMass);  
00037                 momentOfInertia(segmentInfo.inertia);
00038                 mass(segmentInfo.mass);     
00039                 if(linkInfo != null){
00040                         int n = segmentInfo.shapeIndices.length;
00041                         for(int i=0; i<n; i++)
00042                                 addTransformedShapeIndex(linkInfo.shapeIndices[segmentInfo.shapeIndices[i]]);
00043                         buildShapeTransforms(linkInfo.inlinedShapeTransformMatrices);
00044                 }
00045             }else{
00046                 transform( new double[]{        1.0, 0.0, 0.0, 0.0, 
00047                                                                                 0.0, 1.0, 0.0, 0.0,
00048                                                                                 0.0, 0.0, 1.0, 0.0 });
00049                 centerOfMass(new double[]{0.0, 0.0, 0.0});  
00050                 momentOfInertia(new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0});
00051                 mass(0.0);
00052             }
00053         initMenu();
00054         }
00055 
00056         private void mass(double mass){
00057                 mass_ = mass;
00058         setDbl("mass", mass);
00059         _updateScaleOfBall();
00060         if (model_ != null)             model_.notifyModified();
00061         }
00062         
00063         private void momentOfInertia(double[] inertia){
00064                 if(inertia == null || inertia.length != 9) return;
00065                 momentOfInertia_ = inertia;
00066                 setDblAry("momentsOfInertia", inertia);
00067         _updateScaleOfBall();
00068         if (model_ != null)             model_.notifyModified();
00069         }
00070         
00071         private void centerOfMass(double[] centerOfMass){
00072                 if (centerOfMass == null || centerOfMass.length != 3) return;
00073                 centerOfMass_ = centerOfMass;
00074                 setDblAry("centerOfMass", centerOfMass);
00075                 Transform3D t3d = new Transform3D();
00076         tgCom_.getTransform(t3d);
00077         t3d.setTranslation(new Vector3d(centerOfMass_));
00078         tgCom_.setTransform(t3d);
00079         if (model_ != null)             model_.notifyModified();
00080         }
00081        
00082     public boolean propertyChanged(String property, String value) {
00083         if (property.equals("name")){ //$NON-NLS-1$
00084                         rename(value);
00085         }else if(property.equals("translation")){ //$NON-NLS-1$
00086                 translation(value);
00087                 ((GrxLinkItem)parent_).modifyCenterOfMass();
00088         }else if(property.equals("rotation")){ //$NON-NLS-1$
00089                 rotation(value);
00090                 ((GrxLinkItem)parent_).modifyCenterOfMass();
00091         }else if(property.equals("centerOfMass")){ //$NON-NLS-1$
00092                 centerOfMass(getDblAry(value));
00093                 ((GrxLinkItem)parent_).modifyCenterOfMass();
00094         }else if(property.equals("momentsOfInertia")){ //$NON-NLS-1$
00095                 momentOfInertia(getDblAry(value));
00096                 ((GrxLinkItem)parent_).modifyInertia();
00097         }else if(property.equals("mass")){ //$NON-NLS-1$
00098                 mass(getDbl(value));
00099                 ((GrxLinkItem)parent_).modifyMass();
00100         }else{
00101                 return false;
00102         }
00103         return true;
00104     }
00105  
00106     public void setFocused(boolean b){
00107         if (b)
00108                 resizeBoundingBox();
00109         super.setFocused(b);
00110         switchCom_.setWhichChild(b? Switch.CHILD_ALL:Switch.CHILD_NONE);
00111     }
00112     
00113     private void _updateScaleOfBall(){
00114                 Matrix3d I = new Matrix3d(momentOfInertia_);
00115                 Vector3d scale = CalcInertiaUtil.calcScale(I, mass_);
00116                 Transform3D t3d = new Transform3D();
00117                 tgCom_.getTransform(t3d);
00118                 t3d.setScale(scale);
00119                 try{
00120                         tgCom_.setTransform(t3d);
00121                 }catch(BadTransformException ex){
00122                         System.out.println("BadTransformException in _updateScaleOfBall"); //$NON-NLS-1$
00123                 }
00124     }
00125 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:16