00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include "QtGBrowserGeoDrawHelper.h"
00015 #ifdef ROOT_QExGeoDrawHelper
00016 #include "THashList.h"
00017 #include "TGeometry.h"
00018 #include "TMap.h"
00019 #include "TRotMatrix.h"
00020
00021 #include "TGeoVolume.h"
00022 #include "TVolume.h"
00023
00024 #include "TGeoNode.h"
00025 #include "TGeoManager.h"
00026 #include "TGeoMatrix.h"
00027 #include "TGeoShape.h"
00028 #include "TGeoBBox.h"
00029 #include "TGeoPara.h"
00030 #include "TGeoTube.h"
00031 #include "TGeoCone.h"
00032 #include "TGeoPcon.h"
00033 #include "TGeoPgon.h"
00034 #include "TGeoEltu.h"
00035 #include "TGeoArb8.h"
00036 #include "TGeoTrd1.h"
00037 #include "TGeoTrd2.h"
00038 #include "TGeoSphere.h"
00039 #include "TGeoCompositeShape.h"
00040 #include "TGeoBoolNode.h"
00041 #include "TGeoMaterial.h"
00042
00043 #include "TBRIK.h"
00044 #include "TPARA.h"
00045 #include "TTUBE.h"
00046 #include "TCTUB.h"
00047 #include "TTUBS.h"
00048 #include "TCONE.h"
00049 #include "TCONS.h"
00050 #include "TPCON.h"
00051 #include "TPGON.h"
00052 #include "TELTU.h"
00053 #include "TTRD1.h"
00054 #include "TTRD2.h"
00055 #include "TTRAP.h"
00056 #include "TSPHE.h"
00057 #include "TGTRA.h"
00058
00059
00060 static inline Bool_t CompareMatrix(const double *pa,const TRotMatrix &b)
00061 { double *pb=((TRotMatrix *)&b)->GetMatrix();
00062 for (int i=0; i<9; i++) if (pa[i]!=pb[i]) return kFALSE;
00063 return kTRUE;
00064 }
00065
00066 static inline TRotMatrix *GetMatrix(const double *rotation)
00067 {
00068 THashList *list = gGeometry->GetListOfMatrices();
00069 TIter nextmatrix(list);
00070 TRotMatrix *matrix=0;
00071
00072 if (!matrix) {
00073 char mname[20];
00074 int n=list->GetSize(); sprintf(mname,"matrix%d",n+1);
00075
00076 Double_t mx[9];
00077 mx[0] = rotation[0]; mx[1] = rotation[3]; mx[2] = rotation[6];
00078 mx[3] = rotation[1]; mx[4] = rotation[4]; mx[5] = rotation[7];
00079 mx[6] = rotation[2]; mx[7] = rotation[5]; mx[8] = rotation[8];
00080 matrix = new TRotMatrix(mname,mname,mx);
00081 }
00082 return matrix;
00083 }
00084
00085
00086
00087
00088
00089 class TARB8 : public TBRIK {
00090
00091 protected:
00092 Double_t fXY[8][2];
00093
00094 public:
00095 TARB8(){;}
00096 TARB8(const char *name, const char *title, const char *material, Double_t dz, Double_t *vertices=0)
00097 : TBRIK(name, title,material,0,0,dz) { if (vertices) memcpy(fXY,vertices,sizeof(fXY)); }
00098 virtual ~TARB8(){;}
00099 #if ROOT_VERSION_CODE >= ROOT_VERSION(4,03,3)
00100 virtual void Paint(Option_t *){}
00101 #if ROOT_VERSION_CODE >= ROOT_VERSION(5,03,0)
00102 virtual void SetPoints(Double_t *buff) const { ((TARB8*)this)->SetPoints(buff); }
00103 #endif
00104 virtual void SetPoints(Double_t *buff) {
00105
00106
00107
00108
00109 Float_t dz;
00110
00111 dz = TBRIK::fDz;
00112 static const int x = 0;
00113 static const int y = 1;
00114 int i = 0;
00115 if (buff) {
00116 buff[ 0] = fXY[i][x]; buff[ 1] = fXY[i++][y]; buff[ 2] = -dz;
00117 buff[ 3] = fXY[i][x]; buff[ 4] = fXY[i++][y]; buff[ 5] = -dz;
00118 buff[ 6] = fXY[i][x]; buff[ 7] = fXY[i++][y]; buff[ 8] = -dz;
00119 buff[ 9] = fXY[i][x]; buff[10] = fXY[i++][y]; buff[11] = -dz;
00120
00121 buff[12] = fXY[i][x]; buff[13] = fXY[i++][y]; buff[14] = dz;
00122 buff[15] = fXY[i][x]; buff[16] = fXY[i++][y]; buff[17] = dz;
00123 buff[18] = fXY[i][x]; buff[19] = fXY[i++][y]; buff[20] = dz;
00124 buff[21] = fXY[i][x]; buff[22] = fXY[i++][y]; buff[23] = dz;
00125 }
00126 }
00127 #endif
00128 virtual void SetPoints(Float_t *buff) {
00129
00130
00131
00132
00133 Float_t dz;
00134
00135 dz = TBRIK::fDz;
00136 static const int x = 0;
00137 static const int y = 1;
00138 int i = 0;
00139 if (buff) {
00140 buff[ 0] = fXY[i][x]; buff[ 1] = fXY[i++][y]; buff[ 2] = -dz;
00141 buff[ 3] = fXY[i][x]; buff[ 4] = fXY[i++][y]; buff[ 5] = -dz;
00142 buff[ 6] = fXY[i][x]; buff[ 7] = fXY[i++][y]; buff[ 8] = -dz;
00143 buff[ 9] = fXY[i][x]; buff[10] = fXY[i++][y]; buff[11] = -dz;
00144
00145 buff[12] = fXY[i][x]; buff[13] = fXY[i++][y]; buff[14] = dz;
00146 buff[15] = fXY[i][x]; buff[16] = fXY[i++][y]; buff[17] = dz;
00147 buff[18] = fXY[i][x]; buff[19] = fXY[i++][y]; buff[20] = dz;
00148 buff[21] = fXY[i][x]; buff[22] = fXY[i++][y]; buff[23] = dz;
00149 }
00150 }
00151 };
00152
00153
00154
00155
00156
00157
00158 TGeoDrawHelper::TGeoDrawHelper(TGeoVolume *geoVolume)
00159 {
00160
00161
00162 fGeoVolume = geoVolume;
00163 if (gGeoManager) {
00164 if (!fGeoVolume) fGeoVolume = gGeoManager->GetTopVolume();
00165 fVolume = MakeVolume(fGeoVolume);
00166 }
00167 }
00168
00169 TGeoDrawHelper::~TGeoDrawHelper()
00170 { }
00171
00172
00173 Int_t TGeoDrawHelper::DistancetoPrimitive(Int_t px, Int_t py)
00174 { return fVolume ? fVolume->DistancetoPrimitive(px, py) : 999999; }
00175
00176 void TGeoDrawHelper::Draw(Option_t *option)
00177 {
00178 if (fVolume) {
00179 fVolume->SetBit(kCanDelete);
00180 fVolume->Draw(option);
00181 }
00182 }
00183
00184 const char *TGeoDrawHelper::GetName() const
00185 {
00186 return fVolume ? fVolume->GetName():GetName();
00187 }
00188
00189 const char *TGeoDrawHelper::GetIconName() const
00190 {
00191 return fVolume ? fVolume->GetIconName(): GetIconName();
00192 }
00193
00194 void TGeoDrawHelper::Paint(Option_t *option)
00195 {
00196 if (fVolume) fVolume->Paint(option);
00197 }
00198
00199 TVolume *TGeoDrawHelper::MakeCompositeShape(const TGeoCompositeShape *top)
00200 {
00201
00202
00203
00204 TVolume *topCompositeVolume = 0;
00205 if (top) {
00206
00207
00208
00209
00210 TString title = top->GetTitle();
00211 if (title.IsNull() ) title = top->ClassName();
00212
00213 TGeoBoolNode *shapeNode = top->GetBoolNode();
00214 if (shapeNode) {
00215 TString compositeName = Form("{%s}",top->GetName());
00216 topCompositeVolume = new TVolume((const char *)compositeName,title,(TShape *)0);
00217
00218 TGeoMatrix *geoMatrice[2] = { shapeNode->GetLeftMatrix(), shapeNode->GetRightMatrix()};
00219 TGeoShape *geoShape[2] = { shapeNode->GetLeftShape(), shapeNode->GetRightShape() };
00220
00221 for (Int_t i = 0; i < 2 ; i++) {
00222 if (!geoShape[i]) continue;
00223
00224 TGeoMatrix *geoMatrix = geoMatrice[i];
00225 const Double_t *trans = geoMatrix->GetTranslation();
00226 const Double_t *rotation = geoMatrix->GetRotationMatrix();
00227 TRotMatrix *matrix = geoMatrix->IsIdentity() ? 0 : GetMatrix(rotation);
00228 TVolume *nextVolume = 0;
00229 if ( geoShape[i]->IsComposite() ) {
00230 nextVolume = MakeCompositeShape((TGeoCompositeShape *)geoShape[i]);
00231 } else {
00232 title = geoShape[i]->GetTitle();
00233 if (title.IsNull() ) title = geoShape[i]->ClassName();
00234 nextVolume = new TVolume(geoShape[i]->GetName(),title,MakeShape(geoShape[i]));
00235 }
00236 topCompositeVolume->Add(nextVolume, trans[0],trans[1],trans[2],matrix, 999);
00237 }
00238 }
00239 }
00240 return topCompositeVolume;
00241 }
00242
00243 TVolume *TGeoDrawHelper::MakeVolume( TGeoVolume *top, std::map<TGeoVolume *,TVolume *> *volumeMap) {
00244 static int depth = 0;
00245 std::map<TGeoVolume *,TVolume *> *toFlag = volumeMap;
00246 if (!toFlag) depth = 0;
00247 TVolume *topVolume = 0;
00248 TObjArray *nodes = 0;
00249 if (top) {
00250
00251 TGeoShape *geoShape = top->IsAssembly() ? 0: top->GetShape();
00252 TShape *thisShape = 0;
00253 TVolume *compositeVolume = 0;
00254 if (geoShape) {
00255 if (geoShape->IsComposite()) {
00256 compositeVolume = MakeCompositeShape((TGeoCompositeShape *)geoShape);
00257 } else {
00258 thisShape=MakeShape(geoShape);
00259 }
00260 }
00261 TString title = top->GetTitle();
00262 if (title.IsNull() && ( top->Class() != TGeoVolume::Class()) ) title = top->ClassName();
00263
00264 TGeoMedium *media = top->GetMedium();
00265 TGeoMaterial *matter = 0;
00266 if (media) matter = top->GetMaterial();
00267 title += matter ? Form("(%s)",matter->GetName())
00268 : Form("(unknown material)");
00269
00270 topVolume = new TVolume(top->GetName(),title,thisShape);
00271 topVolume->SetLineColor(top->GetLineColor()); topVolume->SetLineStyle(top->GetLineStyle());
00272 topVolume->SetLineWidth(top->GetLineWidth()); topVolume->SetFillColor(top->GetLineColor());
00273 if (compositeVolume) {
00274 topVolume->Add(compositeVolume);
00275 compositeVolume->SetLineColor(top->GetLineColor()); compositeVolume->SetLineStyle(top->GetLineStyle());
00276 compositeVolume->SetLineWidth(top->GetLineWidth()); compositeVolume->SetFillColor(top->GetLineColor());
00277 }
00278 if (!top->IsVisible()) topVolume->SetVisibility(TVolume::kThisUnvisible);
00279 if ( (nodes = top->GetNodes()) ) {
00280 TIter next(nodes);
00281 TGeoNode *geoNode;
00282 TGeoVolume *geoVolume = 0;
00283 Int_t nNodes = top->GetNdaughters();
00284 Int_t i = 0;
00285 for (i = 0; (i < nNodes) ; i++) {
00286 geoNode = top->GetNode(i);
00287 geoVolume = geoNode ? geoNode->GetVolume(): 0;
00288 if (geoVolume) {
00289 TVolume *nextVolume = 0;
00290 if (!volumeMap) {
00291 volumeMap = new std::map<TGeoVolume *,TVolume *>;
00292 depth = 1;
00293 } else {
00294 std::map <TGeoVolume *,TVolume *> :: const_iterator volumeFinder;
00295 volumeFinder = volumeMap->find(geoVolume);
00296 if (volumeFinder != volumeMap->end( ) )
00297 nextVolume = volumeFinder->second;
00298 }
00299 depth++;
00300 if (!nextVolume) {
00301 typedef std::pair <TGeoVolume *, TVolume *> VOLUME_PAIR;
00302 gGeoManager->CdDown(i);
00303 nextVolume= MakeVolume(geoVolume,volumeMap);
00304 gGeoManager->CdUp();
00305 volumeMap->insert(VOLUME_PAIR(geoVolume,nextVolume));
00306 }
00307 --depth;
00308 TGeoMatrix *geoMatrix = geoNode->GetMatrix();
00309 const Double_t *trans = geoMatrix->GetTranslation();
00310 const Double_t *rotation = geoMatrix->GetRotationMatrix();
00311 TRotMatrix *matrix = geoMatrix->IsIdentity() ? 0 : GetMatrix(rotation);
00312 topVolume->Add(nextVolume, trans[0],trans[1],trans[2],matrix, geoNode->GetNumber());
00313 } } } }
00314 if (!toFlag) delete volumeMap;
00315 return topVolume;
00316 }
00317
00318
00319 TShape *TGeoDrawHelper::MakeShape(const TGeoBBox &shp) {
00320 return
00321 new TBRIK(shp.GetName()
00322 ,"BRIK","void",shp.GetDX(),shp.GetDY(),shp.GetDZ());
00323 }
00324
00325
00326 TShape *TGeoDrawHelper::MakeShape(const TGeoPara &shp) {
00327 return
00328 new TPARA(shp.GetName(),"PARA","void",
00329 shp.GetX(),shp.GetY(),shp.GetZ()
00330 ,shp.GetAlpha(),shp.GetTheta(),shp.GetPhi());
00331 }
00332
00333
00334 TShape *TGeoDrawHelper::MakeShape(const TGeoTube &shp) {
00335 return
00336 new TTUBE(shp.GetName(),"TUBE","void",
00337 shp.GetRmin(),shp.GetRmax(),shp.GetDz());
00338 }
00339
00340
00341 TShape *TGeoDrawHelper::MakeShape(const TGeoTubeSeg &shp) {
00342 return
00343 new TTUBS(shp.GetName(),"TUBS","void",
00344 shp.GetRmin(),shp.GetRmax(),shp.GetDz(),shp.GetPhi1(),shp.GetPhi2());
00345 }
00346
00347
00348 TShape *TGeoDrawHelper::MakeShape(const TGeoCone &shp) {
00349 return
00350 new TCONE(shp.GetName(),"CONE","void",
00351 shp.GetDz(),shp.GetRmin1(),shp.GetRmax1(),shp.GetRmin2(),shp.GetRmax2());
00352 }
00353
00354
00355 TShape *TGeoDrawHelper::MakeShape(const TGeoConeSeg &shp) {
00356 return
00357 new TCONS(shp.GetName(),"CONE","void",
00358 shp.GetDz()
00359 ,shp.GetRmin1(),shp.GetRmax1()
00360 ,shp.GetRmin2(),shp.GetRmax2()
00361 ,shp.GetPhi1 (),shp.GetPhi2 () );
00362 }
00363
00364
00365 TShape *TGeoDrawHelper::MakeShape(const TGeoPcon &shp) {
00366 TPCON *t =
00367 new TPCON(shp.GetName(),"PCON","void"
00368 ,shp.GetPhi1(),shp.GetDphi(),shp.GetNz());
00369 for (Int_t i=0; i<shp.GetNz(); i++)
00370 t->DefineSection(i,shp.GetZ(i),shp.GetRmin(i),shp.GetRmax(i));
00371 return t;
00372 }
00373
00374
00375 TShape *TGeoDrawHelper::MakeShape(const TGeoPgon &shp) {
00376 TPGON *t =
00377 new TPGON(shp.GetName(),"PGON","void"
00378 ,shp.GetPhi1(),shp.GetDphi(),shp.GetNedges(),shp.GetNz());
00379 for (Int_t i=0; i<shp.GetNz(); i++)
00380 t->DefineSection(i,shp.GetZ(i),shp.GetRmin(i),shp.GetRmax(i));
00381 return t;
00382 }
00383
00384
00385 TShape *TGeoDrawHelper::MakeShape(const TGeoEltu &shp) {
00386 return
00387 new TELTU(shp.GetName(),"ELTU","void",
00388 shp.GetA(),shp.GetB(),shp.GetDz());
00389 }
00390
00391
00392 TShape *TGeoDrawHelper::MakeShape(const TGeoTrap &shp) {
00393 return
00394 new TTRAP(shp.GetName(),"TRAP","void",
00395 shp.GetDz(),shp.GetTheta(),shp.GetPhi()
00396 ,shp.GetH1(),shp.GetBl1(),shp.GetTl1(),shp.GetAlpha1()
00397 ,shp.GetH2(),shp.GetBl2(),shp.GetTl2(),shp.GetAlpha2() );
00398 }
00399
00400
00401 TShape *TGeoDrawHelper::MakeShape(const TGeoCtub &shp) {
00402 return
00403 new TCTUB(shp.GetName(),"CTUB","void",
00404 shp.GetRmin(),shp.GetRmax(),shp.GetDz(),shp.GetPhi1(),shp.GetPhi2()
00405 ,shp.GetNlow()[0], shp.GetNlow()[1], shp.GetNlow()[2]
00406 ,shp.GetNhigh()[0],shp.GetNhigh()[1],shp.GetNhigh()[2] );
00407 }
00408
00409
00410 TShape *TGeoDrawHelper::MakeShape(const TGeoTrd1 &shp) {
00411 return
00412 new TTRD1(shp.GetName(),"TRD1","void",
00413 shp.GetDx1(),shp.GetDx2(),shp.GetDy(),shp.GetDz());
00414 }
00415
00416
00417 TShape *TGeoDrawHelper::MakeShape(const TGeoTrd2 &shp) {
00418 return
00419 new TTRD2(shp.GetName(),"TRD2","void",
00420 shp.GetDx1(),shp.GetDx2(),shp.GetDy1(),shp.GetDy2(),shp.GetDz());
00421 }
00422
00423
00424 TShape *TGeoDrawHelper::MakeShape(const TGeoSphere &shp) {
00425 return
00426 new TSPHE(shp.GetName(),"TSPHE","void",
00427 shp.GetRmin(),shp.GetRmax()
00428 ,shp.GetTheta1(),shp.GetTheta2()
00429 ,shp.GetPhi1(),shp.GetPhi2());
00430 }
00431
00432
00433 TShape *TGeoDrawHelper::MakeShape(const TGeoGtra &shp) {
00434 return
00435 new TGTRA(shp.GetName(),"TGTRA","void",
00436 shp.GetDz(),shp.GetTheta(),shp.GetPhi()
00437 ,shp.GetTwistAngle()
00438 ,shp.GetH1(),shp.GetBl1(),shp.GetTl1(),shp.GetAlpha1()
00439 ,shp.GetH2(),shp.GetBl2(),shp.GetTl2(),shp.GetAlpha2() );
00440 }
00441
00442
00443 TShape *TGeoDrawHelper::MakeShape(const TGeoArb8 &shp) {
00444 return
00445 new TARB8(shp.GetName(),"TARB8","void",
00446 shp.GetDz(),((TGeoArb8 &)shp).GetVertices() );
00447 }
00448
00449
00450
00451
00452 #define GEOSHAPE(shapeCode) \
00453 if ( shape->IsA() == (_NAME2_(T,shapeCode)::Class() ) ) { t=MakeShape(*(_NAME2_(T,shapeCode *))shape); }
00454
00455
00456
00457
00458
00459
00460
00461 TShape *TGeoDrawHelper::MakeShape(const TGeoShape *shape) {
00462 TShape *t = 0;
00463 if (shape) {
00464
00465
00466 if ( shape->TestShapeBit(TGeoShape::kGeoBad ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoBad \n",shape->GetName()); }
00467 if ( shape->TestShapeBit(TGeoShape::kGeoRSeg ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoRSeg \n",shape->GetName()); }
00468 if ( shape->TestShapeBit(TGeoShape::kGeoPhiSeg ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoPhiSeg\n",shape->GetName()); }
00469 if ( shape->TestShapeBit(TGeoShape::kGeoThetaSeg ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoThetaSeg \n",shape->GetName()); }
00470 if ( shape->TestShapeBit(TGeoShape::kGeoVisX ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoVisX \n",shape->GetName()); }
00471 if ( shape->TestShapeBit(TGeoShape::kGeoVisY ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoVisY \n",shape->GetName()); }
00472 if ( shape->TestShapeBit(TGeoShape::kGeoVisZ ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoVisZ\n",shape->GetName()); }
00473 if ( shape->TestShapeBit(TGeoShape::kGeoRunTimeShape ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoRunTimeShape\n",shape->GetName()); }
00474 if ( shape->TestShapeBit(TGeoShape::kGeoInvalidShape ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoInvalidShape\n",shape->GetName()); }
00475 if ( shape->TestShapeBit(TGeoShape::kGeoTorus ) ) { printf(" This shape has not been implemented yet %s TGeoShape::kGeoTorus\n",shape->GetName()); }
00476
00477 if ( shape->TestShapeBit(TGeoShape::kGeoBox ) ) { t=MakeShape(*(TGeoBBox *)shape); }
00478 GEOSHAPE(GeoPara);
00479
00480 GEOSHAPE(GeoSphere);
00481 GEOSHAPE(GeoTube);
00482 GEOSHAPE(GeoTubeSeg);
00483 GEOSHAPE(GeoCone);
00484 GEOSHAPE(GeoConeSeg);
00485 GEOSHAPE(GeoPcon);
00486 GEOSHAPE(GeoPgon);
00487
00488
00489 GEOSHAPE(GeoArb8);
00490 GEOSHAPE(GeoEltu);
00491 GEOSHAPE(GeoTrap);
00492 GEOSHAPE(GeoCtub);
00493 GEOSHAPE(GeoTrd1);
00494 GEOSHAPE(GeoTrd2);
00495
00496 if ( shape->TestShapeBit(TGeoShape::kGeoComb ) ) { printf(" This shape has not been implemented yet %s\n",shape->GetName()); }
00497
00498 GEOSHAPE(GeoGtra);
00499
00500
00503
00504
00505
00506
00507
00508 }
00509 if (!t) t= new TBRIK("DEFAULT","BRIK","void",10,10,10);
00510 return t;
00511 }
00512 #endif