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   * Draws one or more ellipses, centered at HepRepPoints, with given "Radius" and "Radius2", 
19   * positioned using "Phi", "Theta" and "Omega".
20   * @author Mark Donszelmann
21   * @version $Id: DrawAsEllipse.java 645 2005-02-27 02:23:41Z duns $
22   */
23  
24  public class DrawAsEllipse extends AbstractDrawAs {
25  
26      private double uvw[][] = new double[3][PolyPoint.ELLIPSEPOINTS];
27  
28      public String getKey() {
29          return "ellipse";
30      }
31  
32      public String getName() {
33          return "Ellipse";
34      }
35      
36      public String getDescription() {
37          return "Draws a HepRepInstance as an Ellipse.";
38      }
39  
40      public void draw(VectorGraphics graphics, HepRepInstance instance,
41                       Attributes atts,  GraphicsMode mode, 
42                       Projection projection, ViewPort viewPort) {
43  
44          Iterator iterator = instance.getPoints().iterator();
45          while (iterator.hasNext()) {
46              HepRepPoint center = (HepRepPoint)iterator.next();
47      
48              int n = PolyPoint.ellipse(center.getAttValue("radius").getDouble(), 
49                                        center.getAttValue("radius2").getDouble(),
50                                        center.getX(), center.getY(), center.getZ(),
51                                        center.getAttValue("phi").getDouble(), 
52                                        center.getAttValue("theta").getDouble(), 
53                                        center.getAttValue("omega").getDouble(), 
54                                        uvw);
55              if (n == 0) continue;
56                                                    
57              uvw = projection.transform(viewPort, uvw, n);
58  
59              if (atts.isFilled()) {
60                  graphics.setColor(atts.getFillColor());
61                  graphics.fillPolygon(uvw[U], uvw[V], n);
62                  graphics.setColor(atts.getColor());
63              }
64              graphics.drawPolygon(uvw[U], uvw[V], n);
65          }
66      }
67  
68      public void frame(VectorGraphics graphics, HepRepInstance instance,
69                        Attributes atts,  GraphicsMode mode, 
70                        Projection projection, ViewPort viewPort) {
71  
72          graphics.setColor(atts.getFrameColor());
73          graphics.setLineWidth(atts.getFrameWidth()*2+atts.getLineWidth());
74  
75          Iterator iterator = instance.getPoints().iterator();
76          while (iterator.hasNext()) {
77              HepRepPoint center = (HepRepPoint)iterator.next();
78              int n = PolyPoint.ellipse(center.getAttValue("radius").getDouble(), 
79                                        center.getAttValue("radius2").getDouble(),
80                                        center.getX(), center.getY(), center.getZ(),
81                                        center.getAttValue("phi").getDouble(), 
82                                        center.getAttValue("theta").getDouble(), 
83                                        center.getAttValue("omega").getDouble(), 
84                                        uvw);
85              if (n == 0) continue;
86              uvw = projection.transform(viewPort, uvw, n);
87  
88              graphics.drawPolygon(uvw[U], uvw[V], n);
89          }
90  
91          graphics.setLineWidth(atts.getLineWidth());
92          graphics.setColor(atts.getColor());
93      }
94  }