use of maspack.geometry.Face in project artisynth_core by artisynth.
the class IntersectionTester method computePenetratingFaceArea.
double computePenetratingFaceArea(ArrayList<PenetratingPoint> points) {
double area = 0;
HashSet<Vertex3d> vertices = new HashSet<Vertex3d>();
for (PenetratingPoint p : points) {
vertices.add(p.vertex);
}
HashSet<Face> faces = new HashSet<Face>();
for (PenetratingPoint p : points) {
Vertex3d vtx = p.vertex;
Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
while (it.hasNext()) {
HalfEdge he = it.next();
Face face = he.getFace();
if (!faces.contains(face) && faceIsPenetrating(face, vertices)) {
area += face.computeArea();
System.out.println(" adding face " + face.getIndex() + " " + area);
faces.add(face);
}
}
}
return area;
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class OffWriter method writeMesh.
public void writeMesh(PolygonalMesh mesh) throws IOException {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
pw.println("OFF");
pw.printf("%d %d %d\n", mesh.numVertices(), mesh.numFaces(), 0);
pw.flush();
int[] oldIdxs = new int[mesh.numVertices()];
int idx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
Point3d pnt = vtx.getPosition();
pw.println(myFmt.format(pnt.x) + " " + myFmt.format(pnt.y) + " " + myFmt.format(pnt.z));
// protect vertex indices numbers
oldIdxs[idx] = vtx.getIndex();
vtx.setIndex(idx);
idx++;
}
for (Face face : mesh.getFaces()) {
int nf = face.numVertices();
pw.print(nf);
for (int j = 0; j < face.numVertices(); j++) {
pw.print(" " + face.getVertex(j).getIndex());
}
pw.println();
}
pw.flush();
// restore vertex indices
idx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
vtx.setIndex(oldIdxs[idx]);
idx++;
}
}
use of maspack.geometry.Face in project artisynth_core by artisynth.
the class GtsWriter method writeMesh.
public void writeMesh(PolygonalMesh mesh) throws IOException {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
int[] oldIdxs = new int[mesh.numVertices()];
int vidx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
// protect vertex indices numbers
oldIdxs[vidx] = vtx.getIndex();
vtx.setIndex(vidx);
vidx++;
}
LinkedHashMap<Edge, Integer> edgeList = new LinkedHashMap<Edge, Integer>();
for (Face f : mesh.getFaces()) {
HalfEdge he0 = f.firstHalfEdge();
HalfEdge he = he0;
do {
HalfEdge next = he.getNext();
Edge edge = new Edge(he.head, next.head);
if (edgeList.get(edge) == null) {
edgeList.put(edge, edgeList.size());
}
he = next;
} while (he != he0);
}
pw.println(mesh.numVertices() + " " + edgeList.size() + " " + mesh.numFaces());
for (Vertex3d vtx : mesh.getVertices()) {
vtx.pnt.write(pw, myFmt);
pw.println("");
}
for (Edge edge : edgeList.keySet()) {
pw.println((edge.myVtx1.getIndex() + 1) + " " + (edge.myVtx2.getIndex() + 1));
}
for (Face f : mesh.getFaces()) {
HalfEdge he0 = f.firstHalfEdge();
HalfEdge he = he0;
do {
HalfEdge next = he.getNext();
Edge edge = new Edge(he.head, next.head);
Integer idx = edgeList.get(edge);
pw.print((idx + 1) + " ");
he = next;
} while (he != he0);
pw.println("");
}
// restore vertex indices
vidx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
vtx.setIndex(oldIdxs[vidx]);
vidx++;
}
}
use of maspack.geometry.Face 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.Face in project artisynth_core by artisynth.
the class MeshIntersectingProbe method findNextEdge.
// NOTE: only works for convex faces (so, triangular is okay)
// finds the next edge while clipping around in a circle
private static HalfEdge findNextEdge(LinkedList<Point3d> contour, ArrayList<Face> faceList, Intersector2d ti, SplitStorage info, Vector3d vx, Vector3d vy, Point3d o) {
Vector3d dir = new Vector3d();
Point3d vtxp = info.vtx.getWorldPoint();
Point2d vtx2d = Intersector2d.get2dCoordinate(vtxp, vx, vy, o);
dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
for (Face face : faceList) {
HalfEdge he0 = face.getEdge(0);
HalfEdge he = he0;
do {
if (info.vtx != he.head && info.vtx != he.tail) {
Point2d p1 = Intersector2d.get2dCoordinate(he.head.getWorldPoint(), vx, vy, o);
Point2d p2 = Intersector2d.get2dCoordinate(he.tail.getWorldPoint(), vx, vy, o);
ArrayList<Point2d> pnts = new ArrayList<Point2d>();
Vector2d lineDir = Intersector2d.get2dVector(dir, vx, vy);
int npoints = ti.intersectLineLineSegment(vtx2d, lineDir, p1, p2, pnts);
if (npoints == 1) {
Point3d p = Intersector2d.get3dCoordinate(pnts.get(0), vx, vy, o);
Vector3d ldir = new Vector3d(p.x - vtxp.x, p.y - vtxp.y, p.z - vtxp.z);
// check direction
if (ldir.dot(dir) > -ti.epsilon) {
// check if we passed the next point
Point3d pNext = contour.get(info.idx + 1);
if (ldir.norm() < pNext.distance(vtxp) + ti.epsilon) {
if (p.distance(pNext) < ti.epsilon) {
// move to next point
info.idx++;
}
info.vtx = createOrGetVertex(p, face.getVertices(), ti.epsilon);
return he;
} else {
// advance to next vertex
info.vtx = createOrGetVertex(pNext, face.getVertices(), ti.epsilon);
info.face = face;
// move to next point
info.idx++;
return null;
}
}
}
}
he = he.getNext();
} while (he != he0);
}
info.face = null;
return null;
}
Aggregations