From: Michael T H. <mic...@us...> - 2003-09-28 23:46:14
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel In directory sc8-pr-cvs1:/tmp/cvs-serv17717/src/org/openscience/jmol/viewer/datamodel Modified Files: ArcTest.java DotsRenderer.java FrameRenderer.java MeasurementRenderer.java MeasurementShape.java Log Message: some changes to improve measurement rendering in the Graphics3D world Index: ArcTest.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/ArcTest.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- ArcTest.java 17 Sep 2003 20:08:41 -0000 1.3 +++ ArcTest.java 28 Sep 2003 22:41:39 -0000 1.4 @@ -114,7 +114,7 @@ pointT.set(center); pointT.add(vector1); matrixT.transform(pointT); - g3d.plotPoint(viewer.transformPoint(pointT)); + g3d.drawPixel(viewer.transformPoint(pointT)); } } } Index: DotsRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/DotsRenderer.java,v retrieving revision 1.17 retrieving revision 1.18 diff -u -r1.17 -r1.18 --- DotsRenderer.java 25 Sep 2003 21:21:25 -0000 1.17 +++ DotsRenderer.java 28 Sep 2003 22:41:39 -0000 1.18 @@ -179,7 +179,7 @@ matrixT1.transform(torus.outerRadial, pointT1); matrixT.transform(pointT1); pointT1.add(pointT); - g3d.plotPoint(viewer.transformPoint(pointT1)); + g3d.drawPixel(viewer.transformPoint(pointT1)); } } } Index: FrameRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/FrameRenderer.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- FrameRenderer.java 26 Sep 2003 08:12:58 -0000 1.11 +++ FrameRenderer.java 28 Sep 2003 22:41:39 -0000 1.12 @@ -110,7 +110,7 @@ for (int i = frame.measurementShapeCount; --i >= 0; ) { MeasurementShape measurementShape = frame.measurementShapes[i]; - measurementShape.transform(viewer); + // measurementShape.transform(viewer); measurementRenderer.render(measurementShape); } Index: MeasurementRenderer.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/MeasurementRenderer.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- MeasurementRenderer.java 26 Sep 2003 08:12:58 -0000 1.1 +++ MeasurementRenderer.java 28 Sep 2003 22:41:39 -0000 1.2 @@ -77,20 +77,57 @@ default: throw new NullPointerException(); } - if (showMeasurementLabels) - paintMeasurementString(); } void renderDistance() { + AtomShape atomA = frame.getAtomAt(measurement.atomIndices[0]); + AtomShape atomB = frame.getAtomAt(measurement.atomIndices[1]); + int diamMax = atomA.diameter; + if (atomB.diameter > diamMax) + diamMax = atomB.diameter; + int zOffset = diamMax; + int zA = atomA.z - zOffset; + if (zA < 0) zA = 0; + int zB = atomB.z - zOffset; + if (zB < 0) zB = 0; g3d.drawDottedLine(colixDistance, - measurement.x, measurement.y, measurement.z, - measurement.xEnd, measurement.yEnd, measurement.zEnd); + atomA.x, atomA.y, zA, atomB.x, atomB.y, zB); + paintMeasurementString((atomA.x + atomB.x) / 2, + (atomA.y + atomB.y) / 2, + (zA + zB) / 2); } + void renderDihedral() { + AtomShape atomA = frame.getAtomAt(measurement.atomIndices[0]); + AtomShape atomB = frame.getAtomAt(measurement.atomIndices[1]); + AtomShape atomC = frame.getAtomAt(measurement.atomIndices[2]); + AtomShape atomD = frame.getAtomAt(measurement.atomIndices[3]); + int diamMax = atomA.diameter; + if (atomB.diameter > diamMax) + diamMax = atomB.diameter; + if (atomC.diameter > diamMax) + diamMax = atomC.diameter; + if (atomD.diameter > diamMax) + diamMax = atomD.diameter; + int zOffset = diamMax; + int zA = atomA.z - zOffset; + if (zA < 0) zA = 0; + int zB = atomB.z - zOffset; + if (zB < 0) zB = 0; + int zC = atomC.z - zOffset; + if (zC < 0) zC = 0; + int zD = atomD.z - zOffset; + if (zD < 0) zD = 0; g3d.drawDottedLine(colixDistance, - measurement.x, measurement.y, measurement.z, - measurement.xEnd, measurement.yEnd, measurement.zEnd); + atomA.x, atomA.y, zA, atomB.x, atomB.y, zB); + g3d.drawDottedLine(colixDistance, + atomB.x, atomB.y, zB, atomC.x, atomC.y, zC); + g3d.drawDottedLine(colixDistance, + atomC.x, atomC.y, zC, atomD.x, atomD.y, zD); + paintMeasurementString((atomA.x + atomB.x + atomC.x + atomD.x) / 4, + (atomA.y + atomB.y + atomC.y + atomD.y) / 4, + (zA + zB + zC + zD) / 4); } AxisAngle4f aaT = new AxisAngle4f(); @@ -99,38 +136,63 @@ void renderAngle() { g3d.setColix(colixDistance); + AtomShape atomA = frame.getAtomAt(measurement.atomIndices[0]); + AtomShape atomB = frame.getAtomAt(measurement.atomIndices[1]); + AtomShape atomC = frame.getAtomAt(measurement.atomIndices[2]); + int diamMax = atomA.diameter; + if (atomB.diameter > diamMax) + diamMax = atomB.diameter; + if (atomC.diameter > diamMax) + diamMax = atomC.diameter; + int zOffset = diamMax; + int zA = atomA.z - zOffset; + if (zA < 0) zA = 0; + int zB = atomB.z - zOffset; + if (zB < 0) zB = 0; + int zC = atomC.z - zOffset; + if (zC < 0) zC = 0; + g3d.drawDottedLine(colixDistance, + atomA.x, atomA.y, zA, atomB.x, atomB.y, zB); + g3d.drawDottedLine(colixDistance, + atomB.x, atomB.y, zB, atomC.x, atomC.y, zC); + AxisAngle4f aa = measurement.aa; - Vector3f vector21 = measurement.vector21; // FIXME mth -- this really should be a function of pixelsPerAngstrom int dotCount = (int)((aa.angle / (2 * Math.PI)) * 64); float stepAngle = aa.angle / dotCount; aaT.set(aa); + int iMid = dotCount / 2; for (int i = dotCount; --i >= 0; ) { aaT.angle = i * stepAngle; matrixT.set(aaT); - pointT.set(vector21); - pointT.scale(0.75f); + pointT.set(measurement.pointArc); matrixT.transform(pointT); - pointT.add(measurement.center); - g3d.plotPoint(viewer.transformPoint(pointT)); + pointT.add(atomB.point3f); + Point3i screenArc = viewer.transformPoint(pointT); + int zArc = screenArc.z - zOffset; + if (zArc < 0) zArc = 0; + g3d.drawPixel(screenArc.x, screenArc.y, zArc); + if (i == iMid) { + pointT.set(measurement.pointArc); + pointT.scale(1.1f); + matrixT.transform(pointT); + pointT.add(atomB.point3f); + Point3i screenLabel = viewer.transformPoint(pointT); + int zLabel = screenLabel.z - zOffset; + if (zLabel < 0) zLabel = 0; + paintMeasurementString(screenLabel.x, screenLabel.y, zLabel); + } } - int xC, yC, zC; - Point3i pointC = viewer.transformPoint(measurement.center); - g3d.drawDottedLine(colixDistance, - pointC.x, pointC.y, pointC.z, measurement.x, measurement.y, measurement.z); - g3d.drawDottedLine(colixDistance, - pointC.x, pointC.y, pointC.z, measurement.xEnd, measurement.yEnd, measurement.zEnd); } - void paintMeasurementString() { + void paintMeasurementString(int x, int y, int z) { + if (! showMeasurementLabels) + return; String strMeasurement = measurement.strMeasurement; Font font = viewer.getMeasureFont(10); g3d.setFont(font); FontMetrics fontMetrics = g3d.getFontMetrics(font); int j = fontMetrics.stringWidth(strMeasurement); - int xT = (measurement.x + measurement.xEnd) / 2; - int yT = (measurement.y + measurement.yEnd) / 2; - int zT = (measurement.z + measurement.zEnd) / 2; - g3d.drawString(strMeasurement, colixDistance, xT, yT, zT); + g3d.drawString(strMeasurement, colixDistance, x+2, y, z); } } Index: MeasurementShape.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/viewer/datamodel/MeasurementShape.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- MeasurementShape.java 26 Sep 2003 08:12:58 -0000 1.11 +++ MeasurementShape.java 28 Sep 2003 22:41:39 -0000 1.12 @@ -33,73 +33,49 @@ import javax.vecmath.Matrix3f; import javax.vecmath.AxisAngle4f; -public class MeasurementShape extends LineShape { +public class MeasurementShape { + public int count; public int[] atomIndices; public String strMeasurement; - public Point3f center, pointT; - Vector3f vector21; - public int count; - AxisAngle4f aa, aaT; - Matrix3f matrixT; - + AxisAngle4f aa; + Point3f pointArc; + public MeasurementShape(JmolFrame frame, int count, int[] atomIndices) { - Point3f point1 = frame.getAtomPoint3f(atomIndices[0]); - Point3f point2 = frame.getAtomPoint3f(atomIndices[1]); - Point3f point3 = null; - Point3f point4 = null; + Point3f pointA = frame.getAtomPoint3f(atomIndices[0]); + Point3f pointB = frame.getAtomPoint3f(atomIndices[1]); + Point3f pointC = null; + Point3f pointD = null; this.count = count; switch (count) { case 2: - strMeasurement = formatDistance(point1.distance(point2));; - - pointOrigin = point1; - pointEnd = point2; + strMeasurement = formatDistance(pointA.distance(pointB)); break; case 3: - point3 = frame.getAtomPoint3f(atomIndices[2]); - vector21 = new Vector3f(point1); - vector21.sub(point2); - Vector3f vector23 = new Vector3f(point3); - vector23.sub(point2); - float angle = vector21.angle(vector23); + pointC = frame.getAtomPoint3f(atomIndices[2]); + Vector3f vectorBA = new Vector3f(); + Vector3f vectorBC = new Vector3f(); + vectorBA.sub(pointA, pointB); + vectorBC.sub(pointC, pointB); + float angle = vectorBA.angle(vectorBC); float degrees = toDegrees(angle); strMeasurement = formatAngle(degrees); - float len21 = vector21.length(); - float len23 = vector23.length(); - if (len21 < len23) - vector23.scale(len21/len23); - else - vector21.scale(len23/len21); - - pointOrigin = new Point3f(point2); - pointOrigin.add(vector21); - pointEnd = new Point3f(point2); - pointEnd.add(vector23); - - center = point2; Vector3f vectorAxis = new Vector3f(); - vectorAxis.cross(vector21, vector23); + vectorAxis.cross(vectorBA, vectorBC); aa = new AxisAngle4f(vectorAxis.x, vectorAxis.y, vectorAxis.z, angle); - pointT = new Point3f(); - aaT = new AxisAngle4f(); - matrixT = new Matrix3f(); + vectorBA.normalize(); + vectorBA.scale(0.5f); + pointArc = new Point3f(vectorBA); + break; case 4: - point3 = frame.getAtomPoint3f(atomIndices[2]); - point4 = frame.getAtomPoint3f(atomIndices[3]); - float dihedral = computeDihedral(point1, point2, point3, point4); + pointC = frame.getAtomPoint3f(atomIndices[2]); + pointD = frame.getAtomPoint3f(atomIndices[3]); + float dihedral = computeDihedral(pointA, pointB, pointC, pointD); strMeasurement = formatAngle(dihedral); - - pointOrigin = new Point3f(point1); - pointOrigin.add(point2); - pointOrigin.scale(0.5f); - pointEnd = new Point3f(point3); - pointEnd.add(point4); - pointEnd.scale(0.5f); break; default: System.out.println("Invalid count to measurement shape:" + count); |