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.services.ViewPort;
15  
16  /***
17   * Draws a closed set of lines, given a set of HepRepPoints.
18   *
19   * @author Mark Donszelmann
20   * @version $Id: DrawAsPolygon.java 645 2005-02-27 02:23:41Z duns $
21   */
22  
23  public class DrawAsPolygon extends AbstractDrawAs {
24      
25      // FIXME WIRED-253, limited.
26      private double uvw[][] = new double[3][10000];
27  
28      public String getKey() {
29          return "polygon";
30      }
31      
32      public String getName() {
33          return "Polygon";
34      }
35      
36      public String getDescription() {
37          return "Draws a closed set of line segments for all HepRepPoints.";
38      }
39      
40      public void draw(VectorGraphics graphics, HepRepInstance instance,
41                       Attributes atts, GraphicsMode mode, 
42                       Projection projection, ViewPort viewPort) {
43  
44          int n = instance.getPoints(uvw);
45  
46          if (n < 0) {
47              n = 0;
48              for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
49  
50                  HepRepPoint p = (HepRepPoint)i.next();
51                  uvw[U][n] = p.getX();
52                  uvw[V][n] = p.getY();
53                  uvw[W][n] = p.getZ();
54                  n++;
55              }
56          }
57          if (n == 0) return;
58          
59          uvw = projection.transform(viewPort, uvw, n);        
60          
61          if (atts.isFilled()) {
62              graphics.setColor(atts.getFillColor());
63              graphics.fillPolygon(uvw[U], uvw[V], n);
64              graphics.setColor(atts.getColor());
65          }
66          graphics.drawPolygon(uvw[U], uvw[V], n);
67      }
68  
69      public void frame(VectorGraphics graphics, HepRepInstance instance,
70                        Attributes atts, GraphicsMode mode, 
71                        Projection projection, ViewPort viewPort) {
72  
73          int n = instance.getPoints(uvw);
74  
75          if (n < 0) {
76              n = 0;
77              for (Iterator i=instance.getPoints().iterator(); i.hasNext(); ) {
78  
79                  HepRepPoint p = (HepRepPoint)i.next();
80                  uvw[U][n] = p.getX();
81                  uvw[V][n] = p.getY();
82                  uvw[W][n] = p.getZ();
83                  n++;
84              }
85          }
86          if (n == 0) return;
87                           
88          uvw = projection.transform(viewPort, uvw, n);        
89          
90          graphics.setColor(atts.getFrameColor());
91          graphics.setLineWidth(atts.getFrameWidth()*2+atts.getLineWidth());
92          graphics.drawPolygon(uvw[U], uvw[V], n);
93          graphics.setLineWidth(atts.getLineWidth());
94          graphics.setColor(atts.getColor());
95      }
96  }