00001
00002
00004
00005 #include "geometry/Plane.h"
00006 #include "geometry/Conic.h"
00007 #include "gismo/Detector.h"
00008
00009 #include "gui/DisplayRep.h"
00010 #include "geomrep/ArcRep.h"
00011 #include "geomrep/ConeRep.h"
00012 #include <cassert>
00013 #include <strstream>
00014
00015 SlicedCone::SlicedCone(Medium* mother, const Cone& cone)
00016
00017 :LayeredMedium(mother, cone.surfaceCount() )
00018 , m_length(0)
00019 {
00020 const Point& p = m_vol->center();
00021 static Vector z_axis(0,0,1);
00022 int n=0;
00023
00024 m_vol->setSurface(n++, new Plane(p, Vector(0,0,-1),0) );
00025 m_vol->setSurface(n++, new Plane(p, Vector(0,0, 1),0) );
00026
00027
00028 double len = cone.length();
00029 m_outer_radius = cone.outerRadius(-len/2);
00030 m_inner_radius = cone.innerRadius(-len/2);
00031 m_outer_slope = (cone.outerRadius(1-len/2)-m_outer_radius);
00032 m_inner_slope = (cone.innerRadius(1-len/2)-m_inner_radius);
00033
00034 m_vol->setSurface(n++,
00035 new Conic(p, z_axis, m_outer_radius, m_outer_slope) );
00036 if( cone.surfaceCount()>3) {
00037 m_vol->setSurface(n++,
00038 new Conic(p, z_axis, -m_inner_radius,-m_inner_slope) );
00039
00040 }
00041 }
00042
00043 Medium&
00044 SlicedCone::addLayer(double thickness, const char* material, Detector* det)
00045
00046 {
00047
00048 Medium* med = new Medium(this, 0, material, det);
00049
00050
00051 std::ostrstream title;
00052 title << "SlicedCone Layer#" << innerMediaCount() << '\0';
00053 med->setTitle(title.str());
00054
00055
00056 if( m_length>0) moveZ(-m_length/2);
00057
00058
00059 Medium & t = LayeredMedium::addLayer(med, thickness);
00060 moveZ(m_length/2-thickness/2);
00061 m_length += thickness;
00062 return t;
00063 }
00064
00065
00066
00067 void
00068 SlicedCone::createDetectorView(gui::DisplayRep& v)
00069
00070 {
00071 Vector a = axis();
00072 Point c = center();
00073
00074
00075
00076 double h = m_length/2;
00077 Cone cone(m_length,
00078 m_inner_radius, m_outer_radius,
00079 m_inner_radius+2*h*m_inner_slope, m_outer_radius+2*h*m_outer_slope);
00080
00081 Vector z_axis(0,0,1);
00082
00083 if( a.z() != 1.0 ) {
00084
00085 Vector r= z_axis.cross(a);
00086 if( r.mag()<1e-6) r = Vector(0,1,0);
00087 cone.rotate( acos(a.z()), r.unit());
00088 }
00089 cone.move(c+0.5*m_length*a);
00090 v.append(ConeRep(cone));
00091
00092
00093 Vector xhat (1,0,0);
00094 xhat = xhat.cross(a).unit();
00095 Vector yhat=xhat.cross(a).unit();
00096
00097 gui::DisplayRep& nv = v.nested();
00098
00099 for( std::vector<double>::const_iterator it=m_offset.begin();
00100 it < m_offset.end(); ++it){
00101 double d = *it;
00102 double radius = m_outer_radius + (d)*m_outer_slope;
00103 ArcRep arc(c+a*d, radius, xhat, yhat, 2*M_PI);
00104 arc.update();
00105 nv.append(arc);
00106 if( m_inner_radius ==0) continue;
00107 radius = m_inner_radius + (d)*m_inner_slope;
00108 ArcRep inner_arc(c+a*d, radius, xhat, yhat, 2*M_PI);
00109 inner_arc.update();
00110 nv.append(inner_arc);
00111 }
00112
00113 }
00115