Search in sources :

Example 11 with PointParticleAttachment

use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method createEmbedded.

/**
 * Assumes the mesh is in "rest" coordinates, not current coordinates
 * @param surf mfree surface to populate (or null to create one)
 * @param mesh mesh to embed
 * @param mfree model to embed mesh in
 * @return populated or created mesh
 */
public static MFreeMeshComp createEmbedded(MFreeMeshComp surf, MeshBase mesh, MFreeModel3d mfree) {
    double reduceTol = 1e-8;
    ArrayList<MFreeNode3d> nodes = new ArrayList<MFreeNode3d>();
    VectorNd weights = new VectorNd();
    if (surf == null) {
        surf = new MFreeMeshComp(mfree);
    }
    surf.setMesh(mesh);
    ArrayList<Vertex3d> verts = mesh.getVertices();
    Point3d coords = new Point3d();
    ArrayList<FemNode3d> deps = new ArrayList<>();
    MLSShapeFunction sfunc = new MLSShapeFunction();
    surf.myVertexAttachments.clear();
    for (int i = 0; i < verts.size(); i++) {
        // this could works very similarly to the code that adds
        // marker points into a mesh
        Vertex3d vtx = verts.get(i);
        deps.clear();
        mfree.findDependentNodesAtRest(vtx.pnt, deps);
        // compute shape function
        VectorNd N = new VectorNd(deps.size());
        MFreeNode3d[] dnodes = deps.toArray(new MFreeNode3d[deps.size()]);
        sfunc.update(vtx.pnt, dnodes);
        sfunc.eval(N);
        // first see if there's a node within reduceTol of the point,
        // and if so just use that
        double maxDist = Double.NEGATIVE_INFINITY;
        double minDist = Double.POSITIVE_INFINITY;
        MFreeNode3d nearestNode = null;
        for (int k = 0; k < dnodes.length; k++) {
            double d = vtx.pnt.distance(dnodes[k].getRestPosition());
            if (d > maxDist) {
                maxDist = d;
            }
            if (d < minDist) {
                minDist = d;
                nearestNode = dnodes[k];
            }
        }
        if (minDist / maxDist <= reduceTol) {
            // weight everything to the nearest node
            nodes.clear();
            nodes.add(nearestNode);
            weights.setSize(0);
            weights.append(1.0);
        } else {
            nodes.clear();
            weights.setSize(0);
            for (int k = 0; k < N.size(); k++) {
                if (Math.abs(N.get(k)) >= reduceTol) {
                    nodes.add(dnodes[k]);
                    weights.append(N.get(k));
                }
            }
        }
        if (weights.size() > 1) {
            PointFem3dAttachment attacher = new PointFem3dAttachment();
            attacher.setFromNodes(nodes, weights);
            surf.myVertexAttachments.add(attacher);
        } else if (weights.size() == 1) {
            PointParticleAttachment attacher = new PointParticleAttachment(nodes.get(0), null);
            surf.myVertexAttachments.add(attacher);
        }
    }
    surf.buildNodeVertexMap();
    return surf;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) ArrayList(java.util.ArrayList) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point) Point3d(maspack.matrix.Point3d) VectorNd(maspack.matrix.VectorNd) FemNode3d(artisynth.core.femmodels.FemNode3d) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 12 with PointParticleAttachment

use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method updateVertexColors.

protected void updateVertexColors() {
    if (mySurfaceRendering != SurfaceRender.Stress && mySurfaceRendering != SurfaceRender.Strain) {
        return;
    }
    if (myStressPlotRanging == Ranging.Auto) {
        myStressPlotRange.merge(myModel.getNodalPlotRange(mySurfaceRendering));
    }
    RenderProps rprops = getRenderProps();
    float alpha = (float) rprops.getAlpha();
    MeshBase mesh = getMesh();
    double sval = 0;
    for (int i = 0; i < myVertexAttachments.size(); i++) {
        PointAttachment attacher = myVertexAttachments.get(i);
        sval = 0;
        if (attacher instanceof PointFem3dAttachment) {
            PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
            FemNode[] nodes = pfa.getNodes();
            VectorNd weights = pfa.getCoordinates();
            for (int j = 0; j < nodes.length; j++) {
                if (nodes[j] instanceof MFreeNode3d) {
                    // paranoid!
                    MFreeNode3d node = (MFreeNode3d) nodes[j];
                    double w = weights.get(j);
                    if (mySurfaceRendering == SurfaceRender.Strain) {
                        sval += w * node.getVonMisesStrain();
                    } else if (mySurfaceRendering == SurfaceRender.Stress) {
                        sval += w * node.getVonMisesStress();
                    }
                }
            }
        } else if (attacher instanceof PointParticleAttachment) {
            PointParticleAttachment ppa = (PointParticleAttachment) attacher;
            MFreeNode3d node = (MFreeNode3d) ppa.getParticle();
            if (mySurfaceRendering == SurfaceRender.Strain) {
                sval = node.getVonMisesStrain();
            } else if (mySurfaceRendering == SurfaceRender.Stress) {
                sval = node.getVonMisesStress();
            }
        }
        double smin = myStressPlotRange.getLowerBound();
        double srng = myStressPlotRange.getRange();
        double c = (sval - smin) / srng;
        c = Math.max(0, Math.min(c, 1.0));
        myColorMap.getRGB(c, colorArray);
        mesh.setColor(i, colorArray[0], colorArray[1], colorArray[2], alpha);
    }
}
Also used : FemNode(artisynth.core.femmodels.FemNode) RenderProps(maspack.render.RenderProps) MeshBase(maspack.geometry.MeshBase) FemMeshBase(artisynth.core.femmodels.FemMeshBase) VectorNd(maspack.matrix.VectorNd) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Example 13 with PointParticleAttachment

use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.

the class MFreeMeshComp method postscanItem.

protected boolean postscanItem(Deque<ScanToken> tokens, CompositeComponent ancestor) throws IOException {
    if (postscanAttributeName(tokens, "fem")) {
        myModel = postscanReference(tokens, MFreeModel3d.class, ancestor);
        return true;
    } else if (postscanAttributeName(tokens, "attachments")) {
        for (int i = 0; i < myVertexAttachments.size(); i++) {
            PointAttachment va = myVertexAttachments.get(i);
            FemNode[] nodes = ScanWriteUtils.postscanReferences(tokens, FemNode.class, ancestor);
            if (va instanceof PointParticleAttachment) {
                PointParticleAttachment ppa = (PointParticleAttachment) va;
                ppa.setParticle(nodes[0]);
            } else if (va instanceof PointFem3dAttachment) {
                PointFem3dAttachment pfa = (PointFem3dAttachment) va;
                double[] coords = (double[]) tokens.poll().value();
                pfa.setFromNodes(nodes, coords);
            }
        }
        buildNodeVertexMap();
        return true;
    }
    return super.postscanItem(tokens, ancestor);
}
Also used : FemNode(artisynth.core.femmodels.FemNode) PointFem3dAttachment(artisynth.core.femmodels.PointFem3dAttachment) PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 14 with PointParticleAttachment

use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.

the class FemMeshComp method writeAttachment.

protected void writeAttachment(PointAttachment attacher, PrintWriter pw, NumberFormat fmt, CompositeComponent ancestor) throws IOException {
    pw.print("[ ");
    if (attacher instanceof PointParticleAttachment) {
        PointParticleAttachment ppa = (PointParticleAttachment) attacher;
        FemNode node = (FemNode) ppa.getParticle();
        pw.print(ComponentUtils.getWritePathName(ancestor, node) + " 1 ");
    } else if (attacher instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) attacher;
        FemNode[] nodes = pfa.getNodes();
        VectorNd weights = pfa.getCoordinates();
        for (int i = 0; i < nodes.length; i++) {
            pw.print(ComponentUtils.getWritePathName(ancestor, nodes[i]) + " " + fmt.format(weights.get(i)) + " ");
        }
    }
    pw.println("]");
}
Also used : VectorNd(maspack.matrix.VectorNd) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment)

Example 15 with PointParticleAttachment

use of artisynth.core.mechmodels.PointParticleAttachment in project artisynth_core by artisynth.

the class FemMeshComp method writeVertexInfo.

private void writeVertexInfo(PrintWriter pw, Vertex3d vtx, NumberFormat fmt) {
    PointAttachment pa = null;
    if (vtx.getIndex() < myVertexAttachments.size()) {
        pa = getAttachment(vtx.getIndex());
    }
    if (pa instanceof PointFem3dAttachment) {
        PointFem3dAttachment pfa = (PointFem3dAttachment) pa;
        FemNode[] masters = pfa.getNodes();
        pw.print("v");
        for (int j = 0; j < masters.length; j++) {
            pw.print(" " + masters[j].getNumber() + " " + fmt.format(pfa.getCoordinate(j)));
        }
        pw.println("");
    } else if (pa instanceof PointParticleAttachment) {
        PointParticleAttachment ppa = (PointParticleAttachment) pa;
        FemNode3d n = (FemNode3d) ppa.getParticle();
        pw.println("v " + n.getNumber() + " 1.0");
    } else {
        pw.println("v -1 " + vtx.getPosition().toString(fmt));
    }
}
Also used : PointAttachment(artisynth.core.mechmodels.PointAttachment) PointParticleAttachment(artisynth.core.mechmodels.PointParticleAttachment) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

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