Search in sources :

Example 11 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class RigidTransformWidget method updateInternalValue.

/**
 * Updates the internal representation of the value, updates any result
 * holders, and returns true if the new value differs from the old value.
 */
protected boolean updateInternalValue(Object value) {
    if (!valuesEqual(value, myValue)) {
        myTranslationField.maskValueChangeListeners(true);
        myRotationField.maskValueChangeListeners(true);
        if (value instanceof RigidTransform3d) {
            RigidTransform3d newX = (RigidTransform3d) value;
            if (myTranslationField.valueIsVoid() || !newX.p.equals(getTranslation())) {
                myTranslationField.setValue(newX.p);
            }
            RotationMatrix3d R = new RotationMatrix3d();
            if (!myRotationField.valueIsVoid()) {
                R.setAxisAngle(getRotation());
            }
            if (myRotationField.valueIsVoid() || !newX.R.equals(R)) {
                AxisAngle newAxisAngle = new AxisAngle();
                newX.R.getAxisAngle(newAxisAngle);
                myRotationField.setValue(newAxisAngle);
            }
            value = new RigidTransform3d(newX);
        } else if (value == Property.VoidValue) {
            myTranslationField.setValue(Property.VoidValue);
            myRotationField.setValue(Property.VoidValue);
        }
        myTranslationField.maskValueChangeListeners(false);
        myRotationField.maskValueChangeListeners(false);
        myValue = value;
        return true;
    } else {
        return false;
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 12 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class Main method createViewerFrame.

public GLViewerFrame createViewerFrame() {
    GLViewerFrame frame = new GLViewerFrame(myViewer, PROJECT_NAME, 400, 400);
    GLViewer viewer = frame.getViewer();
    // ViewerToolBar toolBar = new ViewerToolBar(viewer, this);
    AxisAngle REW = getDefaultViewOrientation(getRootModel());
    myViewerManager.addViewer(viewer);
    ViewerToolBar toolBar = new ViewerToolBar(viewer, /*addGridPanel=*/
    true);
    frame.getContentPane().add(toolBar, BorderLayout.PAGE_START);
    viewer.setDefaultAxialView(AxisAlignedRotation.getNearest(new RotationMatrix3d(REW)));
    initializeViewer(viewer, REW);
    frame.setVisible(true);
    return frame;
}
Also used : ViewerToolBar(maspack.widgets.ViewerToolBar) GLViewer(maspack.render.GL.GLViewer) AxisAngle(maspack.matrix.AxisAngle) GLViewerFrame(maspack.render.GL.GLViewerFrame) RotationMatrix3d(maspack.matrix.RotationMatrix3d)

Example 13 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class FemModel3dAgent method restoreDefaultValues.

private void restoreDefaultValues() {
    maskAllValueChangeListeners(true);
    lastScale = 1.0;
    scaleField.setValue(lastScale);
    positionField.setVoidValueEnabled(true);
    positionField.setValue(Property.VoidValue);
    positionField.setVoidValueEnabled(false);
    orientationField.setValue(new AxisAngle());
    GLViewer viewer = myMain.getMain().getViewer();
    double width = viewer.distancePerPixel(viewer.getCenter()) * viewer.getScreenWidth() / 6;
    // Grid fields
    double gridWidth = DEFAULT_GRID_DIM.x;
    if (width > gridWidth) {
        for (int i = -1; width > gridWidth; i++) {
            gridWidth *= (i % 3 == 0) ? 2.5 : 2.0;
        }
    } else {
        for (int i = -1; width < gridWidth; i++) {
            gridWidth /= (i % 3 == 0) ? 2.5 : 2.0;
        }
    }
    gridDimField.setValue(new Vector3d(gridWidth, gridWidth, gridWidth));
    gridDivField.setValue(DEFAULT_GRID_DIV);
    // Tube fields
    double tubeScale = 1;
    if (width > tubeScale * DEFAULT_TUBE_DIM.z) {
        for (int i = -1; width > tubeScale * DEFAULT_TUBE_DIM.z; i++) {
            tubeScale *= (i % 3 == 0) ? 2.5 : 2.0;
        }
    } else {
        for (int i = -1; width < tubeScale * DEFAULT_TUBE_DIM.z; i++) {
            tubeScale /= (i % 3 == 0) ? 2.5 : 2.0;
        }
    }
    tubeScale /= 2.0;
    tubeDimField.setValue(new Vector3d(DEFAULT_TUBE_DIM.x * tubeScale, DEFAULT_TUBE_DIM.y * tubeScale, DEFAULT_TUBE_DIM.z * tubeScale));
    tubeDivField.setValue(DEFAULT_TUBE_DIV);
    // Torus fields
    double torusScale = 1;
    if (width > torusScale * (DEFAULT_TORUS_DIM.x + DEFAULT_TORUS_DIM.z)) {
        for (int i = -1; width > torusScale * (DEFAULT_TORUS_DIM.x + DEFAULT_TORUS_DIM.z); i++) {
            torusScale *= (i % 3 == 0) ? 2.5 : 2.0;
        }
    } else {
        for (int i = -1; width < torusScale * (DEFAULT_TORUS_DIM.x + DEFAULT_TORUS_DIM.z); i++) {
            torusScale /= (i % 3 == 0) ? 2.5 : 2.0;
        }
    }
    torusScale /= 2.0;
    torusDimField.setValue(new Vector3d(DEFAULT_TORUS_DIM.x * torusScale, DEFAULT_TORUS_DIM.y * torusScale, DEFAULT_TORUS_DIM.z * torusScale));
    torusDivField.setValue(DEFAULT_TORUS_DIV);
    // Sphere field
    sphereNodesField.setValue(SPHERE_NODE_OPTIONS[0]);
    // Extrusion fields
    extrusDepthField.setValue(DEFAULT_EXTRUSION_DEPTH);
    extrusLayersField.setValue(DEFAULT_EXTRUSION_LAYERS);
    extrusFileField.setValue(null);
    // Ansys fields
    ansysNodeFileField.setValue(null);
    ansysElemFileField.setValue(null);
    // Tetgen fields
    tetgenNodeFileField.setValue(null);
    tetgenEleFileField.setValue(null);
    // UCD field
    ucdMeshFileField.setValue(null);
    // Surface mesh field
    surfaceMeshFileField.setValue(null);
    maskAllValueChangeListeners(false);
}
Also used : AxisAngle(maspack.matrix.AxisAngle) GLViewer(maspack.render.GL.GLViewer) Vector3d(maspack.matrix.Vector3d)

Example 14 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class CutPlaneProbe method getOrientation.

/**
 * Gets the orientation of the display
 */
public AxisAngle getOrientation() {
    AxisAngle axisAng = new AxisAngle();
    XGridToWorld.R.getAxisAngle(axisAng);
    return axisAng;
}
Also used : AxisAngle(maspack.matrix.AxisAngle)

Example 15 with AxisAngle

use of maspack.matrix.AxisAngle in project artisynth_core by artisynth.

the class FemCollision method build.

public void build(String[] args) throws IOException {
    try {
        MechModel mechmod = new MechModel();
        // mechmod.setIntegrator (Integrator.ConstrainedBackwardEuler);
        mechmod.setIntegrator(Integrator.BackwardEuler);
        // mechmod.setProfiling (true);
        CollisionManager collisions = mechmod.getCollisionManager();
        RenderProps.setVisible(collisions, true);
        RenderProps.setEdgeWidth(collisions, 4);
        RenderProps.setEdgeColor(collisions, Color.YELLOW);
        RenderProps.setLineWidth(collisions, 3);
        RenderProps.setLineColor(collisions, Color.GREEN);
        collisions.setDrawContactNormals(true);
        RigidBody table = new RigidBody("table");
        table.setDynamic(false);
        // table.setMesh (new PolygonalMesh (new File (rbpath+ "box.obj")), null);
        table.setMesh(MeshFactory.createBox(2, 2, 2));
        AffineTransform3d trans = new AffineTransform3d();
        trans.setIdentity();
        trans.applyScaling(4, 2, 0.5);
        table.transformGeometry(trans);
        table.setPose(new RigidTransform3d(new Vector3d(1, 0, 0.8077474533228615), new AxisAngle(1, 0, 0, Math.toRadians(mu == 0 ? 0.0 : 1.5))));
        if (wireFrame) {
            RenderProps.setFaceStyle(table, Renderer.FaceStyle.NONE);
            RenderProps.setDrawEdges(table, true);
        }
        mechmod.addRigidBody(table);
        if (incBox0) {
            box0 = new RigidBody("box0");
            // box0.setMesh (
            // new PolygonalMesh (new File (rbpath + "box.obj")), null);
            box0.setMesh(MeshFactory.createBox(2, 2, 2));
            trans.setIdentity();
            trans.applyScaling(1.5, 1.5, 0.5);
            box0.transformGeometry(trans);
            box0.setInertia(SpatialInertia.createBoxInertia(10000, 4, 4, 1));
            box0.setPose(new RigidTransform3d(new Vector3d(-0.5, 0, 3.5), new AxisAngle()));
            RenderProps.setFaceColor(box0, Color.GREEN.darker());
            if (wireFrame) {
                RenderProps.setFaceStyle(box0, Renderer.FaceStyle.NONE);
                RenderProps.setDrawEdges(box0, true);
            }
            mechmod.addRigidBody(box0);
        }
        if (incFem0) {
            String fem0Name = // "torus546";
            "sphere2";
            // "box0023";
            // "box0048";
            // "box0144";
            // "box0604";
            // "box1056";
            // "box2463";
            // "box4257";
            fem0 = TetGenReader.read("fem0", 5000, fempath + fem0Name + ".1.node", fempath + fem0Name + ".1.ele", new Vector3d(0.8, 0.8, 0.8));
            fem0.transformGeometry(new RigidTransform3d(new Vector3d(2, 0, 3.5), new AxisAngle()));
            fem0.setLinearMaterial(1000000, 0.33, true);
            if (!wireFrame)
                fem0.setSurfaceRendering(SurfaceRender.Shaded);
            fem0.setParticleDamping(0.1);
            RenderProps.setFaceColor(fem0, new Color(0.5f, 0f, 0f));
            // RenderProps.setAlpha(fem0, 0.33);
            RenderProps.setAlpha(fem0, 0.5);
            RenderProps.setShading(fem0, Shading.NONE);
            RenderProps.setDrawEdges(fem0, true);
            RenderProps.setVisible(fem0.getElements(), false);
            RenderProps.setVisible(fem0.getNodes(), false);
            // RenderProps.setLineColor(fem0, Color.GRAY);
            mechmod.addModel(fem0);
        }
        if (incFem1) {
            // Use this code for a box
            /*
             * double mySize = 1; fem1 = createFem (name, mySize);
             * FemFactory.createTetGrid ( fem1, 1*mySize, 4*mySize, mySize, 1,
             * 1, 1);
             */
            // end box code
            // Use this code for a ball
            String fem1Name = "sphere2";
            fem1 = TetGenReader.read("fem1", 5000, fempath + fem1Name + ".1.node", fempath + fem1Name + ".1.ele", new Vector3d(0.8, 0.8, 0.8));
            fem1.setLinearMaterial(1000000, 0.33, true);
            fem1.setParticleDamping(0.1);
            // end ball code
            fem1.setIncompressible(FemModel3d.IncompMethod.AUTO);
            fem1.transformGeometry(new RigidTransform3d(new Vector3d(1.25, 0, 2), new AxisAngle()));
            fem1.setSurfaceRendering(wireFrame ? SurfaceRender.None : SurfaceRender.Shaded);
            RenderProps.setAlpha(fem1, 0.5);
            RenderProps.setShading(fem1, Shading.NONE);
            RenderProps.setDrawEdges(fem1, true);
            RenderProps.setVisible(fem1.getElements(), false);
            RenderProps.setVisible(fem1.getNodes(), false);
            RenderProps.setFaceColor(fem1, new Color(0f, 0f, 0.8f));
            mechmod.addModel(fem1);
        }
        if (incFem0) {
            mechmod.setCollisionBehavior(fem0, table, true, mu);
            mechmod.setCollisionResponse(fem0, Collidable.Deformable);
            mechmod.setCollisionResponse(fem0, table);
        }
        if (incFem1 & incFem0) {
            mechmod.setCollisionBehavior(fem0, fem1, true, mu);
        }
        if (incBox0 & incFem0) {
            mechmod.setCollisionBehavior(box0, fem0, true, mu);
        }
        if (incFem1) {
            mechmod.setCollisionBehavior(fem1, table, true, mu);
            mechmod.setCollisionResponse(fem1, Collidable.AllBodies);
        }
        if (incBox0 & incFem1) {
            mechmod.setCollisionBehavior(box0, fem1, true, mu);
        }
        if (incBox0) {
            mechmod.setCollisionBehavior(box0, table, true, mu);
            mechmod.setCollisionResponse(box0, table);
        }
        addModel(mechmod);
    // mechmod.setIntegrator (Integrator.BackwardEuler);
    // addBreakPoint (2.36);
    // reset();
    } catch (IOException e) {
        throw e;
    }
}
Also used : MechModel(artisynth.core.mechmodels.MechModel) RigidTransform3d(maspack.matrix.RigidTransform3d) AxisAngle(maspack.matrix.AxisAngle) CollisionManager(artisynth.core.mechmodels.CollisionManager) Vector3d(maspack.matrix.Vector3d) Color(java.awt.Color) RigidBody(artisynth.core.mechmodels.RigidBody) IOException(java.io.IOException) AffineTransform3d(maspack.matrix.AffineTransform3d)

Aggregations

AxisAngle (maspack.matrix.AxisAngle)38 Vector3d (maspack.matrix.Vector3d)19 RigidTransform3d (maspack.matrix.RigidTransform3d)18 PolygonalMesh (maspack.geometry.PolygonalMesh)8 Point3d (maspack.matrix.Point3d)7 RotationMatrix3d (maspack.matrix.RotationMatrix3d)7 AffineTransform3d (maspack.matrix.AffineTransform3d)5 RigidBody (artisynth.core.mechmodels.RigidBody)4 MechModel (artisynth.core.mechmodels.MechModel)3 Font (java.awt.Font)3 File (java.io.File)3 IOException (java.io.IOException)3 GLViewer (maspack.render.GL.GLViewer)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 CollisionManager (artisynth.core.mechmodels.CollisionManager)2 HashMap (java.util.HashMap)2 JFrame (javax.swing.JFrame)2 RenderProps (maspack.render.RenderProps)2 ReaderTokenizer (maspack.util.ReaderTokenizer)2 AxisAngleField (maspack.widgets.AxisAngleField)2