From: <ha...@us...> - 2009-12-22 04:40:44
|
Revision: 11969 http://jmol.svn.sourceforge.net/jmol/?rev=11969&view=rev Author: hansonr Date: 2009-12-22 04:40:35 +0000 (Tue, 22 Dec 2009) Log Message: ----------- 11.9.12 # new feature: preliminary Tachyon ray tracer support # new feature: axes labels "x" "y" "z" # new feature: axes labels ON # new feature: axes labels OFF # new feature: axes ticks [x|y|z] {major,minor,subminor} format ["%0.2f", ...] scale {x y z}|x.xx # new feature: boundbox ticks [x|y|z] {major,minor,subminor} format ["%0.2f", ...] scale {x y z}|x.xx first x.xxx # new feature: measure ticks {major,minor,subminor} format ["%0.2f", ...] scale {x y z}|x.xx first x.xxx {point1} {point2} # new feature: unitcell ticks ..... with special option "scale hkl" to indicate unit cell dimension scaling # bug fix: signed applet should not consider "/xxx" to be local # bug fix: stereo mode results in zoom for entire right panel. # bug fix: Jmol application not saving/restoring window position # code: preliminary plot3d command # code: better handling of syntax errors in ScriptEvaluator.isosurface # code: reworking of measurements; adding TickInfo # code: refactoring of org.jmol.export Modified Paths: -------------- trunk/Jmol/src/org/jmol/export/_TachyonExporter.java trunk/Jmol/src/org/jmol/export/_VrmlExporter.java trunk/Jmol/src/org/jmol/export/_X3dExporter.java trunk/Jmol/src/org/jmol/export/___Exporter.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/viewer/RepaintManager.java Modified: trunk/Jmol/src/org/jmol/export/_TachyonExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_TachyonExporter.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/export/_TachyonExporter.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -43,6 +43,32 @@ public class _TachyonExporter extends __RayTracerExporter { + boolean wasPerspectiveDepth; + String lighting; + + UseTable textures = new UseTable(" "); + + boolean initializeOutput(Viewer viewer, Graphics3D g3d, Object output) { + //wasPerspectiveDepth = viewer.getPerspectiveDepth(); + //viewer.setPerspectiveDepth(false); + getLightingInfo(); + return super.initializeOutput(viewer, g3d, output); + } + + private void getLightingInfo() { + lighting = " AMBIENT " + round(Graphics3D.getAmbientPercent() / 100f) + + " DIFFUSE " + round(Graphics3D.getDiffusePercent()/100f) + + " SPECULAR " + round(Graphics3D.getSpecularPercent() / 100f); + } + + /* + public String finalizeOutput() { + if (wasPerspectiveDepth) + viewer.setPerspectiveDepth(true); + return super.finalizeOutput(); + } + */ + protected void outputHeader() { super.outputHeader(); viewer.transformPoint(center, tempP1); @@ -63,21 +89,21 @@ output("\n"); output("Begin_Scene\n"); output("Resolution " + screenWidth + " " + screenHeight + "\n"); - output("Shader_Mode Medium\n"); + output("Shader_Mode Medium\n"); // not documented. output(" Trans_VMD\n"); output(" Fog_VMD\n"); output("End_Shader_Mode\n"); output("Camera\n"); - output(" Zoom 0.666667\n"); + output(" PerspectiveMode ORTHOGRAPHIC\n"); + output(" Zoom 3.0\n"); output(" Aspectratio 1\n"); output(" Antialiasing 12\n"); output(" Raydepth 8\n"); output(" Center " + triad(tempP1) + "\n"); output(" Viewdir 0 0 1\n"); - output(" Updir 0 1 0\n"); + output(" Updir 0 -1 0\n"); output("End_Camera\n"); - output("Directional_Light Direction 0.1 -0.1 1 Color 1 1 1\n"); - output("Directional_Light Direction -1 -2 0.5 Color 1 1 1\n"); + output("Directional_Light Direction " + round(Graphics3D.getLightSource()) + " Color 1 1 1\n"); output("\n"); output("Background " + rgbFractionalFromColix(viewer.getObjectColix(0), ' ') + "\n"); @@ -103,20 +129,32 @@ return "" + (translevel == 0 ? 1f : 1 - translevel / 255f); } - private void outputColorTexture(short colix) { - output(" Texture"); - output(" Ambient 0 Diffuse 0.65 Specular 0 Opacity " + opacityFractionalFromColix(colix)); - output(" Phong Plastic 0.5 Phong_size 40"); - output(" Color " + rgbFractionalFromColix(colix, ' ')); - output(" TexFunc 0\n"); + private String getTexture(short colix) { + String code = textures.getDef("tc" + colix); + if (!code.startsWith(" ")) { + output("TexDef " + code); + output(lighting); + output(" Opacity " + opacityFractionalFromColix(colix)); + output(" Phong Plastic 0.5 Phong_size 40"); + output(" Color " + rgbFractionalFromColix(colix, ' ')); + output(" TexFunc 0\n"); + code = " " + code; + } + return code + "\n"; } - private void outputColorTexture(int argb) { - output(" Texture"); - output(" Ambient 0 Diffuse 0.65 Specular 0 Opacity " + opacityFractionalFromArgb(argb)); - output(" Phong Plastic 0.5 Phong_size 40"); - output(" Color " + rgbFractionalFromArgb(argb, ' ')); - output(" TexFunc 0\n"); + private String getTexture(int argb) { + String code = textures.getDef("ta" + argb); + if (!code.startsWith(" ")) { + output("TexDef " + code); + output(lighting); + output(" Ambient 0 Diffuse 0.65 Specular 0 Opacity " + + opacityFractionalFromArgb(argb)); + output(" Phong Plastic 0.5 Phong_size 40"); + output(" Color " + rgbFractionalFromArgb(argb, ' ')); + output(" TexFunc 0\n"); + } + return " " + code + "\n"; } protected void outputCircle(int x, int y, int z, float radius, short colix, @@ -133,13 +171,14 @@ private void outputRing(int x, int y, int z, Vector3f tempV1, float radius, short colix, boolean doFill) { - output("Ring Center "); - output(triad(x, y, z)); - output(" Normal " + triad(tempV1)); - output(" Inner " + (doFill ? 0 : radius * 0.95)); - output(" Outer " + radius); - outputColorTexture(colix); - } + String code = getTexture(colix); + output("Ring Center "); + output(triad(x, y, z)); + output(" Normal " + triad(tempV1)); + output(" Inner " + (doFill ? 0 : radius * 0.95)); + output(" Outer " + radius); + output(code); + } protected void outputComment(String comment) { output("# "); @@ -154,12 +193,13 @@ protected void outputCylinder(Point3f screenA, Point3f screenB, float radius, short colix, boolean withCaps) { + String code = getTexture(colix); output("FCylinder Base "); output(triad(screenA)); output(" Apex "); output(triad(screenB)); output(" Rad " + radius); - outputColorTexture(colix); + output(code); if (withCaps) { tempV1.sub(screenA, screenB); outputRing((int) screenA.x, (int) screenA.y, (int) screenA.z, tempV1, radius, colix, true); @@ -201,6 +241,7 @@ } return; } + String code = getTexture(Graphics3D.BLUE); output("VertexArray Numverts " + nVertices + "\nCoords\n"); for (int i = 0; i < nVertices; i++) { viewer.transformPoint(vertices[i], tempP1); @@ -215,7 +256,7 @@ for (int i = 0; i < nVertices; i++) { output(colixes == null ? rgb : rgbFromColix(colixes[i], ' ') + "\n"); } - outputColorTexture(Graphics3D.BLUE); + output(code); output("\nTriMesh " + nFaces + "\n"); for (int i = 0; i < nVertices; i++) { output(colixes == null ? rgb : rgbFromColix(colixes[i], ' ') + "\n"); @@ -236,26 +277,29 @@ // should be a reference to a names texture + String code = getTexture(colix); output("Sphere Center "); output(triad(x, y, z)); output(" Rad " + radius); - outputColorTexture(colix); + output(code); } protected void outputTextPixel(int x, int y, int z, int argb) { + String code = getTexture(argb); output("BOX MIN "); output(triad(x, y, z)); output(" MAX "); output(triad(x + 1, y + 1, z + 1)); - outputColorTexture(argb); + output(code); } protected void outputTriangle(Point3f ptA, Point3f ptB, Point3f ptC, short colix) { + String code = getTexture(colix); output("TRI"); output(" V0 " + triad(ptA)); output(" V1 " + triad(ptB)); output(" V2 " + triad(ptC)); - outputColorTexture(colix); + output(code); } } Modified: trunk/Jmol/src/org/jmol/export/_VrmlExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/export/_VrmlExporter.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -53,30 +53,12 @@ private AxisAngle4f viewpoint = new AxisAngle4f(); private void output(Tuple3f pt) { - output(round(pt.x) + " " + round(pt.y) + " " + round(pt.z)); + output(round(pt)); } - - private int iObj; - private Hashtable htDefs = new Hashtable(); - /** - * Hashtable htDefs contains references to _n where n is a number. - * we look up a key for anything and see if an object has been assigned. - * If it is there, we just return the phrase "USE _n". - * It it is not there, we return the DEF name that needs to be assigned. - * The calling method must then make that definition. - * - * @param key - * @return "_n" or "DEF _n" - */ - private String getDef(String key) { - if (htDefs.containsKey(key)) - return "USE " + htDefs.get(key); - String id = "_" + (iObj++); - htDefs.put(key, id); - return id; - } + private UseTable useTable = new UseTable("USE "); + protected void outputHeader() { output("#VRML V2.0 utf8 Generated by Jmol " + Viewer.getJmolVersion() + "\n"); @@ -109,13 +91,13 @@ } protected void outputFooter() { - htDefs = null; + useTable = null; output("\n]\n"); output("}}\n"); } private void outputAppearance(short colix, boolean isText) { - String def = getDef((isText ? "T" : "") + colix); + String def = useTable.getDef((isText ? "T" : "") + colix); output(" appearance "); if (def.charAt(0) == '_') { String color = rgbFractionalFromColix(colix, ' '); @@ -149,7 +131,7 @@ // draw a thin torus - String child = getDef("C" + colix + "_" + radius); + String child = useTable.getDef("C" + colix + "_" + radius); outputTransRot(pt1, pt2, 0, 0, 1); tempP3.set(1, 1, 1); tempP3.scale(radius); @@ -191,10 +173,10 @@ outputTransRot(tempP1, tempP2, 0, 1, 0); output(" children "); String cone = "o" + (int) (height * 100) + "_" + (int) (radius * 100); - String child = getDef("c" + cone + "_" + colix); + String child = useTable.getDef("c" + cone + "_" + colix); if (child.charAt(0) == '_') { output("DEF " + child + " Shape{geometry "); - cone = getDef(cone); + cone = useTable.getDef(cone); if (cone.charAt(0) == '_') { output("DEF " + cone + " Cone{height " + round(height) + " bottomRadius " + round(radius) + "}"); @@ -224,12 +206,12 @@ byte endcaps, float radius) { output(" children "); float length = round(pt1.distance(pt2)); - String child = getDef("C" + colix + "_" + (int) (length * 100) + "_" + radius + String child = useTable.getDef("C" + colix + "_" + (int) (length * 100) + "_" + radius + "_" + endcaps); if (child.charAt(0) == '_') { output("DEF " + child); output(" Shape{geometry "); - String cyl = getDef("c" + length + "_" + endcaps + "_" + radius); + String cyl = useTable.getDef("c" + length + "_" + endcaps + "_" + radius); if (cyl.charAt(0) == '_') { output("DEF " + cyl + " Cylinder{height " + length + " radius " + radius @@ -386,7 +368,7 @@ output("Transform{translation "); output(center); output(" children "); - String child = getDef("S" + colix + "_" + (int) (radius * 100)); + String child = useTable.getDef("S" + colix + "_" + (int) (radius * 100)); if (child.charAt(0) == '_') { output("DEF " + child); output(" Shape{geometry Sphere{radius " + radius + "}"); @@ -403,7 +385,7 @@ output("Transform{translation "); output(pt); output(" children "); - String child = getDef("p" + argb); + String child = useTable.getDef("p" + argb); if (child.charAt(0) == '_') { output("DEF " + child + " Shape{geometry Sphere{radius 0.01}"); output(" appearance Appearance{material Material{diffuseColor 0 0 0 specularColor 0 0 0 ambientIntensity 0.0 shininess 0.0 emissiveColor " @@ -454,12 +436,12 @@ // These x y z are 3D coordinates of echo or the atom the label is attached // to. output(" children "); - String child = getDef("T" + colix + useFontFace + useFontStyle + "_" + text); + String child = useTable.getDef("T" + colix + useFontFace + useFontStyle + "_" + text); if (child.charAt(0) == '_') { output("DEF " + child + " Billboard{axisOfRotation 0 0 0 children Transform{children Shape{"); outputAppearance(colix, true); output(" geometry Text{fontStyle "); - String fontstyle = getDef("F" + useFontFace + useFontStyle); + String fontstyle = useTable.getDef("F" + useFontFace + useFontStyle); if (fontstyle.charAt(0) == '_') { output("DEF " + fontstyle + " FontStyle{size 0.4 family \"" + useFontFace + "\" style \"" + useFontStyle + "\"}"); @@ -483,5 +465,6 @@ * interpreted */ - } + + Modified: trunk/Jmol/src/org/jmol/export/_X3dExporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/_X3dExporter.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/export/_X3dExporter.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -50,30 +50,10 @@ private AxisAngle4f viewpoint = new AxisAngle4f(); private void output(Tuple3f pt) { - output(round(pt.x) + " " + round(pt.y) + " " + round(pt.z)); + output(round(pt)); } - - private int iObj; - private Hashtable htDefs = new Hashtable(); + UseTable useTable = new UseTable("USE "); - /** - * Hashtable htDefs contains references to _n where n is a number. - * we look up a key for anything and see if an object has been assigned. - * If it is there, we just return the phrase "USE _n". - * It it is not there, we return the DEF name that needs to be assigned. - * The calling method must then make that definition. - * - * @param key - * @return "_n" or "DEF _n" - */ - private String getDef(String key) { - if (htDefs.containsKey(key)) - return "USE='" + htDefs.get(key) +"'"; - String id = "_" + (iObj++); - htDefs.put(key, id); - return id; - } - protected void outputHeader() { output("<X3D profile='Immersive' version='3.1' " + "xmlns:xsd='http://www.w3.org/2001/XMLSchema-instance' " @@ -124,14 +104,14 @@ } protected void outputFooter() { - htDefs = null; + useTable = null; output("</Transform>\n"); output("</Scene>\n"); output("</X3D>\n"); } private void outputAppearance(short colix, boolean isText) { - String def = getDef((isText ? "T" : "") + colix); + String def = useTable.getDef((isText ? "T" : "") + colix); output("<Appearance "); if (def.charAt(0) == '_') { String color = rgbFractionalFromColix(colix, ' '); @@ -168,7 +148,7 @@ // draw a thin torus - String child = getDef("C" + colix + "_" + radius); + String child = useTable.getDef("C" + colix + "_" + radius); output("<Transform"); outputTransRot(tempP3, pt1, 0, 0, 1); tempP3.set(1, 1, 1); @@ -213,10 +193,10 @@ outputTransRot(ptBase, ptTip, 0, 1, 0); output(">\n<Shape "); String cone = "o" + (int) (height * 100) + "_" + (int) (radius * 100); - String child = getDef("c" + cone + "_" + colix); + String child = useTable.getDef("c" + cone + "_" + colix); if (child.charAt(0) == '_') { output("DEF='" + child + "'>"); - cone = getDef(cone); + cone = useTable.getDef(cone); output("<Cone "); if (cone.charAt(0) == '_') { output("DEF='"+ cone + "' height='" + round(height) @@ -248,13 +228,13 @@ private void outputCylinderChild(Point3f pt1, Point3f pt2, short colix, byte endcaps, float radius) { float length = round(pt1.distance(pt2)); - String child = getDef("C" + colix + "_" + (int) (length * 100) + "_" + String child = useTable.getDef("C" + colix + "_" + (int) (length * 100) + "_" + radius + "_" + endcaps); output("<Shape "); if (child.charAt(0) == '_') { output("DEF='" + child + "'>"); output("<Cylinder "); - String cyl = getDef("c" + length + "_" + endcaps + "_" + radius); + String cyl = useTable.getDef("c" + length + "_" + endcaps + "_" + radius); if (cyl.charAt(0) == '_') { output("DEF='" + cyl @@ -440,7 +420,7 @@ output("<Transform translation='"); output(center); output("'>\n<Shape "); - String child = getDef("S" + colix + "_" + (int) (radius * 100)); + String child = useTable.getDef("S" + colix + "_" + (int) (radius * 100)); if (child.charAt(0) == '_') { output("DEF='" + child + "'>"); output("<Sphere radius='" + radius + "'/>"); @@ -488,7 +468,7 @@ output("<Transform translation='"); output(pt); output("'>\n<Shape "); - String child = getDef("p" + argb); + String child = useTable.getDef("p" + argb); if (child.charAt(0) == '_') { output("DEF='" + child + "'>"); output("<Sphere radius='0.01'/>"); @@ -517,7 +497,7 @@ // These x y z are 3D coordinates of echo or the atom the label is attached // to. output("<Billboard "); - String child = getDef("T" + colix + useFontFace + useFontStyle + "_" + text); + String child = useTable.getDef("T" + colix + useFontFace + useFontStyle + "_" + text); if (child.charAt(0) == '_') { output("DEF='" + child + "' axisOfRotation='0 0 0'>" + "<Transform translation='0.0 0.0 0.0'>" @@ -525,7 +505,7 @@ outputAppearance(colix, true); output("<Text string=" + Escape.escape(text) + ">"); output("<FontStyle "); - String fontstyle = getDef("F" + useFontFace + useFontStyle); + String fontstyle = useTable.getDef("F" + useFontFace + useFontStyle); if (fontstyle.charAt(0) == '_') { output("DEF='" + fontstyle + "' size='0.4' family='" + useFontFace + "' style='" + useFontStyle + "'/>"); Modified: trunk/Jmol/src/org/jmol/export/___Exporter.java =================================================================== --- trunk/Jmol/src/org/jmol/export/___Exporter.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/export/___Exporter.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -42,6 +42,7 @@ import javax.vecmath.Matrix4f; import javax.vecmath.Point3f; import javax.vecmath.Point3i; +import javax.vecmath.Tuple3f; import javax.vecmath.Vector3f; import org.jmol.api.JmolRendererInterface; @@ -230,15 +231,18 @@ protected void outputJmolPerspective() { outputComment("Jmol perspective:"); + outputComment("screen width height dim: " + screenWidth + " " + screenHeight + " " + viewer.getScreenDim()); outputComment("scalePixelsPerAngstrom: " + viewer.getScalePixelsPerAngstrom(false)); + outputComment("perspectiveDepth: " + viewer.getPerspectiveDepth()); outputComment("cameraDepth: " + viewer.getCameraDepth()); + outputComment("light source: " + Graphics3D.getLightSource()); + outputComment("lighting: " + viewer.getSpecularState().replace('\n', ' ')); outputComment("center: " + center); outputComment("rotationRadius: " + viewer.getRotationRadius()); outputComment("boundboxCenter: " + viewer.getBoundBoxCenter()); outputComment("translationOffset: " + viewer.getTranslationScript()); outputComment("zoom: " + viewer.getZoomPercentFloat()); outputComment("moveto command: " + viewer.getOrientationText(Token.moveto)); - outputComment("screen width height dim: " + screenWidth + " " + screenHeight + " " + viewer.getScreenDim()); } protected void outputFooter() { @@ -344,6 +348,10 @@ return (float) Math.round(number*1000)/1000; // leave just 3 decimals } + protected static String round(Tuple3f pt) { + return round(pt.x) + " " + round(pt.y) + " " + round(pt.z); + } + /** * input an array of colixes; returns a Vector for the color list and a HashTable * for correlating the colix with a specific color index @@ -459,6 +467,35 @@ g3d.plotText(x, y, z, g3d.getColorArgbOrGray(colix), text, font3d, jmolRenderer); outputComment("end text " + nText + ": " + text); } +} +class UseTable extends Hashtable { + private int iObj; + private String keyword; + UseTable(String keyword) { + this.keyword = keyword; + } + + /** + * Hashtable htDefs contains references to _n where n is a number. + * we look up a key for anything and see if an object has been assigned. + * If it is there, we just return the phrase "USE _n". + * It it is not there, we return the DEF name that needs to be assigned. + * The calling method must then make that definition. + * + * @param key + * @return "_n" or "[keyword]_n" + */ + + String getDef(String key) { + if (containsKey(key)) + return keyword + get(key); + String id = "_" + (iObj++); + put(key, id); + return id; + } + } + + Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -7368,7 +7368,6 @@ int direction = 1; int tok; boolean axesOrientationRasmol = viewer.getAxesOrientationRasmol(); - for (int i = 1; i < statementLength; ++i) { switch (tok = getToken(i).tok) { case Token.spin: Modified: trunk/Jmol/src/org/jmol/viewer/RepaintManager.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/RepaintManager.java 2009-12-21 19:08:28 UTC (rev 11968) +++ trunk/Jmol/src/org/jmol/viewer/RepaintManager.java 2009-12-22 04:40:35 UTC (rev 11969) @@ -189,7 +189,6 @@ String generateOutput(String type, Graphics3D g3d, ModelSet modelSet, String fileName) { - viewer.finalizeTransformParameters(); JmolRendererInterface g3dExport = null; Object output = null; boolean isOK = false; @@ -212,6 +211,7 @@ Logger.error("Cannot export " + type); return null; } + viewer.finalizeTransformParameters(); g3dExport.renderBackground(); for (int i = 0; i < JmolConstants.SHAPE_MAX; ++i) { Shape shape = modelSet.getShape(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |