Search in sources :

Example 6 with Vector2d

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

the class GLMouseAdapter method mousePressed.

public void mousePressed(MouseEvent e) {
    int mask = (e.getModifiersEx() & ALL_MODIFIERS);
    int selectionMask = getSelectionButtonMask();
    // Start checking draggers
    Dragger3d drawTool = viewer.myDrawTool;
    boolean grabbed = false;
    if (viewer.myDraggers.size() > 0 || drawTool != null) {
        MouseRayEvent rayEvt = MouseRayEvent.create(e, viewer);
        for (Dragger3d d : viewer.myDraggers) {
            // pass event to any visible Dragger3dBase, or any other Dragger3d
            if (d.isVisible()) {
                updateDraggerModeAndFlags(mask, d);
                if (d.mousePressed(rayEvt)) {
                    grabbed = true;
                    dragAction = DRAGGER_ACTION;
                    break;
                }
            }
        }
        if (drawTool != null && drawTool.isVisible()) {
            updateDraggerModeAndFlags(mask, drawTool);
            if (drawTool.mousePressed(rayEvt)) {
                grabbed = true;
                dragAction = DRAGGER_ACTION;
            }
        }
    }
    if (grabbed) {
        viewer.repaint();
    } else {
        if (viewer.getEllipticCursorActive() && (mask & ellipticCursorResizeMask) == ellipticCursorResizeMask) {
            dragAction = ELLIPTIC_CURSOR_RESIZE;
            ellipticCursorStartSize = new Vector2d(viewer.getEllipticCursorSize());
        } else if (mask == getTranslateButtonMask()) {
            dragAction = TRANSLATE;
        } else if (mask == getRotateButtonMask()) {
            dragAction = ROTATE;
        } else if (mask == getZoomButtonMask()) {
            dragAction = ZOOM;
        } else if (viewer.isSelectionEnabled() && (mask & selectionMask) == selectionMask) {
            if (viewer.getSelectOnPress()) {
                checkForSelection(e);
                dragAction = NO_ACTION;
                viewer.setDragBox(null);
            } else {
                if (viewer.getEllipticSelection()) {
                    checkForSelection(e);
                }
                dragAction = DRAG_SELECT;
            }
        } else {
            dragAction = NO_ACTION;
        }
    }
    dragStartX = lastX = e.getX();
    dragStartY = lastY = e.getY();
}
Also used : Vector2d(maspack.matrix.Vector2d) MouseRayEvent(maspack.render.MouseRayEvent) Point(java.awt.Point) Dragger3d(maspack.render.Dragger3d)

Example 7 with Vector2d

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

the class FemModel3d method findNearestSurfaceElement.

/**
 * Returns the nearest surface element to a specified point,
 * which is found by projecting the point onto the FEM surface.
 * The location of the projection is returned in <code>loc</code>.
 *
 * @param loc Projected location of the point onto the surface.
 * @param pnt Point for which nearest surface element is desired.
 * @return Nearest surface element.
 */
public FemElement3d findNearestSurfaceElement(Point3d loc, Point3d pnt) {
    Vector2d coords = new Vector2d();
    PolygonalMesh surf = getSurfaceMesh();
    if (surf == null || surf.numFaces() == 0) {
        surf = getInternalSurfaceMesh();
    }
    if (surf != null) {
        Face face = BVFeatureQuery.getNearestFaceToPoint(loc, coords, surf, pnt);
        FemElement3d elem = getSurfaceElement(face);
        if (elem == null) {
            throw new InternalErrorException("surface element not found for face");
        }
        return elem;
    } else {
        return null;
    }
}
Also used : Vector2d(maspack.matrix.Vector2d) InternalErrorException(maspack.util.InternalErrorException) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 8 with Vector2d

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

the class SkinMeshBody method createPointAttachment.

public PointSkinAttachment createPointAttachment(Point pnt) {
    if (!(getMesh() instanceof PolygonalMesh)) {
        return null;
    }
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    if (!mesh.isTriangular()) {
        return null;
    }
    // Find nearest face to the point; we'll need this to
    // estimate a basePosition for the attachments from the
    // start by find
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d near = new Point3d();
    Vector2d uv = new Vector2d();
    Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
    // Create a new PointSkinAttachment
    MeshDistCalc dcalc = new MeshDistCalc();
    dcalc.computeDistancesAndWeights(pnt.getPosition(), myLastSigma);
    PointSkinAttachment a = dcalc.computeDisplacementAttachment();
    a.setSkinMesh(this);
    // Now estimate the basePosition from the face vertices
    Point3d basePos = new Point3d();
    Vertex3d[] vtxs = face.getTriVertices();
    double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
    for (int i = 0; i < vtxs.length; i++) {
        PointSkinAttachment va = (PointSkinAttachment) myVertexAttachments.get(vtxs[i].getIndex());
        basePos.scaledAdd(wgts[i], va.getBasePosition());
    }
    a.setBasePosition(basePos);
    a.setPoint(pnt);
    return a;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 9 with Vector2d

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

the class FemMeshComp method createPointAttachment.

public PointFem3dAttachment createPointAttachment(Point pnt) {
    if (!(getMesh() instanceof PolygonalMesh)) {
        return null;
    }
    PolygonalMesh mesh = (PolygonalMesh) getMesh();
    if (!mesh.isTriangular()) {
        return null;
    }
    // Find nearest face to the point. The vertices of this face will be used
    // to find the nodes and weight for the attachment.
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d near = new Point3d();
    Vector2d uv = new Vector2d();
    Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
    Vertex3d[] vtxs = face.getTriVertices();
    double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
    HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
    for (int i = 0; i < vtxs.length; i++) {
        PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
        if (va instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) va;
            FemNode node = (FemNode) ppa.getParticle();
            accumulateNodeWeights(node, wgts[i], nodeWeights);
        } else if (va instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) va;
            for (int k = 0; k < pfa.numMasters(); k++) {
                FemNode node = pfa.getNodes()[k];
                double w = pfa.getCoordinate(k);
                accumulateNodeWeights(node, w * wgts[i], nodeWeights);
            }
        }
    }
    // Create a new PointFem3dAttachment
    PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
    VectorNd weightVec = new VectorNd();
    for (Double d : nodeWeights.values()) {
        weightVec.append(d);
    }
    ax.setFromNodes(nodeWeights.keySet(), weightVec);
    return ax;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 10 with Vector2d

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

the class MeshIntersectingProbe method findNextFace.

// does not add the vertex, goes in a loop around contour until we hit a face
private Face findNextFace(Point3d pnt, LinkedList<Point3d> contour, OBBTree obbt, Intersector2d ti, Vector3d vx, Vector3d vy, Point3d o, SplitStorage info) {
    Face face = null;
    Vector3d dir = new Vector3d();
    if (info.idx < contour.size() - 1) {
        dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
    } else {
        dir.sub(contour.get(info.idx), contour.get(info.idx - 1));
    }
    dir.normalize();
    while (face == null && info.idx < contour.size() - 1) {
        Point3d pntNext = contour.get(info.idx + 1);
        Point2d pnt2d = Intersector2d.get2dCoordinate(pnt, vx, vy, o);
        Point2d pnt2dNext = Intersector2d.get2dCoordinate(pntNext, vx, vy, o);
        Vector2d diff2d = new Vector2d();
        ArrayList<BVNode> bvNodes = new ArrayList<BVNode>();
        // get close nodes
        obbt.intersectLineSegment(bvNodes, pnt, pntNext);
        double minDist = Double.MAX_VALUE;
        Point2d minPnt = null;
        for (BVNode node : bvNodes) {
            for (int i = 0; i < node.getNumElements(); i++) {
                Boundable ps = node.getElements()[i];
                if (ps instanceof Face) {
                    Face f = (Face) ps;
                    Vertex3d[] vtxs = f.getVertices();
                    Point2d p0 = Intersector2d.get2dCoordinate(vtxs[0].getWorldPoint(), vx, vy, o);
                    Point2d p1 = Intersector2d.get2dCoordinate(vtxs[1].getWorldPoint(), vx, vy, o);
                    Point2d p2 = Intersector2d.get2dCoordinate(vtxs[2].getWorldPoint(), vx, vy, o);
                    ArrayList<Point2d> points = new ArrayList<Point2d>();
                    ti.intersectTriangleLineSegment(p0, p1, p2, pnt2d, pnt2dNext, points);
                    // check points
                    for (Point2d p : points) {
                        diff2d.sub(p, pnt2d);
                        if (diff2d.norm() < minDist) {
                            face = f;
                            minDist = diff2d.norm();
                            minPnt = p;
                        }
                    }
                }
            }
        }
        if (face == null || minDist >= pnt2dNext.distance(pnt2d)) {
            face = null;
            // move to next point
            info.idx++;
            pnt = contour.get(info.idx);
            if (info.idx < contour.size() - 1) {
                dir.sub(contour.get(info.idx + 1), pnt);
            }
        } else {
            // snap to edge if within tolerance
            Point3d pos = Intersector2d.get3dCoordinate(minPnt, vx, vy, o);
            if (pos.distance(pnt) < ti.epsilon) {
                pos.set(pnt);
            }
            // check if we have to make a new vertex
            info.vtx = createOrGetVertex(pos, face.getVertices(), ti.epsilon);
        }
    }
    return face;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point2d(maspack.matrix.Point2d) Point3d(maspack.matrix.Point3d) BVNode(maspack.geometry.BVNode) Boundable(maspack.geometry.Boundable) Face(maspack.geometry.Face)

Aggregations

Vector2d (maspack.matrix.Vector2d)35 Point3d (maspack.matrix.Point3d)16 Vector3d (maspack.matrix.Vector3d)11 Face (maspack.geometry.Face)9 Vertex3d (maspack.geometry.Vertex3d)8 ArrayList (java.util.ArrayList)7 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RigidTransform3d (maspack.matrix.RigidTransform3d)6 Point2d (maspack.matrix.Point2d)5 PolygonalMesh (maspack.geometry.PolygonalMesh)4 ContactPoint (artisynth.core.mechmodels.ContactPoint)3 Point (artisynth.core.mechmodels.Point)3 Point (java.awt.Point)3 VectorNd (maspack.matrix.VectorNd)3 PointAttachment (artisynth.core.mechmodels.PointAttachment)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 Rectangle (java.awt.Rectangle)2 HashMap (java.util.HashMap)2 BVTree (maspack.geometry.BVTree)2 Matrix2dBase (maspack.matrix.Matrix2dBase)2