use of artisynth.core.femmodels.PointSkinAttachment.FrameConnection 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);
}
}
}
}
}
Aggregations