From: <ha...@us...> - 2009-02-24 03:08:33
|
Revision: 10675 http://jmol.svn.sourceforge.net/jmol/?rev=10675&view=rev Author: hansonr Date: 2009-02-24 03:08:26 +0000 (Tue, 24 Feb 2009) Log Message: ----------- version=11.7.27_dev polygonColixes[] support # new feature: JVXL format supports polygonColixes[] # code: polygonColixes[] to define polygon colors rather than vertex-based colors (as in OBJ file) Modified Paths: -------------- trunk/Jmol/applet.classes trunk/Jmol/appletweb/Jmol.js trunk/Jmol/src/org/jmol/api/JmolExportInterface.java trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java trunk/Jmol/src/org/jmol/export/Export3D.java trunk/Jmol/src/org/jmol/export/IsosurfaceGenerator.java trunk/Jmol/src/org/jmol/export/LcaoCartoonGenerator.java trunk/Jmol/src/org/jmol/export/MolecularOrbitalGenerator.java trunk/Jmol/src/org/jmol/export/PmeshGenerator.java trunk/Jmol/src/org/jmol/export/_MayaExporter.java trunk/Jmol/src/org/jmol/export/_PovrayExporter.java trunk/Jmol/src/org/jmol/export/_U3dExporter.java trunk/Jmol/src/org/jmol/export/_VrmlExporter.java trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/jvxl/api/MeshDataServer.java trunk/Jmol/src/org/jmol/jvxl/api/VertexDataServer.java trunk/Jmol/src/org/jmol/jvxl/calc/MarchingCubes.java trunk/Jmol/src/org/jmol/jvxl/calc/MarchingSquares.java trunk/Jmol/src/org/jmol/jvxl/data/MeshData.java trunk/Jmol/src/org/jmol/jvxl/readers/EfvetReader.java trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java trunk/Jmol/src/org/jmol/jvxl/readers/ObjReader.java trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java trunk/Jmol/src/org/jmol/shape/MeshRenderer.java trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/applet.classes =================================================================== --- trunk/Jmol/applet.classes 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/applet.classes 2009-02-24 03:08:26 UTC (rev 10675) @@ -17,6 +17,9 @@ org/jmol/geodesic/*.java org/jmol/i18n/*.java +org/jmol/jvxl/data/*.java +org/jmol/jvxl/calc/*.java +org/jmol/jvxl/readers/*.java org/jmol/jvxl/*.java org/jmol/minimize/*.java Modified: trunk/Jmol/appletweb/Jmol.js =================================================================== --- trunk/Jmol/appletweb/Jmol.js 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/appletweb/Jmol.js 2009-02-24 03:08:26 UTC (rev 10675) @@ -97,6 +97,9 @@ //////////////////////////////////////////////////////////////// function jmolInitialize(codebaseDirectory, fileNameOrUseSignedApplet) { + if (_jmol.initialized) + return; + _jmol.initialized = true; if(allowJMOLJAR && document.location.search.indexOf("JMOLJAR=")>=0) { var f = document.location.search.split("JMOLJAR=")[1].split("&")[0]; if (f.indexOf("/") >= 0) { @@ -116,7 +119,6 @@ _jmolSetCodebase(codebaseDirectory); _jmolGetJarFilename(fileNameOrUseSignedApplet); _jmolOnloadResetForms(); - _jmol.initialized = true; } function jmolSetTranslation(TF) { @@ -729,11 +731,11 @@ } if (useIEObject) { // use MSFT IE6 object tag with .cab file reference winCodebase = (windowsCabUrl ? " codebase='" + windowsCabUrl + "'\n" : ""); + params.code = 'JmolApplet'; tHeader = "<object name='jmolApplet" + nameSuffix + "' id='jmolApplet" + nameSuffix + "' " + appletCssText + "\n" + " classid='" + windowsClassId + "'\n" + winCodebase + widthAndHeight + ">\n"; - params.code = 'JmolApplet'; tFooter = "</object>"; } else if (useHtml4Object) { // use HTML4 object tag tHeader = @@ -797,8 +799,6 @@ if (_jmol.initChecked) return; _jmol.initChecked = true; - if (_jmol.initialized) - return; jmolInitialize(defaultdir, defaultjar) } @@ -1087,6 +1087,7 @@ } function _jmolOnloadResetForms() { + // must be evaluated ONLY once _jmol.previousOnloadHandler = window.onload; window.onload = function() { Modified: trunk/Jmol/src/org/jmol/api/JmolExportInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolExportInterface.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/api/JmolExportInterface.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -42,7 +42,8 @@ abstract void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, - int nVertices, int faceVertexMax); + int nVertices, int faceVertexMax, + short[] polygonColixes, int nPolygons); abstract void renderText(Text t); Modified: trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -287,7 +287,7 @@ public abstract void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax); + int faceVertexMax, short[] polygonColixes, int nPolygons); public abstract boolean isInDisplayRange(int x, int y); Modified: trunk/Jmol/src/org/jmol/export/Export3D.java =================================================================== --- trunk/Jmol/src/org/jmol/export/Export3D.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/Export3D.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -652,9 +652,9 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax) { + int faceVertexMax, short[] polygonColixes, int nPolygons) { exporter.renderIsosurface(vertices, colix, colixes, normals, - indices, bsFaces, nVertices, faceVertexMax); + indices, bsFaces, nVertices, faceVertexMax, null, nPolygons); } public void renderEllipsoid(int x, int y, int z, int diameter, Modified: trunk/Jmol/src/org/jmol/export/IsosurfaceGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/export/IsosurfaceGenerator.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/IsosurfaceGenerator.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -32,6 +32,7 @@ protected void renderExport() { g3d.getExporter().renderIsosurface(imesh.vertices, imesh.colix, imesh.isColorSolid ? null : imesh.vertexColixes, - imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, imesh.vertexCount, 3); + imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, imesh.vertexCount, 3, + imesh.isColorSolid ? imesh.polygonColixes : null, imesh.polygonCount); } } Modified: trunk/Jmol/src/org/jmol/export/LcaoCartoonGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/export/LcaoCartoonGenerator.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/LcaoCartoonGenerator.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -32,6 +32,7 @@ protected void renderExport() { g3d.getExporter().renderIsosurface(imesh.vertices, imesh.colix, imesh.isColorSolid ? null : imesh.vertexColixes, - imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, imesh.vertexCount, 3); + imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, imesh.vertexCount, 3, + imesh.polygonColixes, imesh.polygonCount); } } Modified: trunk/Jmol/src/org/jmol/export/MolecularOrbitalGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/export/MolecularOrbitalGenerator.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/MolecularOrbitalGenerator.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -32,6 +32,7 @@ protected void renderExport() { g3d.getExporter().renderIsosurface(imesh.vertices, imesh.colix, imesh.isColorSolid ? null : imesh.vertexColixes, - imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, imesh.vertexCount, 3); + imesh.getVertexNormals(), imesh.polygonIndexes, bsFaces, + imesh.vertexCount, 3, null, imesh.polygonCount); } } Modified: trunk/Jmol/src/org/jmol/export/PmeshGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/export/PmeshGenerator.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/PmeshGenerator.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -31,7 +31,7 @@ protected void renderExport() { g3d.getExporter().renderIsosurface(mesh.vertices, mesh.colix, null, - mesh.getVertexNormals(), mesh.polygonIndexes, bsFaces, mesh.vertexCount, - 4); + mesh.getVertexNormals(), mesh.polygonIndexes, bsFaces, + mesh.vertexCount, 4, null, mesh.polygonCount); } } Modified: trunk/Jmol/src/org/jmol/export/_MayaExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_MayaExporter.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/_MayaExporter.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -157,7 +157,8 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, - int nVertices, int faceVertexMax) { + int nVertices, int faceVertexMax, + short[] polygonColixes, int nPolygons) { } public void renderText(Text t) { Modified: trunk/Jmol/src/org/jmol/export/_PovrayExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -40,7 +40,6 @@ import org.jmol.g3d.Graphics3D; import org.jmol.modelset.Atom; import org.jmol.shape.Text; -import org.jmol.util.BitSetUtil; import org.jmol.util.TextFormat; import org.jmol.viewer.JmolConstants; import org.jmol.viewer.Viewer; @@ -406,20 +405,43 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax) { + int faceVertexMax, short[] polygonColixes, int nPolygons) { if (nVertices == 0) return; int nFaces = 0; - for (int i = BitSetUtil.length(bsFaces); --i >= 0;) + for (int i = nPolygons; --i >= 0;) if (bsFaces.get(i)) nFaces += (faceVertexMax == 4 && indices[i].length == 4 ? 2 : 1); if (nFaces == 0) return; + + if (polygonColixes != null) { + for (int i = nPolygons; --i >= 0;) { + if (!bsFaces.get(i)) + continue; + //if ((p++) % 10 == 0) + // output("\n"); + output("polygon { 4\n"); + for (int j = 0; j <= 3; j++) { + viewer.transformPoint(vertices[indices[i][j % 3]], tempP1); + output(", <" + triad(tempP1) + ">"); + } + output("\n"); + output("pigment{rgbt<" + color4(colix = polygonColixes[i]) + ">}\n"); + output(" translucentFinish(" + translucencyFractionalFromColix(colix) + + ")\n"); + output(" check_shadow()\n"); + output(" clip()\n"); + output("}\n"); + } + + return; + } + Hashtable htColixes = new Hashtable(); String color; output("mesh2 {\n"); - output("vertex_vectors { " + nVertices); for (int i = 0; i < nVertices; i++) { //if (i % 10 == 0) @@ -467,7 +489,7 @@ } output("face_indices { " + nFaces); //int p = 0; - for (int i = BitSetUtil.length(bsFaces); --i >= 0;) { + for (int i = nPolygons; --i >= 0;) { if (!bsFaces.get(i)) continue; //if ((p++) % 10 == 0) Modified: trunk/Jmol/src/org/jmol/export/_U3dExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_U3dExporter.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/_U3dExporter.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -35,7 +35,6 @@ import org.jmol.g3d.Font3D; import org.jmol.modelset.Atom; import org.jmol.shape.Text; -import org.jmol.util.BitSetUtil; public class _U3dExporter extends _Exporter { @@ -121,16 +120,17 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax) { + int faceVertexMax, short[] polygonColixes, int nPolygons) { if (nVertices == 0) return; int nFaces = 0; - for (int i = BitSetUtil.length(bsFaces); --i >= 0;) + for (int i = nPolygons; --i >= 0;) if (bsFaces.get(i)) nFaces += (faceVertexMax == 4 && indices[i].length == 4 ? 2 : 1); if (nFaces == 0) return; + //TODO /* String color = rgbFractionalFromColix(colix, ' '); output("Shape {\n"); Modified: trunk/Jmol/src/org/jmol/export/_VrmlExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -35,7 +35,6 @@ import org.jmol.g3d.Font3D; import org.jmol.modelset.Atom; import org.jmol.shape.Text; -import org.jmol.util.BitSetUtil; import org.jmol.viewer.Viewer; @@ -146,12 +145,12 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax) { + int faceVertexMax, short[] polygonColixes, int nPolygons) { if (nVertices == 0) return; int nFaces = 0; - for (int i = BitSetUtil.length(bsFaces); --i >= 0;) + for (int i = nPolygons; --i >= 0;) if (bsFaces.get(i)) nFaces += (faceVertexMax == 4 && indices[i].length == 4 ? 2 : 1); if (nFaces == 0) @@ -178,7 +177,7 @@ output(" }\n"); output(" coordIndex [\n"); String sep = " "; - for (int i = BitSetUtil.length(bsFaces); --i >= 0;) { + for (int i = nPolygons; --i >= 0;) { if (!bsFaces.get(i)) continue; output(sep + indices[i][0] + " " + indices[i][1] + " " + indices[i][2] Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -1463,7 +1463,7 @@ public void renderIsosurface(Point3f[] vertices, short colix, short[] colixes, Vector3f[] normals, int[][] indices, BitSet bsFaces, int nVertices, - int faceVertexMax) { + int faceVertexMax, short[] polygonColixes, int nPolygons) { // generator only } Modified: trunk/Jmol/src/org/jmol/jvxl/api/MeshDataServer.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/api/MeshDataServer.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/api/MeshDataServer.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -32,4 +32,5 @@ public abstract void notifySurfaceGenerationCompleted(); public abstract void notifySurfaceMappingCompleted(); public abstract Point3f[] calculateGeodesicSurface(BitSet bsSelected, float envelopeRadius); + public abstract int getColixArgb(short colix); } Modified: trunk/Jmol/src/org/jmol/jvxl/api/VertexDataServer.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/api/VertexDataServer.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/api/VertexDataServer.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -95,9 +95,10 @@ * @param iC * @param check * @param isAbsolute + * @param color */ public abstract void addTriangleCheck(int iA, int iB, int iC, int check, - boolean isAbsolute); + boolean isAbsolute, int color); /** * Modified: trunk/Jmol/src/org/jmol/jvxl/calc/MarchingCubes.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/calc/MarchingCubes.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/calc/MarchingCubes.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -305,7 +305,7 @@ surfaceReader.addTriangleCheck(edgePointIndexes[ia], edgePointIndexes[ib], edgePointIndexes[ic], - edgeType, isCutoffAbsolute); + edgeType, isCutoffAbsolute, 0); } Modified: trunk/Jmol/src/org/jmol/jvxl/calc/MarchingSquares.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/calc/MarchingSquares.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/calc/MarchingSquares.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -966,7 +966,7 @@ : iA == mesh1 && iC == mesh2 || iC == mesh1 && iA == mesh2 ? 4 : 0); if (iA >= 0 && iB >= 0 && iC >= 0) - surfaceReader.addTriangleCheck(iA, iB, iC, check, false); + surfaceReader.addTriangleCheck(iA, iB, iC, check, false, 0); k = triangleVertexList[i]; } } Modified: trunk/Jmol/src/org/jmol/jvxl/data/MeshData.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/data/MeshData.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/data/MeshData.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -117,6 +117,7 @@ import javax.vecmath.Point3f; +import org.jmol.g3d.Graphics3D; import org.jmol.util.*; public class MeshData { @@ -133,6 +134,7 @@ public int vertexCount; public float[] vertexValues; public int[][] polygonIndexes; + public short[] polygonColixes; public BitSet[] surfaceSet; public int[] vertexSets; @@ -172,7 +174,10 @@ return vertexCount++; } - public void addTriangleCheck(int vertexA, int vertexB, int vertexC, int check) { + private int lastColor; + private short lastColix; + + public void addTriangleCheck(int vertexA, int vertexB, int vertexC, int check, int color) { if (vertexValues != null && (Float.isNaN(vertexValues[vertexA])||Float.isNaN(vertexValues[vertexB])||Float.isNaN(vertexValues[vertexC]))) return; if (Float.isNaN(vertices[vertexA].x)||Float.isNaN(vertices[vertexB].x)||Float.isNaN(vertices[vertexC].x)) @@ -181,6 +186,16 @@ polygonIndexes = new int[SEED_COUNT][]; else if (polygonCount == polygonIndexes.length) polygonIndexes = (int[][]) ArrayUtil.doubleLength(polygonIndexes); + if (color != 0) { + if (polygonColixes == null) { + polygonColixes = new short[SEED_COUNT]; + lastColor = 0; + } + else if (polygonCount == polygonColixes.length) { + polygonColixes = (short[]) ArrayUtil.doubleLength(polygonColixes); + } + polygonColixes[polygonCount] = (color == lastColor ? lastColix : (lastColix = Graphics3D.getColix(lastColor = color))); + } polygonIndexes[polygonCount++] = new int[] {vertexA, vertexB, vertexC, check}; } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/EfvetReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/EfvetReader.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/EfvetReader.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -126,7 +126,7 @@ nTriangles = parseInt(); for (int i = 0; i < nTriangles; i++) { skipTo("<triangle", "vertex"); - addTriangleCheck(parseInt() - 1, parseInt() - 1, parseInt() - 1, 7, false); + addTriangleCheck(parseInt() - 1, parseInt() - 1, parseInt() - 1, 7, false, 0); } } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/JvxlReader.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -32,6 +32,7 @@ import org.jmol.shapesurface.IsosurfaceMesh; import org.jmol.util.*; +import org.jmol.jvxl.api.MeshDataServer; import org.jmol.jvxl.data.JvxlData; import org.jmol.jvxl.data.MeshData; import org.jmol.jvxl.data.VolumeData; @@ -915,7 +916,8 @@ //0.9e adds color contours for planes and min/max range, contour settings } - public static String jvxlGetFile(JvxlData jvxlData, MeshData meshData, + public static String jvxlGetFile(MeshDataServer meshDataServer, + JvxlData jvxlData, MeshData meshData, String[] title, String msg, boolean includeHeader, int nSurfaces, String state, String comment) { @@ -942,16 +944,16 @@ sb.append("<jvxlSurfaceData>\n"); sb.append(jvxlEncodeTriangleData(meshData.polygonIndexes, meshData.polygonCount, vertexIdNew)); - sb.append(jvxlEncodeVertexData(jvxlData, vertexIdNew, meshData.vertices, - meshData.vertexValues, meshData.vertexCount, jvxlData.jvxlColorData - .length() > 0)); + sb.append(jvxlEncodeVertexData(meshDataServer, jvxlData, vertexIdNew, + meshData.vertices, meshData.vertexValues, meshData.vertexCount, + meshData.polygonColixes, meshData.polygonCount, + jvxlData.jvxlColorData.length() > 0)); sb.append("</jvxlSurfaceData>\n"); } else if (jvxlData.jvxlPlane == null) { //no real point in compressing this unless it's a sign-based coloring sb.append(jvxlData.jvxlSurfaceData); - sb.append(jvxlCompressString(jvxlData.jvxlEdgeData)) - .append('\n').append(jvxlCompressString(jvxlData.jvxlColorData)) - .append('\n'); + sb.append(jvxlCompressString(jvxlData.jvxlEdgeData)).append('\n').append( + jvxlCompressString(jvxlData.jvxlColorData)).append('\n'); } else { sb.append(jvxlCompressString(jvxlData.jvxlColorData)).append('\n'); } @@ -975,13 +977,14 @@ data.append("</jvxlContourData>\n"); } if (comment != null) - data.append("<jvxlSurfaceCommand>\n ").append(comment).append( - "\n</jvxlSurfaceCommand>\n"); + data.append("<jvxlSurfaceCommand>\n ").append(comment).append( + "\n</jvxlSurfaceCommand>\n"); if (state != null) - data.append("<jvxlSurfaceState>\n ").append(state).append( - "\n</jvxlSurfaceState>\n"); + data.append("<jvxlSurfaceState>\n ").append(state).append( + "\n</jvxlSurfaceState>\n"); if (includeHeader) - data.append("<jvxlFileTitle>\n").append(jvxlData.jvxlFileTitle).append("</jvxlFileTitle>\n"); + data.append("<jvxlFileTitle>\n").append(jvxlData.jvxlFileTitle).append( + "</jvxlFileTitle>\n"); return data.toString(); } @@ -1258,20 +1261,26 @@ * The resultant string is really two strings of length nData * where the first string lists the "high" part of the positions, * and the second string lists the "low" part of the positions. + * @param meshDataServer * * @param jvxlData * @param vertexIdNew * @param vertices * @param vertexValues * @param vertexCount + * @param polygonColixes + * @param polygonCount * @param addColorData * @return string of encoded data */ - public static String jvxlEncodeVertexData(JvxlData jvxlData, + public static String jvxlEncodeVertexData(MeshDataServer meshDataServer, + JvxlData jvxlData, int[] vertexIdNew, Point3f[] vertices, float[] vertexValues, int vertexCount, + short[] polygonColixes, + int polygonCount, boolean addColorData) { Point3f min = new Point3f(Float.MAX_VALUE, Float.MAX_VALUE, Float.MAX_VALUE); Point3f max = new Point3f(Float.MIN_VALUE, Float.MIN_VALUE, Float.MIN_VALUE); @@ -1313,6 +1322,27 @@ list.append(" <jvxlVertexData len=\"" + list1.length() + "\" count=\"" + vertexCount + "\" min=\"" + min + "\" max=\"" + max + "\">\n "); list.append(list1).append("\n </jvxlVertexData>\n"); + if (polygonColixes != null) { + list1 = new StringBuffer(); + int count = 0; + short colix = 0; + boolean done = false; + for (int i = 0; i < polygonCount || (done = true) == true; i++) { + if (done || polygonColixes[i] != colix) { + if (count != 0) + list1.append(" ").append(count).append(" ").append( + (colix == 0 ? 0 : meshDataServer.getColixArgb(colix))); + if (done) + break; + colix = polygonColixes[i]; + count = 1; + } else { + count++; + } + } + list.append(" <jvxlPolygonColorData len=\"" + list1.length() + "\" count=\"" + + polygonCount+ "\">\n ").append(list1).append("\n </jvxlPolygonColorData>\n"); + } if (!addColorData) return list.toString(); @@ -1342,7 +1372,8 @@ private void getEncodedVertexData() throws Exception { String data = getXmlData("jvxlSurfaceData", null, true); jvxlDecodeVertexData(getXmlData("jvxlVertexData", data, true), false); - jvxlDecodeTriangleData(getXmlData("jvxlTriangleData", data, true), false); + String polygonColorData = getXmlData("jvxlPolygonColorData", data, false); + jvxlDecodeTriangleData(getXmlData("jvxlTriangleData", data, true), polygonColorData, false); Logger.info("Checking for vertex values"); jvxlColorDataRead = jvxlUncompressString(getXmlData("jvxlColorData", data, false)); jvxlDataIsColorMapped = (jvxlColorDataRead.length() > 0); @@ -1527,11 +1558,15 @@ * as created with jvxlEncodeTriangleData (see above) * * @param data tag and contents + * @param colorData * @param asArray or just addTriangleCheck * @return int[][] if desired */ - int[][] jvxlDecodeTriangleData(String data, boolean asArray) { + int[][] jvxlDecodeTriangleData(String data, String colorData, boolean asArray) { int[] next = new int[1]; + int[] nextc = new int[1]; + int nColors = (colorData == null ? -1 : 0); + int color = 0; setNext(data, "count", next, 2); int nData = Parser.parseInt(data, next); if (!asArray) @@ -1584,8 +1619,18 @@ if (++p % 3 == 0) { i++; p = 0; - if (!asArray) - addTriangleCheck(triangle[0], triangle[1], triangle[2], 7, false); + if (!asArray) { + if (nColors >= 0) { + if (nColors == 0) { + nColors = Parser.parseInt(colorData, nextc); + color = Parser.parseInt(colorData, nextc); + if (color == Integer.MIN_VALUE) + color = nColors = 0; + } + nColors--; + } + addTriangleCheck(triangle[0], triangle[1], triangle[2], 7, false, color); + } } } return triangles; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/ObjReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/ObjReader.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/ObjReader.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -27,6 +27,7 @@ import javax.vecmath.Point3f; +import org.jmol.g3d.Graphics3D; import org.jmol.util.Logger; import org.jmol.util.Parser; @@ -124,11 +125,15 @@ private boolean readPolygons() { nPolygons = 0; + int color = 0; try { if (!params.readAllData) { for (int i = 0; i < params.fileIndex; i++) { while (line != null && line.indexOf("g ") != 0) line = br.readLine(); + if (line == null) + break; + color = Graphics3D.getArgbFromString("[" + line.substring(3) + "]"); line = br.readLine(); } } @@ -144,14 +149,16 @@ int vertexCount = (id == Integer.MIN_VALUE ? 3 : 4); if (vertexCount == 4) { nTriangles += 2; - addTriangleCheck(ia - 1, ib - 1, ic - 1, 5, false); - addTriangleCheck(ib - 1, ic - 1, id - 1, 3, false); + addTriangleCheck(ia - 1, ib - 1, ic - 1, 5, false, color); + addTriangleCheck(ib - 1, ic - 1, id - 1, 3, false, color); } else { nTriangles++; - addTriangleCheck(ia - 1, ib - 1, ic - 1, 7, false); + addTriangleCheck(ia - 1, ib - 1, ic - 1, 7, false, color); } - } else if (line.indexOf("g ") == 0 && !params.readAllData) { - break; + } else if (line.indexOf("g ") == 0) { + if (!params.readAllData) + break; + color = Graphics3D.getArgbFromString("[x" + line.substring(3) + "]"); } line = br.readLine(); } Modified: trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -216,11 +216,11 @@ // 2 if (vertexCount == 4) { nTriangles += 2; - addTriangleCheck(vertices[0], vertices[1], vertices[3], 5, false); - addTriangleCheck(vertices[1], vertices[2], vertices[3], 3, false); + addTriangleCheck(vertices[0], vertices[1], vertices[3], 5, false, 0); + addTriangleCheck(vertices[1], vertices[2], vertices[3], 3, false, 0); } else { nTriangles++; - addTriangleCheck(vertices[0], vertices[1], vertices[2], 7, false); + addTriangleCheck(vertices[0], vertices[1], vertices[2], 7, false, 0); } } return true; Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceGenerator.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -911,7 +911,7 @@ public Object getProperty(String property, int index) { if (property == "jvxlFileData") - return JvxlReader.jvxlGetFile(jvxlData, null, params.title, "", true, + return JvxlReader.jvxlGetFile(meshDataServer, jvxlData, null, params.title, "", true, index, null, null); if (property == "jvxlFileInfo") return jvxlData.jvxlInfoLine; // for Jvxl.java Modified: trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java =================================================================== --- trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/jvxl/readers/SurfaceReader.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -508,14 +508,14 @@ } public void addTriangleCheck(int iA, int iB, int iC, int check, - boolean isAbsolute) { + boolean isAbsolute, int color) { if (meshDataServer == null) { if (isAbsolute && !MeshData.checkCutoff(iA, iB, iC, meshData.vertexValues)) return; - meshData.addTriangleCheck(iA, iB, iC, check); + meshData.addTriangleCheck(iA, iB, iC, check, color); } else { - meshDataServer.addTriangleCheck(iA, iB, iC, check, isAbsolute); + meshDataServer.addTriangleCheck(iA, iB, iC, check, isAbsolute, color); } } @@ -627,7 +627,7 @@ float[] vertexValues = meshData.vertexValues; short[] vertexColixes = meshData.vertexColixes; - + meshData.polygonColixes = null; float valueBlue = jvxlData.valueMappedToBlue; float valueRed = jvxlData.valueMappedToRed; short minColorIndex = jvxlData.minColorIndex; Modified: trunk/Jmol/src/org/jmol/shape/MeshRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/shape/MeshRenderer.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/shape/MeshRenderer.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -231,7 +231,7 @@ protected void renderExport() { //not implemented for this yet. g3d.renderIsosurface(mesh.vertices, mesh.colix, null, - mesh.getVertexNormals(), mesh.polygonIndexes, bsFaces, mesh.vertexCount, 4); + mesh.getVertexNormals(), mesh.polygonIndexes, bsFaces, mesh.vertexCount, 4, null, nPolygons); } } Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -202,10 +202,12 @@ if (thisMesh != null) { //thisMesh.vertexColixes = null; thisMesh.isColorSolid = true; + thisMesh.polygonColixes = null; } else if (!TextFormat.isWild(previousMeshID)){ for (int i = meshCount; --i >= 0;) { //isomeshes[i].vertexColixes = null; isomeshes[i].isColorSolid = true; + isomeshes[i].polygonColixes = null; } } setPropertySuper(propertyName, value, bs); @@ -426,11 +428,11 @@ meshData = new MeshData(); fillMeshData(meshData, MeshData.MODE_GET_VERTICES); } - return JvxlReader.jvxlGetFile(jvxlData, meshData, title, "", true, index, thisMesh + return JvxlReader.jvxlGetFile(this, jvxlData, meshData, title, "", true, index, thisMesh .getState(myType), (thisMesh.scriptCommand == null ? "" : thisMesh.scriptCommand)); } if (property == "jvxlSurfaceData") // MO only - return JvxlReader.jvxlGetFile(jvxlData, null, title, "", false, 1, thisMesh + return JvxlReader.jvxlGetFile(this, jvxlData, null, title, "", false, 1, thisMesh .getState(myType), (thisMesh.scriptCommand == null ? "" : thisMesh.scriptCommand)); if (property == "jvxlFileInfo") return jvxlData.jvxlInfoLine; @@ -694,12 +696,14 @@ meshData.vertexIncrement = thisMesh.vertexIncrement; meshData.polygonCount = thisMesh.polygonCount; meshData.polygonIndexes = thisMesh.polygonIndexes; + meshData.polygonColixes = thisMesh.polygonColixes; return; case MeshData.MODE_GET_COLOR_INDEXES: if (thisMesh.vertexColixes == null || thisMesh.vertexCount > thisMesh.vertexColixes.length) thisMesh.vertexColixes = new short[thisMesh.vertexCount]; meshData.vertexColixes = thisMesh.vertexColixes; + meshData.polygonIndexes = null; return; case MeshData.MODE_PUT_SETS: thisMesh.surfaceSet = meshData.surfaceSet; @@ -714,6 +718,7 @@ thisMesh.vertexIncrement = meshData.vertexIncrement; thisMesh.polygonCount = meshData.polygonCount; thisMesh.polygonIndexes = meshData.polygonIndexes; + thisMesh.polygonColixes = meshData.polygonColixes; return; } } @@ -780,10 +785,10 @@ } public void addTriangleCheck(int iA, int iB, int iC, int check, - boolean isAbsolute) { + boolean isAbsolute, int color) { if (isAbsolute && !MeshData.checkCutoff(iA, iB, iC, thisMesh.vertexValues)) return; - thisMesh.addTriangleCheck(iA, iB, iC, check); + thisMesh.addTriangleCheck(iA, iB, iC, check, color); } //////////////////////////////////////////////////////////////////// @@ -851,6 +856,7 @@ JvxlData jvxlData = thisMesh.jvxlData; float[] vertexValues = thisMesh.vertexValues; short[] vertexColixes = thisMesh.vertexColixes; + thisMesh.polygonColixes = null; if (vertexValues == null || jvxlData.isBicolorMap || jvxlData.vertexCount == 0) return; @@ -961,6 +967,9 @@ return (d2 < dmin2 ? d2 : -1); } + public int getColixArgb(short colix) { + return viewer.getColixArgb(colix); + } } Modified: trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -152,16 +152,37 @@ Graphics3D.getColixTranslucent(vertexColixes[i], isTranslucent, iLevel); } - void addTriangleCheck(int vertexA, int vertexB, int vertexC, int check) { - if (vertices == null || vertexValues != null && (Float.isNaN(vertexValues[vertexA])||Float.isNaN(vertexValues[vertexB])||Float.isNaN(vertexValues[vertexC]))) + public short[] polygonColixes; + private int lastColor; + private short lastColix; + + void addTriangleCheck(int vertexA, int vertexB, int vertexC, int check, + int color) { + if (vertices == null + || vertexValues != null + && (Float.isNaN(vertexValues[vertexA]) + || Float.isNaN(vertexValues[vertexB]) || Float + .isNaN(vertexValues[vertexC]))) return; - if (Float.isNaN(vertices[vertexA].x)||Float.isNaN(vertices[vertexB].x)||Float.isNaN(vertices[vertexC].x)) + if (Float.isNaN(vertices[vertexA].x) || Float.isNaN(vertices[vertexB].x) + || Float.isNaN(vertices[vertexC].x)) return; if (polygonCount == 0) polygonIndexes = new int[SEED_COUNT][]; else if (polygonCount == polygonIndexes.length) polygonIndexes = (int[][]) ArrayUtil.doubleLength(polygonIndexes); - polygonIndexes[polygonCount++] = new int[] {vertexA, vertexB, vertexC, check}; + if (color != 0) { + if (polygonColixes == null) { + polygonColixes = new short[SEED_COUNT]; + lastColor = 0; + } else if (polygonCount == polygonColixes.length) { + polygonColixes = (short[]) ArrayUtil.doubleLength(polygonColixes); + } + polygonColixes[polygonCount] = (color == lastColor ? lastColix + : (lastColix = Graphics3D.getColix(lastColor = color))); + } + polygonIndexes[polygonCount++] = new int[] { vertexA, vertexB, vertexC, + check }; } void invalidateTriangles() { Modified: trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceRenderer.java 2009-02-24 03:08:26 UTC (rev 10675) @@ -112,7 +112,7 @@ if (imesh.vertexColixes != null) g3d.setColix(imesh.vertexColixes[i]); g3d.fillSphereCentered(diam, screens[i]); - if (showNumbers) + if (showNumbers && screens[i].z > 10) g3d.drawStringNoSlab(i + (imesh.isColorSolid ? "" : " " + imesh.vertexValues[i]), null, screens[i].x, screens[i].y, screens[i].z); @@ -152,6 +152,7 @@ colorSolid = true; colix = Graphics3D.BLACK; } + boolean colorArrayed = (fill && colorSolid && imesh.polygonColixes != null); // two-sided means like a plane, with no front/back distinction for (int i = imesh.polygonCount; --i >= 0;) { @@ -171,6 +172,11 @@ continue; short colixA, colixB, colixC; if (colorSolid) { + if (colorArrayed && i < imesh.polygonColixes.length) { + short c = imesh.polygonColixes[i]; + if (c != 0) + colix = c; + } colixA = colixB = colixC = colix; } else { colixA = vertexColixes[iA]; Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-02-23 17:52:59 UTC (rev 10674) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2009-02-24 03:08:26 UTC (rev 10675) @@ -3,6 +3,8 @@ version=11.7.27_dev +# new feature: JVXL format supports polygonColixes[] +# code: polygonColixes[] to define polygon colors rather than vertex-based colors (as in OBJ file) # new feature: isosurface points can be retrieved using $id[n] where n=0,1,2,3... similar to $draw[n] # debugging: setTestflag2() turns on vertex labeling in isosurfaces # new feature: isosurface OBJ file reader using This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |