Search in sources :

Example 6 with BVFeatureQuery

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

the class PointDistributor method sphereGridFill.

// fills a mesh based on a regular grid of points
public static Point3d[] sphereGridFill(PolygonalMesh mesh, double r) {
    ArrayList<Point3d> pnts = new ArrayList<Point3d>();
    RigidTransform3d trans = getPrincipalAxes(mesh);
    Point3d[] box = getTightBox(mesh, trans);
    Point3d center = new Point3d(box[0]);
    center.add(box[6]);
    center.scale(0.5);
    trans.setTranslation(center);
    Vector3d l = new Vector3d(box[0]);
    l.sub(box[6]);
    l.inverseTransform(trans);
    double alpha = 2 * Math.sqrt(2) * r;
    int nx = (int) Math.ceil(l.x / alpha) + 1;
    int ny = (int) Math.ceil(l.y / alpha) + 1;
    int nz = (int) Math.ceil(l.z / alpha) + 1;
    double xoffset = -(nx - 1) * alpha / 2;
    double yoffset = -(ny - 1) * alpha / 2;
    double zoffset = -(nz - 1) * alpha / 2;
    BVTree bvh = mesh.getBVTree();
    Vector2d coords = new Vector2d();
    Point3d nearest = new Point3d();
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d p;
    for (int i = 0; i < nx; i++) {
        for (int j = 0; j < ny; j++) {
            for (int k = 0; k < nz; k++) {
                double x = i * alpha + xoffset;
                double y = j * alpha + yoffset;
                double z = k * alpha + zoffset;
                p = new Point3d(x, y, z);
                p.transform(trans);
                addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
            }
        }
    }
    return pnts.toArray(new Point3d[pnts.size()]);
}
Also used : BVTree(maspack.geometry.BVTree) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 7 with BVFeatureQuery

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

the class PointDistributor method sphereFCCFill.

// fills a mesh with spheres based on face-centered cubic packing
public static Point3d[] sphereFCCFill(PolygonalMesh mesh, double r) {
    ArrayList<Point3d> pnts = new ArrayList<Point3d>();
    RigidTransform3d trans = getPrincipalAxes(mesh);
    Point3d[] box = getTightBox(mesh, trans);
    Point3d center = new Point3d(box[0]);
    center.add(box[6]);
    center.scale(0.5);
    trans.setTranslation(center);
    Vector3d l = new Vector3d(box[0]);
    l.sub(box[6]);
    l.inverseTransform(trans);
    double alpha = 2 * Math.sqrt(2) * r;
    int nx = (int) Math.ceil(l.x / alpha) + 1;
    int ny = (int) Math.ceil(l.y / alpha) + 1;
    int nz = (int) Math.ceil(l.z / alpha) + 1;
    double xoffset = -(nx - 1) * alpha / 2;
    double yoffset = -(ny - 1) * alpha / 2;
    double zoffset = -(nz - 1) * alpha / 2;
    BVTree bvh = mesh.getBVTree();
    Vector2d coords = new Vector2d();
    Point3d nearest = new Point3d();
    BVFeatureQuery query = new BVFeatureQuery();
    Point3d p;
    for (int i = 0; i < nx; i++) {
        for (int j = 0; j < ny; j++) {
            for (int k = 0; k < nz; k++) {
                double x = i * alpha + xoffset;
                double y = j * alpha + yoffset;
                double z = k * alpha + zoffset;
                p = new Point3d(x, y, z);
                p.transform(trans);
                addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                // face centers
                if (i < nx - 1 && k < nz - 1) {
                    p = new Point3d(x + alpha / 2, y, z + alpha / 2);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
                if (j < ny - 1 && k < nz - 1) {
                    p = new Point3d(x, y + alpha / 2, z + alpha / 2);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
                if (i < nx - 1 && j < ny - 1) {
                    p = new Point3d(x + alpha / 2, y + alpha / 2, z);
                    p.transform(trans);
                    addIfIntersects(pnts, p, r, bvh, nearest, coords, query);
                }
            }
        }
    }
    return pnts.toArray(new Point3d[pnts.size()]);
}
Also used : BVTree(maspack.geometry.BVTree) RigidTransform3d(maspack.matrix.RigidTransform3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 8 with BVFeatureQuery

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

the class CollisionRenderer method buildFaceSegments.

protected void buildFaceSegments(RenderObject ro, CollisionHandler handler, ArrayList<TriTriIntersection> intersections) {
    BVFeatureQuery query = new BVFeatureQuery();
    PolygonalMesh mesh0 = handler.getCollidable(0).getCollisionMesh();
    PolygonalMesh mesh1 = handler.getCollidable(1).getCollisionMesh();
    ArrayList<Face> faces = new ArrayList<Face>();
    // mark faces as visited and add segments
    for (TriTriIntersection isect : intersections) {
        isect.face0.setVisited();
        isect.face1.setVisited();
    // add partials?
    }
    // mark interior faces and add segments
    for (TriTriIntersection isect : intersections) {
        if (isect.face0.getMesh() != mesh0) {
            findInsideFaces(isect.face0, query, mesh0, faces);
            findInsideFaces(isect.face1, query, mesh1, faces);
        } else {
            findInsideFaces(isect.face0, query, mesh1, faces);
            findInsideFaces(isect.face1, query, mesh0, faces);
        }
    }
    for (TriTriIntersection isect : intersections) {
        isect.face0.clearVisited();
        isect.face1.clearVisited();
    }
    // add faces to render object and clear visited flag
    Vector3d nrm = new Vector3d();
    Point3d p0 = new Point3d();
    Point3d p1 = new Point3d();
    Point3d p2 = new Point3d();
    for (Face face : faces) {
        face.clearVisited();
        face.getWorldNormal(nrm);
        ro.addNormal((float) nrm.x, (float) nrm.y, (float) nrm.z);
        HalfEdge he = face.firstHalfEdge();
        he.head.getWorldPoint(p0);
        he = he.getNext();
        he.head.getWorldPoint(p1);
        he = he.getNext();
        he.head.getWorldPoint(p2);
        int v0idx = ro.vertex((float) p0.x, (float) p0.y, (float) p0.z);
        int v1idx = ro.vertex((float) p1.x, (float) p1.y, (float) p1.z);
        int v2idx = ro.vertex((float) p2.x, (float) p2.y, (float) p2.z);
        ro.addTriangle(v0idx, v1idx, v2idx);
    }
}
Also used : Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) TriTriIntersection(maspack.geometry.TriTriIntersection) HalfEdge(maspack.geometry.HalfEdge) Face(maspack.geometry.Face) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint)

Example 9 with BVFeatureQuery

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

the class FemDisplayProbe method updateVertexIndicators.

/**
 *  determines which vertices are inside the supplied mesh
 */
protected void updateVertexIndicators() {
    vtxIndicatorMap = new HashMap<Vertex3d, Boolean>(myPlaneSurface.numVertices());
    TriangleIntersector ti = new TriangleIntersector();
    BVFeatureQuery query = new BVFeatureQuery();
    ti.setEpsilon(myIntersectionTolerance);
    if (myFem != null) {
        PolygonalMesh mesh = myFem.getSurfaceMesh();
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            Point3d pnt = vtx.getWorldPoint();
            if (query.isInsideOrientedMesh(mesh, pnt, myIntersectionTolerance)) {
                vtxIndicatorMap.put(vtx, true);
            } else {
                vtxIndicatorMap.put(vtx, false);
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point3d(maspack.matrix.Point3d) TriangleIntersector(maspack.geometry.TriangleIntersector) BVFeatureQuery(maspack.geometry.BVFeatureQuery) PolygonalMesh(maspack.geometry.PolygonalMesh)

Example 10 with BVFeatureQuery

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

the class MeshIntersectingProbe method updateVertexIndicators.

/**
 * Computes vertex indicators, determining if vertex is inside or outside mesh
 */
protected void updateVertexIndicators() {
    BVFeatureQuery query = new BVFeatureQuery();
    vtxIndicatorMap = new HashMap<Vertex3d, Boolean>(myPlaneSurface.numVertices());
    if (myIntersectingMesh != null) {
        for (Vertex3d vtx : myPlaneSurface.getVertices()) {
            boolean inside = query.isInsideOrientedMesh(myIntersectingMesh, vtx.getWorldPoint(), 1e-10);
            if (inside) {
                vtxIndicatorMap.put(vtx, true);
            } else {
                vtxIndicatorMap.put(vtx, false);
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Aggregations

BVFeatureQuery (maspack.geometry.BVFeatureQuery)14 Point3d (maspack.matrix.Point3d)9 Vertex3d (maspack.geometry.Vertex3d)7 Vector2d (maspack.matrix.Vector2d)7 Face (maspack.geometry.Face)6 PolygonalMesh (maspack.geometry.PolygonalMesh)6 Vector3d (maspack.matrix.Vector3d)5 Point (artisynth.core.mechmodels.Point)4 ArrayList (java.util.ArrayList)4 ContactPoint (artisynth.core.mechmodels.ContactPoint)3 TriTriIntersection (maspack.geometry.TriTriIntersection)3 RigidTransform3d (maspack.matrix.RigidTransform3d)3 FemElement3d (artisynth.core.femmodels.FemElement3d)2 PointAttachment (artisynth.core.mechmodels.PointAttachment)2 PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)2 HashMap (java.util.HashMap)2 BVTree (maspack.geometry.BVTree)2 VectorNd (maspack.matrix.VectorNd)2 FemNode (artisynth.core.femmodels.FemNode)1 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)1