use of maspack.collision.IntersectionPoint in project artisynth_core by artisynth.
the class SurfaceMeshIntersector method printFaceMips.
private void printFaceMips(Face face) {
HalfEdge he0 = face.firstHalfEdge();
HalfEdge he = he0;
do {
EdgeInfo einfo = myEdgeInfos.get(he.getPrimary());
System.out.println(" " + he.vertexStr() + " " + (he == he.getPrimary() ? ">" : "<"));
NumberFormat fmt = new NumberFormat("%3d");
if (einfo != null) {
int kstart = 0;
int kinc = 1;
int kend = einfo.numMips();
if (he.getPrimary() != he) {
kstart = einfo.numMips() - 1;
kinc = -1;
kend = -1;
}
for (int k = kstart; k != kend; k += kinc) {
IntersectionPoint p = einfo.getMip(k);
boolean entering = (p.findSegmentFace(face.getMesh()) == face);
System.out.println(" " + fmt.format(p.contourIndex) + " " + p.toString("%12.8f") + " " + getContourIndex(p.contour) + " " + (entering ? "E" : "X") + " " + (p.isCoincident() ? "C" : " "));
}
}
he = he.getNext();
} while (he != he0);
}
use of maspack.collision.IntersectionPoint in project artisynth_core by artisynth.
the class SurfaceMeshIntersector method findCoincidentBounds.
int[] findCoincidentBounds(IntersectionPoint p, EdgeInfo einfo) {
int k = einfo.indexOfMip(p);
int lo = k;
while (lo > 0 && einfo.getMip(lo - 1).primaryCoincident == p.primaryCoincident) {
lo--;
}
int hi = k;
while (hi < einfo.numMips() - 1 && einfo.getMip(hi + 1).primaryCoincident == p.primaryCoincident) {
hi++;
}
return new int[] { lo, hi };
}
use of maspack.collision.IntersectionPoint in project artisynth_core by artisynth.
the class SurfaceMeshIntersector method toString.
/**
* Comprehensive string representation of a mesh intersection point,
* showing most relevant information. Used for debugging.
*
* The string contains the following information:
*
* 1) index of the point with respect to the contour
* 2) the degeneracy code for the intersection (as a two digit hex number)
* 3) 'C' if the point is coincident, or ' ' otherwise
* 4) the point's edge and face, if edge belongs to mesh, or
* the point's face and edge
* 5) the segment faces of the point with respect to the mesh and the
* other mesh (or blank if this is the last point of an open contour)
* 6) the point's coordinates
*/
public String toString(IntersectionPoint p, RigidTransform3d T) {
NumberFormat ifmt = new NumberFormat("%3d");
NumberFormat dfmt = new NumberFormat("%2x");
int dgen = p.getDegeneracies();
String dstr = (dgen != 0 ? dfmt.format(dgen) : " ");
String prefix = ifmt.format(p.contourIndex) + " " + dstr + " " + (p.isCoincident() ? "C " : " ");
if (p.edge.getHead().getMesh() == myMesh0) {
prefix += ("E" + pad(p.edge.faceStr(), 10) + "F" + pad("" + p.face.getIndex(), 10));
} else {
prefix += ("F" + pad("" + p.face.getIndex(), 10) + "E" + pad(p.edge.faceStr(), 10));
}
int idx = p.contourIndex;
Face face0 = p.contour.findSegmentFace(idx, myMesh0);
Face face1 = p.contour.findSegmentFace(idx, myMesh1);
String faceStr0 = (face0 != null ? " F" + face0.getIndex() : "NULL");
String faceStr1 = (face1 != null ? " F" + face1.getIndex() : "NULL");
prefix += (" " + pad(faceStr0, 6) + pad(faceStr1, 6) + " ");
Point3d pnt = new Point3d();
pnt.transform(T, p);
String str = prefix + pnt.toString("%g");
return str;
}
use of maspack.collision.IntersectionPoint in project artisynth_core by artisynth.
the class SurfaceMeshIntersector method nextEdgeXip.
// Triangulation code:
IntersectionPoint nextEdgeXip(IntersectionPoint mip, HalfEdge edge, boolean clockwise, boolean debug) {
// tailToHead means that we are moving in the tail to head
// direction with respect to the edge associated with mips
boolean tailToHead = (edge.getPrimary() == edge);
if (clockwise) {
tailToHead = !tailToHead;
}
HalfEdge pedge = edge.getPrimary();
EdgeInfo einfo = myEdgeInfos.get(pedge);
int k = einfo.indexOfXip(mip);
if (tailToHead) {
if (k < einfo.numXips() - 1) {
return einfo.getXip(k + 1);
}
} else {
if (k > 0) {
return einfo.getXip(k - 1);
}
}
return null;
}
use of maspack.collision.IntersectionPoint in project artisynth_core by artisynth.
the class SurfaceMeshIntersector method traceFacePolygon.
Vertex3dList traceFacePolygon(IntersectionPoint mip0, Face face, PenetrationRegion region, boolean clockwise, Polygon3dCalc calc, HashSet<IntersectionPoint> visitedMips, HashMap<Vertex3d, Vertex3d> vertexMap) {
Vertex3dList poly = new Vertex3dList(/*closed=*/
true);
PolygonalMesh mesh = (PolygonalMesh) face.getMesh();
int meshNum = (region.myMesh == myMesh0 ? 0 : 1);
// = getPointEdge (mip0, face);
HalfEdge edge;
// XXX handle coincident points in nearestInsideMip
IntersectionPoint mip = mip0;
boolean debug = isDebugFace(face);
if (debug) {
System.out.println("TRACE face poly " + face.getIndex() + " clockwise=" + clockwise);
}
Vertex3d firstVtx = null;
Vertex3d curVtx = null;
do {
IntersectionContour c = mip.contour;
if (debug) {
System.out.println(" entering " + mip.toString("%12.7f") + " " + mip.isCoincident());
System.out.println(" visiting " + mip.contourIndex + " on " + getContourIndex(mip.contour));
}
if (!visitedMips.add(mip)) {
System.out.println("faceMips for " + face.getIndex() + ":");
printFaceXips(face);
for (IntersectionContour con : myContours) {
System.out.println("contour " + getContourIndex(con) + ":");
for (IntersectionPoint p : con) {
System.out.println(toString(p));
}
}
throw new InternalErrorException("Mip " + mip.contourIndex + " already visited on face " + face.getIndex() + " mesh0=" + (mesh == myMesh0));
}
// while ((segFace=c.findSegmentFace(k, mesh)) == face) {
while (traceFaceContinue(mip, face, meshNum)) {
if (mip.myVertex != curVtx) {
curVtx = mip.myVertex;
poly.add(curVtx);
if (debug) {
System.out.println(" ADD " + mip.contourIndex + " " + curVtx.pnt.toString("%20.16f"));
}
if (firstVtx == null) {
firstVtx = curVtx;
}
}
mip = mip.next();
}
if (mip.myVertex != curVtx) {
curVtx = mip.myVertex;
poly.add(curVtx);
if (debug) {
System.out.println(" ADD " + mip.contourIndex + " " + curVtx.pnt.toString("%20.16f"));
}
}
if (debug) {
System.out.println(" exiting at " + mip.contourIndex);
}
visitedMips.add(mip);
edge = getExtendedPointEdge(mip, face);
EdgeInfo einfo = myEdgeInfos.get(edge.getPrimary());
int mi0 = einfo.normalizedIndexOfXip(mip, edge, clockwise);
IntersectionPoint nextMip = null;
while (nextMip == null) {
for (int mi = mi0 + 1; mi < einfo.numXips(); mi++) {
IntersectionPoint p = einfo.getXip(mi, edge, clockwise);
int emptyMark;
if (debug) {
System.out.println(" mip " + p.contourIndex + " mark=" + p.getEmptyMark(meshNum));
}
if ((emptyMark = p.getEmptyMark(meshNum)) != 0) {
if (p.findSegmentFace(mesh) != face) {
if ((emptyMark & IntersectionPoint.EMPTY_PROJECTED) != 0) {
if (p.myVertex != curVtx) {
curVtx = p.myVertex;
poly.add(curVtx);
if (debug) {
System.out.println(" ADD P(a) " + p.contourIndex + " " + curVtx.pnt.toString("%20.16f"));
}
}
}
} else {
if ((emptyMark & IntersectionPoint.EMPTY_END) != 0) {
nextMip = p;
break;
} else if ((emptyMark & IntersectionPoint.EMPTY_BEGIN) != 0) {
// the empty polygon will be discarded.
if (debug) {
System.out.println("SUB POLY inside empty region, mip " + p.contourIndex + " on " + getContourIndex(p.contour));
}
poly.clear();
return poly;
}
}
} else {
nextMip = p;
break;
}
}
if (!useEmptySegmentProjection) {
if (edge.opposite != null && !region.myFaces.contains(edge.opposite.getFace())) {
curVtx = addEmptyFaceVertices(poly, edge, mip, nextMip, region, curVtx, clockwise, debug);
}
}
if (nextMip == null) {
Vertex3d newVtx = getNewVertex(edge, vertexMap, clockwise);
if (newVtx != curVtx && newVtx != firstVtx) {
// only add if unique from previously added vertices
curVtx = newVtx;
poly.add(curVtx);
if (debug) {
Vertex3d oldVtx = (clockwise ? edge.getTail() : edge.getHead());
System.out.println(" ADD vtx(a) " + oldVtx.getIndex() + ":" + oldVtx.getWorldPoint().toString("%20.16f"));
}
}
edge = getNextEdge(edge, clockwise);
einfo = myEdgeInfos.get(edge.getPrimary());
mip = null;
mi0 = -1;
}
}
mip = nextMip;
} while (mip != mip0);
if (debug) {
System.out.println("TRACE face poly end, size=" + poly.size());
}
// check if we added an extra vertex when the mesh was closed
if (poly.get(0) == poly.get(poly.size() - 1)) {
poly.remove(poly.getNode(poly.size() - 1));
}
if (clockwise) {
if (debug) {
System.out.println("reversing");
}
poly.reverse();
}
return poly;
}
Aggregations