Search in sources :

Example 66 with Vertex3d

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

the class SurfaceMeshContourIxer method robustIntersectionWithFace.

/*
    * Test for intersection using adaptive exact arithmetic and SOS tiebreaking.
    */
protected boolean robustIntersectionWithFace(HalfEdge he, Face face, IntersectionPoint mip, boolean edgeOnMesh0) {
    HalfEdge he0 = face.firstHalfEdge();
    Vertex3d v = he0.tail;
    if (v == he.head)
        return false;
    if (v == he.tail)
        return false;
    v = he0.head;
    if (v == he.head)
        return false;
    if (v == he.tail)
        return false;
    v = he0.getNext().head;
    if (v == he.head)
        return false;
    if (v == he.tail)
        return false;
    int res = RobustPreds.intersectEdgeTriangle(mip, he, face, myMaxLength, edgeOnMesh0, /*worldCoords=*/
    true);
    if (res == 0) {
        return false;
    } else {
        mip.edge = he;
        mip.face = face;
        // mip.edgeOnMesh0 = edgeOnMesh0;
        mip.intersectionCode = res;
        // mip.degeneracies = (res & RobustPreds.DEGENERACY_MASK);
        return true;
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HalfEdge(maspack.geometry.HalfEdge) IntersectionPoint(maspack.collision.IntersectionPoint)

Example 67 with Vertex3d

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

the class MeshColliderTest method displayContacts.

void displayContacts(PolygonalMesh m0, PolygonalMesh m1) {
    final PolygonalMesh mesh0 = m0;
    final PolygonalMesh mesh1 = m1;
    MeshCollider collider = new MeshCollider();
    final ContactInfo info = collider.getContacts(mesh0, mesh1);
    // final ContactInfo info = new ContactInfo(mesh0, mesh1);
    // System.out.println("intersections " + info.intersections.size());
    // System.out.println("regions " + info.regions.size());
    GLViewerFrame frame = new GLViewerFrame("", 512, 512);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    mesh0.getRenderProps().setDrawEdges(true);
    // mesh0.getRenderProps().setAlpha(0.3);
    mesh1.getRenderProps().setDrawEdges(true);
    // mesh1.getRenderProps().setAlpha(0.3);
    frame.getViewer().addRenderable(mesh0);
    frame.getViewer().addRenderable(mesh1);
    frame.getViewer().addRenderable(new IsRenderable() {

        public int getRenderHints() {
            // TODO Auto-generated method stub
            return 0;
        }

        public void prerender(RenderList list) {
        }

        public void render(Renderer renderer, int flags) {
            renderer.setShading(Shading.NONE);
            if (info != null) {
                renderer.setColor(0, 0, 1);
                renderer.setPointSize(6);
                ArrayList<TriTriIntersection> intersections = info.getIntersections();
                if (intersections != null) {
                    renderer.beginDraw(DrawMode.POINTS);
                    for (TriTriIntersection isect : intersections) {
                        for (Point3d p : isect.points) {
                            renderer.addVertex(p);
                        }
                    }
                    renderer.endDraw();
                }
                renderer.setColor(1, 0, 0);
                renderer.beginDraw(DrawMode.LINES);
                for (ContactPlane region : info.getContactPlanes()) {
                    Point3d avg = new Point3d();
                    int np = 0;
                    for (Point3d rp : region.points) {
                        avg.add(rp);
                        np++;
                    }
                    avg.scale(1.0 / np);
                    renderer.addVertex(avg);
                    avg.add(region.normal);
                    renderer.addVertex(avg);
                }
                renderer.endDraw();
            }
            ;
            // mesh0.getObbtree().render(renderer);
            // mesh1.getObbtree().render(renderer);
            // ////////////////////////////
            // draw mesh numbers
            Vector3d avg0 = new Vector3d();
            Vector3d avg1 = new Vector3d();
            for (Vertex3d v : mesh0.getVertices()) avg0.add(v.pnt);
            avg0.scale(1.0 / mesh0.getVertices().size());
            avg0.add(mesh0.getMeshToWorld().p);
            for (Vertex3d v : mesh1.getVertices()) avg1.add(v.pnt);
            avg1.scale(1.0 / mesh1.getVertices().size());
            avg1.add(mesh1.getMeshToWorld().p);
            // GLUT glut = new GLUT();
            renderer.setColor(1, 1, 1);
            // gl.glRasterPos3d (avg0.x, avg0.y, avg0.z);
            // glut.glutBitmapString (GLUT.BITMAP_HELVETICA_18, "0");
            // gl.glRasterPos3d (avg1.x, avg1.y, avg1.z);
            // glut.glutBitmapString (GLUT.BITMAP_HELVETICA_18, "1");
            // draw mesh normals
            // //////////////////////////////
            renderer.setShading(Shading.FLAT);
        }

        public void updateBounds(Vector3d pmin, Vector3d pmax) {
        // TODO Auto-generated method stub
        }
    });
    frame.getViewer().rerender();
    frame.getViewer().autoFit();
    frame.setVisible(true);
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) TriTriIntersection(maspack.geometry.TriTriIntersection) PolygonalMesh(maspack.geometry.PolygonalMesh) RenderList(maspack.render.RenderList) IsRenderable(maspack.render.IsRenderable) Vector3d(maspack.matrix.Vector3d) GLViewerFrame(maspack.render.GL.GLViewerFrame) Point3d(maspack.matrix.Point3d) Renderer(maspack.render.Renderer)

Example 68 with Vertex3d

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

the class ContactInfo method computePenetratingPoints.

ArrayList<PenetratingPoint> computePenetratingPoints(PolygonalMesh mesh0, PolygonalMesh mesh1) {
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d wpnt = new Point3d();
    Point3d nearest = new Point3d();
    Vector2d uv = new Vector2d();
    Vector3d disp = new Vector3d();
    ArrayList<PenetratingPoint> points = new ArrayList<PenetratingPoint>();
    for (Vertex3d vtx : mesh0.getVertices()) {
        // John Lloyd, Jan 3, 2014: rewrote to use isInsideOrientedMesh()
        // to determine if a vertex is inside another mesh. Previous code
        // would not always work and broke when the BVTree code was
        // refactored.
        vtx.getWorldPoint(wpnt);
        if (query.isInsideOrientedMesh(mesh1, wpnt, -1)) {
            Face f = query.getFaceForInsideOrientedTest(nearest, uv);
            mesh1.transformToWorld(nearest);
            disp.sub(nearest, wpnt);
            points.add(new PenetratingPoint(vtx, f, uv, nearest, disp, /*region=*/
            null));
        }
    }
    return points;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face)

Example 69 with Vertex3d

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

the class ContactPlane method vertexFaceContact.

/*
    * Handle the case where there are insufficient contact points in the contour
    * to define a plane. and one region has 1 or 2 penetrating vertices while
    * the other region has none.
    */
boolean vertexFaceContact(PenetrationRegion region0, PenetrationRegion region1) {
    LinkedHashSet<Face> fs;
    LinkedHashSet<Vertex3d> vs;
    if (region0.numVertices() > 0) {
        vs = region0.myVertices;
        fs = region1.getFaces();
    } else {
        vs = region1.myVertices;
        fs = region0.getFaces();
    }
    depth = 0;
    for (Vertex3d v : vs) {
        Face f = fs.iterator().next();
        /*
                                           * Assume the vertex contacted the
                                           * first face. For more accurate
                                           * results, we could choose the face
                                           * for each vertex more carefully.
                                           */
        normal.set(f.getWorldNormal());
        double d = Math.abs(f.getPoint0DotNormal() - // distance from vertex to face
        (normal.dot(v.getWorldPoint())));
        depth = Math.max(depth, d);
        minProjectedDistance = maxProjectedDistance = 0;
    }
    return true;
}
Also used : Vertex3d(maspack.geometry.Vertex3d)

Example 70 with Vertex3d

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

the class FemModel3d method testSimpleSurfaceMesh.

private void testSimpleSurfaceMesh() {
    FemMeshComp sfm = getSurfaceMeshComp();
    if (sfm != null) {
        for (Vertex3d vtx : sfm.getMesh().getVertices()) {
            FemNode3d node = getSurfaceNode(vtx);
            if (node == null) {
                throw new TestException("no node found for vertex " + vtx.getIndex());
            }
            Vertex3d chk = getSurfaceVertex(node);
            if (chk != vtx) {
                throw new TestException("no vertex found for node " + node.getNumber());
            }
        }
        System.out.println("SURFACE OK");
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) TestException(maspack.util.TestException)

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