From: <ha...@us...> - 2011-08-17 04:39:41
|
Revision: 15973 http://jmol.svn.sourceforge.net/jmol/?rev=15973&view=rev Author: hansonr Date: 2011-08-17 04:39:34 +0000 (Wed, 17 Aug 2011) Log Message: ----------- version=12.2.RC5_dev # new feature: isosurface KEY ON|OFF # -- creates a vertical hoverable key on the left # -- only the most recent and visible isosurface # -- is not exported # -- not for contoured isosurface (yet) Modified Paths: -------------- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/script/Token.java trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java trunk/Jmol/src/org/jmol/util/ColorEncoder.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -16318,6 +16318,18 @@ propertyName = "scale3d"; propertyValue = Float.valueOf(floatParameter(++i)); break; + case Token.key: + propertyName = "key"; + switch (getToken(++i).tok) { + case Token.on: + case Token.off: + propertyValue = Integer.valueOf(tokAt(i)); + break; + default: + error(ERROR_invalidArgument); + break; + } + break; case Token.period: sbCommand.append(" periodic"); propertyName = "periodic"; Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -2675,7 +2675,7 @@ return addX(ScriptVariable.sizeOf(x2)); case Token.type: return addX(ScriptVariable.typeOf(x2)); - case Token.keys: + case Token.key: if (x2.tok != Token.hash) return addX(""); Object[] keys = ((Map<String, ScriptVariable>) x2.value).keySet() Modified: trunk/Jmol/src/org/jmol/script/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/script/Token.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/script/Token.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -545,7 +545,7 @@ public final static int unitxyz =13 | mathproperty | atomproperty; public final static int vibxyz =14 | mathproperty | atomproperty | settable; final static int w =15 | mathproperty; - final static int keys =16 | mathproperty; + final static int key =16 | mathproperty; // occupancy, radius, and structure are odd, because they takes different meanings when compared @@ -1827,7 +1827,8 @@ "isAromatic", new Token(isaromatic), "Jmol", new Token(jmol), "join", new Token(join), - "keys", new Token(keys), + "key", new Token(key), + "keys", null, "last", new Token(last), "left", new Token(left), "length", new Token(length), Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -197,6 +197,7 @@ //private boolean allowContourLines; boolean allowMesh = true; + int showKey; @SuppressWarnings("unchecked") @Override @@ -210,6 +211,12 @@ navigate(((Integer) value).intValue()); return; } + if ("key" == propertyName) { + // assuming LEFT for now + int iValue = ((Integer) value).intValue(); + showKey = (iValue == Token.off ? 0 : iValue); + return; + } if ("delete" == propertyName) { setPropertySuper(propertyName, value, bs); if (!explicitID) @@ -1404,6 +1411,10 @@ @Override public boolean checkObjectHovered(int x, int y, BitSet bsVisible) { + if (keyXy != null && x >= keyXy[0] && y >= keyXy[1] && x < keyXy[2] && y < keyXy[3]) { + hoverKey(x, y); + return true; + } if (!viewer.getDrawHover()) return false; String s = findValue(x, y, false, bsVisible); @@ -1418,8 +1429,21 @@ return true; } + private void hoverKey(int x, int y) { + try { + float f = 1 - 1.0f * (y - keyXy[1]) / (keyXy[3] - keyXy[1]); + f = thisMesh.colorEncoder.unquantize(f); + float g = 1 - 1.0f * (y - keyXy[1] + keyXy[4]) / (keyXy[3] - keyXy[1]); + g = thisMesh.colorEncoder.unquantize(g); + String s = "" + g + " - " + f; + viewer.hoverOn(x, y, s); + } catch (Exception e) { + // never mind! + } + } private final static int MAX_OBJECT_CLICK_DISTANCE_SQUARED = 10 * 10; private final Point3i ptXY = new Point3i(); + int[] keyXy; @Override public Point3fi checkObjectClicked(int x, int y, int action, BitSet bsVisible) { Modified: trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -42,10 +42,13 @@ protected int nError = 0; protected float[] vertexValues; protected IsosurfaceMesh imesh; - + private Isosurface isosurface; private boolean isNavigationMode; private boolean iShowNormals; private boolean showNumbers; + private Boolean showKey; + private boolean haveVertexColors; + @Override protected void initRenderer() { @@ -56,16 +59,22 @@ iShowNormals = viewer.getTestFlag(4); showNumbers = viewer.getTestFlag(3); isExport = (exportType != Graphics3D.EXPORT_NOT); - Isosurface isosurface = (Isosurface) shape; + isosurface = (Isosurface) shape; exportPass = (isExport ? 2 : 0); isNavigationMode = viewer.getNavigationMode(); int mySlabValue = Integer.MAX_VALUE; int slabValue = g3d.getSlab(); + showKey = (isosurface.showKey != 0 ? Boolean.TRUE : null); if (isNavigationMode) mySlabValue = (int) viewer.getNavigationOffset().z; + isosurface.keyXy = null; for (int i = isosurface.meshCount; --i >= 0;) { imesh = (IsosurfaceMesh) isosurface.meshes[i]; + haveVertexColors = false; renderMesh(mySlabValue, slabValue); + if (!isExport && haveVertexColors && imesh.colorEncoder != null && Boolean.TRUE == showKey) { + showKey(); + } if (isExport && haveBsSlabGhost) { exportPass = 1; renderMesh(mySlabValue, slabValue); @@ -74,6 +83,23 @@ } } + private void showKey() { + showKey = Boolean.FALSE; // once only + int[] colors = imesh.colorEncoder.getColorSchemeArray(imesh.colorEncoder.currentPalette); + int height = viewer.getScreenHeight(); + // todo: antialiasdisplay? + int dy = height / 2 / colors.length; + int y = height / 4 * 3; + int x = 10; + int dx = 20; + isosurface.keyXy = new int[] { x, 0, x + dx, y + dy, dy }; + for (int i = 0; i < colors.length; i++, y -= dy) { + g3d.setColor(colors[i]); + g3d.fillRect(x, y, 5, 5, dx, dy); + } + isosurface.keyXy[1] = y + dy; + } + private void renderMesh(int mySlabValue, int slabValue) { volumeRender = (imesh.jvxlData.colorDensity && imesh.jvxlData.allowVolumeRender); if (!isNavigationMode) { @@ -297,10 +323,10 @@ short[] contourColixes = imesh.jvxlData.contourColixes; // two-sided means like a plane, with no front/back distinction + haveVertexColors = !colorSolid; for (int i = imesh.polygonCount; --i >= 0;) { int[] vertexIndexes = polygonIndexes[i]; if (vertexIndexes == null || haveBsSlabDisplay && !bsSlab.get(i)) - continue; int iA = vertexIndexes[0]; int iB = vertexIndexes[1]; Modified: trunk/Jmol/src/org/jmol/util/ColorEncoder.java =================================================================== --- trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2011-08-17 04:39:34 UTC (rev 15973) @@ -132,6 +132,7 @@ public int currentPalette = ROYGB; + public int currentSegmentCount = 1; public boolean isTranslucent = false; public float lo; public float hi; @@ -606,6 +607,10 @@ return propertyColorEncoder.paletteBW = b; } + public float unquantize(float x) { + return (x <= 0 ? lo : x >= 1 ? hi : lo + (hi - lo) * x); + } + public final static int quantize(float val, float lo, float hi, int segmentCount) { /* oy! Say you have an array with 10 values, so segmentCount=10 * then we expect 0,1,2,...,9 EVENLY Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-08-16 19:01:59 UTC (rev 15972) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2011-08-17 04:39:34 UTC (rev 15973) @@ -3,6 +3,11 @@ version=12.2.RC5_dev +# new feature: isosurface KEY ON|OFF +# -- creates a vertical hoverable key on the left +# -- only the most recent and visible isosurface +# -- is not exported +# -- not for contoured isosurface (yet) # -------------------------------------------------------------- #version=12.2.RC4 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |