Search in sources :

Example 1 with Intersector2d

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

the class MeshIntersectingProbe method clipMesh.

// does the clipping of a planar surface based on a contour
private void clipMesh(PolygonalMesh surface, LinkedList<Point3d> contour, double tol) {
    SplitStorage info = new SplitStorage();
    Intersector2d ti = new Intersector2d();
    ti.setEpsilon(tol);
    // coordinate system
    Vector3d vx = new Vector3d();
    Vector3d vy = new Vector3d();
    Point3d o = getPosition();
    XGridToWorld.R.getColumn(0, vx);
    XGridToWorld.R.getColumn(1, vy);
    OBBTree obbt = new OBBTree(surface, 2, tol);
    ArrayList<Face> faceList = null;
    while (info.idx + 1 < contour.size()) {
        if (info.vtx == null) {
            Face face = findNextFace(contour.get(info.idx), contour, obbt, ti, vx, vy, o, info);
            // so now I have a vertex and a face it lies on
            if (face != null) {
                // we may be on multiple faces
                faceList = findFaces(info.vtx.getWorldPoint(), obbt, vx, vy, o, tol);
                for (Face f : faceList) {
                    splitFace(surface, f, info.vtx, tol);
                }
            }
        } else {
            // find all faces this vertex is on, project in direction of contour
            faceList = getFaces(info.vtx);
            HalfEdge he = findNextEdge(contour, faceList, ti, info, vx, vy, o);
            if (he != null) {
                // we landed on an edge
                Face oppFace = null;
                if (he.opposite != null) {
                    oppFace = he.opposite.getFace();
                }
                splitFace(surface, he.getFace(), info.vtx, tol);
                if (oppFace != null) {
                    splitFace(surface, oppFace, info.vtx, tol);
                }
            } else if (info.face != null) {
                splitFace(surface, info.face, info.vtx, tol);
            } else {
                // move to next point
                info.idx++;
                info.vtx = null;
            }
        }
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) HalfEdge(maspack.geometry.HalfEdge) OBBTree(maspack.geometry.OBBTree) Face(maspack.geometry.Face) Intersector2d(maspack.geometry.Intersector2d)

Aggregations

Face (maspack.geometry.Face)1 HalfEdge (maspack.geometry.HalfEdge)1 Intersector2d (maspack.geometry.Intersector2d)1 OBBTree (maspack.geometry.OBBTree)1 Point3d (maspack.matrix.Point3d)1 Vector3d (maspack.matrix.Vector3d)1