use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.
the class FemModel3d method createPointAttachment.
public PointAttachment createPointAttachment(Point pnt, double reduceTol) {
if (pnt.isAttached()) {
throw new IllegalArgumentException("point is already attached");
}
if (ComponentUtils.isAncestorOf(this, pnt)) {
throw new IllegalArgumentException("FemModel is an ancestor of the point");
}
Point3d loc = new Point3d();
FemElement3d elem = findNearestElement(loc, pnt.getPosition());
FemNode3d nearestNode = null;
double nearestDist = Double.MAX_VALUE;
for (FemNode3d n : elem.getNodes()) {
double d = n.distance(pnt);
if (d < nearestDist) {
nearestNode = n;
nearestDist = d;
}
}
if (nearestDist <= reduceTol) {
// just attach to the node
return new PointParticleAttachment(nearestNode, pnt);
} else {
return PointFem3dAttachment.create(pnt, elem, loc, reduceTol);
// Coords are computed in createNearest. the point's position will be
// updated, if necessary, by the addRemove hook when the attachement
// is added.
}
}
use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.
the class FemMeshComp method createPointAttachment.
public PointFem3dAttachment createPointAttachment(Point pnt) {
if (!(getMesh() instanceof PolygonalMesh)) {
return null;
}
PolygonalMesh mesh = (PolygonalMesh) getMesh();
if (!mesh.isTriangular()) {
return null;
}
// Find nearest face to the point. The vertices of this face will be used
// to find the nodes and weight for the attachment.
BVFeatureQuery query = new BVFeatureQuery();
Point3d near = new Point3d();
Vector2d uv = new Vector2d();
Face face = query.nearestFaceToPoint(near, uv, mesh, pnt.getPosition());
Vertex3d[] vtxs = face.getTriVertices();
double[] wgts = new double[] { 1 - uv.x - uv.y, uv.x, uv.y };
HashMap<FemNode, Double> nodeWeights = new HashMap<FemNode, Double>();
for (int i = 0; i < vtxs.length; i++) {
PointAttachment va = myVertexAttachments.get(vtxs[i].getIndex());
if (va instanceof PointParticleAttachment) {
PointParticleAttachment ppa = (PointParticleAttachment) va;
FemNode node = (FemNode) ppa.getParticle();
accumulateNodeWeights(node, wgts[i], nodeWeights);
} else if (va instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) va;
for (int k = 0; k < pfa.numMasters(); k++) {
FemNode node = pfa.getNodes()[k];
double w = pfa.getCoordinate(k);
accumulateNodeWeights(node, w * wgts[i], nodeWeights);
}
}
}
// Create a new PointFem3dAttachment
PointFem3dAttachment ax = new PointFem3dAttachment(pnt);
VectorNd weightVec = new VectorNd();
for (Double d : nodeWeights.values()) {
weightVec.append(d);
}
ax.setFromNodes(nodeWeights.keySet(), weightVec);
return ax;
}
use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.
the class FemMeshComp method addVertexNodes.
private void addVertexNodes(HashSet<FemNode3d> nodes, Vertex3d vtx) {
PointAttachment pa = getAttachment(vtx.getIndex());
if (pa instanceof PointFem3dAttachment) {
PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
FemNode[] masters = pfa.getNodes();
for (int j = 0; j < masters.length; j++) {
nodes.add((FemNode3d) masters[j]);
}
} else {
PointParticleAttachment ppa = (PointParticleAttachment) pa;
nodes.add((FemNode3d) ppa.getParticle());
}
}
use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.
the class FemMeshComp method createSurface.
// Throwable throwable = null;
public void createSurface(Collection<FemElement3d> elems) {
initializeSurfaceBuild();
// nodeVertexMap is used during the construction of this surface,
// so we build it during the construction rather then letting
// it be built in finalizeSurfaceBuild()
myNodeVertexMap = new HashMap<FemNode3d, Vertex3d>();
myNumSingleAttachments = 0;
LinkedList<FaceNodes3d> allFaces = new LinkedList<FaceNodes3d>();
// faces adjacent to each node
ArrayList<LinkedList<FaceNodes3d>> nodeFaces = new ArrayList<LinkedList<FaceNodes3d>>(myFem.numNodes());
for (int i = 0; i < myFem.numNodes(); i++) {
nodeFaces.add(new LinkedList<FaceNodes3d>());
}
PointList<FemNode3d> femNodes = myFem.getNodes();
// each node, create a list of all the faces it is associated with
for (FemElement3d e : elems) {
FaceNodes3d[] faces = e.getFaces();
for (FaceNodes3d f : faces) {
addEdgeNodesToFace(f, myFem);
for (FemNode3d n : f.getAllNodes()) {
int idx = femNodes.indexOf(n);
if (idx == -1) {
throw new InternalErrorException("Element " + e.getNumber() + ": bad node " + n.getNumber());
}
nodeFaces.get(femNodes.indexOf(n)).add(f);
}
allFaces.add(f);
}
}
// now for each face, check to see if it is overlapping with other faces
HashSet<FaceNodes3d> adjacentFaces = new HashSet<FaceNodes3d>();
for (FaceNodes3d f : allFaces) {
if (!f.isHidden()) {
adjacentFaces.clear();
for (FemNode3d n : f.getAllNodes()) {
Iterator<FaceNodes3d> it = nodeFaces.get(femNodes.indexOf(n)).iterator();
while (it.hasNext()) {
FaceNodes3d g = it.next();
if (g.isHidden()) {
it.remove();
} else if (g.getElement() != f.getElement()) {
adjacentFaces.add(g);
}
}
}
for (FaceNodes3d g : adjacentFaces) {
if (f.isContained(g)) {
f.setHidden(true);
g.setOverlapping(true);
}
if (g.isContained(f)) {
g.setHidden(true);
f.setOverlapping(true);
}
}
}
}
int num = 0;
for (FaceNodes3d f : allFaces) {
if (!f.isOverlapping() && !f.isSelfAttachedToFace()) {
num++;
}
}
// form the surface mesh from the non-overlapping faces
PolygonalMesh mesh = (PolygonalMesh) getMesh();
for (FaceNodes3d f : allFaces) {
if (!f.isOverlapping() && !f.hasSelfAttachedNode() && !f.isSelfAttachedToFace()) {
FemNode3d[][] triangles = f.triangulate();
boolean triangulatedQuad = (triangles.length == 2 && triangles[0][0] == triangles[1][0]);
for (int i = 0; i < triangles.length; i++) {
FemNode3d[] tri = triangles[i];
Vertex3d[] vtxs = new Vertex3d[3];
for (int j = 0; j < 3; j++) {
FemNode3d node = tri[j];
if ((vtxs[j] = myNodeVertexMap.get(node)) == null) {
Vertex3d vtx = new Vertex3d(new Point3d(node.getPosition()));
mesh.addVertex(vtx);
myVertexAttachments.add(new PointParticleAttachment(node, null));
myNumSingleAttachments++;
myNodeVertexMap.put(node, vtx);
vtxs[j] = vtx;
}
}
Face face = mesh.addFace(vtxs);
if (triangulatedQuad && i == 0) {
face.setFirstQuadTriangle(true);
}
}
}
}
finalizeSurfaceBuild();
// throwable = null;
}
use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.
the class FemMeshComp method createVertex.
private Vertex3d createVertex(FemNode3d node, Vertex3d v) {
Vertex3d vtx = new Vertex3d(v.getPosition());
PointParticleAttachment attacher = new PointParticleAttachment(node, null);
myVertexAttachments.add(attacher);
getMesh().addVertex(vtx);
return vtx;
}
Aggregations