Search in sources :

Example 61 with Vertex3d

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

the class MeshIntersectingProbe method findFaces.

// finds faces near a points
private ArrayList<Face> findFaces(Point3d p, OBBTree obbt, Vector3d vx, Vector3d vy, Point3d o, double tol) {
    ArrayList<Face> faces = new ArrayList<Face>();
    ArrayList<BVNode> nodes = new ArrayList<BVNode>();
    obbt.intersectPoint(nodes, p);
    Point2d p2d = Intersector2d.get2dCoordinate(p, vx, vy, o);
    Point3d uvw = new Point3d();
    for (BVNode obbn : nodes) {
        for (int i = 0; i < obbn.getNumElements(); i++) {
            Boundable ps = obbn.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);
                Intersector2d.getBarycentric(p2d, p0, p1, p2, uvw);
                if (uvw.x > -tol && uvw.y > -tol && uvw.z > -tol) {
                    faces.add(f);
                }
            }
        }
    }
    return faces;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Point2d(maspack.matrix.Point2d) BVNode(maspack.geometry.BVNode) Point3d(maspack.matrix.Point3d) ArrayList(java.util.ArrayList) Boundable(maspack.geometry.Boundable) Face(maspack.geometry.Face)

Example 62 with Vertex3d

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

Example 63 with Vertex3d

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

the class MDLMeshIO method write.

/**
 * Writes the specified mesh to a PrintWriter, using the MDL
 * file format. Vertices are printed first by x, y, and z coordinates.
 * Normals are printed next by x, y, and z coordinates.
 * Faces are printed next  by a list of
 * integers which gives the indices of that face's vertices in
 * counter-clockwise order followed by the indices of the vertex normals.
 *
 * <p>
 * The format used to print vertex
 * coordinates is specified by a C <code>printf</code> style format
 * string contained in the parameter fmtStr. For a description of the
 * format string syntax, see {@link maspack.util.NumberFormat
 * NumberFormat}.
 *
 * @param mesh polygonal mesh to write to file
 * @param pw PrintWriter to write this mesh to
 * @param fmt format for writing the vertex coordinates
 */
public static void write(PolygonalMesh mesh, String filename, PrintWriter pw, NumberFormat fmt) {
    pw.println(defaultTopHeader);
    pw.println(filename);
    pw.println("\n" + defaultVerticesHeader);
    pw.println(mesh.getVertices().size());
    for (Iterator<Vertex3d> it = mesh.getVertices().iterator(); it.hasNext(); ) {
        Point3d pnt = ((Vertex3d) it.next()).pnt;
        pw.println(fmt.format(pnt.x) + " " + fmt.format(pnt.y) + " " + fmt.format(pnt.z));
    }
    pw.println("\n" + defaultNormalsHeader);
    ArrayList<Vector3d> normals = mesh.getNormals();
    int[] indexOffs = mesh.getFeatureIndexOffsets();
    int[] nidxs = mesh.getNormalIndices();
    if (normals == null) {
        // no normals specified; need to compute them
        normals = new ArrayList<Vector3d>();
        nidxs = mesh.computeVertexNormals(normals, /*multi=*/
        false);
    }
    pw.println(normals.size());
    for (Vector3d vn : normals) {
        pw.println(fmt.format(vn.x) + " " + fmt.format(vn.y) + " " + fmt.format(vn.z));
    }
    pw.println("\n" + defaultFacesHeader);
    pw.println(mesh.getFaces().size());
    for (int i = 0; i < mesh.getFaces().size(); i++) {
        int[] vi = mesh.getFaces().get(i).getVertexIndices();
        pw.print(vi[0] + " " + vi[1] + " " + vi[2] + " ");
        int foff = indexOffs[i];
        pw.println(nidxs[foff] + " " + nidxs[foff + 1] + " " + nidxs[foff + 2]);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d)

Example 64 with Vertex3d

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

the class SurfaceMeshCollider method collideVerticesWithFaces.

/*
    * For each penetrating vertex, find the closest opposing face and add a
    * corresponding new element to the list of ContactPenetratingPoints
    */
public static void collideVerticesWithFaces(ArrayList<PenetratingPoint> cpps, PenetrationRegion region, PolygonalMesh otherMesh) {
    BVFeatureQuery query = new BVFeatureQuery();
    Vector2d uv = new Vector2d();
    Point3d nearPnt = new Point3d();
    Vector3d disp = new Vector3d();
    Point3d wpnt = new Point3d();
    PenetratingPoint cpp;
    for (Vertex3d vtx : region.myVertices) {
        vtx.getWorldPoint(wpnt);
        Face face = query.nearestFaceToPoint(nearPnt, uv, otherMesh, wpnt);
        disp.sub(nearPnt, wpnt);
        cpp = new PenetratingPoint(vtx, face, uv, nearPnt, disp, region);
        cpps.add(cpp);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) Vector2d(maspack.matrix.Vector2d) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) BVFeatureQuery(maspack.geometry.BVFeatureQuery)

Example 65 with Vertex3d

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

the class SurfaceMeshContourIxer method perturbVertices.

/**
 * Perturb all vertices of a Face
 *
 * @param f face whose vertices are to be perturbed
 */
protected void perturbVertices(Face f) {
    double dx, dy, dz;
    double eps = 1e-12;
    for (Vertex3d v : f.getVertices()) {
        dx = Math.random() * eps;
        dy = Math.random() * eps;
        dz = Math.random() * eps;
        v.pnt.add(dx, dy, dz);
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d)

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