use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class GtsWriter method writeMesh.
public void writeMesh(PolygonalMesh mesh) throws IOException {
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(myOstream)));
int[] oldIdxs = new int[mesh.numVertices()];
int vidx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
// protect vertex indices numbers
oldIdxs[vidx] = vtx.getIndex();
vtx.setIndex(vidx);
vidx++;
}
LinkedHashMap<Edge, Integer> edgeList = new LinkedHashMap<Edge, Integer>();
for (Face f : mesh.getFaces()) {
HalfEdge he0 = f.firstHalfEdge();
HalfEdge he = he0;
do {
HalfEdge next = he.getNext();
Edge edge = new Edge(he.head, next.head);
if (edgeList.get(edge) == null) {
edgeList.put(edge, edgeList.size());
}
he = next;
} while (he != he0);
}
pw.println(mesh.numVertices() + " " + edgeList.size() + " " + mesh.numFaces());
for (Vertex3d vtx : mesh.getVertices()) {
vtx.pnt.write(pw, myFmt);
pw.println("");
}
for (Edge edge : edgeList.keySet()) {
pw.println((edge.myVtx1.getIndex() + 1) + " " + (edge.myVtx2.getIndex() + 1));
}
for (Face f : mesh.getFaces()) {
HalfEdge he0 = f.firstHalfEdge();
HalfEdge he = he0;
do {
HalfEdge next = he.getNext();
Edge edge = new Edge(he.head, next.head);
Integer idx = edgeList.get(edge);
pw.print((idx + 1) + " ");
he = next;
} while (he != he0);
pw.println("");
}
// restore vertex indices
vidx = 0;
for (Vertex3d vtx : mesh.getVertices()) {
vtx.setIndex(oldIdxs[vidx]);
vidx++;
}
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class FemDisplayProbe method updatePosState.
/**
* Move vertices of clipped mesh along with FEM, like an embedded mesh
*/
protected synchronized void updatePosState() {
if (clipped && !useRestCoordinates) {
for (Vertex3d vtx : myPlaneSurface.getVertices()) {
VtxInfo vi = clippedVtxMap.get(vtx);
vtx.pnt.setZero();
for (int i = 0; i < vi.nodes.length; i++) {
vtx.pnt.scaledAdd(vi.coords[i], vi.nodes[i].getPosition());
}
}
}
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class FemDisplayProbe method computeClippedVertexColors.
// if we are clipped to the FEM, then the shape function values are fixed
private void computeClippedVertexColors() {
RenderProps rprops = getRenderProps();
float alpha = (float) rprops.getAlpha();
Color faceColor = rprops.getFaceColor();
Color femFaceColor = null;
double stressVal = 0;
if (mySurfaceRendering == SurfaceRender.Stress || mySurfaceRendering == SurfaceRender.Strain) {
if (myStressPlotRanging == Ranging.Auto) {
myStressPlotRange.merge(myFem.getNodalPlotRange(mySurfaceRendering));
}
} else {
femFaceColor = myFem.getRenderProps().getFaceColor();
}
float[] carray = new float[3];
// use our stored map of values
for (Vertex3d vtx : myPlaneSurface.getVertices()) {
switch(mySurfaceRendering) {
case None:
setColor(vtx, faceColor, alpha);
break;
case Strain:
stressVal = getStrainValue(clippedVtxMap.get(vtx));
myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
setColor(vtx, carray[0], carray[1], carray[2], alpha);
break;
case Stress:
stressVal = getStressValue(clippedVtxMap.get(vtx));
myColorMap.getRGB(stressVal / myStressPlotRange.getRange(), carray);
setColor(vtx, carray[0], carray[1], carray[2], alpha);
break;
default:
setColor(vtx, femFaceColor, alpha);
}
}
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class FemDisplayProbe method updateVertexIndicators.
/**
* determines which vertices are inside the supplied mesh
*/
protected void updateVertexIndicators() {
vtxIndicatorMap = new HashMap<Vertex3d, Boolean>(myPlaneSurface.numVertices());
TriangleIntersector ti = new TriangleIntersector();
BVFeatureQuery query = new BVFeatureQuery();
ti.setEpsilon(myIntersectionTolerance);
if (myFem != null) {
PolygonalMesh mesh = myFem.getSurfaceMesh();
for (Vertex3d vtx : myPlaneSurface.getVertices()) {
Point3d pnt = vtx.getWorldPoint();
if (query.isInsideOrientedMesh(mesh, pnt, myIntersectionTolerance)) {
vtxIndicatorMap.put(vtx, true);
} else {
vtxIndicatorMap.put(vtx, false);
}
}
}
}
use of maspack.geometry.Vertex3d in project artisynth_core by artisynth.
the class FemDisplayProbe method createVtxMap.
// map of vertices to coordinates inside FEM
private void createVtxMap() {
clippedVtxMap = new HashMap<Vertex3d, VtxInfo>(myPlaneSurface.numVertices());
Point3d loc = new Point3d();
Vector3d ncoords = new Vector3d();
for (Vertex3d vtx : myPlaneSurface.getVertices()) {
FemElement3d elem = myFem.findNearestElement(loc, vtx.getWorldPoint());
elem.getNaturalCoordinates(ncoords, vtx.getWorldPoint());
VtxInfo info = new VtxInfo();
info.nodes = elem.getNodes();
info.coords = new double[info.nodes.length];
for (int i = 0; i < info.coords.length; i++) {
info.coords[i] = elem.getN(i, ncoords);
}
clippedVtxMap.put(vtx, info);
}
}
Aggregations