Search in sources :

Example 21 with AffineTransform3d

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

the class DicomViewer method init.

private void init(String name, DicomImage image) {
    setName(ModelComponentBase.makeValidName(name));
    myRenderProps = createRenderProps();
    robj = null;
    robjValid = false;
    myTransform = new AffineTransform3d(RigidTransform3d.IDENTITY);
    drawBox = true;
    drawSlice = new boolean[] { true, true, true };
    coord = new Vector3d();
    setImage(image);
    setSliceCoordinates(0.5, 0.5, 0.5);
}
Also used : Vector3d(maspack.matrix.Vector3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 22 with AffineTransform3d

use of maspack.matrix.AffineTransform3d 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)

Example 23 with AffineTransform3d

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

the class MatricesUBO method updateMatrices.

public void updateMatrices(GL3 gl, Matrix4d proj, RigidTransform3d view, AffineTransform3dBase model, AffineTransform2dBase texture) {
    ByteBuffer buff = getBuffer();
    // model view
    AffineTransform3d modelview = new AffineTransform3d(view);
    modelview.mul(model);
    // pvm matrix
    buff.position(getByteOffset(PVM_IDX));
    mul(proj, modelview, buff);
    // model-view
    buff.position(getByteOffset(VM_IDX));
    putMatrix(buff, modelview);
    // model matrix
    buff.position(getByteOffset(M_IDX));
    putMatrix(buff, model);
    // normal
    buff.position(getByteOffset(NORMAL_IDX));
    if (model instanceof RigidTransform3d) {
        putMatrix(buff, modelview);
    } else {
        // invert model matrix
        Matrix3d A = new Matrix3d(model.getMatrix());
        if (!A.invert()) {
            // deal with non-invertible
            SVDecomposition3d svd3 = new SVDecomposition3d(model.getMatrix());
            svd3.pseudoInverse(A);
        }
        mulTranspose4x4(view.R, A, buff);
    }
    buff.position(getByteOffset(TEXTURE_IDX));
    putMatrix(buff, texture);
    buff.flip();
    update(gl, buff);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Matrix3d(maspack.matrix.Matrix3d) SVDecomposition3d(maspack.matrix.SVDecomposition3d) ByteBuffer(java.nio.ByteBuffer) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 24 with AffineTransform3d

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

the class MultiViewerTesterBase method addCylinder.

protected static void addCylinder(MultiViewer tester) {
    // cylinder
    RenderObject cylinderRO = RenderObjectFactory.createCylinder(32, true);
    RenderObjectWrapper rcylinder = new RenderObjectWrapper(cylinderRO);
    AffineTransform3d cscale = new AffineTransform3d();
    cscale.setTranslation(0.3, 0.3, 0);
    cscale.setRotation(new AxisAngle(1d / Math.sqrt(2), -1d / Math.sqrt(2), 0, Math.PI / 8));
    cscale.applyScaling(0.05, 0.05, 1.0);
    rcylinder.setTransform(cscale);
    RenderProps rprops2 = rcylinder.getRenderProps();
    rprops2.setFaceColor(Color.CYAN);
    rprops2.setShading(Shading.SMOOTH);
    tester.addRenderable(rcylinder);
}
Also used : AxisAngle(maspack.matrix.AxisAngle) RenderProps(maspack.render.RenderProps) RenderObject(maspack.render.RenderObject) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 25 with AffineTransform3d

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

the class AffineTransformWidget 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, getInternalValue())) {
        maskValueChanges(true);
        if (value == Property.VoidValue) {
            for (LabeledTextField c : myFields) {
                c.setValue(Property.VoidValue);
            }
            myValueIsVoid = true;
        } else {
            RotationMatrix3d R = new RotationMatrix3d();
            Vector3d p = new Vector3d();
            Vector3d scale = new Vector3d(1, 1, 1);
            Vector3d shear = new Vector3d(0, 0, 0);
            if (value instanceof RigidTransform3d) {
                RigidTransform3d newX = (RigidTransform3d) value;
                p.set(newX.p);
                R.set(newX.R);
            // System.out.println ("newT\n" + newX.toString("%10.6f"));
            } else if (value instanceof AffineTransform3d) {
                AffineTransform3d newX = (AffineTransform3d) value;
                p.set(newX.p);
                newX.factorA(R, scale, shear);
            // System.out.println ("newX\n" + newX.toString("%10.6f"));
            } else {
                throw new InternalErrorException("Unknown value type " + value.getClass());
            }
            setTranslation(p);
            setRotation(R.getAxisAngle());
            setScale(scale);
            setShear(shear);
            myValueIsVoid = false;
        }
        maskValueChanges(false);
        return true;
    } else {
        return false;
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) InternalErrorException(maspack.util.InternalErrorException) RotationMatrix3d(maspack.matrix.RotationMatrix3d) AffineTransform3d(maspack.matrix.AffineTransform3d)

Aggregations

AffineTransform3d (maspack.matrix.AffineTransform3d)46 Vector3d (maspack.matrix.Vector3d)14 RigidTransform3d (maspack.matrix.RigidTransform3d)13 Point3d (maspack.matrix.Point3d)7 PolygonalMesh (maspack.geometry.PolygonalMesh)5 AxisAngle (maspack.matrix.AxisAngle)5 Matrix3d (maspack.matrix.Matrix3d)4 RotationMatrix3d (maspack.matrix.RotationMatrix3d)4 InstanceTransformType (maspack.render.RenderInstances.InstanceTransformType)4 RenderProps (maspack.render.RenderProps)4 RigidBody (artisynth.core.mechmodels.RigidBody)3 Point (java.awt.Point)3 IOException (java.io.IOException)3 RenderObject (maspack.render.RenderObject)3 CollisionManager (artisynth.core.mechmodels.CollisionManager)2 MechModel (artisynth.core.mechmodels.MechModel)2 File (java.io.File)2 ByteBuffer (java.nio.ByteBuffer)2 ArrayList (java.util.ArrayList)2 Vertex3d (maspack.geometry.Vertex3d)2