From: <ha...@us...> - 2011-06-17 13:05:56
|
Revision: 15604 http://jmol.svn.sourceforge.net/jmol/?rev=15604&view=rev Author: hansonr Date: 2011-06-17 13:05:48 +0000 (Fri, 17 Jun 2011) Log Message: ----------- version=12.1.50_dev # new feature: JVXL files now save and return color and colorscheme information # # new feature: color isosurface {atom expression} <color> # -- specific to surface types (vdw, molecular, sasurface) # -- similar to PyMOL command "set surface_color, (color), (selection)" # -- allows painting of specific atom-related isosurface areas specific colors # -- example: isosurface molecular; color isosurface {hydrophobic} white # # new feature: super-fast isosurface MAP PROPERTY when isosurfacePropertySmoothing = false # Modified Paths: -------------- trunk/Jmol/src/org/jmol/adapter/readers/xtal/SiestaReader.java trunk/Jmol/src/org/jmol/export/___Exporter.java trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java trunk/Jmol/src/org/jmol/jvxl/readers/AtomPropertyMapper.java trunk/Jmol/src/org/jmol/jvxl/readers/JvxlXmlReader.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/shape/Mesh.java trunk/Jmol/src/org/jmol/shape/MeshCollection.java trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java trunk/Jmol/src/org/jmol/shapesurface/LcaoCartoon.java trunk/Jmol/src/org/jmol/util/ColorEncoder.java trunk/Jmol/src/org/jmol/util/XmlUtil.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/adapter/readers/xtal/SiestaReader.java =================================================================== --- trunk/Jmol/src/org/jmol/adapter/readers/xtal/SiestaReader.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/adapter/readers/xtal/SiestaReader.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -16,7 +16,7 @@ public class SiestaReader extends AtomSetCollectionReader { - private boolean geomMod = false; + //private boolean geomMod = false; private int noAtoms; @Override @@ -29,7 +29,7 @@ protected boolean checkLine() throws Exception { if (line.contains("%block LatticeVectors")) { - geomMod = false; + //geomMod = false; setCell(); return true; } else if (line.contains("AtomicCoordinatesFormat Ang")) { @@ -37,7 +37,7 @@ return true; } else if (line.contains("NumberOfAtoms")){ readNoAtoms(); - geomMod = true; + //geomMod = true; return true; } else if (line.contains("Begin CG move =")) { setNewmodel(); Modified: trunk/Jmol/src/org/jmol/export/___Exporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/___Exporter.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/export/___Exporter.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -348,11 +348,11 @@ } protected static String translucencyFractionalFromColix(short colix) { - return round(Graphics3D.translucencyFractionalFromColix(colix)); + return round(Graphics3D.getColixTranslucencyFractional(colix)); } protected static String opacityFractionalFromColix(short colix) { - return round(1 - Graphics3D.translucencyFractionalFromColix(colix)); + return round(1 - Graphics3D.getColixTranslucencyFractional(colix)); } protected static String opacityFractionalFromArgb(int argb) { Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -2134,7 +2134,7 @@ } } - public static float translucencyFractionalFromColix(short colix) { + public static float getColixTranslucencyFractional(short colix) { int translevel = getColixTranslucencyLevel(colix); return ( translevel == -1 ? 0.5f @@ -2167,6 +2167,10 @@ return (isTranslucent ? applyColorTranslucencyLevel(colix, translucentLevel) : colix); } + public final static short copyColixTranslucency(short colixFrom, short colixTo) { + return getColixTranslucent(colixTo, isColixTranslucent(colixFrom), getColixTranslucencyFractional(colixFrom)); + } + public int getColorArgbOrGray(short colix) { if (colix < 0) colix = changeableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlCoder.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -29,6 +29,7 @@ import java.util.ArrayList; import java.util.BitSet; import java.util.List; +import java.util.Map; import org.jmol.util.BitSetUtil; import org.jmol.util.Escape; @@ -145,18 +146,25 @@ jvxlData.isJvxlPrecisionColor, jvxlData.valueMappedToRed, jvxlData.valueMappedToBlue); } - appendEncodedBitSetTag(sb, "jvxlInvalidatedVertexData", jvxlData.jvxlExcluded[1], -1); + appendEncodedBitSetTag(sb, "jvxlInvalidatedVertexData", jvxlData.jvxlExcluded[1], -1, null); if (jvxlData.excludedVertexCount > 0) { - appendEncodedBitSetTag(sb, "jvxlExcludedVertexData", jvxlData.jvxlExcluded[0], jvxlData.excludedVertexCount); - appendEncodedBitSetTag(sb, "jvxlExcludedPlaneData", jvxlData.jvxlExcluded[2], -1); + appendEncodedBitSetTag(sb, "jvxlExcludedVertexData", jvxlData.jvxlExcluded[0], jvxlData.excludedVertexCount, null); + appendEncodedBitSetTag(sb, "jvxlExcludedPlaneData", jvxlData.jvxlExcluded[2], -1, null); } - appendEncodedBitSetTag(sb, "jvxlExcludedTriangleData", jvxlData.jvxlExcluded[3], jvxlData.excludedTriangleCount); + appendEncodedBitSetTag(sb, "jvxlExcludedTriangleData", jvxlData.jvxlExcluded[3], jvxlData.excludedTriangleCount, null); XmlUtil.closeTag(sb, "jvxlSurfaceData"); int len = sb.length(); data.append(sb); if (jvxlData.vContours != null && jvxlData.vContours.length > 0) { jvxlEncodeContourData(jvxlData.vContours, data); } + if (jvxlData.vertexColorMap != null) { + XmlUtil.openTag(data, "jvxlVertexColorData"); + for (Map.Entry<String, BitSet> entry : jvxlData.vertexColorMap.entrySet()) + appendEncodedBitSetTag(data, "jvxlColorMap", entry.getValue(), -1, new Object[] { "color", entry.getKey() }); + jvxlData.vertexColorMap = null; + XmlUtil.closeTag(data, "jvxlVertexColorData"); + } XmlUtil.closeTag(data, "jvxlSurface"); if (includeHeader) { XmlUtil.closeTag(data, "jvxlSurfaceSet"); @@ -165,14 +173,15 @@ return jvxlSetCompressionRatio(data, jvxlData, len); } - private static void appendEncodedBitSetTag(StringBuffer sb, String name, BitSet bs, int count) { + private static void appendEncodedBitSetTag(StringBuffer sb, String name, BitSet bs, int count, Object[] attribs) { if (count < 0) count = BitSetUtil.cardinalityOf(bs); if (count == 0) return; StringBuffer sb1 = new StringBuffer("\n "); jvxlEncodeBitSet(bs, -1, sb1); - XmlUtil.appendTag(sb, name, new String[] { + XmlUtil.appendTag(sb, name, new Object[] { + attribs, "bsEncoding", "base90+35", "count", "" + count, "len", "" + bs.length() }, @@ -264,6 +273,15 @@ if (nColorData > 0) addAttrib(attribs, "\n nBytesUncompressedColorData", "" + nColorData); // TODO: later? } + jvxlData.excludedVertexCount = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[0]); + jvxlData.excludedTriangleCount = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[3]); + if (jvxlData.excludedVertexCount > 0) + addAttrib(attribs, "\n nExcludedVertexes", "" + jvxlData.excludedVertexCount); + if (jvxlData.excludedTriangleCount > 0) + addAttrib(attribs, "\n nExcludedTriangles", "" + jvxlData.excludedTriangleCount); + int n = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[1]); + if (n > 0) + addAttrib(attribs, "\n nInvalidatedVertexes", "" + n); //next is for information only -- will be superceded by "encoding" attribute of jvxlColorData if (jvxlData.isJvxlPrecisionColor) addAttrib(attribs, "\n precisionColor", "true"); @@ -287,15 +305,24 @@ addAttrib(attribs, "\n colorMapped", "true"); addAttrib(attribs, "\n plane", Escape.escape(jvxlData.jvxlPlane)); } - jvxlData.excludedVertexCount = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[0]); - jvxlData.excludedTriangleCount = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[3]); - if (jvxlData.excludedVertexCount > 0) - addAttrib(attribs, "\n nExcludedVertexes", "" + jvxlData.excludedVertexCount); - if (jvxlData.excludedTriangleCount > 0) - addAttrib(attribs, "\n nExcludedTriangles", "" + jvxlData.excludedTriangleCount); - int n = BitSetUtil.cardinalityOf(jvxlData.jvxlExcluded[1]); - if (n > 0) - addAttrib(attribs, "\n nInvalidatedVertexes", "" + n); + addAttrib(attribs, "\n color", jvxlData.color); + addAttrib(attribs, "\n translucency", "" + jvxlData.translucency); + if (jvxlData.colorScheme != null) + addAttrib(attribs, "\n colorScheme", jvxlData.colorScheme); + if (jvxlData.nVertexColors > 0) + addAttrib(attribs, "\n nVertexColors", "" + jvxlData.nVertexColors); + + float min = (jvxlData.mappedDataMin == Float.MAX_VALUE ? 0f + : jvxlData.mappedDataMin); + float blue = (jvxlData.isColorReversed ? jvxlData.valueMappedToRed : jvxlData.valueMappedToBlue); + float red = (jvxlData.isColorReversed ? jvxlData.valueMappedToBlue : jvxlData.valueMappedToRed); + + if (jvxlData.jvxlColorData != null && jvxlData.jvxlColorData.length() > 0 && !jvxlData.isBicolorMap) { + addAttrib(attribs, "\n dataMinimum", "" + min); + addAttrib(attribs, "\n dataMaximum", "" + jvxlData.mappedDataMax); + addAttrib(attribs, "\n valueMappedToRed", "" + red); + addAttrib(attribs, "\n valueMappedToBlue", "" + blue); + } if (jvxlData.isContoured) { if (jvxlData.contourValues == null || jvxlData.contourColixes == null) { if (jvxlData.vContours == null) @@ -308,19 +335,6 @@ addAttrib(attribs, "\n contourColors", jvxlData.contourColors); } } - // ... mappedDataMin mappedDataMax valueMappedToRed valueMappedToBlue ... - //TODO: again, these really should not be necessary here - float min = (jvxlData.mappedDataMin == Float.MAX_VALUE ? 0f - : jvxlData.mappedDataMin); - float blue = (jvxlData.isColorReversed ? jvxlData.valueMappedToRed : jvxlData.valueMappedToBlue); - float red = (jvxlData.isColorReversed ? jvxlData.valueMappedToBlue : jvxlData.valueMappedToRed); - - if (jvxlData.jvxlColorData != null && jvxlData.jvxlColorData.length() > 0 && !jvxlData.isBicolorMap) { - addAttrib(attribs, "\n dataMinimum", "" + min); - addAttrib(attribs, "\n dataMaximum", "" + jvxlData.mappedDataMax); - addAttrib(attribs, "\n valueMappedToRed", "" + red); - addAttrib(attribs, "\n valueMappedToBlue", "" + blue); - } //TODO: confusing flag insideOut: if (jvxlData.insideOut) addAttrib(attribs, "\n insideOut", "true"); Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -64,6 +64,7 @@ import java.util.BitSet; import java.util.List; +import java.util.Map; import javax.vecmath.Point3f; import javax.vecmath.Point4f; @@ -148,6 +149,13 @@ public float dataMin, dataMax; public int saveVertexCount; + // added Jmol 12.1.50 + public Map<String, BitSet> vertexColorMap; // from color isosurface {atom subset} red + public int nVertexColors; + public String color; + public int translucency; + public String colorScheme; + public void setSurfaceInfo(Point4f thePlane, int nSurfaceInts, String surfaceData) { jvxlSurfaceData = surfaceData; if (jvxlSurfaceData.indexOf("--") == 0) Modified: trunk/Jmol/src/org/jmol/jvxl/readers/AtomPropertyMapper.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/AtomPropertyMapper.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/jvxl/readers/AtomPropertyMapper.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -34,7 +34,7 @@ class AtomPropertyMapper extends AtomDataReader { - private MepCalculationInterface m; + private MepCalculationInterface mepCalc; private String mepType; private int calcType = 0; AtomPropertyMapper(SurfaceGenerator sg, String mepType) { @@ -52,6 +52,7 @@ protected void setup() { super.setup(); // MAP only + haveSurfaceAtoms = true; volumeData.sr = this; volumeData.doIterate = false; point = params.point; @@ -73,7 +74,7 @@ doSmoothProperty = true; if (params.mep_calcType >= 0) calcType = params.mep_calcType; - m = (MepCalculationInterface) Interface.getOptionInterface("quantum." + mepCalc = (MepCalculationInterface) Interface.getOptionInterface("quantum." + mepType + "Calculation"); } if (!doSmoothProperty && maxDistance == Integer.MAX_VALUE) @@ -127,13 +128,21 @@ // not applicable } + + private int iAtomSurface; @Override + public int getSurfaceAtomIndex() { + return iAtomSurface; + } + + @Override public float getValueAtPoint(Point3f pt) { float dmin = Float.MAX_VALUE; float dminNearby = Float.MAX_VALUE; float value = (doSmoothProperty ? 0 : Float.NaN); float vdiv = 0; atomDataServer.setIteratorForPoint(iter, modelIndex, pt, maxDistance); + iAtomSurface = -1; while (iter.hasNext()) { int iAtom = myIndex[iter.next()]; boolean isNearby = (iAtom >= firstNearbyAtom); @@ -152,11 +161,12 @@ } } else if (d2 < dmin) { dmin = d2; + iAtomSurface = iAtom; if (!doSmoothProperty) value = p; } - if (m != null) { - value += m.valueFor(p, d2, calcType); + if (mepCalc != null) { + value += mepCalc.valueFor(p, d2, calcType); } else if (doSmoothProperty) { d2 = (float) Math.pow(d2, smoothingPower); vdiv += d2; @@ -164,7 +174,7 @@ } } //System.out.println(pt + " " + value + " " + vdiv + " " + value / vdiv); - return (m != null ? value : doSmoothProperty ? (vdiv == 0 + return (mepCalc != null ? value : doSmoothProperty ? (vdiv == 0 || dminNearby < dmin ? Float.NaN : value / vdiv) : value); } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/JvxlXmlReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/JvxlXmlReader.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/jvxl/readers/JvxlXmlReader.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -27,6 +27,7 @@ import java.io.BufferedReader; import java.util.ArrayList; import java.util.BitSet; +import java.util.Hashtable; import java.util.List; import javax.vecmath.Point3f; @@ -111,10 +112,18 @@ jvxlData.jvxlExcluded[1] = JvxlCoder.jvxlDecodeBitSet( xr.getXmlData("jvxlInvalidatedVertexData", null, false, false)); -if (invalidatedVertexCount > 0) - System.out.println(Escape.escape(jvxlData.jvxlExcluded[1])); if (haveContourData) jvxlDecodeContourData(jvxlData, xr.getXmlData("jvxlContourData", null, false, false)); + if (jvxlData.nVertexColors > 0) { + jvxlData.vertexColorMap = new Hashtable<String, BitSet>(); + for (int i = 0; i < jvxlData.nVertexColors; i++) { + String s = xr.getXmlData("jvxlColorMap", null, true, false); + String color = XmlReader.getXmlAttrib(s, "color"); + BitSet bs = JvxlCoder.jvxlDecodeBitSet(xr.getXmlData("jvxlColorMap", s, false, false)); + jvxlData.vertexColorMap.put(color, bs); + } + } + } catch (Exception e) { Logger.error(e.toString()); return false; @@ -205,6 +214,7 @@ params.nContours = (haveContourData ? nContourData : nContoursRead); //TODO ? params.contourFromZero = false; // MEP data to complete the plane } + jvxlData.nVertexColors = parseInt(XmlReader.getXmlAttrib(data, "nVertexColors")); params.isBicolorMap = XmlReader.getXmlAttrib(data, "bicolorMap").equals("true"); if (params.isBicolorMap || params.colorBySign) jvxlCutoff = 0; @@ -238,6 +248,18 @@ invalidatedVertexCount = parseInt(XmlReader.getXmlAttrib(data, "nInvalidatedVertexes")); colorDataCount = Math.max(0, parseInt(XmlReader.getXmlAttrib(data, "nBytesUncompressedColorData"))); jvxlDataIs2dContour = (params.thePlane != null && jvxlDataIsColorMapped); + + // new Jmol 12.1.50 + jvxlData.color = XmlReader.getXmlAttrib(data, "color"); + if (jvxlData.color.length() == 0) + jvxlData.color = "orange"; + jvxlData.translucency = parseInt(XmlReader.getXmlAttrib(data, "translucency")); + if (jvxlData.translucency == Integer.MAX_VALUE) + jvxlData.translucency = 0; + jvxlData.colorScheme = XmlReader.getXmlAttrib(data, "colorScheme"); + if (jvxlData.colorScheme.length() == 0) + jvxlData.colorScheme = "rgb"; + if (jvxlDataIs2dContour) params.isContoured = true; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -194,6 +194,7 @@ protected VolumeData volumeData; private String edgeData; + protected boolean haveSurfaceAtoms = false; protected boolean allowSigma = false; protected boolean isProgressive = false; protected boolean isXLowToHigh = false; //can be overridden in some readers by --progressive @@ -390,7 +391,7 @@ jvxlData.vertexDataOnly = vertexDataOnly; jvxlData.saveVertexCount = 0; - if (jvxlDataIsColorMapped) { + if (jvxlDataIsColorMapped || jvxlData.nVertexColors > 0) { if (meshDataServer != null) { meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES, null); meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_COLOR_INDEXES, null); @@ -727,7 +728,8 @@ hasColorData || vertexDataOnly || params.colorDensity || params.isBicolorMap && !params.isContoured; if (!useMeshDataValues) { - + if (haveSurfaceAtoms && meshData.vertexSource == null) + meshData.vertexSource = new int[meshData.vertexCount]; float min = Float.MAX_VALUE; float max = -Float.MAX_VALUE; float value; @@ -739,15 +741,18 @@ * the key to making the JVXL contours work. * */ - if (params.colorBySets) + if (params.colorBySets) { value = meshData.vertexSets[i]; - else if (params.colorByPhase) + } else if (params.colorByPhase) { value = getPhase(meshData.vertices[i]); //else if (jvxlDataIs2dContour) //marchingSquares // .getInterpolatedPixelValue(meshData.vertices[i]); - else + } else { value = volumeData.lookupInterpolatedVoxelValue(meshData.vertices[i]); + if (haveSurfaceAtoms) + meshData.vertexSource[i] = getSurfaceAtomIndex(); + } if (value < min) min = value; if (value > max && value != Float.MAX_VALUE) @@ -768,6 +773,9 @@ JvxlCoder.jvxlCreateColorData(jvxlData, (saveColorData ? meshData.vertexValues : null)); + if (haveSurfaceAtoms && meshDataServer != null) + meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_VERTICES, null); + if (meshDataServer != null && params.colorBySets) meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS, null); } @@ -1044,4 +1052,9 @@ // release any iterators } + public int getSurfaceAtomIndex() { + // atomPropertyMapper + return -1; + } + } Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -1136,9 +1136,6 @@ } else { if (isBondOrMatrix) addTokenToPrefix(new Token(Token.bitset, new BondSet(bs))); - // occasionally BondSet appears unknown in Eclipse even though it - // is defined - // in Eval.java -- doesn't seem to matter. else addTokenToPrefix(new Token(Token.bitset, bs)); return CONTINUE; Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -5769,7 +5769,10 @@ if (tokAt(++i) == Token.expressionBegin || tokAt(i) == Token.bitset) { bsOrList = atomExpression(i); } else { - ScriptVariable vl = parameterExpressionList(-i, 1, false).get(0); + List<ScriptVariable> what = parameterExpressionList(-i, 1, false); + if (what == null || what.size() < 1) + error(ERROR_invalidArgument); + ScriptVariable vl = what.get(0); switch (vl.tok) { case Token.bitset: bsOrList = ScriptVariable.getBitSet(vl, false); @@ -7539,14 +7542,33 @@ getToken(++index); if (isBackground) prefix = "bg"; - else if (isIsosurface && theTok == Token.mesh) { - getToken(++index); - prefix = "mesh"; + else if (isIsosurface) { + switch (theTok) { + case Token.mesh: + getToken(++index); + prefix = "mesh"; + break; + case Token.bitset: + case Token.expressionBegin: + if (theToken.value instanceof BondSet) { + bs = (BondSet) theToken.value; + prefix = "vertex"; + } else { + bs = atomExpression(index); + // don't allow isosurface partial translucency (yet) + prefix = "atom"; + } + translucentLevel = Float.MIN_VALUE; + getToken(index = iToken + 1); + break; + } } if (!isSyntaxCheck && shapeType == JmolConstants.SHAPE_MO && !mo(true)) return; boolean isTranslucent = (theTok == Token.translucent); if (isTranslucent || theTok == Token.opaque) { + if (translucentLevel == Float.MIN_VALUE) + error(ERROR_invalidArgument); translucency = parameterAsString(index++); if (isTranslucent && isFloatParameter(index)) translucentLevel = getTranslucentLevel(index++); @@ -15600,9 +15622,9 @@ } private boolean listIsosurface(int iShape) throws ScriptException { - checkLength(2); + checkLength23(); if (!isSyntaxCheck) - showString((String) getShapeProperty(iShape, "list")); + showString((String) getShapeProperty(iShape, "list" + (tokAt(2) == Token.nada ? "" : " " + getToken(2).value))); return true; } Modified: trunk/Jmol/src/org/jmol/shape/Mesh.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/Mesh.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/shape/Mesh.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -26,6 +26,7 @@ import java.util.BitSet; import java.util.List; +import java.util.Map; import org.jmol.util.BitSetUtil; import org.jmol.util.Escape; @@ -72,6 +73,8 @@ public Point3f ptCenter = new Point3f(0,0,0); public String meshType; public Mesh linkedMesh; //for lcaoOrbitals + public Map<String, BitSet> vertexColorMap; + public int index; public int atomIndex = -1; Modified: trunk/Jmol/src/org/jmol/shape/MeshCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -421,11 +421,12 @@ } if (property == "ID") return (currentMesh == null ? null : currentMesh.thisID); - if (property == "list") { + if (property.startsWith("list")) { StringBuffer sb = new StringBuffer(); int k = 0; + String id = (property == "list" ? null : property.substring(5)); for (int i = 0; i < meshCount; i++) { - if ((m = meshes[i]) == null || m.vertexCount == 0) + if ((m = meshes[i]) == null || m.vertexCount == 0 || id != null && !id.equalsIgnoreCase(m.thisID)) continue; sb.append((++k)).append(" id:" + m.thisID).append( "; model:" + viewer.getModelNumberDotted(m.modelIndex)).append( @@ -440,6 +441,11 @@ sb.append(s); } sb.append('\n'); + if (id != null) { + Object info = getProperty("jvxlFileInfo", 0); + if (info != null) + sb.append(info).append('\n'); + } } return sb.toString(); } Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -220,7 +220,7 @@ if ("remapColor" == propertyName) { if (thisMesh != null) { - remapColors((ColorEncoder) value); + thisMesh.remapColors((ColorEncoder) value, translucentLevel); } return; } @@ -232,18 +232,34 @@ return; } + if ("atomcolor" == propertyName) { + if (thisMesh != null) { + thisMesh.colorAtoms(Graphics3D.getColix(value), bs); + } + return; + } + + if ("vertexcolor" == propertyName) { + if (thisMesh != null) { + thisMesh.colorVertices(Graphics3D.getColix(value), bs); + } + return; + } + if ("color" == propertyName) { if (thisMesh != null) { // thisMesh.vertexColixes = null; thisMesh.isColorSolid = true; thisMesh.polygonColixes = null; thisMesh.colorEncoder = null; + thisMesh.vertexColorMap = null; } else if (!TextFormat.isWild(previousMeshID)) { for (int i = meshCount; --i >= 0;) { // isomeshes[i].vertexColixes = null; isomeshes[i].isColorSolid = true; isomeshes[i].polygonColixes = null; isomeshes[i].colorEncoder = null; + isomeshes[i].vertexColorMap = null; } } setPropertySuper(propertyName, value, bs); @@ -399,7 +415,7 @@ thisMesh.initialize(thisMesh.lighting, null, null); if (thisMesh.colorEncoder != null) { thisMesh.vertexColixes = null; - remapColors(thisMesh.colorEncoder); + thisMesh.remapColors(null, translucentLevel); } return; } @@ -668,10 +684,13 @@ } StringBuffer sb = new StringBuffer(); getMeshCommand(sb, thisMesh.index); + thisMesh.setJvxlColorMap(true); return JvxlCoder.jvxlGetFile(jvxlData, meshData, title, "", true, 1, sb.toString(), null); } - if (property == "jvxlFileInfo") + if (property == "jvxlFileInfo") { + thisMesh.setJvxlColorMap(false); return JvxlCoder.jvxlGetInfo(jvxlData); + } if (property == "command") { String key = previousMeshID.toUpperCase(); boolean isWild = TextFormat.isWild(key); @@ -776,15 +795,19 @@ appendCmd(sb, getColorCommand(myType, mesh.colix)); appendCmd(sb, mesh.colorCommand); } - getColorState(sb, mesh); + boolean colorArrayed = (mesh.isColorSolid && ((IsosurfaceMesh) mesh).polygonColixes != null); + if (mesh.isColorSolid && !colorArrayed) + appendCmd(sb, getColorCommand(myType, mesh.colix)); + if (mesh.vertexColorMap != null) + for (Map.Entry<String, BitSet> entry : mesh.vertexColorMap.entrySet()) { + BitSet bs = entry.getValue(); + if (!bs.isEmpty()) + appendCmd(sb, "color " + myType + " " + Escape.escape(bs, true) + + " " + entry.getKey()); + } } } - private void getColorState(StringBuffer sb, Mesh mesh) { - boolean colorArrayed = (mesh.isColorSolid && ((IsosurfaceMesh) mesh).polygonColixes != null); - if (mesh.isColorSolid && !colorArrayed) - appendCmd(sb, getColorCommand(myType, mesh.colix)); - } private String script; @@ -1159,7 +1182,7 @@ || mesh.vertexCount > mesh.vertexColixes.length) mesh.vertexColixes = new short[mesh.vertexCount]; meshData.vertexColixes = mesh.vertexColixes; - meshData.polygonIndexes = null; + //meshData.polygonIndexes = null; return; case MeshData.MODE_PUT_SETS: mesh.surfaceSet = meshData.surfaceSet; @@ -1189,6 +1212,8 @@ thisMesh.vertexSource = sg.getVertexSource(); thisMesh.calculatedArea = null; thisMesh.calculatedVolume = null; + // from JVXL file: + thisMesh.setColorsFromJvxlData(); thisMesh.initialize(sg.isFullyLit() ? JmolConstants.FULLYLIT : lighting, null, sg.getPlane()); if (sg.getParams().psi_monteCarloCount > 0) @@ -1199,50 +1224,21 @@ } public void notifySurfaceMappingCompleted() { - //setModelIndex(); - //viewer.setCurrentColorRange(jvxlData.valueMappedToRed, - // jvxlData.valueMappedToBlue); - //viewer.setPropertyColorScheme(schemeName, sg.getParams().colorSchemeTranslucent, false); thisMesh.isColorSolid = false; thisMesh.colorDensity = jvxlData.colorDensity; thisMesh.colorEncoder = sg.getColorEncoder(); thisMesh.getContours(); - //if (thisMesh.jvxlData.jvxlPlane != null) - //allowContourLines = false; if (thisMesh.jvxlData.nContours != 0 && thisMesh.jvxlData.nContours != -1) explicitContours = true; if (explicitContours && thisMesh.jvxlData.jvxlPlane != null) thisMesh.havePlanarContours = true; setPropertySuper("token", Integer.valueOf(explicitContours ? Token.nofill : Token.fill), null); setPropertySuper("token", Integer.valueOf(explicitContours ? Token.contourlines : Token.nocontourlines), null); + // may not be the final color scheme, though. - setColorCommand(thisMesh.colorEncoder); - /* - viewer.setCurrentColorRange(jvxlData.mappedDataMin, jvxlData.mappedDataMax); - thisMesh.isColorSolid = false; - thisMesh.colorCommand = "color $" + thisMesh.thisID + " " + getUserColorScheme(schemeName) + " range " - + (jvxlData.isColorReversed ? jvxlData.mappedDataMax + " " + jvxlData.mappedDataMin : - jvxlData.mappedDataMin + " " + jvxlData.mappedDataMax); - - */ + thisMesh.setColorCommand(); } - private void setColorCommand(ColorEncoder ce) { - if (ce == null) - return; - String schemeName = ce.getColorSchemeName(); - boolean isTranslucentScheme = ce.isTranslucent; - if (thisMesh == null) - return; - String list = (ce.currentPalette < 0 ? ColorEncoder.getColorSchemeList(ce.getColorSchemeArray(ce.currentPalette)) : schemeName); - thisMesh.colorCommand = "color $" + thisMesh.thisID - + (isTranslucentScheme ? " translucent " : " ") - + Escape.escape(list) + " range "; - thisMesh.colorCommand += (jvxlData.isColorReversed ? jvxlData.valueMappedToBlue - + " " + jvxlData.valueMappedToRed - : jvxlData.valueMappedToRed + " " + jvxlData.valueMappedToBlue); - } - public Point3f[] calculateGeodesicSurface(BitSet bsSelected, float envelopeRadius) { return viewer.calculateSurface(bsSelected, envelopeRadius); @@ -1361,63 +1357,6 @@ return V; } - private void remapColors(ColorEncoder ce) { - float min = ce.lo; - float max = ce.hi; - - JvxlData jvxlData = thisMesh.jvxlData; - float[] vertexValues = thisMesh.vertexValues; - short[] vertexColixes = thisMesh.vertexColixes; - thisMesh.polygonColixes = null; - if (vertexValues == null || jvxlData.isBicolorMap - || jvxlData.vertexCount == 0) - return; - if (vertexColixes == null) - vertexColixes = thisMesh.vertexColixes = new short[thisMesh.vertexCount]; - thisMesh.jvxlData.isColorReversed = ce.isReversed; - if (max != Float.MAX_VALUE) { - jvxlData.valueMappedToRed = min; - jvxlData.valueMappedToBlue = max; - } - ce.setRange(jvxlData.valueMappedToRed, jvxlData.valueMappedToBlue, thisMesh.jvxlData.isColorReversed); - // thisMesh.colix must be translucent if the scheme is translucent - // but may be translucent if the scheme is not translucent - boolean isTranslucent = Graphics3D.isColixTranslucent(thisMesh.colix); - if (ce.isTranslucent) { - if (!isTranslucent) - thisMesh.colix = Graphics3D.getColixTranslucent(thisMesh.colix, true, 0.5f); - // still, if the scheme is translucent, we don't want to color the vertices translucent - isTranslucent = false; - } - for (int i = thisMesh.vertexCount; --i >= 0;) { - vertexColixes[i] = ce.getColorIndex(vertexValues[i]); - if (isTranslucent) - vertexColixes[i] = Graphics3D.getColixTranslucent(vertexColixes[i], true, translucentLevel); - } - thisMesh.colorEncoder = ce; - List<Object>[] contours = thisMesh.getContours(); - if (contours != null) { - for (int i = contours.length; --i >= 0; ) { - float value = ((Float)contours[i].get(JvxlCoder.CONTOUR_VALUE)).floatValue(); - short[] colix = ((short[])contours[i].get(JvxlCoder.CONTOUR_COLIX)); - colix[0] = ce.getColorIndex(value); - int[] color = ((int[])contours[i].get(JvxlCoder.CONTOUR_COLOR)); - color[0] = Graphics3D.getArgb(colix[0]); - } - } - //TODO -- still not right. - if (thisMesh.contourValues != null) { - thisMesh.contourColixes = new short[thisMesh.contourValues.length]; - for (int i = 0; i < thisMesh.contourValues.length; i++) - thisMesh.contourColixes[i] = ce.getColorIndex(thisMesh.contourValues[i]); - thisMesh.setDiscreteColixes(null, null); - } - jvxlData.isJvxlPrecisionColor = true; - JvxlCoder.jvxlCreateColorData(jvxlData, vertexValues); - setColorCommand(thisMesh.colorEncoder); - thisMesh.isColorSolid = false; - } - public float[] getPlane(int x) { // only for surface readers return null; Modified: trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -54,7 +54,7 @@ Object calculatedArea; Object calculatedVolume; public boolean isSolvent; - + IsosurfaceMesh(String thisID, Graphics3D g3d, short colix, int index) { super(thisID, g3d, colix, index); checkByteCount = 2; @@ -62,39 +62,47 @@ } void clear(String meshType, boolean iAddGridPoints) { - super.clear(meshType); - nSets = 0; - thisSet = -1; - vertexIncrement = 1; - firstRealVertex = -1; - hasGridPoints = iAddGridPoints; - showPoints = iAddGridPoints; + super.clear(meshType); + jvxlData.jvxlSurfaceData = ""; jvxlData.jvxlEdgeData = ""; jvxlData.jvxlColorData = ""; jvxlData.jvxlVolumeDataXml = ""; - isColorSolid = true; - colorEncoder = null; - vertexColixes = null; - vertexValues = null; - polygonColixes = null; + jvxlData.color = null; + jvxlData.colorScheme = null; jvxlData.contourValues = null; jvxlData.contourValuesUsed = null; jvxlData.contourColixes = null; jvxlData.contourColors = null; + jvxlData.vContours = null; + jvxlData.colorDensity = false; + jvxlData.vertexColorMap = null; + jvxlData.nVertexColors = 0; + jvxlData.translucency = 0; + assocGridPointMap = null; assocGridPointNormals = null; - vertexSets = null; centers = null; - jvxlData.vContours = null; - jvxlData.colorDensity = false; + colorEncoder = null; + vertexColorMap = null; + firstRealVertex = -1; + hasGridPoints = iAddGridPoints; + isColorSolid = true; + nSets = 0; + polygonColixes = null; + showPoints = iAddGridPoints; surfaceSet = null; - } + thisSet = -1; + vertexColixes = null; + vertexIncrement = 1; + vertexValues = null; + vertexSets = null; + } void allocVertexColixes() { if (vertexColixes == null) { vertexColixes = new short[vertexCount]; - for (int i = vertexCount; --i >= 0; ) + for (int i = vertexCount; --i >= 0;) vertexColixes[i] = colix; } isColorSolid = false; @@ -103,7 +111,8 @@ Map<Integer, Integer> assocGridPointMap; Map<Integer, Vector3f> assocGridPointNormals; - int addVertexCopy(Point3f vertex, float value, int assocVertex, boolean associateNormals) { + int addVertexCopy(Point3f vertex, float value, int assocVertex, + boolean associateNormals) { int vPt = addVertexCopy(vertex, value); switch (assocVertex) { case MarchingSquares.CONTOUR_POINT: @@ -137,13 +146,13 @@ public void setTranslucent(boolean isTranslucent, float iLevel) { super.setTranslucent(isTranslucent, iLevel); if (vertexColixes != null) - for (int i = vertexCount; --i >= 0; ) - vertexColixes[i] = - Graphics3D.getColixTranslucent(vertexColixes[i], isTranslucent, iLevel); + for (int i = vertexCount; --i >= 0;) + vertexColixes[i] = Graphics3D.getColixTranslucent(vertexColixes[i], + isTranslucent, iLevel); } - + int thisSet = -1; - + @Override protected void sumVertexNormals(Point3f[] vertices, Vector3f[] vectorSums) { super.sumVertexNormals(vertices, vectorSums); @@ -161,7 +170,8 @@ if (assocGridPointMap != null) { for (Map.Entry<Integer, Integer> entry : assocGridPointMap.entrySet()) { Integer I = entry.getKey(); - assocGridPointNormals.get(entry.getValue()).add(vectorSums[I.intValue()]); + assocGridPointNormals.get(entry.getValue()).add( + vectorSums[I.intValue()]); } for (Map.Entry<Integer, Integer> entry : assocGridPointMap.entrySet()) { Integer I = entry.getKey(); @@ -169,8 +179,9 @@ } } } - + Point3f[] centers; + Point3f[] getCenters() { if (centers != null) return centers; @@ -183,36 +194,29 @@ pt.add(vertices[pi[0]]); pt.add(vertices[pi[1]]); pt.add(vertices[pi[2]]); - pt.scale(1/3f); + pt.scale(1 / 3f); } return centers; } - + Point4f getFacePlane(int i, Vector3f vNorm) { Point4f plane = new Point4f(); - Measure.getPlaneThroughPoints(vertices[polygonIndexes[i][0]], - vertices[polygonIndexes[i][1]], vertices[polygonIndexes[i][2]], - vNorm, vAB, vAC, plane); + Measure.getPlaneThroughPoints(vertices[polygonIndexes[i][0]], + vertices[polygonIndexes[i][1]], vertices[polygonIndexes[i][2]], vNorm, + vAB, vAC, plane); return plane; } - + /** - * create a set of contour data. + * create a set of contour data. * - * Each contour is a Vector containing: - * 0 Integer number of polygons (length of BitSet) - * 1 BitSet of critical triangles - * 2 Float value - * 3 int[] [colorArgb] - * 4 StringBuffer containing encoded data for each segment: - * char type ('3', '6', '5') indicating which two edges - * of the triangle are connected: - * '3' 0x011 AB-BC - * '5' 0x101 AB-CA - * '6' 0x110 BC-CA - * char fraction along first edge (jvxlFractionToCharacter) - * char fraction along second edge (jvxlFractionToCharacter) - * 5- stream of pairs of points for rendering + * Each contour is a Vector containing: 0 Integer number of polygons (length + * of BitSet) 1 BitSet of critical triangles 2 Float value 3 int[] [colorArgb] + * 4 StringBuffer containing encoded data for each segment: char type ('3', + * '6', '5') indicating which two edges of the triangle are connected: '3' + * 0x011 AB-BC '5' 0x101 AB-CA '6' 0x110 BC-CA char fraction along first edge + * (jvxlFractionToCharacter) char fraction along second edge + * (jvxlFractionToCharacter) 5- stream of pairs of points for rendering * * @return contour vector set */ @@ -254,7 +258,7 @@ for (int i = 0; i < n; i++) { float value = jvxlData.contourValuesUsed[i]; get3dContour(vContours[i], value, jvxlData.contourColixes[i]); - } + } } jvxlData.contourColixes = new short[n]; jvxlData.contourValues = new float[n]; @@ -264,7 +268,7 @@ } return jvxlData.vContours = vContours; } - + private void get3dContour(List<Object> v, float value, short colix) { BitSet bsContour = new BitSet(polygonCount); StringBuffer fData = new StringBuffer(); @@ -272,13 +276,13 @@ setContourVector(v, polygonCount, bsContour, value, colix, color, fData); for (int i = 0; i < polygonCount; i++) if (setABC(i)) - addContourPoints(v, bsContour, i, fData, vertices, - vertexValues, iA, iB, iC, value); + addContourPoints(v, bsContour, i, fData, vertices, vertexValues, iA, + iB, iC, value); } public static void setContourVector(List<Object> v, int nPolygons, - BitSet bsContour, float value, short colix, - int color, StringBuffer fData) { + BitSet bsContour, float value, + short colix, int color, StringBuffer fData) { v.add(JvxlCoder.CONTOUR_NPOLYGONS, Integer.valueOf(nPolygons)); v.add(JvxlCoder.CONTOUR_BITSET, bsContour); v.add(JvxlCoder.CONTOUR_VALUE, new Float(value)); @@ -343,35 +347,28 @@ } /** - * two values -- v1, and v2, which need not be ordered v1 < v2. - * v == v1 --> 0 - * v == v2 --> 1 - * v1 < v < v2 --> f in (0,1) - * v2 < v < v1 --> f in (0,1) - * i.e. (v1 < v) == (v < v2) - * - * We check AB, then (usually) BC, then (sometimes) CA. - * - * What if two end points are identical values? - * So, for example, if v = 1.0 and: - * - * A 1.0 0.5 1.0 1.0 - * / \ / \ / \ / \ / \ - * / \ / \ / \ / \ / \ - * C-----B 1.0--0.5 1.0--1.0 0.5--1.0 1.0---1.0 - * case I case II case III case IV - * - * case I: AB[0] and BC[1], type == 3 --> CA not tested. - * case II: AB[1] and CA[0]; f1 == 1.0 --> BC not tested. - * case III: AB[0] and BC[0], type == 3 --> CA not tested. - * case IV: AB[0] and BC[0], type == 3 --> CA not tested. - * - * what if v = 0.5? - * - * case I: AB[1]; BC not tested --> type == 1, invalid. - * case II: AB[0]; type == 1, f1 == 0.0 --> CA not tested. - * case III: BC[1]; f2 == 1.0 --> CA not tested. - * + * two values -- v1, and v2, which need not be ordered v1 < v2. v == v1 --> 0 + * v == v2 --> 1 v1 < v < v2 --> f in (0,1) v2 < v < v1 --> f in (0,1) i.e. + * (v1 < v) == (v < v2) + * + * We check AB, then (usually) BC, then (sometimes) CA. + * + * What if two end points are identical values? So, for example, if v = 1.0 + * and: + * + * A 1.0 0.5 1.0 1.0 / \ / \ / \ / \ / \ / \ / \ / \ / \ / \ C-----B 1.0--0.5 + * 1.0--1.0 0.5--1.0 1.0---1.0 case I case II case III case IV + * + * case I: AB[0] and BC[1], type == 3 --> CA not tested. case II: AB[1] and + * CA[0]; f1 == 1.0 --> BC not tested. case III: AB[0] and BC[0], type == 3 + * --> CA not tested. case IV: AB[0] and BC[0], type == 3 --> CA not tested. + * + * what if v = 0.5? + * + * case I: AB[1]; BC not tested --> type == 1, invalid. case II: AB[0]; type + * == 1, f1 == 0.0 --> CA not tested. case III: BC[1]; f2 == 1.0 --> CA not + * tested. + * * @param vertexValues * @param i * @param j @@ -380,13 +377,12 @@ */ private static float checkPt(float[] vertexValues, int i, int j, float v) { float v1, v2; - return (v == (v1 = vertexValues[i]) ? 0 - : v == (v2 = vertexValues[j]) ? 1 - : (v1 < v) == (v < v2) ? (v - v1) / (v2 - v1) - : Float.NaN); + return (v == (v1 = vertexValues[i]) ? 0 : v == (v2 = vertexValues[j]) ? 1 + : (v1 < v) == (v < v2) ? (v - v1) / (v2 - v1) : Float.NaN); } - private static Point3f getContourPoint(Point3f[] vertices, int i, int j, float f) { + private static Point3f getContourPoint(Point3f[] vertices, int i, int j, + float f) { Point3f pt = new Point3f(); pt.set(vertices[j]); pt.sub(vertices[i]); @@ -398,7 +394,7 @@ float[] contourValues; short[] contourColixes; ColorEncoder colorEncoder; - + public void setDiscreteColixes(float[] values, short[] colixes) { if (values != null) jvxlData.contourValues = values; @@ -416,13 +412,14 @@ float vMax = values[n - 1]; colorCommand = null; boolean haveColixes = (colixes != null && colixes.length > 0); - isColorSolid = haveColixes && jvxlData.jvxlPlane != null; + isColorSolid = (haveColixes && jvxlData.jvxlPlane != null); if (jvxlData.vContours != null) { if (haveColixes) for (int i = 0; i < jvxlData.vContours.length; i++) { - short colix = colixes[i % colixes.length]; + short colix = colixes[i % colixes.length]; ((short[]) jvxlData.vContours[i].get(JvxlCoder.CONTOUR_COLIX))[0] = colix; - ((int[]) jvxlData.vContours[i].get(JvxlCoder.CONTOUR_COLOR))[0] = Graphics3D.getArgb(colix); + ((int[]) jvxlData.vContours[i].get(JvxlCoder.CONTOUR_COLOR))[0] = Graphics3D + .getArgb(colix); } return; } @@ -433,7 +430,7 @@ if (pi == null) continue; polygonColixes[i] = defaultColix; - float v = (vertexValues[pi[0]] + vertexValues[pi[1]] + vertexValues[pi[2]])/3; + float v = (vertexValues[pi[0]] + vertexValues[pi[1]] + vertexValues[pi[2]]) / 3; //System.out.println(i + " " + v); for (int j = n; --j >= 0;) { if (v >= values[j] && v < vMax) { @@ -453,12 +450,15 @@ */ Map<String, Object> getContourList(Viewer viewer) { Map<String, Object> ht = new Hashtable<String, Object>(); - ht.put("values", (jvxlData.contourValuesUsed == null ? jvxlData.contourValues : jvxlData.contourValuesUsed)); + ht.put("values", + (jvxlData.contourValuesUsed == null ? jvxlData.contourValues + : jvxlData.contourValuesUsed)); List<Point3f> colors = new ArrayList<Point3f>(); if (jvxlData.contourColixes != null) { // set in SurfaceReader.colorData() for (int i = 0; i < jvxlData.contourColixes.length; i++) { - colors.add(Graphics3D.colorPointFromInt2(Graphics3D.getArgb(jvxlData.contourColixes[i]))); + colors.add(Graphics3D.colorPointFromInt2(Graphics3D + .getArgb(jvxlData.contourColixes[i]))); } ht.put("colors", colors); } @@ -472,9 +472,246 @@ jvxlData.vContours = null; } + /** + * color a specific set of vertices based on a set of atoms + * + * @param colix + * @param bs + */ + void colorAtoms(short colix, BitSet bs) { + colorVertices(colix, bs, true); + } + + /** + * color a specific set of vertices + * + * @param colix + * @param bs + */ + void colorVertices(short colix, BitSet bs) { + colorVertices(colix, bs, false); + } + + /** + * color a specific set of vertices a specific color + * + * @param colix + * @param bs + * @param isAtoms + */ + private void colorVertices(short colix, BitSet bs, boolean isAtoms) { + if (vertexSource == null) + return; + colix = Graphics3D.copyColixTranslucency(this.colix, colix); + BitSet bsVertices = (isAtoms ? new BitSet() : bs); + if (vertexColixes == null || vertexColorMap == null && isColorSolid) { + vertexColixes = new short[vertexCount]; + for (int i = 0; i < vertexCount; i++) + vertexColixes[i] = this.colix; + } + isColorSolid = false; + // TODO: color translucency? + if (isAtoms) + for (int i = 0; i < vertexCount; i++) { + if (bs.get(vertexSource[i])) { + vertexColixes[i] = colix; + bsVertices.set(i); + } + } + else + for (int i = 0; i < vertexCount; i++) + if (bsVertices.get(i)) + vertexColixes[i] = colix; + + if (!isAtoms) { + // JVXL file color maps do not have to be saved here. + // They are just kept in jvxlData + return; + } + String color = Graphics3D.getHexCode(colix); + if (vertexColorMap == null) + vertexColorMap = new Hashtable<String, BitSet>(); + addColorToMap(vertexColorMap, color, bs); + } + + /** + * adds a set of specifically-colored vertices to the map, + * ensuring that no vertex is in two maps. + * + * @param colorMap + * @param color + * @param bs + */ + private static void addColorToMap(Map<String, BitSet> colorMap, String color, + BitSet bs) { + BitSet bsMap = null; + for (Map.Entry<String, BitSet> entry : colorMap.entrySet()) + if (entry.getKey() == color) { + bsMap = entry.getValue(); + bsMap.or(bs); + } else { + entry.getValue().andNot(bs); + } + if (bsMap == null) + colorMap.put(color, bs); + } + + /** + * set up the jvxlData fields needed for either just the + * header (isAll = false) or the full file (isAll = true) + * + * @param isAll + */ + void setJvxlColorMap(boolean isAll) { + jvxlData.color = Graphics3D.getHexCode(colix); + jvxlData.translucency = Graphics3D.getColixTranslucencyLevel(colix); + jvxlData.colorScheme = (colorEncoder == null ? null : colorEncoder + .getColorScheme()); + jvxlData.nVertexColors = (vertexColorMap == null ? 0 : vertexColorMap + .size()); + if (vertexColorMap == null || vertexSource == null || !isAll) + return; + if (jvxlData.vertexColorMap == null) + jvxlData.vertexColorMap = new Hashtable<String, BitSet>(); + for (Map.Entry<String, BitSet> entry : vertexColorMap.entrySet()) { + BitSet bsMap = entry.getValue(); + if (bsMap.isEmpty()) + continue; + String color = entry.getKey(); + BitSet bs = new BitSet(); + for (int i = 0; i < vertexCount; i++) + if (bsMap.get(vertexSource[i])) + bs.set(i); + addColorToMap(jvxlData.vertexColorMap, color, bs); + } + jvxlData.nVertexColors = jvxlData.vertexColorMap.size(); + if (jvxlData.vertexColorMap.size() == 0) + jvxlData.vertexColorMap = null; + } + + /** + * just sets the color command for this isosurface. + */ + void setColorCommand() { + if (colorEncoder == null) + return; + colorCommand = colorEncoder.getColorScheme(); + if (colorCommand == null) + return; + colorCommand = "color $" + + thisID + + " " + + colorCommand + + " range " + + (jvxlData.isColorReversed ? jvxlData.valueMappedToBlue + " " + + jvxlData.valueMappedToRed : jvxlData.valueMappedToRed + " " + + jvxlData.valueMappedToBlue); + } + + /** + * from Isosurface.notifySurfaceGenerationCompleted() + * + * starting with Jmol 12.1.50, JVXL files contain + * color, translucency, color scheme information, + * and vertex color mappings (as from COLOR ISOSURFACE {hydrophobic} WHITE), + * returning these settings when the JVXL file is opened. + */ + void setColorsFromJvxlData() { + if (jvxlData.color != null) + colix = Graphics3D.getColix(jvxlData.color); + if (colix == 0) + colix = Graphics3D.ORANGE; + colix = Graphics3D.getColixTranslucent(colix, jvxlData.translucency != 0, + jvxlData.translucency); + if (colorEncoder == null) + return; + if (jvxlData.colorScheme != null) { + String colorScheme = jvxlData.colorScheme; + boolean isTranslucent = colorScheme.startsWith("translucent "); + if (isTranslucent) + colorScheme = colorScheme.substring(12); + colorEncoder.setColorScheme(colorScheme, isTranslucent); + remapColors(null, jvxlData.translucency); + } + if (jvxlData.vertexColorMap != null) + for (Map.Entry<String, BitSet> entry : jvxlData.vertexColorMap.entrySet()) { + BitSet bsMap = entry.getValue(); + short colix = Graphics3D.copyColixTranslucency(this.colix, Graphics3D + .getColix(entry.getKey())); + for (int i = bsMap.nextSetBit(0); i >= 0; i = bsMap.nextSetBit(i + 1)) + vertexColixes[i] = colix; + } + } + + /** + * remaps colors based on a new color scheme or translucency level + * + * @param ce + * @param translucentLevel + */ + void remapColors(ColorEncoder ce, float translucentLevel) { + if (ce == null) + ce = colorEncoder; + float min = ce.lo; + float max = ce.hi; + + vertexColorMap = null; + polygonColixes = null; + if (vertexValues == null || jvxlData.isBicolorMap + || jvxlData.vertexCount == 0) + return; + if (vertexColixes == null) + vertexColixes = new short[vertexCount]; + jvxlData.isColorReversed = ce.isReversed; + if (max != Float.MAX_VALUE) { + jvxlData.valueMappedToRed = min; + jvxlData.valueMappedToBlue = max; + } + ce.setRange(jvxlData.valueMappedToRed, jvxlData.valueMappedToBlue, + jvxlData.isColorReversed); + // colix must be translucent if the scheme is translucent + // but may be translucent if the scheme is not translucent + boolean isTranslucent = Graphics3D.isColixTranslucent(colix); + if (ce.isTranslucent) { + if (!isTranslucent) + colix = Graphics3D.getColixTranslucent(colix, true, 0.5f); + // still, if the scheme is translucent, we don't want to color the vertices translucent + isTranslucent = false; + } + for (int i = vertexCount; --i >= 0;) { + vertexColixes[i] = ce.getColorIndex(vertexValues[i]); + if (isTranslucent) + vertexColixes[i] = Graphics3D.getColixTranslucent(vertexColixes[i], + true, translucentLevel); + } + colorEncoder = ce; + List<Object>[] contours = getContours(); + if (contours != null) { + for (int i = contours.length; --i >= 0;) { + float value = ((Float) contours[i].get(JvxlCoder.CONTOUR_VALUE)) + .floatValue(); + short[] colix = ((short[]) contours[i].get(JvxlCoder.CONTOUR_COLIX)); + colix[0] = ce.getColorIndex(value); + int[] color = ((int[]) contours[i].get(JvxlCoder.CONTOUR_COLOR)); + color[0] = Graphics3D.getArgb(colix[0]); + } + } + //TODO -- still not right. + if (contourValues != null) { + contourColixes = new short[contourValues.length]; + for (int i = 0; i < contourValues.length; i++) + contourColixes[i] = ce.getColorIndex(contourValues[i]); + setDiscreteColixes(null, null); + } + jvxlData.isJvxlPrecisionColor = true; + JvxlCoder.jvxlCreateColorData(jvxlData, vertexValues); + setColorCommand(); + isColorSolid = false; + } + //private void dumpData() { - //for (int i =0;i<10;i++) { - // System.out.println("P["+i+"]="+polygonIndexes[i][0]+" "+polygonIndexes[i][1]+" "+polygonIndexes[i][2]+" "+ polygonIndexes[i][3]+" "+vertices[i]); - //} + //for (int i =0;i<10;i++) { + // System.out.println("P["+i+"]="+polygonIndexes[i][0]+" "+polygonIndexes[i][1]+" "+polygonIndexes[i][2]+" "+ polygonIndexes[i][3]+" "+vertices[i]); //} + //} } Modified: trunk/Jmol/src/org/jmol/shapesurface/LcaoCartoon.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/LcaoCartoon.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/shapesurface/LcaoCartoon.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -312,7 +312,7 @@ if (isCpk) { short colix = viewer.getModelSet().getAtomColix(iAtom); if (Graphics3D.isColixTranslucent(colix)) { - super.setProperty("translucentLevel", new Float(Graphics3D.translucencyFractionalFromColix(colix)), null); + super.setProperty("translucentLevel", new Float(Graphics3D.getColixTranslucencyFractional(colix)), null); super.setProperty("translucency", "translucent", null); } } else if (isTranslucent) Modified: trunk/Jmol/src/org/jmol/util/ColorEncoder.java =================================================================== --- trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -662,8 +662,14 @@ String name = entry.getKey(); if (name.length() > 0 & n++ >= 0) s.append("color \"" + name + "=" - + ColorEncoder.getColorSchemeList(entry.getValue()) + "\";\n"); + + getColorSchemeList(entry.getValue()) + "\";\n"); } return n; } + + public String getColorScheme() { + return (isTranslucent ? "translucent " : "") + + (currentPalette < 0 ? getColorSchemeList(getColorSchemeArray(currentPalette)) + : getColorSchemeName(currentPalette)); + } } Modified: trunk/Jmol/src/org/jmol/util/XmlUtil.java =================================================================== --- trunk/Jmol/src/org/jmol/util/XmlUtil.java 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/util/XmlUtil.java 2011-06-17 13:05:48 UTC (rev 15604) @@ -69,6 +69,8 @@ if (attributes != null) for (int i = 0; i < attributes.length; i++) { Object o = attributes[i]; + if (o == null) + continue; if (o instanceof Object[]) appendAttrib(sb, ((Object[]) o)[0], ((Object[]) o)[1]); else Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-06-16 15:23:30 UTC (rev 15603) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-06-17 13:05:48 UTC (rev 15604) @@ -3,9 +3,18 @@ version=12.1.50_dev +# new feature: JVXL files now save and return color and colorscheme information +# +# new feature: color isosurface {atom expression} <color> +# -- specific to surface types (vdw, molecular, sasurface) +# -- similar to PyMOL command "set surface_color, (color), (selection)" +# -- allows painting of specific atom-related isosurface areas specific colors +# -- example: isosurface molecular; color isosurface {hydrophobic} white +# +# new feature: super-fast isosurface MAP PROPERTY when isosurfacePropertySmoothing = false +# # code: Renderers made entirely independent -# new feature: super-fast isosurface MAP PROPERTY when isosurfacePropertySmoothing = false - +# # new feature: set defaultLabelPDB "%m%r" -- for set picking LABEL (typically labeling groups) # new feature: set defaultLabelXYZ "%a" -- for set picking LABEL (typically labeling atoms) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |