Search in sources :

Example 36 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class FemDisplayProbe method updateVertexColoringDynamic.

/**
 * Updates vertex colors
 */
protected void updateVertexColoringDynamic() {
    RenderProps rprops = getRenderProps();
    float alpha = (float) rprops.getAlpha();
    float backAlpha = (float) myBackgroundAlpha * alpha;
    Color faceColor = rprops.getFaceColor();
    Color femFaceColor = null;
    double stressVal = 0;
    float[] carray = new float[3];
    if (myFem != null) {
        if (mySurfaceRendering == SurfaceRender.Stress || mySurfaceRendering == SurfaceRender.Strain) {
            if (myStressPlotRanging == Ranging.Auto) {
                myStressPlotRange.merge(myFem.getNodalPlotRange(mySurfaceRendering));
            }
        } else {
            femFaceColor = myFem.getRenderProps().getFaceColor();
        }
    } else {
        // arbitrary, shouldn't be used
        femFaceColor = Color.BLACK;
    }
    // do with some kind of synchronization
    try {
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            if (!vtxIndicatorMap.containsKey(vtx) || !vtxIndicatorMap.get(vtx)) {
                setColor(vtx, faceColor, backAlpha);
            } else {
                switch(mySurfaceRendering) {
                    case None:
                        setColor(vtx, faceColor, alpha);
                        break;
                    case Strain:
                        stressVal = getStrainValue(vtx.getWorldPoint(), myFem);
                        myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
                        setColor(vtx, carray[0], carray[1], carray[2], alpha);
                        break;
                    case Stress:
                        stressVal = getStressValue(vtx.getWorldPoint(), myFem);
                        myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
                        setColor(vtx, carray[0], carray[1], carray[2], alpha);
                        break;
                    default:
                        setColor(vtx, femFaceColor, alpha);
                }
            }
        }
    } catch (Exception e) {
        System.err.println("Error in display probe: " + e.getMessage());
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Color(java.awt.Color) RenderProps(maspack.render.RenderProps) IOException(java.io.IOException)

Example 37 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class MeshIntersectingProbe method trimFaces.

protected static PolygonalMesh trimFaces(PolygonalMesh mesh, HashMap<Vertex3d, Boolean> vtxIndicatorMap) {
    PolygonalMesh out = new PolygonalMesh();
    HashMap<Vertex3d, Vertex3d> vtxMap = new HashMap<Vertex3d, Vertex3d>(mesh.numVertices());
    for (Vertex3d vtx : mesh.getVertices()) {
        if (vtxIndicatorMap.get(vtx)) {
            Vertex3d nvtx = new Vertex3d(new Point3d(vtx.getPosition()));
            vtxMap.put(vtx, nvtx);
            out.addVertex(nvtx);
        }
    }
    for (Face face : mesh.getFaces()) {
        boolean add = true;
        for (Vertex3d vtx : face.getVertices()) {
            if (vtxIndicatorMap.get(vtx) == false) {
                add = false;
                break;
            }
        }
        if (add) {
            Vertex3d[] oldVtxs = face.getVertices();
            Vertex3d[] vtxs = new Vertex3d[face.numVertices()];
            for (int i = 0; i < vtxs.length; i++) {
                vtxs[i] = vtxMap.get(oldVtxs[i]);
            }
            out.addFace(vtxs);
        }
    }
    return out;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 38 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class MeshIntersectingProbe method splitFace.

// splits a face at a point
private static ArrayList<Face> splitFace(PolygonalMesh mesh, Face face, Vertex3d vtx, double tol) {
    ArrayList<Face> newFaces = new ArrayList<Face>();
    Vertex3d[] verts = face.getVertices();
    // if the vtx is one of the corners, don't do anything
    for (Vertex3d v : verts) {
        if (v == vtx) {
            newFaces.add(face);
            return newFaces;
        }
    }
    if (!mesh.containsVertex(vtx)) {
        // transform to mesh coordinate system,
        // then add
        vtx.pnt.inverseTransform(mesh.getMeshToWorld());
        mesh.addVertex(vtx);
    }
    mesh.removeFace(face);
    Vertex3d v1, v2, v3;
    v1 = vtx;
    for (int i = 0; i < verts.length; i++) {
        int j = (i + 1) % verts.length;
        v2 = verts[i];
        v3 = verts[j];
        if (getSignedTriangleArea(v1.getWorldPoint(), v2.getWorldPoint(), v3.getWorldPoint(), face.getWorldNormal()) > tol) {
            newFaces.add(mesh.addFace(v1, v2, v3));
        }
    }
    return newFaces;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) Face(maspack.geometry.Face)

Example 39 with Vertex3d

use of maspack.geometry.Vertex3d 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)

Example 40 with Vertex3d

use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.

the class CutPlaneProbe method extractBoundaries.

/**
 * Gets the boundaries of the supplied display mesh
 */
protected static ArrayList<Vertex3d[]> extractBoundaries(PolygonalMesh surface) {
    ArrayList<Vertex3d[]> boundaries = new ArrayList<Vertex3d[]>(1);
    ArrayList<Vertex3d> vtxList = null;
    LinkedList<HalfEdge> borderEdges = new LinkedList<HalfEdge>(surface.findBorderEdges());
    while (borderEdges.size() > 0) {
        vtxList = new ArrayList<Vertex3d>();
        HalfEdge borderEdge = borderEdges.get(0);
        borderEdges.remove(0);
        vtxList.add(borderEdge.head);
        vtxList.add(borderEdge.tail);
        Vertex3d lastVtx = borderEdge.tail;
        while (lastVtx != vtxList.get(0)) {
            Iterator<HalfEdge> eit = borderEdge.tail.getIncidentHalfEdges();
            HalfEdge he;
            while (eit.hasNext()) {
                he = eit.next();
                if (he != borderEdge && he.opposite == null) {
                    borderEdge = he;
                    break;
                }
            }
            if (borderEdges.contains(borderEdge)) {
                borderEdges.remove(borderEdge);
            }
            lastVtx = borderEdge.tail;
            if (!vtxList.contains(lastVtx) || lastVtx == vtxList.get(0)) {
                vtxList.add(lastVtx);
            } else {
                System.out.println("boundary not closed");
                break;
            }
        }
        boundaries.add(vtxList.toArray(new Vertex3d[vtxList.size()]));
    }
    return boundaries;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) HalfEdge(maspack.geometry.HalfEdge) LinkedList(java.util.LinkedList)

Aggregations

Vertex3d (maspack.geometry.Vertex3d)81 Point3d (maspack.matrix.Point3d)35 Face (maspack.geometry.Face)30 PolygonalMesh (maspack.geometry.PolygonalMesh)24 Vector3d (maspack.matrix.Vector3d)23 ContactPoint (artisynth.core.mechmodels.ContactPoint)22 Point (artisynth.core.mechmodels.Point)22 ArrayList (java.util.ArrayList)19 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)15 HalfEdge (maspack.geometry.HalfEdge)13 PointAttachment (artisynth.core.mechmodels.PointAttachment)10 HashMap (java.util.HashMap)10 Vector2d (maspack.matrix.Vector2d)8 VectorNd (maspack.matrix.VectorNd)8 BVFeatureQuery (maspack.geometry.BVFeatureQuery)7 RenderProps (maspack.render.RenderProps)6 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)5 Color (java.awt.Color)5 FemNode (artisynth.core.femmodels.FemNode)4 BufferedWriter (java.io.BufferedWriter)4