From: <ha...@us...> - 2008-04-24 01:53:15
|
Revision: 9307 http://jmol.svn.sourceforge.net/jmol/?rev=9307&view=rev Author: hansonr Date: 2008-04-23 18:53:12 -0700 (Wed, 23 Apr 2008) Log Message: ----------- version=11.5.31_dev ellipsoid rendering # code: better ellipsoid ball rendering using Shade3D.calcIntensity() # code: 2-fold improvement on rendering of ellipsoids by not using getNormix() Modified Paths: -------------- trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java trunk/Jmol/src/org/jmol/export/Export3D.java trunk/Jmol/src/org/jmol/g3d/Graphics3D.java trunk/Jmol/src/org/jmol/g3d/Normix3D.java trunk/Jmol/src/org/jmol/shapespecial/EllipsoidsRenderer.java trunk/Jmol/src/org/jmol/symmetry/UnitCell.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java =================================================================== --- trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/api/JmolRendererInterface.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -255,6 +255,10 @@ public abstract void fillTriangle(Point3i screenA, Point3i screenB, Point3i screenC); + public void fillTriangle(Point3i screenA, int intensityA, + Point3i screenB, int intensityB, + Point3i screenC, int intensityC); + public abstract void fillTriangle(Point3i screenA, short colixA, short normixA, Point3i screenB, short colixB, short normixB, @@ -288,7 +292,7 @@ public abstract String getHexColorFromIndex(short colix); - public abstract void calcSurfaceShade(Point3i screenA, Point3i screenB, + public abstract int calcSurfaceShade(Point3i screenA, Point3i screenB, Point3i screenC); public abstract byte getFontFid(String fontFace, float fontSize); Modified: trunk/Jmol/src/org/jmol/export/Export3D.java =================================================================== --- trunk/Jmol/src/org/jmol/export/Export3D.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/export/Export3D.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -536,6 +536,15 @@ fillTriangle(ptA, ptB, ptC); } + public void fillTriangle(Point3i pointA, int intensityA, + Point3i pointB, int intensityB, + Point3i pointC, int intensityC) { + ptA.set(pointA.x, pointA.y, pointA.z); + ptB.set(pointB.x, pointB.y, pointB.z); + ptC.set(pointC.x, pointC.y, pointC.z); + exporter.fillTriangle(colix, ptA, ptB, ptC); + } + public void fillTriangle(Point3i pointA, short colixA, short normixA, Point3i pointB, short colixB, short normixB, Point3i pointC, short colixC, short normixC) { @@ -720,8 +729,8 @@ return g3d.getHexColorFromIndex(colix); } - public void calcSurfaceShade(Point3i pointA, Point3i pointB, Point3i pointC) { - g3d.calcSurfaceShade(pointA, pointB, pointC); + public int calcSurfaceShade(Point3i pointA, Point3i pointB, Point3i pointC) { + return g3d.calcSurfaceShade(pointA, pointB, pointC); } public byte getFontFid(String fontFace, float fontSize) { @@ -756,5 +765,5 @@ public byte getFontFid(float fontSize) { return g3d.getFontFid(fontSize); } - + } Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -1259,6 +1259,13 @@ triangle3d.fillTriangle(xA, yA, zA, xB, yB, zB, xC, yC, zC, false); } + public void fillTriangle(Point3i screenA, int intensityA, + Point3i screenB, int intensityB, + Point3i screenC, int intensityC) { + triangle3d.setGouraud(intensityA, intensityB, intensityC); + triangle3d.fillTriangle(screenA, screenB, screenC, true); + } + public void fillTriangle(Point3i screenA, short colixA, short normixA, Point3i screenB, short colixB, short normixB, Point3i screenC, short colixC, short normixC) { @@ -2131,22 +2138,25 @@ private final Vector3f vectorNormal = new Vector3f(); // these points are in screen coordinates even though 3f - public void calcSurfaceShade(Point3i screenA, Point3i screenB, Point3i screenC) { - vectorAB.x = screenB.x - screenA.x; - vectorAB.y = screenB.y - screenA.y; - vectorAB.z = screenB.z - screenA.z; - - vectorAC.x = screenC.x - screenA.x; - vectorAC.y = screenC.y - screenA.y; - vectorAC.z = screenC.z - screenA.z; - - vectorNormal.cross(vectorAB, vectorAC); - int intensity = vectorNormal.z >= 0 ? Shade3D.calcIntensity( - -vectorNormal.x, -vectorNormal.y, vectorNormal.z) : Shade3D - .calcIntensity(vectorNormal.x, vectorNormal.y, -vectorNormal.z); + public int calcSurfaceShade(Point3i screenA, Point3i screenB, Point3i screenC) { + // or center and point, as for an ellipse + vectorAB.set(screenB.x - screenA.x, screenB.y - screenA.y, screenB.z + - screenA.z); + int intensity; + if (screenC == null) { + intensity = Shade3D.calcIntensity(-vectorAB.x, -vectorAB.y, vectorAB.z); + } else { + vectorAC.set(screenC.x - screenA.x, screenC.y - screenA.y, screenC.z + - screenA.z); + vectorAB.cross(vectorAB, vectorAC); + intensity = vectorAB.z >= 0 ? Shade3D.calcIntensity(-vectorAB.x, + -vectorAB.y, vectorAB.z) : Shade3D.calcIntensity(vectorAB.x, + vectorAB.y, -vectorAB.z); + } if (intensity > intensitySpecularSurfaceLimit) intensity = intensitySpecularSurfaceLimit; setColorNoisy(intensity); + return argbCurrent; } private int calcIntensityScreen(Point3f screenA, Modified: trunk/Jmol/src/org/jmol/g3d/Normix3D.java =================================================================== --- trunk/Jmol/src/org/jmol/g3d/Normix3D.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/g3d/Normix3D.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -74,6 +74,7 @@ Logger.debug("begin timings!"); for (int i = 0; i < normixCount; ++i) { short normix = getNormix(vertexVectors[i]); + System.out.println("draw normix" + i + " {" + vertexVectors[i].x + " " + vertexVectors[i].y + " " + vertexVectors[i].z + "} {0 0 0} \""+i+"\""); if (normix != i) if (Logger.debugging) { Logger.debug("" + i + " -> " + normix); Modified: trunk/Jmol/src/org/jmol/shapespecial/EllipsoidsRenderer.java =================================================================== --- trunk/Jmol/src/org/jmol/shapespecial/EllipsoidsRenderer.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/shapespecial/EllipsoidsRenderer.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -39,13 +39,12 @@ private Ellipsoids ellipsoids; private boolean drawDots, drawArcs, drawAxes, drawFill, drawBall; - private boolean wireframeOnly; + private boolean wireframeOnly, perspectiveOn; private int dotCount; private int[] coords; private Vector3f[] axes; private final float[] lengths = new float[3]; private int diameter, diameter0; - protected void render() { ellipsoids = (Ellipsoids) shape; if (ellipsoids.mads == null) @@ -57,7 +56,7 @@ drawDots = viewer.getBooleanProperty("ellipsoidDots") && !wireframeOnly; drawFill = viewer.getBooleanProperty("ellipsoidFill") && !wireframeOnly; diameter0 = (int) (((Float) viewer.getParameter("ellipsoidAxisDiameter")).floatValue() * 1000); - + perspectiveOn = viewer.getPerspectiveDepth(); /* general logic: * * @@ -100,7 +99,7 @@ } private final Point3i[] screens = new Point3i[32]; - private final short[] normixes = new short[32]; + private final int[] intensities = new int[32]; private final Point3f[] points = new Point3f[6]; { for (int i = 0; i < points.length; i++) @@ -113,7 +112,7 @@ // octants are sets of three axisPoints references in proper rotation order // axisPoints[octants[i]] indicates the axis and direction (pos/neg) - private static int[] octants = { +/* private static int[] octants = { 0, 3, 5, 0, 5, 2, //arc 0, 2, 4, @@ -123,14 +122,27 @@ 1, 4, 3, 1, 2, 4 //arc }; - +*/ + private static int[] octants = { + 5, 0, 3, + 5, 2, 0, //arc + 4, 0, 2, + 4, 3, 0, //arc + 5, 2, 1, + 5, 1, 3, //arc + 4, 3, 1, + 4, 1, 2 //arc + }; + private void render1(Atom atom, short mad, Object[] ellipsoid) { s0.set(atom.screenX, atom.screenY, atom.screenZ); + //System.out.println(ellipsoid[2]); axes = (Vector3f[]) ellipsoid[0]; float[] af = (float[]) ellipsoid[1]; float f = mad / 100.0f * 4f; for (int i = 3; --i >= 0; ) lengths[i] = af[i] * f; + //[0] is shortest; [2] is longest if (drawAxes || drawArcs || drawBall) setAxes(atom, 1.0f); diameter = viewer.scaleToScreen(atom.screenZ, wireframeOnly ? 1 : diameter0); @@ -161,6 +173,11 @@ points[i].scaleAdd(f * lengths[i012] * (iAxis < 0 ? -1 : 1), axes[i012], atom); viewer.transformPoint(points[i], screens[i]); } + //System.out.println(atom); + //for (int i = 0; i < 6; i++) { + //s1.scaleAdd(-1, screens[i], s0); + //System.out.println(s1); + //} } private void renderAxes() { @@ -274,7 +291,7 @@ screens[i == 17 ? i + 7 : i + 8]); } - private void renderBall(Point3f ptAtom) { + private void renderBall(Atom atom) { int iCutout = -1; int zMin = Integer.MAX_VALUE; if (drawFill) @@ -289,23 +306,39 @@ } } - for (int i = 0; i < 8; i++) { - int ptA = octants[i * 3]; - int ptB = octants[i * 3 + 1]; - int ptC = octants[i * 3 + 2]; - boolean isSwapped = (axisPoints[ptA] < 0); - renderBall(ptAtom, axisPoints[ptA], axisPoints[ptB], axisPoints[ptC], - isSwapped, iCutout == i); + if (true || perspectiveOn) { + for (int i = 0; i < 8; i++) { + int ptA = octants[i * 3]; + int ptB = octants[i * 3 + 1]; + int ptC = octants[i * 3 + 2]; + boolean isSwapped = (axisPoints[ptA] < 0); + renderBall(atom, axisPoints[ptA], axisPoints[ptB], axisPoints[ptC], + isSwapped, iCutout == i); + } + return; } + // max distance is longest + int scrRadius = viewer.scaleToScreen(atom.screenZ, (int) (lengths[2] * 1000)); + //System.out.println(atom.getAtomIndex() + " " + atom.isClickable() + " r=" + scrRadius + " " + atom.screenX + " "+ atom.screenY + " " + atom.screenZ); + int x = atom.screenX - scrRadius + 1; + int y = atom.screenY - scrRadius + 1; + for (int ix = x; --ix >= 0; ) + for (int iy = y; --iy >= 0; ) { + //pt1.set(ix, iy, ); + //viewer.untransformPoint() + //renderPixel(ix, iy, atom); + } + } + Vector3f a = new Vector3f(); Vector3f b = new Vector3f(); Vector3f c = new Vector3f(); private void renderBall(Point3f ptAtom, int axisA, int axisB, int axisC, boolean isSwapped, boolean cutoutOnly) { - int nSegments = 16; + int nSegments = 24; int i; a.set(axes[i = (Math.abs(axisA) - 1)]); float la = lengths[i]; @@ -326,8 +359,8 @@ renderCutout(ptAtom, c, b, lc, lb, nSegments, isSwapped); return; } - short n2 = 0; - short normix = 0; + int intensity2 = 0; + int intensity = 0; for (int ifx = 0, ify = 0, scrPt = 0; ifx < nSegments; ifx++) { float fx = ifx * 1f / (nSegments - 1); for (ify = 0; ify < nSegments; ify++) { @@ -337,34 +370,39 @@ fy = (float) Math.sqrt(1 - fx * fx); fz = 0; } + //15 ms pt1.scaleAdd(fx * la, a, ptAtom); pt1.scaleAdd(fy * lb, b, pt1); pt1.scaleAdd(fz * lc, c, pt1); viewer.transformPoint(pt1, s1); - v1.set(pt1); - v1.sub(ptAtom); - normix = g3d.getNormix(v1); + //90 ms + intensity = g3d.calcSurfaceShade(s1, s0, null); + //438 ms scrPt = ify + 6; if (ify != 0) { if (ifx != 0) { - if (isSwapped) - g3d.fillQuadrilateral(s2, colix, n2, s1, colix, normix, - screens[scrPt], colix, normixes[scrPt], screens[scrPt - 1], - colix, normixes[scrPt - 1]); - else - g3d.fillQuadrilateral(screens[scrPt - 1], colix, - normixes[scrPt - 1], screens[scrPt], colix, normixes[scrPt], - s1, colix, normix, s2, colix, n2); + if (isSwapped) { + g3d.fillTriangle(s2, intensity2, s1, intensity, + screens[scrPt], intensities[scrPt]); + g3d.fillTriangle(s2, intensity2, screens[scrPt], intensities[scrPt], + screens[scrPt - 1], intensities[scrPt - 1]); + } else { + g3d.fillTriangle(screens[scrPt - 1], intensities[scrPt - 1], + screens[scrPt], intensities[scrPt], s1, intensity); + g3d.fillTriangle(screens[scrPt - 1], intensities[scrPt - 1], + s1, intensity, s2, intensity2); + } } screens[scrPt - 1].set(s2); - normixes[scrPt - 1] = n2; + intensities[scrPt - 1] = intensity2; } s2.set(s1); - n2 = normix; + intensity2 = intensity; } screens[scrPt].set(s2); - normixes[scrPt] = n2; + intensities[scrPt] = intensity2; } + //547 ms } private void renderCutout(Point3f ptAtom, Vector3f a, Vector3f b, Modified: trunk/Jmol/src/org/jmol/symmetry/UnitCell.java =================================================================== --- trunk/Jmol/src/org/jmol/symmetry/UnitCell.java 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/symmetry/UnitCell.java 2008-04-24 01:53:12 UTC (rev 9307) @@ -259,7 +259,7 @@ // System.out.println("draw v" + i + " {0 0 0} " + Escape.escape(v) + "# "+lengths[i]); } // System.out.println(); - return new Object[] {unitVectors, lengths}; + return new Object[] {unitVectors, lengths, BP}; } } Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-04-22 19:07:42 UTC (rev 9306) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2008-04-24 01:53:12 UTC (rev 9307) @@ -3,6 +3,8 @@ version=11.5.31_dev +# code: better ellipsoid ball rendering using Shade3D.calcIntensity() +# code: 2-fold improvement on rendering of ellipsoids by not using getNormix() # bug fix: sequence range for missing sequence numbers returns 0 # ----------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |