use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class SurfaceMeshContourIxer method doFaceFaceCollision.
/**
* Collide one triangular face with the second, but not the other way around.
*
* @param allMips new MIPs are appended to this list
* @param f0 The face which has its edges checked
* @param f1 The face which has its face checked
*
* @return the number of edge/face collisions detected in this call.
*/
protected int doFaceFaceCollision(ArrayList<IntersectionPoint> allMips, Face f0, Face f1, boolean edgeOnMesh0) {
int numFound = 0;
// Faces assumed to be triangular here!
for (int eidx = 0; eidx < 3; eidx++) {
HalfEdge e = f0.getEdge(eidx).getPrimary();
EdgeFacePair pair = new EdgeFacePair(e, f1);
// First check if we've already tested this edge/face pair
if (mySavedEdgeFaceResults.containsKey(pair)) {
if (mySavedEdgeFaceResults.get(pair) != null) {
numFound++;
}
continue;
}
IntersectionPoint mip = new IntersectionPoint();
boolean collided = robustIntersectionWithFace(e, f1, mip, edgeOnMesh0);
if (collided) {
mySavedEdgeFaceResults.put(pair, mip);
allMips.add(mip);
numFound++;
} else {
mySavedEdgeFaceResults.put(pair, null);
}
}
return numFound;
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class AmiraMeshWriter method writeMesh.
public void writeMesh(PolygonalMesh mesh) {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
if (!mesh.isTriangular()) {
throw new IllegalArgumentException("Mesh must be triangular");
}
int nVerts = mesh.numVertices();
int nFaces = mesh.numFaces();
pw.println(FILE_HEADER);
// mesh name
if (mesh.getName() != null) {
pw.println("# " + mesh.getName());
}
pw.println();
pw.println("define Nodes " + nVerts);
pw.println("define Triangles " + nFaces);
pw.println();
pw.println("Parameters {");
// pw.println(" ContentType \"HxLineSet\"");
// XXX confirm with amira about valid parameter set
pw.println("}");
pw.println();
pw.println("Nodes { float[3] Coordinates } = @1");
pw.println("Triangles { int[3] Nodes } = @2");
pw.println();
pw.println("@1 # xyz vertex coordinates");
int idx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
vtx.setIndex(idx++);
pw.println(vtx.getPosition().toString(myFmt));
}
pw.println();
pw.println("@2 # triangular face indices");
for (Face face : mesh.getFaces()) {
HalfEdge he = face.firstHalfEdge();
Vertex3d vtx = he.getHead();
pw.print(vtx.getIndex());
he = he.getNext();
vtx = he.getHead();
pw.print(" " + vtx.getIndex());
he = he.getNext();
vtx = he.getHead();
pw.println(" " + vtx.getIndex());
}
// end loop through faces
pw.flush();
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class SkinMeshBody method collectVertices.
private void collectVertices(Vertex3d vtx, int networkDist, ArrayList<Vertex3d> list) {
if (list.contains(vtx)) {
return;
}
list.add(vtx);
if (networkDist > 0) {
Iterator<HalfEdge> it = vtx.getIncidentHalfEdges();
while (it.hasNext()) {
HalfEdge he = it.next();
Vertex3d vtxTail = he.tail;
collectVertices(vtxTail, networkDist - 1, list);
}
}
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class CollisionRenderer method createPenetrationRenderObject.
RenderObject createPenetrationRenderObject(CollisionHandler handler, ArrayList<PenetratingPoint> points, ArrayList<PenetrationRegion> regions) {
RenderObject rd = new RenderObject();
HashMap<Vertex3d, Double> depthMap = new HashMap<Vertex3d, Double>();
double maxd = 0;
for (PenetratingPoint pp : points) {
depthMap.put(pp.vertex, pp.distance);
if (pp.distance > maxd) {
maxd = pp.distance;
}
}
ScalarRange range = handler.myBehavior.myPenetrationDepthRange;
range.updateInterval(0, maxd);
float[] rgb = new float[3];
for (int i = 0; i < 256; i++) {
handler.myManager.myColorMap.getRGB(i / 255.0, rgb);
rd.addColor(rgb);
}
Point3d wpnt = new Point3d();
Vector3d wnrm = new Vector3d();
for (PenetrationRegion region : regions) {
for (Face face : region.getFaces()) {
HalfEdge he = face.firstHalfEdge();
Vertex3d v0 = he.getHead();
Vertex3d v1 = he.getNext().getHead();
Vertex3d v2 = he.getTail();
v0.getWorldPoint(wpnt);
int pi0 = rd.addPosition(wpnt);
v1.getWorldPoint(wpnt);
int pi1 = rd.addPosition(wpnt);
v2.getWorldPoint(wpnt);
int pi2 = rd.addPosition(wpnt);
int ci0 = getColorIndex(range, v0, depthMap);
int ci1 = getColorIndex(range, v1, depthMap);
int ci2 = getColorIndex(range, v2, depthMap);
face.getWorldNormal(wnrm);
int ni = rd.addNormal(wnrm);
int v0idx = rd.addVertex(pi0, ni, ci0, -1);
int v1idx = rd.addVertex(pi1, ni, ci1, -1);
int v2idx = rd.addVertex(pi2, ni, ci2, -1);
rd.addTriangle(v0idx, v1idx, v2idx);
}
}
return rd;
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class MeshIntersectingProbe method getFaces.
/**
* Returns a list of all faces that use this vertex
*/
public ArrayList<Face> getFaces(Vertex3d vtx) {
Iterator<HalfEdge> hit = vtx.getIncidentHalfEdges();
ArrayList<Face> faces = new ArrayList<Face>();
while (hit.hasNext()) {
HalfEdge he = hit.next();
faces.add(he.getFace());
}
return faces;
}
Aggregations