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

TubeRep.cxx

Go to the documentation of this file.
00001 // $Header: /nfs/slac/g/glast/ground/cvs/geomrep/src/TubeRep.cxx,v 1.3 2001/01/23 01:40:12 burnett Exp $
00002 //   Author: T. Burnett
00003 
00004 #include "geomrep/TubeRep.h"
00005 
00006 #include "geometry/Tube.h"
00007 
00008 TubeRep::TubeRep(const Shape& shape)
00009     : m_tube( dynamic_cast<const Tube& >(shape) )
00010 {};
00011 
00012 
00013 inline static void createPolyLine(gui::DisplayRep* v, Vector a[], unsigned n)
00014 {
00015     v->move_to(a[0]); 
00016     for(unsigned i=1;i<n;i++) 
00017         v->line_to(a[i]);
00018 }
00019 
00020 static inline void createPolyLine(gui::DisplayRep& v, Vector a[], unsigned n)
00021 {
00022   v.move_to(a[0]); 
00023   for(unsigned i=1;i<n;i++) 
00024      v.line_to(a[i]);
00025 }
00026 
00027 void 
00028 TubeRep::update()
00029 {
00030    //  create a representation to draw a Tube by calculating the
00031    //  vertices of polygons used to display a Tube and storing them
00032    //  in arrays
00033    //  the inner and outer cylinders are drawn using ns-sided
00034    //  polygons at each end, connected by lines from one end to the 
00035    //  other at the vertices of the polygons
00036         const int ns = 97, rib=ns/8     ;
00037         Vector vi0[ns];   //  arrays for ns-sided polygons for drawing arcs
00038         Vector vo0[ns];   //  need 1 set of x, y, z arrays for each end
00039         Vector vi1[ns];   //  of inner (i) and outer (o) arcs of a Tube
00040         Vector vo1[ns];
00041         Vector tv;
00042         
00043         int nonzero_inner_radius = m_tube.innerRadius()>0;
00044 //  calculate the coordinates of the inner and outer cylinders
00045         double hl = 0.5 * m_tube.length();
00046         double phi = 0.0;
00047         double dphi = 2.0 * M_PI / ( ns - 1 );
00048         Vector a = m_tube.axis(),
00049                c = m_tube.center(),
00050                c0 = c  -  hl * a,
00051                c1 = c  +  hl * a;
00052         Vector c0hat( 1.0, 0.0, 0.0 );
00053         float ax = a.x();
00054         float ay = a.y();
00055         float d = sqrt( ax * ax  +  ay * ay );
00056         if ( d > 0.0 )
00057                 c0hat = Vector( -ay/d, ax/d, 0.0 );
00058         Vector c1hat = a.cross( c0hat );
00059         int i;
00060         for (  i = 0; i < ns; i++ ) {
00061                 phi = i * dphi;
00062                 tv = cos( phi ) * c0hat  +  sin( phi ) * c1hat;
00063                 vi0[i] = c0  +  m_tube.innerRadius() * tv;
00064                 vi1[i] = c1  +  m_tube.innerRadius() * tv;
00065                 vo0[i] = c0  +  m_tube.outerRadius() * tv;
00066                 vo1[i] = c1  +  m_tube.outerRadius() * tv;
00067         }
00068 //  draw inner cylinder (if inner radius is nonzero)
00069         if ( nonzero_inner_radius ) {
00070                 createPolyLine( this, vi0, ns );
00071                 createPolyLine( this, vi1, ns );
00072         }
00073 //  draw outer cylinder
00074         createPolyLine( this, vo0, ns );
00075         createPolyLine( this, vo1, ns );
00076 //  draw every third "rib" connecting the polygons
00077         for ( i = 0; i < ns; i += rib ) {
00078                 Vector pl[] = { vo0[i], vo1[i], vi1[i], vi0[i], vo0[i] };
00079                 createPolyLine(this,  pl, 5 );
00080         }
00081 }
00082 

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