Search in sources :

Example 1 with PointParticleAttachment

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.
    }
}
Also used : Point3d(maspack.matrix.Point3d) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 2 with PointParticleAttachment

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) PointAttachment(artisynth.core.mechmodels.PointAttachment) PolygonalMesh(maspack.geometry.PolygonalMesh) BVFeatureQuery(maspack.geometry.BVFeatureQuery) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Vector2d(maspack.matrix.Vector2d) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 3 with PointParticleAttachment

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());
    }
}
Also used : PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 4 with PointParticleAttachment

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) InternalErrorException(maspack.util.InternalErrorException) PolygonalMesh(maspack.geometry.PolygonalMesh) LinkedList(java.util.LinkedList) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Point3d(maspack.matrix.Point3d) Face(maspack.geometry.Face) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) HashSet(java.util.HashSet)

Example 5 with PointParticleAttachment

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;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Aggregations

PointParticleAttachment (artisynth.core.mechmodels.PointParticleAttachment)31 ContactPoint (artisynth.core.mechmodels.ContactPoint)21 Point (artisynth.core.mechmodels.Point)21 PointAttachment (artisynth.core.mechmodels.PointAttachment)16 Vertex3d (maspack.geometry.Vertex3d)15 PointFem3dAttachment (artisynth.core.femmodels.PointFem3dAttachment)13 ArrayList (java.util.ArrayList)12 VectorNd (maspack.matrix.VectorNd)11 FemNode (artisynth.core.femmodels.FemNode)10 PolygonalMesh (maspack.geometry.PolygonalMesh)10 Point3d (maspack.matrix.Point3d)9 Face (maspack.geometry.Face)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)3 FemNode3d (artisynth.core.femmodels.FemNode3d)2 ContactMaster (artisynth.core.mechmodels.ContactMaster)2 ObjectToken (artisynth.core.util.ObjectToken)2 BVFeatureQuery (maspack.geometry.BVFeatureQuery)2 HalfEdge (maspack.geometry.HalfEdge)2 MeshBase (maspack.geometry.MeshBase)2