00001
00002
00003
00004 Bool_t raytracing = kTRUE;
00005
00006
00007 void csgdemo ()
00008 {
00009 gSystem->Load("libGeom");
00010 bar = new TControlBar("vertical", "TGeo composite shapes",20,20);
00011 bar->AddButton("How to run ","help()","Instructions ");
00012 bar->AddButton("Union ", "s_union()", "A + B ");
00013 bar->AddButton("Intersection ", "s_intersection()","A * B ");
00014 bar->AddButton("Difference ", "s_difference()","A - B ");
00015
00016 bar->AddButton("Complex composite", "complex_1()","(A * B) + (C - D)");
00017 bar->Show();
00018
00019 gROOT->SaveContext();
00020 }
00021
00022
00023 void MakePicture()
00024 {
00025 gGeoManager->GetGeomPainter()->SetRaytracing(kFALSE);
00026 gPad->Modified();
00027 gPad->Update();
00028 }
00029
00030
00031 void s_union()
00032 {
00033 gROOT->GetListOfCanvases()->Delete();
00034 TCanvas *c = new TCanvas("composite shape", "Union boolean operation", 700, 1000);
00035
00036 c->Divide(1,2,0,0);
00037 c->cd(2);
00038 gPad->SetPad(0,0,1,0.4);
00039 c->cd(1);
00040 gPad->SetPad(0,0.4,1,1);
00041
00042 if (gGeoManager) delete gGeoManager;
00043
00044 new TGeoManager("xtru", "poza12");
00045 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
00046 TGeoMedium *med = new TGeoMedium("MED",1,mat);
00047 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
00048 gGeoManager->SetTopVolume(top);
00049
00050
00051 TGeoPgon *pgon = new TGeoPgon("pg",0.,360.,6,2);
00052 pgon->DefineSection(0,0,0,20);
00053 pgon->DefineSection(1, 30,0,20);
00054
00055 TGeoSphere *sph = new TGeoSphere("sph", 40., 45., 5., 175., 0., 340.);
00056
00057 TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.);
00058 tr->SetName("tr");
00059
00060 tr->RegisterYourself();
00061
00062 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr + pg");
00063
00064 TGeoVolume *vol = new TGeoVolume("COMP1",cs);
00065 top->AddNode(vol,1);
00066 gGeoManager->CloseGeometry();
00067 gGeoManager->SetNsegments(100);
00068 top->Draw();
00069 MakePicture();
00070
00071 c->cd(2);
00072 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
00073 pt->SetLineColor(1);
00074 TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
00075 text->SetTextColor(2);
00076 pt->AddText("----- It's an example of boolean union operation : A + B");
00077 pt->AddText("----- A == part of sphere (5-175, 0-340), B == pgon");
00078 pt->AddText(" ");
00079 pt->SetAllWith("-----","color",4);
00080 pt->SetAllWith("-----","font",72);
00081 pt->SetAllWith("-----","size",0.04);
00082 pt->SetTextAlign(12);
00083 pt->SetTextSize(.044);
00084 pt->Draw();
00085 c->cd(1);
00086 }
00087
00088 void s_intersection()
00089 {
00090 gROOT->GetListOfCanvases()->Delete();
00091 TCanvas *c = new TCanvas("composite shape", "Intersection boolean operation", 700, 1000);
00092
00093 c->Divide(1,2,0,0);
00094 c->cd(2);
00095 gPad->SetPad(0,0,1,0.4);
00096 c->cd(1);
00097 gPad->SetPad(0,0.4,1,1);
00098
00099 if (gGeoManager) delete gGeoManager;
00100
00101 new TGeoManager("xtru", "poza12");
00102 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
00103 TGeoMedium *med = new TGeoMedium("MED",1,mat);
00104 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
00105 gGeoManager->SetTopVolume(top);
00106
00107
00108 TGeoBBox *box = new TGeoBBox("bx", 40., 40., 40.);
00109 TGeoSphere *sph = new TGeoSphere("sph", 40., 45.);
00110
00111 TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.);
00112 tr->SetName("tr");
00113
00114 tr->RegisterYourself();
00115
00116 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr * bx");
00117
00118 TGeoVolume *vol = new TGeoVolume("COMP2",cs);
00119 top->AddNode(vol,1);
00120 gGeoManager->CloseGeometry();
00121 gGeoManager->SetNsegments(100);
00122 top->Draw();
00123 MakePicture();
00124
00125 c->cd(2);
00126
00127 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
00128
00129 pt->SetLineColor(1);
00130
00131 TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
00132
00133 text->SetTextColor(2);
00134 pt->AddText("----- Here is an example of boolean intersection operation : A * B");
00135 pt->AddText("----- A == sphere (with inner radius non-zero), B == box");
00136 pt->AddText(" ");
00137 pt->SetAllWith("-----","color",4);
00138 pt->SetAllWith("-----","font",72);
00139 pt->SetAllWith("-----","size",0.04);
00140 pt->SetTextAlign(12);
00141 pt->SetTextSize(0.044);
00142 pt->Draw();
00143 c->cd(1);
00144 }
00145
00146 void s_difference()
00147 {
00148 gROOT->GetListOfCanvases()->Delete();
00149 TCanvas *c = new TCanvas("composite shape", "Difference boolean operation", 700, 1000);
00150
00151 c->Divide(1,2,0,0);
00152 c->cd(2);
00153 gPad->SetPad(0,0,1,0.4);
00154 c->cd(1);
00155 gPad->SetPad(0,0.4,1,1);
00156
00157 if (gGeoManager) delete gGeoManager;
00158
00159 new TGeoManager("xtru", "poza12");
00160 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
00161 TGeoMedium *med = new TGeoMedium("MED",1,mat);
00162 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
00163 gGeoManager->SetTopVolume(top);
00164
00165
00166 TGeoTorus *tor = new TGeoTorus("tor", 45., 15., 20., 45., 145.);
00167 TGeoSphere *sph = new TGeoSphere("sph", 20., 45., 0., 180., 0., 270.);
00168
00169 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph - tor");
00170
00171 TGeoVolume *vol = new TGeoVolume("COMP3",cs);
00172 top->AddNode(vol,1);
00173 gGeoManager->CloseGeometry();
00174 gGeoManager->SetNsegments(60);
00175 top->Draw();
00176 MakePicture();
00177
00178 c->cd(2);
00179
00180 TPaveText *pt = new TPaveText(.01, .01, .99, .99);
00181
00182 pt->SetLineColor(1);
00183
00184 TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
00185
00186 text->SetTextColor(2);
00187
00188 pt->AddText("----- It's an example of boolean difference: A - B");
00189 pt->AddText("----- A == part of sphere (0-180, 0-270), B == partial torus (45-145)");
00190 pt->AddText(" ");
00191 pt->SetAllWith("-----","color",4);
00192 pt->SetAllWith("-----","font",72);
00193 pt->SetAllWith("-----","size",0.04);
00194 pt->SetTextAlign(12);
00195 pt->SetTextSize(0.044);
00196 pt->Draw();
00197 c->cd(1);
00198 }
00199
00200 void complex_1()
00201 {
00202 gROOT->GetListOfCanvases()->Delete();
00203 TCanvas *c = new TCanvas("composite shape", "A * B - C", 700, 1000);
00204
00205 c->Divide(1,2,0,0);
00206 c->cd(2);
00207 gPad->SetPad(0,0,1,0.4);
00208 c->cd(1);
00209 gPad->SetPad(0,0.4,1,1);
00210
00211 if (gGeoManager) delete gGeoManager;
00212
00213 new TGeoManager("xtru", "poza12");
00214 TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7);
00215 TGeoMedium *med = new TGeoMedium("MED",1,mat);
00216 TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100);
00217 gGeoManager->SetTopVolume(top);
00218
00219
00220 TGeoBBox *box = new TGeoBBox("box", 20., 20., 20.);
00221 TGeoBBox *box1 = new TGeoBBox("box1", 5., 5., 5.);
00222 TGeoSphere *sph = new TGeoSphere("sph", 5., 25.);
00223 TGeoSphere *sph1 = new TGeoSphere("sph1", 1., 15.);
00224
00225 TGeoTranslation *tr = new TGeoTranslation(0., 30., 0.);
00226 TGeoTranslation *tr1 = new TGeoTranslation(0., 40., 0.);
00227 TGeoTranslation *tr2 = new TGeoTranslation(0., 30., 0.);
00228 TGeoTranslation *tr3 = new TGeoTranslation(0., 30., 0.);
00229 tr->SetName("tr");
00230 tr1->SetName("tr1");
00231 tr2->SetName("tr2");
00232 tr3->SetName("tr3");
00233
00234 tr->RegisterYourself();
00235 tr1->RegisterYourself();
00236 tr2->RegisterYourself();
00237 tr3->RegisterYourself();
00238
00239 TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "(sph * box) + (sph1:tr - box1:tr1)");
00240
00241 TGeoVolume *vol = new TGeoVolume("COMP4",cs);
00242
00243 top->AddNode(vol,1);
00244 gGeoManager->CloseGeometry();
00245 gGeoManager->SetNsegments(80);
00246 top->Draw();
00247 MakePicture();
00248
00249 c->cd(2);
00250 TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99);
00251 pt->SetLineColor(1);
00252 TText *text = pt->AddText("TGeoCompositeShape - composite shape class");
00253 text->SetTextColor(2);
00254 pt->AddText("----- (sphere * box) + (sphere - box) ");
00255
00256 pt->AddText(" ");
00257 pt->SetAllWith("-----","color",4);
00258 pt->SetAllWith("-----","font",72);
00259 pt->SetAllWith("-----","size",0.04);
00260 pt->SetTextAlign(12);
00261 pt->SetTextSize(0.044);
00262 pt->Draw();
00263 c->cd(1);
00264
00265 }
00266
00267
00268 void AddText(TPaveText *pave, const char *datamember, Double_t value, const char *comment)
00269 {
00270 char line[128];
00271 for (Int_t i=0; i<128; i++) line[i] = ' ';
00272 memcpy(&line[0], datamember, strlen(datamember));
00273 line[10] = '=';
00274 char number[20];
00275 sprintf(number, "%5.2f", value);
00276 memcpy(&line[12], number, strlen(number));
00277 line[26] = '=';
00278 line[27] = '>';
00279 sprintf(&line[30], "%s",comment);
00280 TText *text = pave->AddText(line);
00281 text->SetTextAlign(12);
00282 }
00283
00284
00285 void AddText(TPaveText *pave, const char *datamember, Int_t value, const char *comment)
00286 {
00287 char line[128];
00288 for (Int_t i=0; i<128; i++) line[i] = ' ';
00289 memcpy(&line[0], datamember, strlen(datamember));
00290 line[10] = '=';
00291 char number[20];
00292 sprintf(number, "%5i", value);
00293 memcpy(&line[12], number, strlen(number));
00294 line[26] = '=';
00295 line[27] = '>';
00296 sprintf(&line[30], "%s",comment);
00297 TText *text = pave->AddText(line);
00298 text->SetTextAlign(12);
00299 }
00300
00301
00302 void AddText(TPaveText *pave, TObject *pf, Int_t iaxis)
00303 {
00304 char line[128];
00305 TGeoPatternFinder *finder = (TGeoPatternFinder*)pf;
00306 if (!pave || !pf) return;
00307 for (Int_t i=0; i<128; i++) line[i] = ' ';
00308 TGeoVolume *volume = finder->GetVolume();
00309 TGeoShape *sh = volume->GetShape();
00310 sprintf(line, "Division of %s on axis %d (%s)", volume->GetName(), iaxis,sh->GetAxisName(iaxis));
00311 TText *text = pave->AddText(line);
00312 text->SetTextColor(3);
00313 text->SetTextAlign(12);
00314 AddText(pave, "fNdiv",finder->GetNdiv(),"number of divisions");
00315 AddText(pave, "fStart",finder->GetStart(),"start divisioning position");
00316 AddText(pave, "fStep",finder->GetStep(),"division step");
00317 }
00318
00319
00320 void raytrace() {
00321 if (!gGeoManager) return;
00322
00323 TVirtualGeoPainter *painter = gGeoManager->GetGeomPainter();
00324
00325 if (!painter) return;
00326
00327 painter->SetRaytracing(raytracing);
00328
00329 if (!gPad) return;
00330
00331 gPad->Modified();
00332 gPad->Update();
00333 }
00334
00335
00336 void help() {
00337
00338
00339 new TCanvas("chelp","Help to run demos",200,10,700,600);
00340
00341 welcome = new TPaveText(.1,.8,.9,.97);
00342 welcome->AddText("Welcome to the new geometry package");
00343 welcome->SetTextFont(32);
00344 welcome->SetTextColor(4);
00345 welcome->SetFillColor(24);
00346 welcome->Draw();
00347
00348 hdemo = new TPaveText(.05,.05,.95,.7);
00349 hdemo->SetTextAlign(12);
00350 hdemo->SetTextFont(52);
00351 hdemo->AddText("- Demo for building TGeo composite shapes");
00352 hdemo->AddText(" ");
00353 hdemo->SetAllWith("....","color",2);
00354 hdemo->SetAllWith("....","font",72);
00355 hdemo->SetAllWith("....","size",0.03);
00356
00357 hdemo->Draw();
00358 }
00359