From: Michael T H. <mic...@us...> - 2003-08-02 00:38:18
|
Update of /cvsroot/jmol/Jmol/src/org/openscience/jmol/render In directory sc8-pr-cvs1:/tmp/cvs-serv17114/src/org/openscience/jmol/render Modified Files: JmolFrame.java LineShape.java Added Files: ArrowLineShape.java Log Message: added arrowlineshape, fixed bug with sphere of size 0, vector work --- NEW FILE: ArrowLineShape.java --- /* $RCSfile: ArrowLineShape.java,v $ * $Author: michaelthoward $ * $Date: 2003/08/02 00:38:15 $ * $Revision: 1.1 $ * * Copyright (C) 2003 The Jmol Development Team * * Contact: jmo...@li... * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA * 02111-1307 USA. */ package org.openscience.jmol.render; import org.openscience.jmol.g25d.Graphics25D; import org.openscience.jmol.DisplayControl; import java.awt.Rectangle; import javax.vecmath.Point3d; import javax.vecmath.Point3i; public class ArrowLineShape extends LineShape { double headWidthAngstroms; int[] ax = new int[4]; int[] ay = new int[4]; int[] az = new int[4]; final static int widthDivisor = 8; final static int shaftDivisor = 5; final static int finDivisor = 6; public ArrowLineShape(Point3d pointOrigin, Point3d pointVector) { super(pointOrigin, pointVector); headWidthAngstroms = pointOrigin.distance(this.pointEnd) / widthDivisor; } public void render(Graphics25D g25d, DisplayControl control) { short colixVector = control.getColixVector(); g25d.drawLine(colixVector, x, y, z, xEnd, yEnd, zEnd); int dx = xEnd - x, xHead = xEnd - (dx / shaftDivisor); int dy = yEnd - y, yHead = yEnd - (dy / shaftDivisor); int mag2d = (int)(Math.sqrt(dx*dx + dy*dy) + 0.5); int dz = zEnd - z, zHead = zEnd - (dz / shaftDivisor); int headWidthPixels = (int)(control.scaleToScreen(zHead, headWidthAngstroms) + 0.5); ax[0] = xEnd; ax[2] = xEnd - dx/finDivisor; ay[0] = yEnd; ay[2] = yEnd - dy/finDivisor; az[0] = zEnd; az[2] = zEnd - dz/finDivisor; int dxHead, dyHead; if (mag2d == 0) { dxHead = 0; dyHead = headWidthPixels; } else { dxHead = headWidthPixels * -dy / mag2d; dyHead = headWidthPixels * dx / mag2d; } ax[1] = xHead - dxHead/2; ax[3] = ax[1] + dxHead; ay[1] = yHead - dyHead/2; ay[3] = ay[1] + dyHead; az[1] = zHead; az[3] = zHead; g25d.fillPolygon4(colixVector, ax, ay, az); } } Index: JmolFrame.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/JmolFrame.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- JmolFrame.java 1 Aug 2003 01:13:15 -0000 1.1 +++ JmolFrame.java 2 Aug 2003 00:38:15 -0000 1.2 @@ -36,6 +36,7 @@ public class JmolFrame { DisplayControl control; + Shape[] shapes; public JmolFrame(DisplayControl control) { this.control = control; @@ -101,9 +102,6 @@ private Point3d centerRotation; private double radiusBoundingBox; private double radiusRotation; - private double minAtomVectorMagnitude; - private double maxAtomVectorMagnitude; - private double atomVectorRange; public double getGeometricRadius() { findBounds(); @@ -140,25 +138,9 @@ } } - public double getMinAtomVectorMagnitude() { - findBounds(); - return minAtomVectorMagnitude; - } - - public double getMaxAtomVectorMagnitude() { - findBounds(); - return maxAtomVectorMagnitude; - } - - public double getAtomVectorRange() { - findBounds(); - return maxAtomVectorMagnitude - minAtomVectorMagnitude; - } - public void clearBounds() { centerBoundingBox = centerRotation = null; - radiusBoundingBox = radiusRotation = - minAtomVectorMagnitude = maxAtomVectorMagnitude = atomVectorRange = 0f; + radiusBoundingBox = radiusRotation = 0; } private void findBounds() { @@ -166,30 +148,9 @@ return; calcBoundingBox(); centerRotation = centerBoundingBox; - calculateAtomVectorMagnitudeRange(); radiusBoundingBox = radiusRotation = calcRadius(centerBoundingBox); } - void calculateAtomVectorMagnitudeRange() { - /* - minAtomVectorMagnitude = maxAtomVectorMagnitude = -1; - for (int i = 0; i < atomShapeCount; ++i) { - AtomShape atom = atomShapes[i]; - if (!atom.hasVector()) - continue; - double magnitude=atom.getVectorMagnitude(); - if (magnitude > maxAtomVectorMagnitude) { - maxAtomVectorMagnitude = magnitude; - } - if ((magnitude < minAtomVectorMagnitude) || - (minAtomVectorMagnitude == -1)) { - minAtomVectorMagnitude = magnitude; - } - } - atomVectorRange = maxAtomVectorMagnitude - minAtomVectorMagnitude; - */ - } - private void calcBoundingBox() { /** * Note that this method is overridden by CrystalFrame @@ -198,23 +159,26 @@ // as stored in the file // Note that this is not really the geometric center of the molecule // ... for this we would need to do a Minimal Enclosing Sphere calculation - Point3d position = atomShapes[0].getPoint3d(); - double minX = position.x, maxX = minX; - double minY = position.y, maxY = minY; - double minZ = position.z, maxZ = minZ; - - for (int i = 1; i < atomShapeCount; ++i) { - position = atomShapes[i].getPoint3d(); - double x = position.x; - if (x < minX) { minX = x; } - if (x > maxX) { maxX = x; } - double y = position.y; - if (y < minY) { minY = y; } - if (y > maxY) { maxY = y; } - double z = position.z; - if (z < minZ) { minZ = z; } - if (z > maxZ) { maxZ = z; } + Point3d point = atomShapes[0].getPoint3d(); + double minX, minY, minZ, maxX, maxY, maxZ; + minX = maxX = point.x; + minY = maxY = point.y; + minZ = maxZ = point.z; + + for (int i = atomShapeCount; --i > 0; ) { // note that the 0 element was set above + point = atomShapes[i].getPoint3d(); + double t; + t = point.x; + if (t < minX) { minX = t; } + else if (t > maxX) { maxX = t; } + t = point.y; + if (t < minY) { minY = t; } + else if (t > maxY) { maxY = t; } + t = point.z; + if (t < minZ) { minZ = t; } + else if (t > maxZ) { maxZ = t; } } + centerBoundingBox = new Point3d((minX + maxX) / 2, (minY + maxY) / 2, (minZ + maxZ) / 2); @@ -261,6 +225,16 @@ } */ } + for (int i = lineShapeCount; --i >= 0; ) { + LineShape ls = lineShapes[i]; + double distLineEnd; + distLineEnd = center.distance(ls.getPoint1()); + if (distLineEnd > radius) + radius = distLineEnd; + distLineEnd = center.distance(ls.getPoint2()); + if (distLineEnd > radius) + radius = distLineEnd; + } return radius; } @@ -269,7 +243,7 @@ return; if (shapes == null || control.hasStructuralChange()) { AtomShape[] atomShapes = this.atomShapes; - Shape[] vectorShapes = this.vectorShapes; + LineShape[] lineShapes = this.lineShapes; Shape[] axisShapes = null; int axisShapeCount = 0; Shape[] bboxShapes = null; @@ -283,16 +257,16 @@ bboxShapeCount = bboxShapes.length; } int shapeCount = - atomShapeCount + vectorShapeCount + axisShapeCount + bboxShapeCount; + atomShapeCount + lineShapeCount + axisShapeCount + bboxShapeCount; shapes = new Shape[shapeCount]; int i = 0; System.arraycopy(atomShapes, 0, shapes, i, atomShapeCount); i += atomShapeCount; - if (vectorShapes != null) { - System.arraycopy(vectorShapes, 0, shapes, i, vectorShapeCount); - i += vectorShapeCount; + if (lineShapes != null) { + System.arraycopy(lineShapes, 0, shapes, i, lineShapeCount); + i += lineShapeCount; } if (axisShapes != null) { System.arraycopy(axisShapes, 0, shapes, i, axisShapeCount); @@ -364,21 +338,18 @@ control.measureRenderer.render(g25d, control); } - private Shape[] shapes = null; - - - private final static int vectorGrowthIncrement = 16; - private int vectorShapeCount = 0; - private Shape[] vectorShapes = null; - - public void addVectorShape(Shape shape) { - if (vectorShapes == null || vectorShapeCount == vectorShapes.length) { - Shape[] newShapes = new Shape[vectorShapeCount + vectorGrowthIncrement]; - if (vectorShapes != null) - System.arraycopy(vectorShapes, 0, newShapes, 0, vectorShapeCount); - vectorShapes = newShapes; + final static int lineGrowthIncrement = 16; + private int lineShapeCount = 0; + private LineShape[] lineShapes = null; + + public void addLineShape(LineShape shape) { + if (lineShapes == null || lineShapeCount == lineShapes.length) { + LineShape[] newShapes = new LineShape[lineShapeCount + lineGrowthIncrement]; + if (lineShapes != null) + System.arraycopy(lineShapes, 0, newShapes, 0, lineShapeCount); + lineShapes = newShapes; } - vectorShapes[vectorShapeCount++] = shape; + lineShapes[lineShapeCount++] = shape; } /**************************************************************** Index: LineShape.java =================================================================== RCS file: /cvsroot/jmol/Jmol/src/org/openscience/jmol/render/LineShape.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- LineShape.java 1 Aug 2003 18:51:32 -0000 1.21 +++ LineShape.java 2 Aug 2003 00:38:15 -0000 1.22 @@ -43,6 +43,14 @@ this.pointEnd = pointEnd; } + public Point3d getPoint1() { + return pointOrigin; + } + + public Point3d getPoint2() { + return pointEnd; + } + public String toString() { return "Primitive line shape"; } |