Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

TubsRep.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/geomrep/src/TubsRep.cxx,v 1.3 2001/01/23 01:40:12 burnett Exp $
00002 //  Author: Toby Burnett
00003 //
00004 // Display of a Tubs
00005 
00006 #include "geomrep/TubsRep.h"
00007 #include "geometry/Tubs.h"
00008 
00009 
00010 static void createPolyLine(gui::DisplayRep* v, Vector a[], unsigned n)
00011 {
00012   v->move_to(a[0]);
00013   for(unsigned i=1;i<n;i++)
00014      v->line_to(a[i]);
00015 }
00016 
00017 void TubsRep::update()
00018 {
00019     // We need two vectors that will point the direction that the two wedge pieces
00020     // are going away from the axis.
00021     // Note that the axis of the wedge is always the axis of the cylinder
00022     Vector axis = m_tubs.axis(),
00023            p1 = - m_tubs.wedge().n1().cross(axis),
00024            p2 =   m_tubs.wedge().n2().cross(axis);
00025 
00026     double openAngle = acos(p1*p2);
00027     if( (p1.cross(p2))*axis<0 )
00028         openAngle += M_PI;
00029 
00030     // Let's set up some arrays to hold the points in...
00031     const int ns = 25; // Number of sides to the circly part
00032     Vector inside1[ns], inside2[ns];
00033     Vector outside1[ns + 2], outside2[ns +2];
00034     // need two extra here for the first and last lines, which will connect the inside and
00035     // outside parts
00036 
00037     // Let's begin going around the circle.....
00038     double dphi = 2.0*M_PI/ns;
00039     double in = m_tubs.innerRadius();
00040     in = ((in>0)? in:0);
00041     double out = m_tubs.outerRadius();
00042 
00043     Vector dir = p1,
00044            disp = axis*.5*m_tubs.length(),
00045            center = m_tubs.center();
00046 
00047 
00048     int c = -1, i; // c is the counter
00049 
00050     for( i=0;  i< openAngle/dphi; i++ ) {
00051         c++;
00052         inside1[c] = center + in*dir + disp;
00053         inside2[c] = center + in*dir - disp;
00054         outside1[c+1] = center + out*dir + disp;
00055         outside2[c+1] = center + out*dir - disp;
00056         dir.rotate(dphi,axis);
00057     }
00058 
00059     // Draw the last segment so it is complete
00060     c++;
00061     dir = p2;
00062     inside1[c] = center + in*dir + disp;
00063     inside2[c] = center + in*dir - disp;
00064     outside1[c+1] = center + out*dir + disp;
00065     outside2[c+1] = center + out*dir - disp;
00066 
00067 
00068     // Now that we have the edges, let's put the two sides in
00069     outside1[0] = inside1[0];
00070     outside1[c+2] = inside1[c];
00071     outside2[0] = inside2[0];
00072     outside2[c+2] = inside2[c];
00073 
00074     // Now draw the polygon
00075     createPolyLine(this, outside1, c+3);
00076     createPolyLine(this, inside1, c+1);
00077     createPolyLine(this, outside2, c+3);
00078     createPolyLine(this, inside2, c+1);
00079 
00080     // Now we need some connecting points to make it have depth....
00081     Vector line_seg[2];
00082     for ( i=0;i<c;i+=3)
00083     {
00084        line_seg[0] = outside1[i+1];
00085        line_seg[1] = outside2[i+1];
00086        createPolyLine(this, line_seg, 2);
00087        line_seg[0] = inside1[i];
00088        line_seg[1] = inside2[i];
00089        createPolyLine(this, line_seg, 2);
00090     }
00091 
00092     // Now we need to connect the end
00093     line_seg[0] = outside1[c+1];
00094     line_seg[1] = outside2[c+1];
00095     createPolyLine(this, line_seg, 2);
00096 
00097     line_seg[0] = inside1[c];
00098     line_seg[1] = inside2[c];
00099     createPolyLine(this, line_seg, 2);
00100 
00101 
00102 }
00103 

Generated at Mon Nov 26 18:18:45 2001 by doxygen1.2.3 written by Dimitri van Heesch, © 1997-2000