use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class FemDisplayProbe method updateVertexColoringDynamic.
/**
* Updates vertex colors
*/
protected void updateVertexColoringDynamic() {
RenderProps rprops = getRenderProps();
float alpha = (float) rprops.getAlpha();
float backAlpha = (float) myBackgroundAlpha * alpha;
Color faceColor = rprops.getFaceColor();
Color femFaceColor = null;
double stressVal = 0;
float[] carray = new float[3];
if (myFem != null) {
if (mySurfaceRendering == SurfaceRender.Stress || mySurfaceRendering == SurfaceRender.Strain) {
if (myStressPlotRanging == Ranging.Auto) {
myStressPlotRange.merge(myFem.getNodalPlotRange(mySurfaceRendering));
}
} else {
femFaceColor = myFem.getRenderProps().getFaceColor();
}
} else {
// arbitrary, shouldn't be used
femFaceColor = Color.BLACK;
}
// do with some kind of synchronization
try {
for (Vertex3d vtx : myPlaneSurface.getVertices()) {
if (!vtxIndicatorMap.containsKey(vtx) || !vtxIndicatorMap.get(vtx)) {
setColor(vtx, faceColor, backAlpha);
} else {
switch(mySurfaceRendering) {
case None:
setColor(vtx, faceColor, alpha);
break;
case Strain:
stressVal = getStrainValue(vtx.getWorldPoint(), myFem);
myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
setColor(vtx, carray[0], carray[1], carray[2], alpha);
break;
case Stress:
stressVal = getStressValue(vtx.getWorldPoint(), myFem);
myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
setColor(vtx, carray[0], carray[1], carray[2], alpha);
break;
default:
setColor(vtx, femFaceColor, alpha);
}
}
}
} catch (Exception e) {
System.err.println("Error in display probe: " + e.getMessage());
}
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class MeshIntersectingProbe method trimFaces.
protected static PolygonalMesh trimFaces(PolygonalMesh mesh, HashMap<Vertex3d, Boolean> vtxIndicatorMap) {
PolygonalMesh out = new PolygonalMesh();
HashMap<Vertex3d, Vertex3d> vtxMap = new HashMap<Vertex3d, Vertex3d>(mesh.numVertices());
for (Vertex3d vtx : mesh.getVertices()) {
if (vtxIndicatorMap.get(vtx)) {
Vertex3d nvtx = new Vertex3d(new Point3d(vtx.getPosition()));
vtxMap.put(vtx, nvtx);
out.addVertex(nvtx);
}
}
for (Face face : mesh.getFaces()) {
boolean add = true;
for (Vertex3d vtx : face.getVertices()) {
if (vtxIndicatorMap.get(vtx) == false) {
add = false;
break;
}
}
if (add) {
Vertex3d[] oldVtxs = face.getVertices();
Vertex3d[] vtxs = new Vertex3d[face.numVertices()];
for (int i = 0; i < vtxs.length; i++) {
vtxs[i] = vtxMap.get(oldVtxs[i]);
}
out.addFace(vtxs);
}
}
return out;
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class MeshIntersectingProbe method splitFace.
// splits a face at a point
private static ArrayList<Face> splitFace(PolygonalMesh mesh, Face face, Vertex3d vtx, double tol) {
ArrayList<Face> newFaces = new ArrayList<Face>();
Vertex3d[] verts = face.getVertices();
// if the vtx is one of the corners, don't do anything
for (Vertex3d v : verts) {
if (v == vtx) {
newFaces.add(face);
return newFaces;
}
}
if (!mesh.containsVertex(vtx)) {
// transform to mesh coordinate system,
// then add
vtx.pnt.inverseTransform(mesh.getMeshToWorld());
mesh.addVertex(vtx);
}
mesh.removeFace(face);
Vertex3d v1, v2, v3;
v1 = vtx;
for (int i = 0; i < verts.length; i++) {
int j = (i + 1) % verts.length;
v2 = verts[i];
v3 = verts[j];
if (getSignedTriangleArea(v1.getWorldPoint(), v2.getWorldPoint(), v3.getWorldPoint(), face.getWorldNormal()) > tol) {
newFaces.add(mesh.addFace(v1, v2, v3));
}
}
return newFaces;
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class MeshIntersectingProbe method findNextFace.
// does not add the vertex, goes in a loop around contour until we hit a face
private Face findNextFace(Point3d pnt, LinkedList<Point3d> contour, OBBTree obbt, Intersector2d ti, Vector3d vx, Vector3d vy, Point3d o, SplitStorage info) {
Face face = null;
Vector3d dir = new Vector3d();
if (info.idx < contour.size() - 1) {
dir.sub(contour.get(info.idx + 1), contour.get(info.idx));
} else {
dir.sub(contour.get(info.idx), contour.get(info.idx - 1));
}
dir.normalize();
while (face == null && info.idx < contour.size() - 1) {
Point3d pntNext = contour.get(info.idx + 1);
Point2d pnt2d = Intersector2d.get2dCoordinate(pnt, vx, vy, o);
Point2d pnt2dNext = Intersector2d.get2dCoordinate(pntNext, vx, vy, o);
Vector2d diff2d = new Vector2d();
ArrayList<BVNode> bvNodes = new ArrayList<BVNode>();
// get close nodes
obbt.intersectLineSegment(bvNodes, pnt, pntNext);
double minDist = Double.MAX_VALUE;
Point2d minPnt = null;
for (BVNode node : bvNodes) {
for (int i = 0; i < node.getNumElements(); i++) {
Boundable ps = node.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);
ArrayList<Point2d> points = new ArrayList<Point2d>();
ti.intersectTriangleLineSegment(p0, p1, p2, pnt2d, pnt2dNext, points);
// check points
for (Point2d p : points) {
diff2d.sub(p, pnt2d);
if (diff2d.norm() < minDist) {
face = f;
minDist = diff2d.norm();
minPnt = p;
}
}
}
}
}
if (face == null || minDist >= pnt2dNext.distance(pnt2d)) {
face = null;
// move to next point
info.idx++;
pnt = contour.get(info.idx);
if (info.idx < contour.size() - 1) {
dir.sub(contour.get(info.idx + 1), pnt);
}
} else {
// snap to edge if within tolerance
Point3d pos = Intersector2d.get3dCoordinate(minPnt, vx, vy, o);
if (pos.distance(pnt) < ti.epsilon) {
pos.set(pnt);
}
// check if we have to make a new vertex
info.vtx = createOrGetVertex(pos, face.getVertices(), ti.epsilon);
}
}
return face;
}
use of maspack.geometry.Vertex3d 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;
}
Aggregations