Search in sources :

Example 1 with Connection

use of artisynth.core.femmodels.PointSkinAttachment.Connection in project artisynth_core by artisynth.

the class SkinMeshBody method smoothWeights.

/**
 * Smooths weights according to a weighting function of distance.  At
 * present, this <i>only</i> smooths the weights associated with Frame
 * connections. Results when the SkinMeshBody contains other types of
 * attachment connections are undefined.
 *
 * @param weightFunction single-input single-output function of distance
 *       to use as weights
 * @param networkDist number of paths to traverse to collect vertices
 */
public void smoothWeights(SISOFunction weightFunction, int networkDist) {
    ArrayList<Vertex3d> vtxs = getMesh().getVertices();
    ArrayList<Vertex3d> vtxList = new ArrayList<Vertex3d>();
    int numf = numFrames();
    // double[] newWeights = new double[nBodies*vtxs.size()];
    double[] w = new double[numf];
    for (int i = 0; i < vtxs.size(); i++) {
        Vertex3d vtx = vtxs.get(i);
        vtxList.clear();
        collectVertices(vtx, networkDist, vtxList);
        Arrays.fill(w, 0);
        double wTotal = 0;
        for (Vertex3d vtxl : vtxList) {
            double d = vtxl.getPosition().distance(vtx.getPosition());
            double wd = weightFunction.eval(d);
            wTotal += wd;
            int idx = vtxs.indexOf(vtxl);
            PointSkinAttachment attacher = myVertexAttachments.getByNumber(idx);
            if (attacher != null) {
                for (int j = 0; j < attacher.numConnections(); j++) {
                    Connection c = attacher.getConnection(j);
                    if (c instanceof FrameConnection) {
                        int fidx = ((FrameConnection) c).getFrameIndex();
                        w[fidx] += wd * attacher.getWeight(j);
                    }
                }
            }
        }
        PointSkinAttachment attacher = myVertexAttachments.getByNumber(i);
        if (attacher != null) {
            for (int j = 0; j < attacher.numConnections(); j++) {
                Connection c = attacher.getConnection(j);
                if (c instanceof FrameConnection) {
                    int fidx = ((FrameConnection) c).getFrameIndex();
                    attacher.setWeight(j, w[fidx] / wTotal);
                }
            }
        }
    }
}
Also used : Vertex3d(maspack.geometry.Vertex3d) FrameConnection(artisynth.core.femmodels.PointSkinAttachment.FrameConnection) ArrayList(java.util.ArrayList) FrameConnection(artisynth.core.femmodels.PointSkinAttachment.FrameConnection) Connection(artisynth.core.femmodels.PointSkinAttachment.Connection) ContactPoint(artisynth.core.mechmodels.ContactPoint) Point(artisynth.core.mechmodels.Point)

Aggregations

Connection (artisynth.core.femmodels.PointSkinAttachment.Connection)1 FrameConnection (artisynth.core.femmodels.PointSkinAttachment.FrameConnection)1 ContactPoint (artisynth.core.mechmodels.ContactPoint)1 Point (artisynth.core.mechmodels.Point)1 ArrayList (java.util.ArrayList)1 Vertex3d (maspack.geometry.Vertex3d)1