From: <ha...@us...> - 2006-05-19 21:10:06
|
Revision: 5146 Author: hansonr Date: 2006-05-19 14:09:40 -0700 (Fri, 19 May 2006) ViewCVS: http://svn.sourceforge.net/jmol/?rev=5146&view=rev Log Message: ----------- bob200603 isosurface -adds fileindex option to isosurface command for reading files with multiple orbitals. -adds empty string "" default filename is current data file. Could be "that or previously read isosurface file?" Modified Paths: -------------- branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java 2006-05-19 14:28:45 UTC (rev 5145) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java 2006-05-19 21:09:40 UTC (rev 5146) @@ -3877,8 +3877,9 @@ } void isosurface() throws ScriptException { + int fileIndexPt = 0; viewer.loadShape(JmolConstants.SHAPE_ISOSURFACE); - viewer.setShapeProperty(JmolConstants.SHAPE_ISOSURFACE, "meshID", null); + viewer.setShapeProperty(JmolConstants.SHAPE_ISOSURFACE, "init", null); boolean colorSeen = false; int colorRangeStage = 0; for (int i = 1; i < statementLength; ++i) { @@ -3887,13 +3888,19 @@ Token token = statement[i]; switch (token.tok) { case Token.identifier: + if (((String)token.value).equalsIgnoreCase("fileIndex")) { + fileIndexPt = i + 1; + break; + } propertyValue = token.value; - // fall into case Token.all: propertyName = "meshID"; break; case Token.string: String filename = (String)token.value; + if (filename.length() == 0) + filename = viewer.getFullPathName(); + System.out.println("reading isosurface data from " + filename); Object t = viewer.getUnzippedBufferedReaderOrErrorMessageFromName(filename); if (t instanceof String) @@ -3911,6 +3918,13 @@ } // fall into case Token.integer: + if (i == fileIndexPt) { + if (token.tok != Token.integer) + integerExpected(); + propertyName = "fileIndex"; + propertyValue = new Integer(token.intValue); + break; + } if (colorRangeStage == 0 || colorRangeStage >= 3) invalidArgument(); propertyName = colorRangeStage == 1 ? "rangeMin" : "rangeMax"; Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java =================================================================== --- branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-19 14:28:45 UTC (rev 5145) +++ branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-19 21:09:40 UTC (rev 5146) @@ -75,6 +75,7 @@ float[][][] voxelData; int edgePointCount = 0; + int fileIndex = 0; //one-based Point3f[] edgePoints; float cutoff = 0.02f; @@ -82,14 +83,22 @@ float minRange, maxRange; void setProperty(String propertyName, Object value, BitSet bs) { + if ("init" == propertyName) { + fileIndex = 1; + super.setProperty("meshID", null, null); + return; + } + if ("fileIndex" == propertyName) { + fileIndex= ((Integer)value).intValue(); + if (fileIndex < 1) fileIndex = 1; + return; + } if ("bufferedReader" == propertyName) { BufferedReader br = (BufferedReader)value; if (currentMesh == null) allocMesh(null); currentMesh.clear("isosurface"); - readVolumetricHeader(br); - calcVolumetricMatrix(); - readVolumetricData(br); + readData(br); calcVoxelVertexVectors(); constructTessellatedSurface(); currentMesh.colix = getDefaultColix(); @@ -117,11 +126,9 @@ return; } if ("colorReader" == propertyName) { + System.out.println("colorReader seen!"); BufferedReader br = (BufferedReader)value; - System.out.println("colorReader seen!"); - readVolumetricHeader(br); - calcVolumetricMatrix(); - readVolumetricData(br); + readData(br); if (! rangeDefined) { minRange = getMinMappedValue(); maxRange = getMaxMappedValue(); @@ -134,7 +141,17 @@ } super.setProperty(propertyName, value, bs); } - + + void readData(BufferedReader br) { + int nSurfaces = readVolumetricHeader(br); + if (nSurfaces < fileIndex) { + System.out.println("not enough surfaces in file -- resetting fileIndex to " + nSurfaces); + fileIndex = nSurfaces; + } + calcVolumetricMatrix(); + readVolumetricData(br); + } + void calcVolumetricMatrix() { for (int i = 3; --i >= 0; ) volumetricMatrix.setColumn(i, volumetricVectors[i]); @@ -189,13 +206,13 @@ // file reading stuff //////////////////////////////////////////////////////////////// - void readVolumetricHeader(BufferedReader br) { + int readVolumetricHeader(BufferedReader br) { try { readTitleLines(br); readAtomCountAndOrigin(br); readVoxelVectors(br); readAtoms(br); - readExtraLine(br); + return readExtraLine(br); } catch (Exception e) { e.printStackTrace(); throw new NullPointerException(); @@ -265,19 +282,19 @@ } } - void readExtraLine(BufferedReader br) throws Exception { - if (negativeAtomCount) - br.readLine(); + int readExtraLine(BufferedReader br) throws Exception { + return (negativeAtomCount ? parseInt(br.readLine()) : 1); } void readVoxelData(BufferedReader br) throws Exception { - System.out.println("entering readVoxelData"); + System.out.println("entering readVoxelData for fileIndex = " + fileIndex); String line = ""; ichNextParse = 0; int voxelCountX = voxelCounts[0]; int voxelCountY = voxelCounts[1]; int voxelCountZ = voxelCounts[2]; voxelData = new float[voxelCountX][][]; + skipData(br, (fileIndex - 1) * voxelCountX * voxelCountY * voxelCountZ); for (int x = 0; x < voxelCountX; ++x) { float[][] plane = new float[voxelCountY][]; voxelData[x] = plane; @@ -302,6 +319,35 @@ " x " + voxelCountZ + " voxels"); } + void skipData(BufferedReader br, int n) throws Exception { + if (n == 0) + return; + System.out.println("skipping " + n + " datapoints"); + String line = ""; + int i=0; + while (i < n) { + line = br.readLine(); + int c = countData(line); + System.out.println(c + " " + i); + i += c; + } + } + + int countData(String str) { + int ich = 0; + int count = 0; + int ichMax = str.length(); + char ch; + while (ich < ichMax) { + while (ich < ichMax && ((ch = str.charAt(ich)) == ' ' || ch == '\t')) + ++ich; + if (ich < ichMax) + ++count; + while (ich < ichMax && ((ch = str.charAt(ich)) != ' ' && ch != '\t')) + ++ich; + } + return count; + } //////////////////////////////////////////////////////////////// // marching cube stuff //////////////////////////////////////////////////////////////// This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |