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;
}
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);
}
}
}
}
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]);
}
}
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);
}
}
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);
}
}
Aggregations