From: <ha...@us...> - 2007-03-13 14:09:44
|
Revision: 7097 http://svn.sourceforge.net/jmol/?rev=7097&view=rev Author: hansonr Date: 2007-03-13 07:09:39 -0700 (Tue, 13 Mar 2007) Log Message: ----------- 11.1.21 numerical translucency now part of state; fix state bug for color elements Modified Paths: -------------- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/viewer/Axes.java trunk/Jmol/src/org/jmol/viewer/Bbcage.java trunk/Jmol/src/org/jmol/viewer/ColorManager.java trunk/Jmol/src/org/jmol/viewer/Dots.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/FontLineShape.java trunk/Jmol/src/org/jmol/viewer/Frank.java trunk/Jmol/src/org/jmol/viewer/Halos.java trunk/Jmol/src/org/jmol/viewer/Labels.java trunk/Jmol/src/org/jmol/viewer/Shape.java trunk/Jmol/src/org/jmol/viewer/StateManager.java trunk/Jmol/src/org/jmol/viewer/Uccage.java Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -1510,7 +1510,7 @@ they are 'screened' where every-other pixel is turned on. - 0x8000 changable flag (elements and isotopes, about 200; negative) + 0x8000 changeable flag (elements and isotopes, about 200; negative) 0x4000 translucent flag 0x3000 translucent level @@ -1561,7 +1561,7 @@ public final static short INHERIT_ALL = 0; private final static short INHERIT_OPAQUE = 1; private final static short INHERIT_TRANSLUCENT = 1 | TRANSLUCENT_FLAG; - public final static short USE_PALETTE = 2; + public final static short USE_PALETTE = 2; final static short UNUSED_OPTION3 = 3; final static short SPECIAL_COLIX_MAX = 4; @@ -1674,9 +1674,18 @@ private final static short applyColorTranslucencyLevel(short colix, float translucentLevel) { - // 0.01 to 1.0 ==> MORE translucent - // 0 1/2, 3/4, 7/8, 1 - // 128 192 224 + // 0.0 to 1.0 ==> MORE translucent + // 1/2, 3/4, 7/8, 1 + // t 128 192 224 256 + // 256-t 128 64 32 0 + // log(256-t) 7 6 5 -inf + // x = 8-log(256-t) 1 2 3 inf + + // t = (2 << 8) - (2 << (8 - x)) + // 256 and 0 have no representations because "translucent 256" is hidden and "translucent 0" is opaque. + // we are not going to fuss over 255/256 business! The point here is to use 256 so that we + // have an easily dividable range starting with 0. + if (translucentLevel < 0) //old Jmol 10.0 return (short) (colix & ~TRANSLUCENT_MASK | TRANSLUCENT_FLAG); if (translucentLevel == 0) //opaque @@ -1686,6 +1695,17 @@ return (short) (colix & ~TRANSLUCENT_MASK | TRANSLUCENT_FLAG | (iLevel << TRANSLUCENT_SHIFT)); } + public final static int getColixTranslucencyLevel(short colix) { + int logAlpha = (colix >> TRANSLUCENT_SHIFT) & 3; + switch (logAlpha) { + case 1: + case 2: + case 3: + return (1 << 8) - (1 << ((1 << 3) - logAlpha)); + } + return -1; + } + public final static short getColix(Object obj) { if (obj == null) return INHERIT_ALL; @@ -1711,7 +1731,7 @@ public int getColixArgb(short colix) { if (colix < 0) - colix = changableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; + colix = changeableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; if (! inGreyscaleMode) return Colix.getArgb(colix); return Colix.getArgbGreyscale(colix); @@ -1719,13 +1739,13 @@ public int[] getShades(short colix) { if (colix < 0) - colix = changableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; + colix = changeableColixMap[colix & UNMASK_CHANGEABLE_TRANSLUCENT]; if (! inGreyscaleMode) return Colix.getShades(colix); return Colix.getShadesGreyscale(colix); } - public final static short getChangableColixIndex(short colix) { + public final static short getChangeableColixIndex(short colix) { if (colix >= 0) return -1; return (short)(colix & UNMASK_CHANGEABLE_TRANSLUCENT); @@ -1752,6 +1772,16 @@ } } + public final static boolean isColixColorInherited(short colix) { + switch (colix) { + case INHERIT_ALL: + case INHERIT_OPAQUE: + return true; + default: //could be translucent of some sort + return (colix & OPAQUE_MASK) == INHERIT_OPAQUE; + } + } + //no references: /* @@ -1766,10 +1796,10 @@ public final short getColixMix(short colixA, short colixB) { return Colix.getColixMix(colixA >= 0 ? colixA : - changableColixMap[colixA & + changeableColixMap[colixA & UNMASK_CHANGEABLE_TRANSLUCENT], colixB >= 0 ? colixB : - changableColixMap[colixB & + changeableColixMap[colixB & UNMASK_CHANGEABLE_TRANSLUCENT]); } */ @@ -1792,29 +1822,29 @@ } /**************************************************************** - * changable colixes + * changeable colixes * give me a short ID and a color, and I will give you a colix * later, you can reassign the color if you want * Used only for colorManager coloring of elements ****************************************************************/ - short[] changableColixMap = new short[16]; + private short[] changeableColixMap = new short[16]; - public short getChangableColix(short id, int argb) { - if (id >= changableColixMap.length) { + public short getChangeableColix(short id, int argb) { + if (id >= changeableColixMap.length) { short[] t = new short[id + 16]; - System.arraycopy(changableColixMap, 0, t, 0, changableColixMap.length); - changableColixMap = t; + System.arraycopy(changeableColixMap, 0, t, 0, changeableColixMap.length); + changeableColixMap = t; } - if (changableColixMap[id] == 0) - changableColixMap[id] = Colix.getColix(argb); + if (changeableColixMap[id] == 0) + changeableColixMap[id] = Colix.getColix(argb); //System.out.println("changeable colix "+Integer.toHexString(id | CHANGEABLE_MASK) + " = "+Integer.toHexString(argb)); return (short)(id | CHANGEABLE_MASK); } public void changeColixArgb(short id, int argb) { - if (id < changableColixMap.length && changableColixMap[id] != 0) - changableColixMap[id] = Colix.getColix(argb); + if (id < changeableColixMap.length && changeableColixMap[id] != 0) + changeableColixMap[id] = Colix.getColix(argb); } /* *************************************************************** Modified: trunk/Jmol/src/org/jmol/viewer/Axes.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Axes.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Axes.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -50,6 +50,7 @@ void initShape() { myType = "axes"; font3d = g3d.getFont3D(JmolConstants.AXES_DEFAULT_FONTSIZE); + super.initShape(); int axesMode = viewer.getAxesMode(); if (axesMode == JmolConstants.AXES_MODE_UNITCELL && frame.cellInfos != null) { UnitCell unitcell = viewer.getCurrentUnitCell(); Modified: trunk/Jmol/src/org/jmol/viewer/Bbcage.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Bbcage.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Bbcage.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -31,5 +31,6 @@ void initShape() { myType = "boundBox"; + super.initShape(); } } Modified: trunk/Jmol/src/org/jmol/viewer/ColorManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -141,20 +141,20 @@ // therefore, a changable colix is allocated in this case id = atom.getAtomicAndIsotopeNumber(); if (id < 256) - return g3d.getChangableColix(id, argbsCpk[id]); + return g3d.getChangeableColix(id, argbsCpk[id]); id = (short) JmolConstants.altElementIndexFromNumber(id); - return g3d.getChangableColix((short) (JmolConstants.elementNumberMax + id), + return g3d.getChangeableColix((short) (JmolConstants.elementNumberMax + id), altArgbsCpk[id]); case JmolConstants.PALETTE_PARTIAL_CHARGE: // This code assumes that the range of partial charges is [-1, 1]. index = quantize(atom.getPartialCharge(), -1, 1, JmolConstants.PARTIAL_CHARGE_RANGE_SIZE); - return g3d.getChangableColix( + return g3d.getChangeableColix( (short) (JmolConstants.PARTIAL_CHARGE_COLIX_RED + index), JmolConstants.argbsRwbScale[index]); case JmolConstants.PALETTE_FORMAL_CHARGE: index = atom.getFormalCharge() - JmolConstants.FORMAL_CHARGE_MIN; - return g3d.getChangableColix( + return g3d.getChangeableColix( (short) (JmolConstants.FORMAL_CHARGE_COLIX_RED + index), JmolConstants.argbsFormalCharge[index]); case JmolConstants.PALETTE_TEMP: Modified: trunk/Jmol/src/org/jmol/viewer/Dots.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Dots.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Dots.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -168,7 +168,6 @@ } void initShape() { - Logger.debug("init dots"); dotsRenderer = (DotsRenderer)frame.getRenderer(JmolConstants.SHAPE_DOTS); geodesicVertices = dotsRenderer.geodesic.vertices; geodesicCount = geodesicVertices.length; @@ -177,6 +176,7 @@ geodesicSolventCount = geodesicSolventVertices.length; geodesicSolventMap = allocateBitmap(geodesicSolventCount); mapT = allocateBitmap(geodesicSolventCount); + translucentAllowed = false; //except for geosurface super.initShape(); } Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -3110,61 +3110,66 @@ String str = parameterAsString(1); argb = getArgbOrPaletteParam(2); checkStatementLength(iToken + 1); - if (str.equalsIgnoreCase("axes")) { - setStringProperty("axesColor", StateManager.escapeColor(argb)); - return; - }else if (StateManager.getObjectIdFromName(str) >= 0) { + if (str.equalsIgnoreCase("axes")) { + setStringProperty("axesColor", StateManager.escapeColor(argb)); + return; + } else if (StateManager.getObjectIdFromName(str) >= 0) { if (!isSyntaxCheck) viewer.setObjectArgb(str, argb); return; } - for (int i = JmolConstants.elementNumberMax; --i >= 0;) { - if (str.equalsIgnoreCase(JmolConstants.elementNameFromNumber(i))) { - if (!isSyntaxCheck) - viewer.setElementArgb(i, argb); - return; - } - } - for (int i = JmolConstants.altElementMax; --i >= 0;) { - if (str.equalsIgnoreCase(JmolConstants.altElementNameFromIndex(i))) { - if (!isSyntaxCheck) - viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), - argb); - return; - } - } - if (str.charAt(0) == '_') { - for (int i = JmolConstants.elementNumberMax; --i >= 0;) { - if (str.equalsIgnoreCase("_" - + JmolConstants.elementSymbolFromNumber(i))) { - if (!isSyntaxCheck) - viewer.setElementArgb(i, argb); - return; - } - } - for (int i = JmolConstants.altElementMax; --i >= JmolConstants.firstIsotope;) { - if (str.equalsIgnoreCase("_" - + JmolConstants.altElementSymbolFromIndex(i))) { - if (!isSyntaxCheck) - viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), - argb); - return; - } - if (str.equalsIgnoreCase("_" - + JmolConstants.altIsotopeSymbolFromIndex(i))) { - if (!isSyntaxCheck) - viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), - argb); - return; - } - } - } + if (changeElementColor(str, argb)) + return; invalidArgument(); default: colorObject(theTok, 2); } } + private boolean changeElementColor(String str, int argb) { + for (int i = JmolConstants.elementNumberMax; --i >= 0;) { + if (str.equalsIgnoreCase(JmolConstants.elementNameFromNumber(i))) { + if (!isSyntaxCheck) + viewer.setElementArgb(i, argb); + return true; + } + } + for (int i = JmolConstants.altElementMax; --i >= 0;) { + if (str.equalsIgnoreCase(JmolConstants.altElementNameFromIndex(i))) { + if (!isSyntaxCheck) + viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), + argb); + return true; + } + } + if (str.charAt(0) != '_') + return false; + for (int i = JmolConstants.elementNumberMax; --i >= 0;) { + if (str.equalsIgnoreCase("_" + JmolConstants.elementSymbolFromNumber(i))) { + if (!isSyntaxCheck) + viewer.setElementArgb(i, argb); + return true; + } + } + for (int i = JmolConstants.altElementMax; --i >= JmolConstants.firstIsotope;) { + if (str + .equalsIgnoreCase("_" + JmolConstants.altElementSymbolFromIndex(i))) { + if (!isSyntaxCheck) + viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), + argb); + return true; + } + if (str + .equalsIgnoreCase("_" + JmolConstants.altIsotopeSymbolFromIndex(i))) { + if (!isSyntaxCheck) + viewer.setElementArgb(JmolConstants.altElementNumberFromIndex(i), + argb); + return true; + } + } + return false; + } + void colorNamedObject(int index) throws ScriptException { // color $ whatever green int shapeType = setShapeByNameParameter(index); Modified: trunk/Jmol/src/org/jmol/viewer/FontLineShape.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/FontLineShape.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/FontLineShape.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -35,6 +35,10 @@ Font3D font3d; String myType; + void initShape() { + translucentAllowed = false; + } + void setProperty(String propertyName, Object value, BitSet bs) { if ("font" == propertyName) { font3d = (Font3D)value; Modified: trunk/Jmol/src/org/jmol/viewer/Frank.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Frank.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Frank.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -47,6 +47,7 @@ void initShape() { myType = "frank"; font3d = g3d.getFont3D(defaultFontName, defaultFontStyle, defaultFontSize); + super.initShape(); } boolean wasClicked(int x, int y) { Modified: trunk/Jmol/src/org/jmol/viewer/Halos.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Halos.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Halos.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -28,11 +28,17 @@ import java.util.BitSet; import org.jmol.g3d.Graphics3D; +import org.jmol.util.Logger; class Halos extends AtomShape { short colixSelection = Graphics3D.USE_PALETTE; + void initState() { + Logger.debug("init halos"); + translucentAllowed = false; + } + void setProperty(String propertyName, Object value, BitSet bs) { if ("translucency" == propertyName) return; Modified: trunk/Jmol/src/org/jmol/viewer/Labels.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Labels.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Labels.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -72,6 +72,7 @@ defaultBgcolix = 0; //"none" -- off defaultOffset = zeroOffset = (JmolConstants.LABEL_DEFAULT_X_OFFSET << 8) | JmolConstants.LABEL_DEFAULT_Y_OFFSET; + translucentAllowed = false; super.initShape(); } Modified: trunk/Jmol/src/org/jmol/viewer/Shape.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Shape.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Shape.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -71,7 +71,8 @@ int shapeID; int myVisibilityFlag; float translucentLevel; - + boolean translucentAllowed = true; + final void setViewerG3dFrame(Viewer viewer, Graphics3D g3d, Frame frame, int shapeID) { this.viewer = viewer; @@ -90,10 +91,10 @@ void setProperty(String propertyName, Object value, BitSet bsSelected) { if (propertyName == "translucentLevel") { - translucentLevel = ((Float)value).floatValue(); + translucentLevel = ((Float) value).floatValue(); return; } - + Logger.warn("unassigned shape setProperty:" + propertyName + ":" + value); } @@ -123,7 +124,7 @@ } boolean checkObjectDragged(int prevX, int prevY, int deltaX, int deltaY, - int modifiers) { + int modifiers) { return false; } @@ -185,17 +186,13 @@ String getColorCommand(String type, byte pid, short colix) { if (pid == JmolConstants.PALETTE_UNKNOWN && colix == Graphics3D.INHERIT_ALL) return ""; - return "color " + type + " " + encodeTransColor(pid, colix); + return "color " + type + " " + encodeTransColor(pid, colix, translucentAllowed); } - String encodeTransColor(short colix) { - return encodeTransColor(JmolConstants.PALETTE_UNKNOWN, colix); - } - - String encodeTransColor(byte pid, short colix) { + private String encodeTransColor(byte pid, short colix, + boolean translucentAllowed) { if (pid == JmolConstants.PALETTE_UNKNOWN && colix == Graphics3D.INHERIT_ALL) return ""; - String s = ""; /* nuance here is that some palettes depend upon a * point-in-time calculation that takes into account * some aspect of the current state, such as what groups @@ -204,26 +201,27 @@ * Serialization of the palette name is just a convenience * anyway. */ - if (pid != JmolConstants.PALETTE_UNKNOWN - && !JmolConstants.isPaletteVariable(pid)) { - if (Graphics3D.isColixTranslucent(colix)) - s += "translucent "; - s += JmolConstants.getPaletteName(pid); - } else { - s += encodeColor(colix); - } - return s; + return (translucentAllowed ? getTranslucentLabel(colix) + " " : "") + + (pid != JmolConstants.PALETTE_UNKNOWN + && !JmolConstants.isPaletteVariable(pid) + ? JmolConstants.getPaletteName(pid) : encodeColor(colix)); } String encodeColor(short colix) { - return (Graphics3D.isColixTranslucent(colix) ? "translucent " : "") - + (colix == 0 ? "none" : StateManager.escapeColor(g3d.getColixArgb(colix))); + // used also by labels for background state (no translucent issues there?) + return (Graphics3D.isColixColorInherited(colix) ? "none" : StateManager + .escapeColor(g3d.getColixArgb(colix))); } + private static String getTranslucentLabel(short colix) { + return (Graphics3D.isColixTranslucent(colix) ? "translucent " + + Graphics3D.getColixTranslucencyLevel(colix): "opaque"); + } + static short getColix(short[] colixes, int i, Atom atom) { return Graphics3D.getColixInherited( (colixes == null || i >= colixes.length ? Graphics3D.INHERIT_ALL : colixes[i]), atom.colixAtom); - } + } } Modified: trunk/Jmol/src/org/jmol/viewer/StateManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/StateManager.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/StateManager.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -771,8 +771,10 @@ if (key.charAt(0) != '@' && doRegister(key)) { Object value = htParameterValues.get(key); if (key.charAt(0) == '_') { - key = key.substring(1); + key = key.substring(1) + " "; } else { + if (key.indexOf("default") == 0) + key = " " + key; key += " = "; if (value instanceof String) value = escape((String) value); Modified: trunk/Jmol/src/org/jmol/viewer/Uccage.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Uccage.java 2007-03-13 07:17:36 UTC (rev 7096) +++ trunk/Jmol/src/org/jmol/viewer/Uccage.java 2007-03-13 14:09:39 UTC (rev 7097) @@ -33,5 +33,6 @@ void initShape() { myType = "unitcell"; + super.initShape(); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |