Search in sources :

Example 6 with TriTriIntersection

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

the class MeshCollider method getContacts.

public ContactInfo getContacts(PolygonalMesh mesh0, PolygonalMesh mesh1) {
    // long t0 = System.nanoTime();
    // collisionMetrics.totalTime -= time;
    // collisionMetrics.cullTime -= time;
    // if (iFirst++ == 0) collisionMetrics.elapsedRealTime = -time;
    mesh0.updateFaceNormals();
    mesh1.updateFaceNormals();
    BVIntersector intersector = new BVIntersector();
    ContactInfo info = new ContactInfo(mesh0, mesh1);
    // boolean didInt =
    // mesh0.getObbtree().intersectFully (
    // mesh1.getObbtree(), info.intersections, intersector);
    info.myIntersections = new ArrayList<TriTriIntersection>();
    boolean didInt = intersector.intersectMeshMesh(info.myIntersections, mesh0, mesh1);
    // collisionMetrics.cullTime += time;
    if (!didInt) {
        // collisionMetrics.report(info);
        return null;
    }
    return info;
}
Also used : TriTriIntersection(maspack.geometry.TriTriIntersection) BVIntersector(maspack.geometry.BVIntersector)

Example 7 with TriTriIntersection

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

the class MeshCollider method traverseRegion.

private static void traverseRegion(AccelerationGrid<TriTriIntersection> accgrid, ContactPlane region, TriTriIntersection isect, double regionTol) {
    if (accgrid.elementidxs.containsKey(isect)) {
        accgrid.remove_element(isect);
        region.intersections.add(isect);
        ArrayList<TriTriIntersection> isects = new ArrayList<TriTriIntersection>();
        Point3d min = new Point3d(), max = new Point3d();
        for (Point3d p : isect.points) {
            min.set(p.x - regionTol / 2, p.y - regionTol / 2, p.z - regionTol / 2);
            max.set(p.x + regionTol / 2, p.y + regionTol / 2, p.z + regionTol / 2);
            ArrayList<TriTriIntersection> candidates = accgrid.find_overlapping_elements(min, max);
            // System.out.println("candidates " + candidates.size());
            for (TriTriIntersection c : candidates) {
                for (Point3d cp : c.points) if (cp.greaterEquals(min) && max.greaterEquals(max)) {
                    isects.add(c);
                }
            }
        }
        for (TriTriIntersection c : isects) {
            traverseRegion(accgrid, region, c, regionTol);
        }
    }
}
Also used : Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) TriTriIntersection(maspack.geometry.TriTriIntersection)

Example 8 with TriTriIntersection

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

Aggregations

TriTriIntersection (maspack.geometry.TriTriIntersection)8 Point3d (maspack.matrix.Point3d)6 ArrayList (java.util.ArrayList)4 BVFeatureQuery (maspack.geometry.BVFeatureQuery)3 PolygonalMesh (maspack.geometry.PolygonalMesh)3 Vector3d (maspack.matrix.Vector3d)3 IntersectionPoint (maspack.collision.IntersectionPoint)2 PenetratingPoint (maspack.collision.PenetratingPoint)2 BVIntersector (maspack.geometry.BVIntersector)2 Face (maspack.geometry.Face)2 Vertex3d (maspack.geometry.Vertex3d)2 Group (artisynth.core.mechmodels.Collidable.Group)1 Method (artisynth.core.mechmodels.CollisionBehavior.Method)1 LinkedHashSet (java.util.LinkedHashSet)1 ContactInfo (maspack.collision.ContactInfo)1 ContactPlane (maspack.collision.ContactPlane)1 EdgeEdgeContact (maspack.collision.EdgeEdgeContact)1 IntersectionContour (maspack.collision.IntersectionContour)1 PenetrationRegion (maspack.collision.PenetrationRegion)1 HalfEdge (maspack.geometry.HalfEdge)1