Search in sources :

Example 36 with AffineTransform3d

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

the class FemModel3dAgent method actionPerformed.

public void actionPerformed(ActionEvent evt) {
    String cmd = evt.getActionCommand();
    if (cmd.equals("Add")) {
        ViewerManager viewerMan = myMain.getWorkspace().getViewerManager();
        viewerMan.removeRenderable(fem.getSurfaceMesh());
        viewerMan.removeDragger(rotator);
        rotator = null;
        setProperties(fem, getPrototypeComponent(myComponentType));
        // basicPropTree.setTreeValuesInHost (
        // fem, getPrototypeComponent (myComponentType));
        // myPropTree.setTreeValuesInHost (
        // fem, getPrototypeComponent (myComponentType));
        setProperties(myPrototype, myPrototype);
        PolygonalMesh mesh = fem.getSurfaceMesh();
        mesh.setRenderProps(mesh.createRenderProps());
        mesh.setMeshToWorld(RigidTransform3d.IDENTITY);
        mesh.setFixed(false);
        mesh.setColorsFixed(false);
        RigidTransform3d rigidX = new RigidTransform3d();
        rigidX.p.set(positionField.getVectorValue());
        rigidX.R.setAxisAngle(orientationField.getAxisAngleValue());
        AffineTransform3d X = new AffineTransform3d();
        X.set(rigidX);
        Object scale = scaleField.getValue();
        resetScaling();
        double sx = 1, sy = 1, sz = 1;
        if (scale instanceof Double) {
            sx = sy = sz = (Double) scale;
        } else if (scale instanceof Vector3d) {
            sx = ((Vector3d) scale).x;
            sy = ((Vector3d) scale).y;
            sz = ((Vector3d) scale).z;
        }
        X.applyScaling(sx, sy, sz);
        fem.transformGeometry(X);
        addComponent(new AddComponentsCommand("add FemModel3d", fem, myContainer));
        myDisplay.setVisible(false);
        dispose();
    } else if (cmd.equals("Clear")) {
        maskAllValueChangeListeners(true);
        restoreDefaultValues();
        myHostList.restoreBackupValues();
        myPropertyPanel.updateWidgetValues();
        // basicHostList.restoreBackupValues();
        // moreHostList.restoreBackupValues();
        // basicPropsPanel.updateWidgetValues();
        // morePropsPanel.updateWidgetValues();
        disposePreviewModel();
        resetState();
        maskAllValueChangeListeners(false);
        updateMeshPanel();
        updateState();
    } else if (cmd.equals("Cancel")) {
        disposePreviewModel();
        myDisplay.setVisible(false);
        dispose();
    } else if (evt.getSource() == autoScaleBtn) {
        if (fem != null) {
            updateScale();
        }
    } else {
        super.actionPerformed(evt);
    }
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) Vector3d(maspack.matrix.Vector3d) ViewerManager(artisynth.core.driver.ViewerManager) PolygonalMesh(maspack.geometry.PolygonalMesh) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 37 with AffineTransform3d

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

the class ColorBar method render.

@Override
public void render(Renderer renderer, int flags) {
    if (!isSelectable() && renderer.isSelecting()) {
        return;
    }
    RenderObject robj = myRenderObject;
    VectorNd labelPos = myLabelPos;
    ArrayList<String> labelText = myLabelText;
    if (robj == null || labelPos == null || labelText == null) {
        System.out.println((robj == null) + " " + (labelPos == null) + " " + (labelText == null));
        return;
    }
    int screenWidth = renderer.getScreenWidth();
    int screenHeight = renderer.getScreenHeight();
    // turn off shading for the labels
    Renderer.Shading savedShadeModel = renderer.getShading();
    renderer.setShading(Renderer.Shading.NONE);
    double x0 = myLoc.x;
    double y0 = myLoc.y;
    double w = myLoc.width;
    double h = myLoc.height;
    if (horizontal) {
        h = myLoc.width;
        w = myLoc.height;
        x0 = myLoc.y;
        y0 = myLoc.x;
    }
    // absolute or normalized -> absolute
    if (Math.abs(x0) <= 1) {
        x0 = x0 * screenWidth;
    }
    if (x0 < 0) {
        x0 = screenWidth + x0;
    }
    if (Math.abs(y0) <= 1) {
        y0 = y0 * screenHeight;
    }
    if (y0 < 0) {
        y0 = screenHeight + y0;
    }
    if (w <= 1) {
        w = w * screenWidth;
    }
    if (h <= 1) {
        h = h * screenHeight;
    }
    renderer.pushModelMatrix();
    renderer.setModelMatrix2d(0, screenWidth, 0, screenHeight);
    // transform so that the colorbar occupies correct location
    AffineTransform3d trans = new AffineTransform3d();
    if (horizontal) {
        trans.setRotation(ROT_Z_270);
        trans.applyScaling(h, w, 1);
    } else {
        trans.applyScaling(w, h, 1);
    }
    trans.setTranslation(x0, y0, 0);
    renderer.mulModelMatrix(trans);
    renderer.setVertexColorMixing(ColorMixing.REPLACE);
    renderer.drawTriangles(robj, 0);
    float savedLineWidth = renderer.getLineWidth();
    LineFaceRenderProps props = (LineFaceRenderProps) getRenderProps();
    renderer.setLineWidth(props.getLineWidth());
    renderer.setLineColoring(props, /*highlight=*/
    false);
    renderer.setVertexColorMixing(ColorMixing.NONE);
    renderer.drawLines(robj, 0);
    renderer.popModelMatrix();
    // return line width
    renderer.setLineWidth(savedLineWidth);
    // labels
    int nLabels = Math.min(labelPos.size(), labelText.size());
    if (nLabels > 0) {
        double tx, ty;
        // // for consistency, assume line top as 3/4 font size
        // double t = myTextSize*0.75;
        // double vc = myTextSize* 0.25;
        // double b = myTextSize*0.25;
        renderer.setFaceColoring(props, isSelected());
        float[] loc = new float[3];
        for (int i = 0; i < nLabels; i++) {
            tx = 0;
            ty = 0;
            // text orientation computation
            String label = labelText.get(i);
            Rectangle2D box = renderer.getTextBounds(myFont, label, myTextSize);
            double bw = box.getWidth();
            double bh = box.getHeight();
            double b = box.getY();
            double vc = b + bh / 2;
            double t = bh + b;
            if (horizontal) {
                switch(hAlignment) {
                    case LEFT:
                        tx = x0 + myTextOffset.x;
                        break;
                    case CENTRE:
                        tx = x0 - bw / 2;
                        break;
                    case RIGHT:
                        tx = x0 - myTextOffset.x - bw;
                        break;
                }
                tx += w * labelPos.get(i);
                switch(vAlignment) {
                    case BOTTOM:
                        ty = y0 - myTextOffset.y - t;
                        break;
                    case CENTRE:
                        ty = y0 - vc + h / 2;
                        break;
                    case TOP:
                        ty = y0 + h + myTextOffset.y + b;
                        break;
                }
            } else {
                switch(hAlignment) {
                    case LEFT:
                        tx = x0 - myTextOffset.x - bw;
                        break;
                    case CENTRE:
                        tx = x0 - bw / 2 + w / 2;
                        break;
                    case RIGHT:
                        tx = x0 + myTextOffset.x + w;
                        break;
                }
                switch(vAlignment) {
                    case BOTTOM:
                        ty = y0 + myTextOffset.y;
                        break;
                    case CENTRE:
                        ty = y0 - vc;
                        break;
                    case TOP:
                        ty = y0 - myTextOffset.y - t;
                        break;
                }
                ty += h * labelPos.get(i);
            }
            loc[0] = (float) tx;
            loc[1] = (float) ty;
            renderer.drawText(myFont, label, loc, myTextSize);
        }
    }
    renderer.setShading(savedShadeModel);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) VectorNd(maspack.matrix.VectorNd) Renderer(maspack.render.Renderer) LineFaceRenderProps(maspack.render.LineFaceRenderProps) RenderObject(maspack.render.RenderObject) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 38 with AffineTransform3d

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

the class DicomPlaneViewer method render.

@Override
public synchronized void render(Renderer renderer, int flags) {
    RenderProps rprops = getRenderProps();
    renderer.pushModelMatrix();
    // adjust for widths and location
    renderer.mulModelMatrix(location);
    AffineTransform3d scaling = new AffineTransform3d();
    scaling.applyScaling(widths.x, widths.y, 1);
    renderer.mulModelMatrix(scaling);
    ColorMapProps oldColorMap = renderer.setColorMap(rprops.getColorMap());
    FaceStyle oldFaceStyle = renderer.setFaceStyle(FaceStyle.FRONT_AND_BACK);
    Shading oldShading = renderer.setShading(rprops.getShading());
    if (!renderer.isSelecting()) {
        renderer.setFaceColoring(rprops, isSelected());
    }
    renderer.drawTriangles(robj, 0);
    renderer.setShading(oldShading);
    renderer.setFaceStyle(oldFaceStyle);
    renderer.setColorMap(oldColorMap);
    renderer.popModelMatrix();
}
Also used : FaceStyle(maspack.render.Renderer.FaceStyle) ColorMapProps(maspack.render.ColorMapProps) LineRenderProps(maspack.render.LineRenderProps) RenderProps(maspack.render.RenderProps) Shading(maspack.render.Renderer.Shading) AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 39 with AffineTransform3d

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

the class DicomViewer method transformGeometry.

@Override
public void transformGeometry(GeometryTransformer gtr, TransformGeometryContext context, int flags) {
    // transform the pose
    AffineTransform3d Xpose = new AffineTransform3d();
    Xpose.set(getTransform());
    gtr.transform(Xpose);
    setTransform(Xpose);
}
Also used : AffineTransform3d(maspack.matrix.AffineTransform3d)

Example 40 with AffineTransform3d

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

the class DicomViewer method updateRenderTransform.

protected void updateRenderTransform() {
    if (myRenderTransform == null) {
        myRenderTransform = new AffineTransform3d();
    }
    myRenderTransform.set(myImage.getVoxelTransform());
    // shift by half pixel
    Vector3d shift = new Vector3d(-0.5, -0.5, -0.5);
    shift.transform(myRenderTransform);
    myRenderTransform.p.add(shift);
    // scale for full image
    myRenderTransform.applyScaling(myImage.getNumCols(), myImage.getNumRows(), myImage.getNumSlices());
    // append myTransform
    myRenderTransform.mul(myTransform, myRenderTransform);
}
Also used : Vector3d(maspack.matrix.Vector3d) 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