View Javadoc

1   // Copyright 2004-2005, FreeHEP.
2   package hep.wired.heprep.representation;
3   
4   import java.util.*;
5   
6   import org.freehep.graphics2d.VectorGraphics;
7   import hep.graphics.heprep.HepRepInstance;
8   import hep.graphics.heprep.HepRepPoint;
9   
10  import hep.wired.heprep.services.GraphicsMode;
11  import hep.wired.heprep.services.Attributes;
12  import hep.wired.heprep.services.Projection;
13  import hep.wired.heprep.services.DrawAs;
14  import hep.wired.heprep.util.PolyPoint;
15  import hep.wired.services.ViewPort;
16  
17  /***
18   * Drows one or more ellipsoids, centered on HepRepPoints with given "Radius", "Radius2" and 
19   * "Radius3", positioned by "Phi", "Theta" and "Omega".
20   *
21   * @author Mark Donszelmann
22   * @version $Id: DrawAsEllipsoid.java 645 2005-02-27 02:23:41Z duns $
23   */
24  
25  public class DrawAsEllipsoid extends AbstractDrawAs {
26  
27      private double uvw[][][] = new double[3][3][PolyPoint.ELLIPSEPOINTS];
28  
29      public String getKey() {
30          return "ellipsoid";
31      }
32  
33      public String getName() {
34          return "Ellipsoid";
35      }
36      
37      public String getDescription() {
38          return "Draws a HepRepInstance as an Ellipse.";
39      }
40  
41      private double[][][] createEllipsoids(double r1, double r2, double r3,
42                                            double x, double y, double z,
43                                            double phi, double theta, double omega, double[][][] uvw) {
44          PolyPoint.ellipse(r3, r2, x, y, z, phi-Math.PI/2, theta, omega, uvw[X]);
45          PolyPoint.ellipse(r1, r3, x, y, z, phi, theta+Math.PI/2, omega, uvw[Y]);
46          PolyPoint.ellipse(r1, r2, x, y, z, phi, theta, omega, uvw[Z]);
47          return uvw;
48      }
49  
50      public void draw(VectorGraphics graphics, HepRepInstance instance,
51                       Attributes atts,  GraphicsMode mode, 
52                       Projection projection, ViewPort viewPort) {
53  
54          Iterator iterator = instance.getPoints().iterator();
55          while (iterator.hasNext()) {
56              HepRepPoint center = (HepRepPoint)iterator.next();
57      
58              uvw = createEllipsoids(center.getAttValue("radius").getDouble(),
59                                     center.getAttValue("radius2").getDouble(),
60                                     center.getAttValue("radius3").getDouble(),
61                                     center.getX(), center.getY(), center.getZ(),
62                                     center.getAttValue("phi").getDouble(), 
63                                     center.getAttValue("theta").getDouble(), 
64                                     center.getAttValue("omega").getDouble(), 
65                                     uvw);
66              uvw[X] = projection.transform(viewPort, uvw[X], PolyPoint.ELLIPSEPOINTS);
67              uvw[Y] = projection.transform(viewPort, uvw[Y], PolyPoint.ELLIPSEPOINTS);
68              uvw[Z] = projection.transform(viewPort, uvw[Z], PolyPoint.ELLIPSEPOINTS);
69  
70              if (atts.isFilled()) {
71                  graphics.setColor(atts.getFillColor());
72                  graphics.fillPolygon(uvw[X][U], uvw[X][V], PolyPoint.ELLIPSEPOINTS);
73                  graphics.fillPolygon(uvw[Y][U], uvw[Y][V], PolyPoint.ELLIPSEPOINTS);
74                  graphics.fillPolygon(uvw[Z][U], uvw[Z][V], PolyPoint.ELLIPSEPOINTS);
75                  graphics.setColor(atts.getColor());
76              }
77              graphics.drawPolygon(uvw[X][U], uvw[X][V], PolyPoint.ELLIPSEPOINTS);
78              graphics.drawPolygon(uvw[Y][U], uvw[Y][V], PolyPoint.ELLIPSEPOINTS);
79              graphics.drawPolygon(uvw[Z][U], uvw[Z][V], PolyPoint.ELLIPSEPOINTS);
80          }
81      }
82  
83      public void frame(VectorGraphics graphics, HepRepInstance instance,
84                        Attributes atts,  GraphicsMode mode, 
85                        Projection projection, ViewPort viewPort) {
86  
87          graphics.setColor(atts.getFrameColor());
88          graphics.setLineWidth(atts.getFrameWidth()*2+atts.getLineWidth());
89  
90          Iterator iterator = instance.getPoints().iterator();
91          while (iterator.hasNext()) {
92              HepRepPoint center = (HepRepPoint)iterator.next();
93              uvw = createEllipsoids(center.getAttValue("radius").getDouble(),
94                                     center.getAttValue("radius2").getDouble(),
95                                     center.getAttValue("radius3").getDouble(),
96                                     center.getX(), center.getY(), center.getZ(),
97                                     center.getAttValue("phi").getDouble(), 
98                                     center.getAttValue("theta").getDouble(), 
99                                     center.getAttValue("omega").getDouble(), 
100                                    uvw);
101             uvw[X] = projection.transform(viewPort, uvw[X], PolyPoint.ELLIPSEPOINTS);
102             uvw[Y] = projection.transform(viewPort, uvw[Y], PolyPoint.ELLIPSEPOINTS);
103             uvw[Z] = projection.transform(viewPort, uvw[Z], PolyPoint.ELLIPSEPOINTS);
104 
105             graphics.drawPolygon(uvw[X][U], uvw[X][V], PolyPoint.ELLIPSEPOINTS);
106             graphics.drawPolygon(uvw[Y][U], uvw[Y][V], PolyPoint.ELLIPSEPOINTS);
107             graphics.drawPolygon(uvw[Z][U], uvw[Z][V], PolyPoint.ELLIPSEPOINTS);
108         }
109 
110         graphics.setLineWidth(atts.getLineWidth());
111         graphics.setColor(atts.getColor());
112     }
113 }