From: <ha...@us...> - 2007-09-01 19:52:35
|
Revision: 8183 http://jmol.svn.sourceforge.net/jmol/?rev=8183&view=rev Author: hansonr Date: 2007-09-01 12:52:24 -0700 (Sat, 01 Sep 2007) Log Message: ----------- 11.3.14 # new feature: expanded color command for properties # # color atoms property partialcharge "rwb" range -1.0 1.0 # # and reverse with range inverted: # # color atoms property partialcharge "rwb" range 1.0 -1.0 # new feature: fully remappable isosurface using COLOR command: # # isosurface s1 molecular map mep # color $s1 "bwr" # color $s1 "rwb" range -0.2 0.2 # color $s1 range 0 10 Modified Paths: -------------- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java trunk/Jmol/src/org/jmol/jvxl/readers/VoxelReader.java trunk/Jmol/src/org/jmol/shape/Mesh.java trunk/Jmol/src/org/jmol/shape/MeshCollection.java trunk/Jmol/src/org/jmol/shape/Shape.java trunk/Jmol/src/org/jmol/shapespecial/Isosurface.java trunk/Jmol/src/org/jmol/util/ColorEncoder.java trunk/Jmol/src/org/jmol/viewer/ColorManager.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/Viewer.java Modified: trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/jvxl/data/JvxlData.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -139,6 +139,7 @@ public boolean isJvxlPrecisionColor; public boolean jvxlDataIsColorMapped; public boolean jvxlDataIs2dContour; + public boolean isColorReversed; public int edgeFractionBase; public int edgeFractionRange; @@ -148,6 +149,7 @@ public boolean isXLowToHigh; public boolean isContoured; public boolean isBicolorMap; + public boolean isTruncated; public float mappedDataMin; public float mappedDataMax; public float valueMappedToRed; @@ -159,9 +161,12 @@ public int nContours; public int nEdges; public int nSurfaceInts; + public int vertexCount; + public short minColorIndex = -1; + public short maxColorIndex = 0; + public String[] title; - } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -45,10 +45,13 @@ protected static void jvxlUpdateInfo(JvxlData jvxlData, String[] title, int nBytes) { jvxlData.title = title; jvxlData.nBytes = nBytes; + jvxlUpdateInfoLines(jvxlData); + } + + public static void jvxlUpdateInfoLines(JvxlData jvxlData) { jvxlData.jvxlDefinitionLine = jvxlGetDefinitionLine(jvxlData, false); jvxlData.jvxlInfoLine = jvxlGetDefinitionLine(jvxlData, true); } - //// methods used for reading any file format, but creating a JVXL file /////////////reading the format/////////// @@ -492,7 +495,7 @@ float contourPlaneMaximumValue = -Float.MAX_VALUE; if (colixes == null || colixes.length < vertexCount) meshData.vertexColixes = colixes = new short[vertexCount]; - int n = (vertexCount); + jvxlData.vertexCount = vertexCount; String data = jvxlColorDataRead; int cpt = 0; short colixNeg = 0, colixPos = 0; @@ -504,7 +507,7 @@ .getColorIndex(params.isColorReversed ? params.colorPos : params.colorNeg); } - for (int i = 0; i < n; i++) { + for (int i = 0; i < vertexCount; i++) { float fraction, value; if (jvxlDataIsPrecisionColor) { // this COULD be an option for mapped surfaces; @@ -514,7 +517,7 @@ // the two parts of the "double-character-precision" value // are in separate lines, separated by n characters. fraction = jvxlFractionFromCharacter2(data.charAt(cpt), data.charAt(cpt - + n), colorFractionBase, colorFractionRange); + + vertexCount), colorFractionBase, colorFractionRange); value = min + fraction * range; } else { // my original encoding scheme @@ -660,7 +663,7 @@ } sb.append(' ').append(dataCount).append('\n'); ++nSurfaceInts; - JvxlReader.setSurfaceInfo(jvxlData,null, nSurfaceInts, sb); + setSurfaceInfo(jvxlData,null, nSurfaceInts, sb); return nDataPoints; } @@ -917,5 +920,42 @@ jvxlData.jvxlEdgeData = String.copyValueOf(chars); } + public static void jvxlCreateColorData(JvxlData jvxlData, float[] vertexValues) { + if (vertexValues == null) { + jvxlData.jvxlColorData = ""; + return; + } + boolean writePrecisionColor = jvxlData.isJvxlPrecisionColor; + boolean doTruncate = jvxlData.isTruncated; + int colorFractionBase = jvxlData.colorFractionBase; + int colorFractionRange = jvxlData.colorFractionRange; + float valueBlue = jvxlData.valueMappedToBlue; + float valueRed = jvxlData.valueMappedToRed; + int vertexCount = jvxlData.vertexCount; + float min = jvxlData.mappedDataMin; + float max = jvxlData.mappedDataMax; + StringBuffer list = null, list1 = null; + list = new StringBuffer(); + list1 = new StringBuffer(); + char[] remainder = new char[1]; + for (int i = 0; i < vertexCount; i++) { + float value = vertexValues[i]; + if (doTruncate) + value = (value > 0 ? 0.999f : -0.999f); + char ch; + if (writePrecisionColor) { + ch = jvxlValueAsCharacter2(value, min, max, + colorFractionBase, colorFractionRange, remainder); + list1.append(remainder[0]); + } else { + //isColorReversed + ch = jvxlValueAsCharacter(value, valueRed, + valueBlue, colorFractionBase, colorFractionRange); + } + list.append(ch); + } + jvxlData.jvxlColorData = list.append(list1).append('\n').toString(); + jvxlUpdateInfoLines(jvxlData); + } } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/VoxelReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/VoxelReader.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/jvxl/readers/VoxelReader.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -35,7 +35,7 @@ import org.jmol.jvxl.api.*; public abstract class VoxelReader implements VertexDataServer { - + /* * JVXL VoxelReader Class * ---------------------- @@ -137,25 +137,25 @@ * given below: * -#comments (optional) -info line1 -info line2 --na originx originy originz [ANGSTROMS/BOHR] optional; BOHR assumed -n1 x y z -n2 x y z -n3 x y z -a1 a1.0 x y z -a2 a2.0 x y z -a3 a3.0 x y z -a4 a4.0 x y z -etc. -- na atoms --ns 35 90 35 90 Jmol voxel format version 1.0 -# more comments -cutoff +/-nEdges +/-nVertices [more here] -integer inside/outside edge data -ascii-encoded fractional edge data -ascii-encoded fractional color data -# optional comments + #comments (optional) + info line1 + info line2 + -na originx originy originz [ANGSTROMS/BOHR] optional; BOHR assumed + n1 x y z + n2 x y z + n3 x y z + a1 a1.0 x y z + a2 a2.0 x y z + a3 a3.0 x y z + a4 a4.0 x y z + etc. -- na atoms + -ns 35 90 35 90 Jmol voxel format version 1.0 + # more comments + cutoff +/-nEdges +/-nVertices [more here] + integer inside/outside edge data + ascii-encoded fractional edge data + ascii-encoded fractional color data + # optional comments * * @@ -165,18 +165,18 @@ protected SurfaceGenerator sg; protected MeshDataServer meshDataServer; - + protected ColorEncoder colorEncoder; - + protected Parameters params; protected MeshData meshData; protected JvxlData jvxlData; protected VolumeData volumeData; - + protected boolean isProgressive = false; protected boolean isXLowToHigh = false; //can be overridden in some readers by --progressive - private float assocCutoff = 0.3f; - + private float assocCutoff = 0.3f; + VoxelReader(SurfaceGenerator sg) { this.sg = sg; this.colorEncoder = sg.getColorEncoder(); @@ -190,7 +190,7 @@ this.meshDataServer = sg.getMeshDataServer(); cJvxlEdgeNaN = (char) (defaultEdgeFractionBase + defaultEdgeFractionRange); } - + final static float ANGSTROMS_PER_BOHR = 0.5291772f; final static int defaultEdgeFractionBase = 35; //#$%....... final static int defaultEdgeFractionRange = 90; @@ -201,7 +201,7 @@ final static float defaultCutoff = 0.02f; private int edgeCount; - + protected Point3f volumetricOrigin; protected Vector3f[] volumetricVectors; protected int[] voxelCounts; @@ -215,10 +215,11 @@ voxelData = v.voxelData; volumeData = v; } - + abstract void readVolumeParameters(); + abstract void readVolumeData(boolean isMapData); - + //////////////////////////////////////////////////////////////// // CUBE/APBS/JVXL file reading stuff //////////////////////////////////////////////////////////////// @@ -236,18 +237,17 @@ protected StringBuffer jvxlFileHeaderBuffer; protected StringBuffer fractionData; - protected String jvxlEdgeDataRead = ""; - protected String jvxlColorDataRead = ""; + protected String jvxlEdgeDataRead = ""; + protected String jvxlColorDataRead = ""; protected boolean jvxlDataIsColorMapped; protected boolean jvxlDataIsPrecisionColor; protected boolean jvxlDataIs2dContour; - protected float jvxlCutoff; - protected int jvxlNSurfaceInts; - protected char cJvxlEdgeNaN; + protected float jvxlCutoff; + protected int jvxlNSurfaceInts; + protected char cJvxlEdgeNaN; - protected int contourVertexCount; - + void jvxlUpdateInfo() { JvxlReader.jvxlUpdateInfo(jvxlData, params.title, nBytes); } @@ -258,7 +258,7 @@ if (justForPlane) { volumeData.setDataDistanceToPlane(params.thePlane); if (meshDataServer != null) - meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES); + meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES); params.setMapRanges(this); } else { readVolumeData(false); @@ -314,13 +314,13 @@ } void discardTempData(boolean discardAll) { - if (!discardAll) + if (!discardAll) return; voxelData = null; sg.setMarchingSquares(marchingSquares = null); marchingCubes = null; } - + protected void initializeVolumetricData() { nPointsX = voxelCounts[0]; nPointsY = voxelCounts[1]; @@ -328,9 +328,9 @@ volumeData.setUnitVectors(); setVolumeData(volumeData); } - + // this needs to be specific for each reader - abstract protected void readVoxelData(boolean isMapData) throws Exception ; + abstract protected void readVoxelData(boolean isMapData) throws Exception; protected void gotoAndReadVoxelData(boolean isMapData) { initializeVolumetricData(); @@ -348,12 +348,12 @@ protected void gotoData(int n, int nPoints) throws Exception { //only for file reader } - + protected String readColorData() { //jvxl only -- overloaded return ""; } - + //////////////////////////////////////////////////////////////// // marching cube stuff //////////////////////////////////////////////////////////////// @@ -370,30 +370,31 @@ marchingSquares = new MarchingSquares(this, volumeData, params.thePlane, params.nContours, params.thisContour, params.contourFromZero); contourType = marchingSquares.getContourType(); - marchingSquares.setMinMax(params.valueMappedToRed, params.valueMappedToBlue); + marchingSquares.setMinMax(params.valueMappedToRed, + params.valueMappedToBlue); } - marchingCubes = new MarchingCubes(this, volumeData, - params.isContoured, contourType, - params.cutoff, params.isCutoffAbsolute); + marchingCubes = new MarchingCubes(this, volumeData, params.isContoured, + contourType, params.cutoff, params.isCutoffAbsolute); edgeCount = marchingCubes.generateSurfaceData(isXLowToHigh); - + if (isJvxl) fractionData = new StringBuffer(jvxlEdgeDataRead); fractionData.append('\n'); } - protected static boolean isInside(float voxelValue, float max, boolean isAbsolute) { + protected static boolean isInside(float voxelValue, float max, + boolean isAbsolute) { return MarchingCubes.isInside(voxelValue, max, isAbsolute); } ///////////////// MarchingReader Interface Methods /////////////////// - + protected final Point3f ptTemp = new Point3f(); final float[] fReturn = new float[1]; - + public int getSurfacePointIndex(float cutoff, boolean isCutoffAbsolute, int x, int y, int z, Point3i offset, int vA, int vB, float valueA, float valueB, @@ -413,70 +414,75 @@ return isContourType ? marchingSquares.addContourVertex(x, y, z, offset, ptTemp, cutoff) : Integer.MAX_VALUE; int assocVertex = (assocCutoff > 0 ? (fReturn[0] < assocCutoff ? vA - : fReturn[0] > 1 - assocCutoff ? vB : MarchingSquares.CONTOUR_POINT) : MarchingSquares.CONTOUR_POINT); + : fReturn[0] > 1 - assocCutoff ? vB : MarchingSquares.CONTOUR_POINT) + : MarchingSquares.CONTOUR_POINT); if (assocVertex >= 0) assocVertex = marchingCubes.getLinearOffset(x, y, z, assocVertex); int iV = addVertexCopy(ptTemp, thisValue, assocVertex); if (params.iAddGridPoints) { marchingCubes.calcVertexPoint(x, y, z, vB, ptTemp); - addVertexCopy(valueA < valueB ? pointA : ptTemp, Float.NaN, MarchingSquares.EDGE_POINT); - addVertexCopy(valueA < valueB ? ptTemp : pointA, Float.NaN, MarchingSquares.EDGE_POINT); + addVertexCopy(valueA < valueB ? pointA : ptTemp, Float.NaN, + MarchingSquares.EDGE_POINT); + addVertexCopy(valueA < valueB ? ptTemp : pointA, Float.NaN, + MarchingSquares.EDGE_POINT); } return iV; } - protected float readSurfacePoint(float cutoff, boolean isCutoffAbsolute, float valueA, - float valueB, Point3f pointA, Vector3f edgeVector, float[] fReturn) { + protected float readSurfacePoint(float cutoff, boolean isCutoffAbsolute, + float valueA, float valueB, Point3f pointA, + Vector3f edgeVector, float[] fReturn) { - //JvxlReader may or may not call this + //JvxlReader may or may not call this - float fraction, thisValue; - float diff = valueB - valueA; - fraction = (cutoff - valueA) / diff; - if (isCutoffAbsolute && (fraction < 0 || fraction > 1)) - fraction = (-cutoff - valueA) / diff; + float fraction, thisValue; + float diff = valueB - valueA; + fraction = (cutoff - valueA) / diff; + if (isCutoffAbsolute && (fraction < 0 || fraction > 1)) + fraction = (-cutoff - valueA) / diff; - if (fraction < 0 || fraction > 1) { - //Logger.error("problem with unusual fraction=" + fraction + " cutoff=" - // + cutoff + " A:" + valueA + " B:" + valueB); - fraction = Float.NaN; - } - fReturn[0] = fraction; - if (!isJvxl) - fractionData.append(JvxlReader.jvxlFractionAsCharacter(fraction, - edgeFractionBase, edgeFractionRange)); + if (fraction < 0 || fraction > 1) { + //Logger.error("problem with unusual fraction=" + fraction + " cutoff=" + // + cutoff + " A:" + valueA + " B:" + valueB); + fraction = Float.NaN; + } + fReturn[0] = fraction; + if (!isJvxl) + fractionData.append(JvxlReader.jvxlFractionAsCharacter(fraction, + edgeFractionBase, edgeFractionRange)); - thisValue = valueA + fraction * diff; - ptTemp.scaleAdd(fraction, edgeVector, pointA); - return thisValue; - } - + thisValue = valueA + fraction * diff; + ptTemp.scaleAdd(fraction, edgeVector, pointA); + return thisValue; + } + public int addVertexCopy(Point3f vertexXYZ, float value, int assocVertex) { if (meshDataServer == null) return meshData.addVertexCopy(vertexXYZ, value, assocVertex); return meshDataServer.addVertexCopy(vertexXYZ, value, assocVertex); } - - public void addTriangleCheck(int iA, int iB, int iC, int check, boolean isAbsolute) { + + public void addTriangleCheck(int iA, int iB, int iC, int check, + boolean isAbsolute) { if (meshDataServer == null) { - if (isAbsolute && !MeshData.checkCutoff(iA, iB, iC, meshData.vertexValues)) + if (isAbsolute + && !MeshData.checkCutoff(iA, iB, iC, meshData.vertexValues)) return; meshData.addTriangleCheck(iA, iB, iC, check); } else { meshDataServer.addTriangleCheck(iA, iB, iC, check, isAbsolute); } } - + //////////////////////////////////////////////////////////////////// - - - //////////////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////////////// // color mapping methods //////////////////////////////////////////////////////////////// void colorIsosurface() { if (params.isContoured && marchingSquares == null) { -// if (params.isContoured && !(jvxlDataIs2dContour || params.thePlane != null)) { + // if (params.isContoured && !(jvxlDataIs2dContour || params.thePlane != null)) { Logger.error("Isosurface error: Cannot contour this type of data."); return; } @@ -485,127 +491,119 @@ } if (params.isContoured) { params.setMapRanges(this); - marchingSquares.setMinMax(params.valueMappedToRed, params.valueMappedToBlue); - contourVertexCount = marchingSquares.generateContourData(jvxlDataIs2dContour); + marchingSquares.setMinMax(params.valueMappedToRed, + params.valueMappedToBlue); + contourVertexCount = marchingSquares + .generateContourData(jvxlDataIs2dContour); if (meshDataServer != null) meshDataServer.notifySurfaceGenerationCompleted(); } - + applyColorScale(); jvxlData.nContours = params.nContours; - jvxlData.jvxlExtraLine = JvxlReader.jvxlExtraLine(jvxlData,1); - - jvxlData.jvxlFileMessage = "mapped: min = " + params.valueMappedToRed + "; max = " - + params.valueMappedToBlue; + jvxlData.jvxlExtraLine = JvxlReader.jvxlExtraLine(jvxlData, 1); + + jvxlData.jvxlFileMessage = "mapped: min = " + params.valueMappedToRed + + "; max = " + params.valueMappedToBlue; } - void applyColorScale() { + colorFractionBase = jvxlData.colorFractionBase = defaultColorFractionBase; + colorFractionRange = jvxlData.colorFractionRange = defaultColorFractionRange; if (params.colorPhase == 0) params.colorPhase = 1; if (meshDataServer == null) { - meshData.vertexColixes = new short[meshData.vertexCount]; + meshData.vertexColixes = new short[meshData.vertexCount]; } else { meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES); meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_COLOR_INDEXES); } - int vertexCount = meshData.vertexCount; - colorFractionBase = defaultColorFractionBase; - colorFractionRange = defaultColorFractionRange; params.setMapRanges(this); - float min = params.mappedDataMin; - float max = params.mappedDataMax; - StringBuffer list = null, list1 = null; //colorBySign is true when colorByPhase is true, but not vice-versa //old: boolean saveColorData = !(params.colorByPhase && !params.isBicolorMap && !params.colorBySign); //sorry! - boolean saveColorData = params.isBicolorMap || params.colorBySign || !params.colorByPhase; - if (saveColorData) { - list = new StringBuffer(); - list1 = new StringBuffer(); - } - int incr = 1; - char[] remainder = new char[1]; - boolean writePrecisionColor = (jvxlDataIsPrecisionColor || params.isContoured || params.remappable); - int lastVertex = (contourVertexCount > 0 ? contourVertexCount : vertexCount); - short minColorIndex = -1; - short maxColorIndex = 0; - if (params.isBicolorMap && !params.isContoured || params.colorBySign) { - minColorIndex = ColorEncoder.getColorIndex(params.isColorReversed ? params.colorPos : params.colorNeg); - maxColorIndex = ColorEncoder.getColorIndex(params.isColorReversed ? params.colorNeg : params.colorPos); - } - for (int i = 0; i < vertexCount; i += incr) { - float value = getVertexColorValue(i, minColorIndex, maxColorIndex); - if (i < lastVertex) { - char ch; - if (writePrecisionColor) { - ch = JvxlReader.jvxlValueAsCharacter2(value, min, max, - colorFractionBase, colorFractionRange, remainder); - if (saveColorData) - list1.append(remainder[0]); - } else { - //isColorReversed - ch = JvxlReader.jvxlValueAsCharacter(value, params.valueMappedToRed, - params.valueMappedToBlue, colorFractionBase, colorFractionRange); - } - if (saveColorData) - list.append(ch); - } - } - jvxlData.isJvxlPrecisionColor = writePrecisionColor; - jvxlData.jvxlColorData = (saveColorData ? list.append(list1).append('\n') - .toString() : ""); + boolean saveColorData = params.isBicolorMap || params.colorBySign + || !params.colorByPhase; + jvxlData.isJvxlPrecisionColor = (jvxlDataIsPrecisionColor + || params.isContoured || params.remappable); jvxlData.valueMappedToRed = params.valueMappedToRed; jvxlData.valueMappedToBlue = params.valueMappedToBlue; jvxlData.mappedDataMin = params.mappedDataMin; jvxlData.mappedDataMax = params.mappedDataMax; + jvxlData.vertexCount = (contourVertexCount > 0 ? contourVertexCount + : meshData.vertexCount); + jvxlData.minColorIndex = -1; + jvxlData.maxColorIndex = 0; + jvxlData.isColorReversed = params.isColorReversed; + if (params.isBicolorMap && !params.isContoured || params.colorBySign) { + jvxlData.minColorIndex = ColorEncoder + .getColorIndex(params.isColorReversed ? params.colorPos + : params.colorNeg); + jvxlData.maxColorIndex = ColorEncoder + .getColorIndex(params.isColorReversed ? params.colorNeg + : params.colorPos); + } + jvxlData.isTruncated = (jvxlData.minColorIndex >= 0 && !params.isContoured); + + float value; + for (int i = meshData.vertexCount; --i >= 0;) { + /* right, so what we are doing here is setting a range within the + * data for which we want red-->blue, but returning the actual + * number so it can be encoded more precisely. This turned out to be + * the key to making the JVXL contours work. + * + */ + if (params.colorBySets) + value = meshData.vertexSets[i]; + else if (params.colorByPhase) + value = getPhase(meshData.vertices[i]); + else if (params.isBicolorMap && !params.isContoured) // will be current mesh only + value = meshData.vertexValues[i]; + else if (jvxlDataIs2dContour) + value = marchingSquares.getInterpolatedPixelValue(meshData.vertices[i]); + else + value = volumeData.lookupInterpolatedVoxelValue(meshData.vertices[i]); + meshData.vertexValues[i] = value; + } + + colorData(); + + JvxlReader.jvxlCreateColorData(jvxlData, + (saveColorData ? null : meshData.vertexValues)); + if (meshDataServer != null && params.colorBySets) meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS); } - private float getVertexColorValue(int vertexIndex, short minColorIndex, short maxColorIndex) { - float value, datum; - /* but RETURNS the actual value, not the truncated one - * right, so what we are doing here is setting a range within the - * data for which we want red-->blue, but returning the actual - * number so it can be encoded more precisely. This turned out to be - * the key to making the JVXL contours work. - * - */ - if (params.colorBySets) - value = meshData.vertexSets[vertexIndex]; - else if (params.colorByPhase) - value = getPhase(meshData.vertices[vertexIndex]); - else if (params.isBicolorMap && !params.isContoured) // will be current mesh only - value = meshData.vertexValues[vertexIndex]; - else if (jvxlDataIs2dContour) - value = marchingSquares.getInterpolatedPixelValue(meshData.vertices[vertexIndex]); - else - value = volumeData.lookupInterpolatedVoxelValue(meshData.vertices[vertexIndex]); + private void colorData() { + + float[] vertexValues = meshData.vertexValues; + short[] vertexColixes = meshData.vertexColixes; - datum = meshData.vertexValues[vertexIndex] = value; + float valueBlue = jvxlData.valueMappedToBlue; + float valueRed = jvxlData.valueMappedToRed; + short minColorIndex = jvxlData.minColorIndex; + short maxColorIndex = jvxlData.maxColorIndex; - if (minColorIndex >= 0) { - if (value <= 0) - meshData.vertexColixes[vertexIndex] = minColorIndex; - else if (value > 0) - meshData.vertexColixes[vertexIndex] = maxColorIndex; - if (!params.isContoured) - datum = (value > 0 ? 0.999f : -0.999f); - } else { - if (value < params.valueMappedToRed) - value = params.valueMappedToRed; - if (value >= params.valueMappedToBlue) - value = params.valueMappedToBlue; - //if (vertexIndex > 90 && vertexIndex < 100) - //System.out.println("applycolor " + meshData.vertexColixes + " " + getColorIndexFromPalette(value) + " " + vertexIndex + " " + value +" " + params.valueMappedToRed + " " + params.valueMappedToBlue ); - meshData.vertexColixes[vertexIndex] = getColorIndexFromPalette(value); + for (int i = meshData.vertexCount; --i >= 0;) { + float value = vertexValues[i]; + if (minColorIndex >= 0) { + if (value <= 0) + vertexColixes[i] = minColorIndex; + else if (value > 0) + vertexColixes[i] = maxColorIndex; + } else { + if (value < valueRed) + value = valueRed; + if (value >= valueBlue) + value = valueBlue; + vertexColixes[i] = getColorIndexFromPalette(value); + } } - return datum; } + + private final static String[] colorPhases = { "_orb", "x", "y", "z", "xy", + "yz", "xz", "x2-y2", "z2" }; - private final static String[] colorPhases = { "_orb", "x", "y", "z", "xy", "yz", - "xz", "x2-y2", "z2" }; - static int getColorPhaseIndex(String color) { int colorPhase = -1; for (int i = colorPhases.length; --i >= 0;) @@ -615,7 +613,7 @@ } return colorPhase; } - + private float getPhase(Point3f pt) { switch (params.colorPhase) { case 0: @@ -639,15 +637,15 @@ } return 1; } - + float getMinMappedValue() { if (params.colorBySets) return 0; - int vertexCount = (contourVertexCount > 0 ? contourVertexCount : meshData.vertexCount); + int vertexCount = (contourVertexCount > 0 ? contourVertexCount + : meshData.vertexCount); Point3f[] vertexes = meshData.vertices; float min = Float.MAX_VALUE; - int incr = 1; - for (int i = 0; i < vertexCount; i += incr) { + for (int i = 0; i < vertexCount; i++) { float challenger; if (jvxlDataIs2dContour) challenger = marchingSquares.getInterpolatedPixelValue(vertexes[i]); @@ -662,7 +660,8 @@ float getMaxMappedValue() { if (params.colorBySets) return Math.max(meshData.nSets - 1, 0); - int vertexCount = (contourVertexCount > 0 ? contourVertexCount : meshData.vertexCount); + int vertexCount = (contourVertexCount > 0 ? contourVertexCount + : meshData.vertexCount); Point3f[] vertexes = meshData.vertices; float max = -Float.MAX_VALUE; int incr = 1; @@ -682,12 +681,12 @@ protected short getColorIndexFromPalette(float value) { if (params.isColorReversed) - return colorEncoder.getColorIndexFromPalette(-value, -params.valueMappedToBlue, - -params.valueMappedToRed); - return colorEncoder.getColorIndexFromPalette(value, params.valueMappedToRed, - params.valueMappedToBlue); + return colorEncoder.getColorIndexFromPalette(-value, + -params.valueMappedToBlue, -params.valueMappedToRed); + return colorEncoder.getColorIndexFromPalette(value, + params.valueMappedToRed, params.valueMappedToBlue); } - + void updateTriangles() { if (meshDataServer == null) { meshData.invalidateTriangles(); @@ -695,36 +694,35 @@ meshDataServer.invalidateTriangles(); } } - + void updateSurfaceData() { updateTriangles(); JvxlReader.jvxlUpdateSurfaceData(jvxlData, meshData.vertexValues, meshData.vertexCount, meshData.vertexIncrement, cJvxlEdgeNaN); } - + public void selectPocket(boolean doExclude) { // solvent reader implements this } - + void excludeMinimumSet() { if (meshDataServer != null) meshDataServer.fillMeshData(meshData, MeshData.MODE_GET_VERTICES); meshData.getSurfaceSet(); BitSet bs; - for (int i = meshData.nSets; --i >= 0;) + for (int i = meshData.nSets; --i >= 0;) //System.out.println(" set " + i + " " + Viewer.cardinalityOf(surfaceSet[i])); if ((bs = meshData.surfaceSet[i]) != null) { int n = 0; - for (int j = bs.size(); --j >= 0; ) // cardinality + for (int j = bs.size(); --j >= 0;) + // cardinality if (bs.get(j)) n++; if (n < params.minSet) meshData.invalidateSurfaceSet(i); - } + } updateSurfaceData(); if (meshDataServer != null) meshDataServer.fillMeshData(meshData, MeshData.MODE_PUT_SETS); } } - - Modified: trunk/Jmol/src/org/jmol/shape/Mesh.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/Mesh.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/shape/Mesh.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -40,6 +40,7 @@ public String thisID; public boolean isValid = true; public String scriptCommand; + public String colorCommand; public boolean visible = true; public short colix; Modified: trunk/Jmol/src/org/jmol/shape/MeshCollection.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/shape/MeshCollection.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -264,8 +264,13 @@ } public Object getProperty(String property, int index) { - if (property == "count") - return new Integer(meshCount); + if (property == "count") { + int n = 0; + for (int i = 0; i < meshCount; i++) + if (meshes[i] != null && meshes[i].vertexCount > 0) + n++; + return new Integer(n); + } if (property == "ID") return (currentMesh == null ? (String) null : currentMesh.thisID); if (property == "list") { @@ -360,6 +365,8 @@ appendCmd(s, mesh.getState(myType)); if (mesh.isColorSolid) appendCmd(s, getColorCommand("$" + mesh.thisID, mesh.colix)); + else if (mesh.colorCommand != null) + appendCmd(s, mesh.colorCommand); } } return s.toString(); Modified: trunk/Jmol/src/org/jmol/shape/Shape.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/Shape.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/shape/Shape.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -162,6 +162,10 @@ paletteID) : colix); } + protected void remapColors() { + + } + public Vector getShapeDetail() { return null; } Modified: trunk/Jmol/src/org/jmol/shapespecial/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapespecial/Isosurface.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/shapespecial/Isosurface.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -172,6 +172,12 @@ return; } + if ("remapcolor" == propertyName) { + if (thisMesh != null) + remapColors(); + return; + } + if ("thisID" == propertyName) { setPropertySuper("thisID", value, null); return; @@ -321,8 +327,6 @@ } public Object getProperty(String property, int index) { - if (property == "list") - return super.getProperty(property, index); if (property == "moNumber") return new Integer(moNumber); if (thisMesh == null) @@ -616,6 +620,13 @@ setModelIndex(); setScriptInfo(); setJvxlInfo(); + String schemeName = colorEncoder.getColorSchemeName(); + viewer.setPropertyColorScheme(schemeName); + viewer.setCurrentColorRange(jvxlData.mappedDataMin, jvxlData.mappedDataMax); + thisMesh.isColorSolid = false; + thisMesh.colorCommand = "color $" + thisMesh.thisID + " \"" + schemeName + "\" range " + + (jvxlData.isColorReversed ? jvxlData.mappedDataMax + " " + jvxlData.mappedDataMin : + jvxlData.mappedDataMin + " " + jvxlData.mappedDataMax); } public Point3f[] calculateGeodesicSurface(BitSet bsSelected, BitSet bsIgnored, @@ -684,5 +695,22 @@ } return V; } - + + protected void remapColors() { + JvxlData jvxlData = thisMesh.jvxlData; + float[] vertexValues = thisMesh.vertexValues; + short[] vertexColixes = thisMesh.vertexColixes; + if (vertexValues == null || vertexColixes == null + || jvxlData.isBicolorMap || jvxlData.vertexCount == 0) + return; + for (int i = thisMesh.vertexCount; --i >= 0;) { + vertexColixes[i] = viewer.getColixForPropertyValue(vertexValues[i]); + } + float[] range = viewer.getCurrentColorRange(); + jvxlData.valueMappedToRed = Math.min(range[0], range[1]); + jvxlData.valueMappedToBlue = Math.max(range[0], range[1]); + jvxlData.isJvxlPrecisionColor = true; + JvxlReader.jvxlCreateColorData(jvxlData, vertexValues); + thisMesh.colorCommand = "color $" + thisMesh.thisID + " \"" + viewer.getPropertyColorScheme() + "\" range " + range[0] + " " + range[1]; + } } Modified: trunk/Jmol/src/org/jmol/util/ColorEncoder.java =================================================================== --- trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/util/ColorEncoder.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -55,6 +55,14 @@ return palette = getColorScheme(colorScheme); } + public String getColorSchemeName() { + return colorSchemes[palette]; + } + + public final static String getColorSchemeName(int i) { + return (i < colorSchemes.length && i >= 0 ? colorSchemes[i] : null); + } + public final static int getColorScheme(String colorScheme) { for (int i = 0; i < colorSchemes.length; i++) if (colorSchemes[i].equalsIgnoreCase(colorScheme)) Modified: trunk/Jmol/src/org/jmol/viewer/ColorManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/viewer/ColorManager.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -263,9 +263,13 @@ private float colorHi, colorLo; private float[] colorData; + float[] getCurrentColorRange() { + return new float[] {colorLo, colorHi}; + } + void setCurrentColorRange(float[] data, BitSet bs, String colorScheme) { colorData = data; - setColorScheme(colorScheme); + palette = ColorEncoder.getColorScheme(colorScheme); colorHi = Float.MIN_VALUE; colorLo = Float.MAX_VALUE; if (data == null) @@ -284,62 +288,23 @@ void setCurrentColorRange(float min, float max) { colorHi = max; colorLo = min; - Logger.info("Property color value range: " + colorLo + " to " + colorHi); + Logger.info("color \"" + ColorEncoder.getColorSchemeName(palette) + "\" range " + colorLo + " " + colorHi); } - short getPropertyColix(int iAtom) { + private short getPropertyColix(int iAtom) { if (colorData == null || iAtom >= colorData.length) return Graphics3D.GRAY; - return getColixFromPalette(colorData[iAtom], colorLo, colorHi); + return getColixForPropertyValue(colorData[iAtom]); } int palette = 0; -/* didn't work - private int rgbRed = 0xFFFF0000; - private int rgbGreen = 0xFF008000; - private int rgbBlue = 0xFF0000FF; - void setRgb(int rgorb, int color) { - switch (rgorb) { - case 0: - rgbRed = color; - break; - case 1: - rgbGreen = color; - break; - case 2: - rgbBlue = color; - } - } - - int getRgb(int rgorb) { - switch (rgorb) { - case 0: - return rgbRed; - case 1: - return rgbGreen; - case 2: - default: - return rgbBlue; - } - } - - int getRgbRed() { - return rgbRed; - } - - int getRgbGreen() { - return rgbGreen; - } - - int getRgbBlue() { - return rgbBlue; - } -*/ int setColorScheme(String colorScheme) { - return palette = ColorEncoder.getColorScheme(colorScheme); + palette = ColorEncoder.getColorScheme(colorScheme); + Logger.info("Property color scheme \"" + ColorEncoder.getColorSchemeName(palette) + "\" color value range: " + colorLo + " to " + colorHi); + return palette; } - + static void setUserScale(int[] scale) { ColorEncoder.setUserScale(scale); } @@ -349,13 +314,11 @@ } short getColixForPropertyValue(float val) { - return ColorEncoder.getColorIndexFromPalette(val, colorLo, colorHi, palette); //, rgbRed, rgbGreen, rgbBlue); + return (colorLo < colorHi ? + ColorEncoder.getColorIndexFromPalette(val, colorLo, colorHi, palette) + :ColorEncoder.getColorIndexFromPalette(-val, -colorLo, -colorHi, palette)); } - short getColixFromPalette(float val, float lo, float hi) { - return ColorEncoder.getColorIndexFromPalette(val, lo, hi, palette); //, rgbRed, rgbGreen, rgbBlue); - } - static short getColixHbondType(short order) { int argbIndex = ((order & JmolConstants.BOND_HYDROGEN_MASK) >> JmolConstants.BOND_HBOND_SHIFT); Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -3236,7 +3236,6 @@ case Token.string: String strColor = stringParameter(1); if (!isSyntaxCheck) { - viewer.setColorScheme(strColor); viewer.setStringProperty("propertyColorScheme", strColor); } if (tokAt(2) == Token.range || tokAt(2) == Token.absolute) { @@ -3415,51 +3414,61 @@ // "cpk" value would be "spacefill" String name = parameterAsString(index).toLowerCase(); - byte pid = (tok == Token.spacefill ? JmolConstants.PALETTE_CPK - : JmolConstants.getPaletteID(name)); + byte pid = (shapeType == JmolConstants.SHAPE_ISOSURFACE ? JmolConstants.PALETTE_PROPERTY + : tok == Token.spacefill ? JmolConstants.PALETTE_CPK + : JmolConstants.getPaletteID(name)); if (pid == JmolConstants.PALETTE_UNKNOWN || pid == JmolConstants.PALETTE_TYPE && shapeType != JmolConstants.SHAPE_HSTICKS) invalidArgument(); + Object data = null; if (pid == JmolConstants.PALETTE_PROPERTY) { - Object data = null; - float min = 0; - float max = Float.MAX_VALUE; + if (shapeType != JmolConstants.SHAPE_ISOSURFACE) + index++; if (name.equals("property") - && Compiler.tokAttr(getToken(++index).tok, Token.atomproperty)) { + && Compiler.tokAttr(getToken(index).tok, Token.atomproperty)) { if (!isSyntaxCheck) { - data = getBitsetProperty(null, getToken(index).tok + data = getBitsetProperty(null, getToken(index++).tok | Token.minmaxmask, null, null, null, null, false); if (!(data instanceof float[])) invalidArgument(); } } - if (optParameterAsString(index+1).length() > 0) - setStringProperty("propertyColorScheme", optParameterAsString(++index)); - if (tokAt(index + 1) == Token.absolute || tokAt(index + 1) == Token.range) { - min = floatParameter(index + 2); - max = floatParameter(index + 3); + } else if (pid == JmolConstants.PALETTE_VARIABLE) { + index++; + name = parameterAsString(index++); + data = new float[viewer.getAtomCount()]; + Parser.parseFloatArray("" + viewer.getParameter(name), null, + (float[]) data); + pid = JmolConstants.PALETTE_PROPERTY; + } + if (pid == JmolConstants.PALETTE_PROPERTY) { + if (tokAt(index) == Token.string) + setStringProperty("propertyColorScheme", parameterAsString(index++)); + float min = 0; + float max = Float.MAX_VALUE; + if (tokAt(index) == Token.absolute || tokAt(index) == Token.range) { + min = floatParameter(index + 1); + max = floatParameter(index + 2); index += 3; } if (!isSyntaxCheck) { - if (data == null) - viewer.setCurrentColorRange(name); - else - viewer.setCurrentColorRange((float[]) data, null); + if (shapeType != JmolConstants.SHAPE_ISOSURFACE) { + if (data == null) + viewer.setCurrentColorRange(name); + else + viewer.setCurrentColorRange((float[]) data, null); + } if (max != Float.MAX_VALUE) viewer.setCurrentColorRange(min, max); } + if (shapeType == JmolConstants.SHAPE_ISOSURFACE) + prefix = "remap"; + } else { + index++; } - if (pid == JmolConstants.PALETTE_VARIABLE) { - name = parameterAsString(++index); - float[] data = new float[viewer.getAtomCount()]; - Parser.parseFloatArray("" + viewer.getParameter(name), null, data); - if (!isSyntaxCheck) - viewer.setCurrentColorRange(data, null); - pid = JmolConstants.PALETTE_PROPERTY; - } colorvalue = new Byte((byte) pid); - checkStatementLength(index + 1); + checkStatementLength(index); } if (isSyntaxCheck) return; Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-09-01 19:52:24 UTC (rev 8183) @@ -15,6 +15,22 @@ # r = 255; g = 255; b = 0; # background {@r,@g,@b} +# new feature: expanded color command for properties +# +# color atoms property partialcharge "rwb" range -1.0 1.0 +# +# and reverse with range inverted: +# +# color atoms property partialcharge "rwb" range 1.0 -1.0 + + +# new feature: fully remappable isosurface using COLOR command: +# +# isosurface s1 molecular map mep +# color $s1 "bwr" +# color $s1 "rwb" range -0.2 0.2 + + # APPLICATION adjustment to console window scaling/size # ----------------------------------------------------------------------------- Modified: trunk/Jmol/src/org/jmol/viewer/Viewer.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Viewer.java 2007-09-01 13:03:40 UTC (rev 8182) +++ trunk/Jmol/src/org/jmol/viewer/Viewer.java 2007-09-01 19:52:24 UTC (rev 8183) @@ -1086,12 +1086,12 @@ } */ - void setPropertyColorScheme(String scheme) { - Logger.info("Property color scheme: " + scheme); + public void setPropertyColorScheme(String scheme) { global.propertyColorScheme = scheme; + colorManager.setColorScheme(scheme); } - String getPropertyColorScheme() { + public String getPropertyColorScheme() { return global.propertyColorScheme; } @@ -1171,11 +1171,6 @@ return ColorManager.getColixHbondType(order); } - int setColorScheme(String colorScheme) { - //isosurface - return colorManager.setColorScheme(colorScheme); - } - public int[] getColorSchemeArray(String colorScheme) { return colorManager.getColorSchemeArray(colorScheme); } @@ -1184,9 +1179,9 @@ ColorManager.setUserScale(scale); } - short getColixFromPalette(float val, float rangeMin, float rangeMax) { + public short getColixForPropertyValue(float val) { //isosurface - return colorManager.getColixFromPalette(val, rangeMin, rangeMax); + return colorManager.getColixForPropertyValue(val); } Point3f getColorPointForPropertyValue(float val) { @@ -2327,10 +2322,14 @@ colorManager.setCurrentColorRange(data, bs, global.propertyColorScheme); } - void setCurrentColorRange(float min, float max) { + public void setCurrentColorRange(float min, float max) { colorManager.setCurrentColorRange(min, max); } + public float[] getCurrentColorRange() { + return colorManager.getCurrentColorRange(); + } + static public float[] getDataFloat(String label) { if (dataValues == null) return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |