Search in sources :

Example 1 with ScalarRange

use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.

the class CollisionManager method setPenetrationDepthRange.

public void setPenetrationDepthRange(ScalarRange range) {
    ScalarRange newRange = range.clone();
    PropertyUtils.updateCompositeProperty(this, "penetrationDepthRange", myPenetrationDepthRange, newRange);
    myPenetrationDepthRange = newRange;
}
Also used : ScalarRange(artisynth.core.util.ScalarRange)

Example 2 with ScalarRange

use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.

the class CollisionRenderer method createPenetrationRenderObject.

RenderObject createPenetrationRenderObject(CollisionHandler handler, ArrayList<PenetratingPoint> points, ArrayList<PenetrationRegion> regions) {
    RenderObject rd = new RenderObject();
    HashMap<Vertex3d, Double> depthMap = new HashMap<Vertex3d, Double>();
    double maxd = 0;
    for (PenetratingPoint pp : points) {
        depthMap.put(pp.vertex, pp.distance);
        if (pp.distance > maxd) {
            maxd = pp.distance;
        }
    }
    ScalarRange range = handler.myBehavior.myPenetrationDepthRange;
    range.updateInterval(0, maxd);
    float[] rgb = new float[3];
    for (int i = 0; i < 256; i++) {
        handler.myManager.myColorMap.getRGB(i / 255.0, rgb);
        rd.addColor(rgb);
    }
    Point3d wpnt = new Point3d();
    Vector3d wnrm = new Vector3d();
    for (PenetrationRegion region : regions) {
        for (Face face : region.getFaces()) {
            HalfEdge he = face.firstHalfEdge();
            Vertex3d v0 = he.getHead();
            Vertex3d v1 = he.getNext().getHead();
            Vertex3d v2 = he.getTail();
            v0.getWorldPoint(wpnt);
            int pi0 = rd.addPosition(wpnt);
            v1.getWorldPoint(wpnt);
            int pi1 = rd.addPosition(wpnt);
            v2.getWorldPoint(wpnt);
            int pi2 = rd.addPosition(wpnt);
            int ci0 = getColorIndex(range, v0, depthMap);
            int ci1 = getColorIndex(range, v1, depthMap);
            int ci2 = getColorIndex(range, v2, depthMap);
            face.getWorldNormal(wnrm);
            int ni = rd.addNormal(wnrm);
            int v0idx = rd.addVertex(pi0, ni, ci0, -1);
            int v1idx = rd.addVertex(pi1, ni, ci1, -1);
            int v2idx = rd.addVertex(pi2, ni, ci2, -1);
            rd.addTriangle(v0idx, v1idx, v2idx);
        }
    }
    return rd;
}
Also used : Vertex3d(maspack.geometry.Vertex3d) HashMap(java.util.HashMap) HalfEdge(maspack.geometry.HalfEdge) IntersectionPoint(maspack.collision.IntersectionPoint) PenetratingPoint(maspack.collision.PenetratingPoint) PenetratingPoint(maspack.collision.PenetratingPoint) Vector3d(maspack.matrix.Vector3d) Point3d(maspack.matrix.Point3d) RenderObject(maspack.render.RenderObject) Face(maspack.geometry.Face) PenetrationRegion(maspack.collision.PenetrationRegion) ScalarRange(artisynth.core.util.ScalarRange)

Example 3 with ScalarRange

use of artisynth.core.util.ScalarRange in project artisynth_core by artisynth.

the class PenetrationRender method prerender.

public void prerender(RenderList list) {
    // In prerender, we update the color bar labels based on the updated
    // penetration range stored in the collision behavior.
    // 
    // Object references are obtained by name using 'findComponent'. This is
    // more robust than using class member variables, since the latter will
    // be lost if we save and restore this model from a file.
    ColorBar cbar = (ColorBar) (renderables().get("colorBar"));
    MechModel mech = (MechModel) findComponent("models/mech");
    RigidBody body0 = (RigidBody) mech.findComponent("rigidBodies/body0");
    RigidBody body1 = (RigidBody) mech.findComponent("rigidBodies/body1");
    CollisionBehavior behav = mech.getCollisionBehavior(body0, body1);
    ScalarRange range = behav.getPenetrationDepthRange();
    cbar.updateLabels(0, 1000 * range.getUpperBound());
    // call the regular prerender method
    super.prerender(list);
}
Also used : ColorBar(artisynth.core.renderables.ColorBar) ScalarRange(artisynth.core.util.ScalarRange)

Aggregations

ScalarRange (artisynth.core.util.ScalarRange)3 ColorBar (artisynth.core.renderables.ColorBar)1 HashMap (java.util.HashMap)1 IntersectionPoint (maspack.collision.IntersectionPoint)1 PenetratingPoint (maspack.collision.PenetratingPoint)1 PenetrationRegion (maspack.collision.PenetrationRegion)1 Face (maspack.geometry.Face)1 HalfEdge (maspack.geometry.HalfEdge)1 Vertex3d (maspack.geometry.Vertex3d)1 Point3d (maspack.matrix.Point3d)1 Vector3d (maspack.matrix.Vector3d)1 RenderObject (maspack.render.RenderObject)1