00001
00002
00004
00005 #include "gismo/LayeredBox.h"
00006 #include "geometry/Plane.h"
00007 #include "gismo/Detector.h"
00008
00009 #include "gui/DisplayRep.h"
00010 #include <cassert>
00011 #include <cstdlib>
00012 #include <stdio.h>
00013
00014 LayeredBox::LayeredBox(Medium* mother, double dx, double dy)
00015 :LayeredMedium(mother, 6)
00016 , m_depth(dy)
00017 , m_width(dx)
00018 , m_height(0)
00019 {
00020
00021 const Point& p = m_vol->center();
00022 int n=0;
00023 m_vol->setSurface(n++, new Plane(p, Vector(0,0,-1),0) );
00024 m_vol->setSurface(n++, new Plane(p, Vector(0,0, 1),0) );
00025 m_vol->setSurface(n++, new Plane(p, Vector(-dx/2,0,0)) );
00026 m_vol->setSurface(n++, new Plane(p, Vector( dx/2,0,0)) );
00027 m_vol->setSurface(n++, new Plane(p, Vector(0,-dy/2,0)) );
00028 m_vol->setSurface(n++, new Plane(p, Vector(0, dy/2,0)) );
00029
00030 }
00031
00032 Medium&
00033 LayeredBox::addLayer(double thickness, const char* material, Detector* det)
00034 {
00035
00036 Medium* med = new Medium(this, 0, material, det);
00037
00038
00039
00040 return addLayer(med, thickness);
00041 }
00042 static inline char* itoa(int i)
00043 { static char buf[20];
00044 sprintf(buf,"%d",i);
00045 return buf;
00046 }
00047
00048 Medium&
00049 LayeredBox::addLayer(Medium* inner_medium, double thickness, const char* mat)
00050 {
00051 assert( inner_medium->parent() == this);
00052
00053 Medium* added_medium = inner_medium;
00054
00055 if( inner_medium->isComposite() ){
00056
00057 pop_back();
00058 added_medium = new CompositeMedium(this, (Shape*)0, mat);
00059 added_medium->addMedium(inner_medium);
00060 }
00061
00062
00063 added_medium->setTitle(
00064 (std::string("BoxLayer#")+itoa(innerMediaCount())).c_str() );
00065
00066
00067
00068
00069 added_medium->moveZ(m_height/2+thickness/2);
00070
00071
00072 moveZ(-thickness/2.0);
00073
00074 m_height+=thickness;
00075
00076 LayeredMedium::addLayer(added_medium, thickness);
00077 return *inner_medium;
00078 }
00079
00080 void
00081 LayeredBox::createDetectorView(gui::DisplayRep& view)
00082 {
00083 Vector vx = m_vol->surface(3).direction() * (m_width/2),
00084 vy = m_vol->surface(5).direction() * (m_depth/2),
00085 vz = m_vol->surface(1).direction() * (m_height);
00086 const Point& c = m_vol->center();
00087 Point vertex[] =
00088 { c+vx+vy,
00089 c-vx+vy,
00090 c+vx-vy,
00091 c-vx-vy,
00092 c+vx+vy+vz,
00093 c-vx+vy+vz,
00094 c+vx-vy+vz,
00095 c-vx-vy+vz};
00096 view.move_to(vertex[0]);
00097 view.line_to(vertex[2]);
00098 view.line_to(vertex[3]);
00099 view.line_to(vertex[1]);
00100 view.line_to(vertex[0]);
00101
00102 view.line_to(vertex[4]);
00103 view.line_to(vertex[6]);
00104 view.line_to(vertex[7]);
00105 view.line_to(vertex[5]);
00106 view.line_to(vertex[4]);
00107
00108 view.move_to(vertex[3]);
00109 view.line_to(vertex[7]);
00110
00111 view.move_to(vertex[1]);
00112 view.line_to(vertex[5]);
00113
00114 view.move_to(vertex[2]);
00115 view.line_to(vertex[6]);
00116
00117
00118 gui::DisplayRep& nview = view.nested();
00119 for( unsigned int i=1; i< size(); ++i){
00120 Vector vz = referenceSurface().direction()* (-m_offset[i]);
00121 nview.move_to(vertex[0]+vz);
00122 nview.line_to(vertex[2]+vz);
00123 nview.line_to(vertex[3]+vz);
00124 nview.line_to(vertex[1]+vz);
00125 nview.line_to(vertex[0]+vz);
00126 }
00127
00128
00129 for(iterator it=begin(); it !=end(); ++it )
00130 (*it)->createDetectorView(nview.nested());
00131 }
00133