use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class IntersectionTester method getPointEdge.
/**
* Return the edge of a face that contains an intersection point.
*/
private HalfEdge getPointEdge(IntersectionPoint pa, Face face) {
PolygonalMesh mesh = (PolygonalMesh) face.getMesh();
if (edgeOnMesh(pa.edge, mesh)) {
if (pa.edge.getFace() == face) {
return pa.edge;
} else if (getOppositeFace(pa.edge) == face) {
return pa.edge.opposite;
} else {
throw new InternalErrorException("Face edge not found for point " + pa);
}
} else {
// convert pa to mesh local coordinates
Point3d paLoc = new Point3d(pa);
paLoc.inverseTransform(mesh.getMeshToWorld());
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
HalfEdge heMin = null;
double dmin = Double.POSITIVE_INFINITY;
do {
double d = LineSegment.distance(he.getHead().pnt, he.getTail().pnt, paLoc);
if (d < dmin) {
heMin = he;
dmin = d;
}
he = he.getNext();
} while (he != he0);
return heMin;
}
}
use of maspack.geometry.HalfEdge 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);
}
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class CollisionRenderer method findInsideFaces.
protected void findInsideFaces(Face face, BVFeatureQuery query, PolygonalMesh mesh, ArrayList<Face> faces) {
face.setVisited();
Point3d pnt = new Point3d();
HalfEdge he = face.firstHalfEdge();
for (int i = 0; i < 3; i++) {
if (he.opposite != null) {
Face oFace = he.opposite.getFace();
if (!oFace.isVisited()) {
// check if inside
oFace.computeWorldCentroid(pnt);
boolean inside = query.isInsideOrientedMesh(mesh, pnt, -1);
if (inside) {
faces.add(oFace);
findInsideFaces(oFace, query, mesh, faces);
}
}
}
he = he.getNext();
}
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class IntersectionTester method faceIsPenetrating.
private boolean faceIsPenetrating(Face face, HashSet<Vertex3d> vertices) {
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
do {
if (!vertices.contains(he.getHead())) {
return false;
}
he = he.getNext();
} while (he != he0);
return true;
}
use of maspack.geometry.HalfEdge 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;
}
Aggregations