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