Search in sources :

Example 1 with JetColorMap

use of maspack.render.color.JetColorMap in project artisynth_core by artisynth.

the class PenetrationRender method build.

public void build(String[] args) {
    MechModel mech = new MechModel("mech");
    addModel(mech);
    // create first body and set its rendering properties
    RigidBody body0 = createHemiBody(mech, "body0", 2, -0.5, false);
    RenderProps.setFaceStyle(body0, FaceStyle.FRONT_AND_BACK);
    RenderProps.setFaceColor(body0, CREAM);
    // create second body and set its pose and rendering properties
    RigidBody body1 = createHemiBody(mech, "body1", 1, 2.0, true);
    body1.setPose(new RigidTransform3d(0, 0, 0.75));
    // set up
    RenderProps.setFaceStyle(body1, FaceStyle.NONE);
    // wireframe
    RenderProps.setShading(body1, Shading.NONE);
    // rendering
    RenderProps.setDrawEdges(body1, true);
    RenderProps.setEdgeColor(body1, GOLD);
    // create and set a collision behavior between body0 and body1, and make
    // collisions INACTIVE since we only care about graphical display
    CollisionBehavior behav = new CollisionBehavior(true, 0);
    behav.setMethod(CollisionBehavior.Method.INACTIVE);
    // show penetration of mesh 0
    behav.setDrawPenetrationDepth(0);
    behav.getPenetrationDepthRange().setUpdating(ScalarRange.Updating.AUTO_FIT);
    mech.setCollisionBehavior(body0, body1, behav);
    CollisionManager cm = mech.getCollisionManager();
    // penetration rendering only works with contour-based collisions
    cm.setColliderType(ColliderType.AJL_CONTOUR);
    // set other rendering properities in the collision manager:
    // enable collision rendering
    RenderProps.setVisible(cm, true);
    // draw contours ...
    cm.setDrawIntersectionContours(true);
    // with a line width of 3
    RenderProps.setEdgeWidth(cm, 3);
    // and a blue color
    RenderProps.setEdgeColor(cm, Color.BLUE);
    // create a custom color map for rendering the penetration depth
    JetColorMap map = new JetColorMap();
    map.setColorArray(new Color[] { // no penetration
    CREAM, createColor(255, 204, 153), createColor(255, 153, 102), createColor(255, 102, 51), createColor(255, 51, 0), // most penetration
    createColor(204, 0, 0) });
    cm.setColorMap(map);
    // create a separate color bar to show depth values associated with the
    // color map
    ColorBar cbar = createColorBar();
    cbar.setColorMap(map);
}
Also used : RigidTransform3d(maspack.matrix.RigidTransform3d) JetColorMap(maspack.render.color.JetColorMap) ColorBar(artisynth.core.renderables.ColorBar)

Aggregations

ColorBar (artisynth.core.renderables.ColorBar)1 RigidTransform3d (maspack.matrix.RigidTransform3d)1 JetColorMap (maspack.render.color.JetColorMap)1