// color("$isosurfaceId", value) # color for a given mapped isosurface value
String colorScheme = (args.length > 0 ? ScriptVariable.sValue(args[0])
: "");
boolean isIsosurface = colorScheme.startsWith("$");
ColorEncoder ce = (isIsosurface ? null : viewer.getColorEncoder(colorScheme));
if (!isIsosurface && ce == null)
return addX("");
float lo = (args.length > 1 ? ScriptVariable.fValue(args[1])
: Float.MAX_VALUE);
float hi = (args.length > 2 ? ScriptVariable.fValue(args[2])
: Float.MAX_VALUE);
float value = (args.length > 3 ? ScriptVariable.fValue(args[3])
: Float.MAX_VALUE);
boolean getValue = (value != Float.MAX_VALUE || lo != Float.MAX_VALUE
&& hi == Float.MAX_VALUE);
boolean haveRange = (hi != Float.MAX_VALUE);
if (!haveRange && colorScheme.length() == 0) {
value = lo;
float[] range = viewer.getCurrentColorRange();
lo = range[0];
hi = range[1];
}
if (isIsosurface) {
// isosurface color scheme
String id = colorScheme.substring(1);
Object[] data = new Object[] { id, null};
if (!viewer.getShapeProperty(JmolConstants.SHAPE_ISOSURFACE, "colorEncoder", data))
return addX("");
ce = (ColorEncoder) data[1];
} else {
ce.setRange(lo, hi, lo > hi);
}
Map key = ce.getColorKey();
if (getValue)
return addX(Graphics3D.colorPointFromInt2(ce
.getArgb(hi == Float.MAX_VALUE ? lo : value)));
return addX(ScriptVariable.getVariable(key));
}