use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class CutPlaneProbe method extractBoundaries.
/**
* Gets the boundaries of the supplied display mesh
*/
protected static ArrayList<Vertex3d[]> extractBoundaries(PolygonalMesh surface) {
ArrayList<Vertex3d[]> boundaries = new ArrayList<Vertex3d[]>(1);
ArrayList<Vertex3d> vtxList = null;
LinkedList<HalfEdge> borderEdges = new LinkedList<HalfEdge>(surface.findBorderEdges());
while (borderEdges.size() > 0) {
vtxList = new ArrayList<Vertex3d>();
HalfEdge borderEdge = borderEdges.get(0);
borderEdges.remove(0);
vtxList.add(borderEdge.head);
vtxList.add(borderEdge.tail);
Vertex3d lastVtx = borderEdge.tail;
while (lastVtx != vtxList.get(0)) {
Iterator<HalfEdge> eit = borderEdge.tail.getIncidentHalfEdges();
HalfEdge he;
while (eit.hasNext()) {
he = eit.next();
if (he != borderEdge && he.opposite == null) {
borderEdge = he;
break;
}
}
if (borderEdges.contains(borderEdge)) {
borderEdges.remove(borderEdge);
}
lastVtx = borderEdge.tail;
if (!vtxList.contains(lastVtx) || lastVtx == vtxList.get(0)) {
vtxList.add(lastVtx);
} else {
System.out.println("boundary not closed");
break;
}
}
boundaries.add(vtxList.toArray(new Vertex3d[vtxList.size()]));
}
return boundaries;
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FaceComponent method drawFaces.
void drawFaces(Renderer renderer, Shading shading, RenderProps props) {
boolean useVertexColors = useVertexColouring;
if (renderer.isSelecting()) {
useVertexColors = false;
}
Face face = myFace;
boolean useVertexNormals = false;
ArrayList<Vector3d> normals = null;
int[] normalIndices = null;
int normalFaceOff = -1;
if ((shading == Shading.SMOOTH || shading == Shading.METAL) && myMesh.hasNormals()) {
useVertexNormals = true;
normals = myMesh.getNormals();
normalIndices = myMesh.getNormalIndices();
normalFaceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
}
Vector3d faceNrm = face.getNormal();
ArrayList<float[]> colors = null;
int[] colorIndices = null;
int colorFaceOff = -1;
if (useVertexColouring) {
colors = myMesh.getColors();
colorIndices = myMesh.getColorIndices();
colorFaceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
}
renderer.beginDraw(DrawMode.TRIANGLE_FAN);
HalfEdge he = face.firstHalfEdge();
int k = 0;
do {
Vertex3d vtx = he.head;
Point3d pnt = vtx.myRenderPnt;
if (useVertexColors) {
int cidx = colorIndices[colorFaceOff + k];
if (cidx != -1) {
float[] color = colors.get(cidx);
renderer.setColor(color);
}
}
if (useVertexNormals) {
int nidx = normalIndices[normalFaceOff + k];
if (nidx != -1) {
Vector3d normal = normals.get(nidx);
renderer.setNormal(normal);
}
} else {
renderer.setNormal(faceNrm);
}
renderer.addVertex(pnt.x, pnt.y, pnt.z);
he = he.getNext();
k++;
} while (he != face.firstHalfEdge());
renderer.endDraw();
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FaceComponent method drawEdges.
private void drawEdges(Renderer renderer, RenderProps props) {
Face face = myFace;
HalfEdge he = face.firstHalfEdge();
ArrayList<float[]> colors;
int[] colorIndices;
int faceOff;
if (useVertexColouring) {
colors = myMesh.getColors();
colorIndices = myMesh.getColorIndices();
faceOff = myMesh.getFeatureIndexOffsets()[face.getIndex()];
} else {
colors = null;
colorIndices = null;
faceOff = -1;
}
int k = 0;
renderer.beginDraw(DrawMode.LINE_LOOP);
do {
if (useVertexColouring) {
int cidx = colorIndices[faceOff + k];
if (cidx != -1) {
float[] color = colors.get(cidx);
renderer.setColor(color);
}
}
Point3d pnt = he.head.myRenderPnt;
renderer.addVertex(pnt);
he = he.getNext();
k++;
} while (he != face.firstHalfEdge());
renderer.endDraw();
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class FaceComponent method prerender.
@Override
public void prerender(RenderList list) {
HalfEdge he0 = myFace.firstHalfEdge();
HalfEdge he = he0;
do {
he.getHead().saveRenderInfo();
he = he.getNext();
} while (he != he0);
myFace.computeRenderNormal();
}
use of maspack.geometry.HalfEdge in project artisynth_core by artisynth.
the class IntersectionTester method findPenetratingFaces.
private Face[] findPenetratingFaces(ArrayList<PenetratingPoint> points) {
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)) {
faces.add(face);
}
}
}
return faces.toArray(new Face[0]);
}
Aggregations