cheongwadae.C: Drawing the Cheongwadae building which is the Presidential Residence of the Republic of Korea, using ROOT geometry class. | Geometry package | geodemo.C: GUI to draw the geometry shapes |
//Conbinatorial Solid Geometry example //Author: Andrei Gheata Bool_t raytracing = kTRUE; //______________________________________________________________________________ void csgdemo () { gSystem->Load("libGeom"); bar = new TControlBar("vertical", "TGeo composite shapes",20,20); bar->AddButton("How to run ","help()","Instructions "); bar->AddButton("Union ", "s_union()", "A + B "); bar->AddButton("Intersection ", "s_intersection()","A * B "); bar->AddButton("Difference ", "s_difference()","A - B "); //These two buttons are disabled cause of bugs bar->AddButton("Complex composite", "complex_1()","(A * B) + (C - D)"); bar->Show(); gROOT->SaveContext(); } //______________________________________________________________________________ void MakePicture() { gGeoManager->GetGeomPainter()->SetRaytracing(kFALSE); gPad->Modified(); gPad->Update(); } void s_union() { gROOT->GetListOfCanvases()->Delete(); TCanvas *c = new TCanvas("composite shape", "Union boolean operation", 700, 1000); c->Divide(1,2,0,0); c->cd(2); gPad->SetPad(0,0,1,0.4); c->cd(1); gPad->SetPad(0,0.4,1,1); if (gGeoManager) delete gGeoManager; new TGeoManager("xtru", "poza12"); TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *med = new TGeoMedium("MED",1,mat); TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100); gGeoManager->SetTopVolume(top); // define shape components with names TGeoPgon *pgon = new TGeoPgon("pg",0.,360.,6,2); pgon->DefineSection(0,0,0,20); pgon->DefineSection(1, 30,0,20); TGeoSphere *sph = new TGeoSphere("sph", 40., 45., 5., 175., 0., 340.); // define named geometrical transformations with names TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.); tr->SetName("tr"); // register all used transformations tr->RegisterYourself(); // create the composite shape based on a Boolean expression TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr + pg"); TGeoVolume *vol = new TGeoVolume("COMP1",cs); top->AddNode(vol,1); gGeoManager->CloseGeometry(); gGeoManager->SetNsegments(100); top->Draw(); MakePicture(); c->cd(2); TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99); pt->SetLineColor(1); TText *text = pt->AddText("TGeoCompositeShape - composite shape class"); text->SetTextColor(2); pt->AddText("----- It's an example of boolean union operation : A + B"); pt->AddText("----- A == part of sphere (5-175, 0-340), B == pgon"); pt->AddText(" "); pt->SetAllWith("-----","color",4); pt->SetAllWith("-----","font",72); pt->SetAllWith("-----","size",0.04); pt->SetTextAlign(12); pt->SetTextSize(.044); pt->Draw(); c->cd(1); } void s_intersection() { gROOT->GetListOfCanvases()->Delete(); TCanvas *c = new TCanvas("composite shape", "Intersection boolean operation", 700, 1000); c->Divide(1,2,0,0); c->cd(2); gPad->SetPad(0,0,1,0.4); c->cd(1); gPad->SetPad(0,0.4,1,1); if (gGeoManager) delete gGeoManager; new TGeoManager("xtru", "poza12"); TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *med = new TGeoMedium("MED",1,mat); TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100); gGeoManager->SetTopVolume(top); // define shape components with names TGeoBBox *box = new TGeoBBox("bx", 40., 40., 40.); TGeoSphere *sph = new TGeoSphere("sph", 40., 45.); // define named geometrical transformations with names TGeoTranslation *tr = new TGeoTranslation(0., 0., 45.); tr->SetName("tr"); // register all used transformations tr->RegisterYourself(); // create the composite shape based on a Boolean expression TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph:tr * bx"); TGeoVolume *vol = new TGeoVolume("COMP2",cs); top->AddNode(vol,1); gGeoManager->CloseGeometry(); gGeoManager->SetNsegments(100); top->Draw(); MakePicture(); c->cd(2); TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99); pt->SetLineColor(1); TText *text = pt->AddText("TGeoCompositeShape - composite shape class"); text->SetTextColor(2); pt->AddText("----- Here is an example of boolean intersection operation : A * B"); pt->AddText("----- A == sphere (with inner radius non-zero), B == box"); pt->AddText(" "); pt->SetAllWith("-----","color",4); pt->SetAllWith("-----","font",72); pt->SetAllWith("-----","size",0.04); pt->SetTextAlign(12); pt->SetTextSize(0.044); pt->Draw(); c->cd(1); } void s_difference() { gROOT->GetListOfCanvases()->Delete(); TCanvas *c = new TCanvas("composite shape", "Difference boolean operation", 700, 1000); c->Divide(1,2,0,0); c->cd(2); gPad->SetPad(0,0,1,0.4); c->cd(1); gPad->SetPad(0,0.4,1,1); if (gGeoManager) delete gGeoManager; new TGeoManager("xtru", "poza12"); TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *med = new TGeoMedium("MED",1,mat); TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100); gGeoManager->SetTopVolume(top); // define shape components with names TGeoTorus *tor = new TGeoTorus("tor", 45., 15., 20., 45., 145.); TGeoSphere *sph = new TGeoSphere("sph", 20., 45., 0., 180., 0., 270.); // create the composite shape based on a Boolean expression TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "sph - tor"); TGeoVolume *vol = new TGeoVolume("COMP3",cs); top->AddNode(vol,1); gGeoManager->CloseGeometry(); gGeoManager->SetNsegments(60); top->Draw(); MakePicture(); c->cd(2); TPaveText *pt = new TPaveText(.01, .01, .99, .99); pt->SetLineColor(1); TText *text = pt->AddText("TGeoCompositeShape - composite shape class"); text->SetTextColor(2); pt->AddText("----- It's an example of boolean difference: A - B"); pt->AddText("----- A == part of sphere (0-180, 0-270), B == partial torus (45-145)"); pt->AddText(" "); pt->SetAllWith("-----","color",4); pt->SetAllWith("-----","font",72); pt->SetAllWith("-----","size",0.04); pt->SetTextAlign(12); pt->SetTextSize(0.044); pt->Draw(); c->cd(1); } void complex_1() { gROOT->GetListOfCanvases()->Delete(); TCanvas *c = new TCanvas("composite shape", "A * B - C", 700, 1000); c->Divide(1,2,0,0); c->cd(2); gPad->SetPad(0,0,1,0.4); c->cd(1); gPad->SetPad(0,0.4,1,1); if (gGeoManager) delete gGeoManager; new TGeoManager("xtru", "poza12"); TGeoMaterial *mat = new TGeoMaterial("Al", 26.98,13,2.7); TGeoMedium *med = new TGeoMedium("MED",1,mat); TGeoVolume *top = gGeoManager->MakeBox("TOP",med,100,100,100); gGeoManager->SetTopVolume(top); // define shape components with names TGeoBBox *box = new TGeoBBox("box", 20., 20., 20.); TGeoBBox *box1 = new TGeoBBox("box1", 5., 5., 5.); TGeoSphere *sph = new TGeoSphere("sph", 5., 25.); TGeoSphere *sph1 = new TGeoSphere("sph1", 1., 15.); // create the composite shape based on a Boolean expression TGeoTranslation *tr = new TGeoTranslation(0., 30., 0.); TGeoTranslation *tr1 = new TGeoTranslation(0., 40., 0.); TGeoTranslation *tr2 = new TGeoTranslation(0., 30., 0.); TGeoTranslation *tr3 = new TGeoTranslation(0., 30., 0.); tr->SetName("tr"); tr1->SetName("tr1"); tr2->SetName("tr2"); tr3->SetName("tr3"); // register all used transformations tr->RegisterYourself(); tr1->RegisterYourself(); tr2->RegisterYourself(); tr3->RegisterYourself(); TGeoCompositeShape *cs = new TGeoCompositeShape("mir", "(sph * box) + (sph1:tr - box1:tr1)"); TGeoVolume *vol = new TGeoVolume("COMP4",cs); // vol->SetLineColor(randomColor()); top->AddNode(vol,1); gGeoManager->CloseGeometry(); gGeoManager->SetNsegments(80); top->Draw(); MakePicture(); c->cd(2); TPaveText *pt = new TPaveText(0.01,0.01,0.99,0.99); pt->SetLineColor(1); TText *text = pt->AddText("TGeoCompositeShape - composite shape class"); text->SetTextColor(2); pt->AddText("----- (sphere * box) + (sphere - box) "); pt->AddText(" "); pt->SetAllWith("-----","color",4); pt->SetAllWith("-----","font",72); pt->SetAllWith("-----","size",0.04); pt->SetTextAlign(12); pt->SetTextSize(0.044); pt->Draw(); c->cd(1); } //______________________________________________________________________________ void AddText(TPaveText *pave, const char *datamember, Double_t value, const char *comment) { char line[128]; for (Int_t i=0; i<128; i++) line[i] = ' '; memcpy(&line[0], datamember, strlen(datamember)); line[10] = '='; char number[20]; sprintf(number, "%5.2f", value); memcpy(&line[12], number, strlen(number)); line[26] = '='; line[27] = '>'; sprintf(&line[30], "%s",comment); TText *text = pave->AddText(line); text->SetTextAlign(12); } //______________________________________________________________________________ void AddText(TPaveText *pave, const char *datamember, Int_t value, const char *comment) { char line[128]; for (Int_t i=0; i<128; i++) line[i] = ' '; memcpy(&line[0], datamember, strlen(datamember)); line[10] = '='; char number[20]; sprintf(number, "%5i", value); memcpy(&line[12], number, strlen(number)); line[26] = '='; line[27] = '>'; sprintf(&line[30], "%s",comment); TText *text = pave->AddText(line); text->SetTextAlign(12); } //______________________________________________________________________________ void AddText(TPaveText *pave, TObject *pf, Int_t iaxis) { char line[128]; TGeoPatternFinder *finder = (TGeoPatternFinder*)pf; if (!pave || !pf) return; for (Int_t i=0; i<128; i++) line[i] = ' '; TGeoVolume *volume = finder->GetVolume(); TGeoShape *sh = volume->GetShape(); sprintf(line, "Division of %s on axis %d (%s)", volume->GetName(), iaxis,sh->GetAxisName(iaxis)); TText *text = pave->AddText(line); text->SetTextColor(3); text->SetTextAlign(12); AddText(pave, "fNdiv",finder->GetNdiv(),"number of divisions"); AddText(pave, "fStart",finder->GetStart(),"start divisioning position"); AddText(pave, "fStep",finder->GetStep(),"division step"); } //______________________________________________________________________________ void raytrace() { if (!gGeoManager) return; TVirtualGeoPainter *painter = gGeoManager->GetGeomPainter(); if (!painter) return; painter->SetRaytracing(raytracing); if (!gPad) return; gPad->Modified(); gPad->Update(); } //______________________________________________________________________________ void help() { // new TCanvas("chelp","Help to run demos",200,10,700,600); welcome = new TPaveText(.1,.8,.9,.97); welcome->AddText("Welcome to the new geometry package"); welcome->SetTextFont(32); welcome->SetTextColor(4); welcome->SetFillColor(24); welcome->Draw(); hdemo = new TPaveText(.05,.05,.95,.7); hdemo->SetTextAlign(12); hdemo->SetTextFont(52); hdemo->AddText("- Demo for building TGeo composite shapes"); hdemo->AddText(" "); hdemo->SetAllWith("....","color",2); hdemo->SetAllWith("....","font",72); hdemo->SetAllWith("....","size",0.03); hdemo->Draw(); } csgdemo.C:1 csgdemo.C:2 csgdemo.C:3 csgdemo.C:4 csgdemo.C:5 csgdemo.C:6 csgdemo.C:7 csgdemo.C:8 csgdemo.C:9 csgdemo.C:10 csgdemo.C:11 csgdemo.C:12 csgdemo.C:13 csgdemo.C:14 csgdemo.C:15 csgdemo.C:16 csgdemo.C:17 csgdemo.C:18 csgdemo.C:19 csgdemo.C:20 csgdemo.C:21 csgdemo.C:22 csgdemo.C:23 csgdemo.C:24 csgdemo.C:25 csgdemo.C:26 csgdemo.C:27 csgdemo.C:28 csgdemo.C:29 csgdemo.C:30 csgdemo.C:31 csgdemo.C:32 csgdemo.C:33 csgdemo.C:34 csgdemo.C:35 csgdemo.C:36 csgdemo.C:37 csgdemo.C:38 csgdemo.C:39 csgdemo.C:40 csgdemo.C:41 csgdemo.C:42 csgdemo.C:43 csgdemo.C:44 csgdemo.C:45 csgdemo.C:46 csgdemo.C:47 csgdemo.C:48 csgdemo.C:49 csgdemo.C:50 csgdemo.C:51 csgdemo.C:52 csgdemo.C:53 csgdemo.C:54 csgdemo.C:55 csgdemo.C:56 csgdemo.C:57 csgdemo.C:58 csgdemo.C:59 csgdemo.C:60 csgdemo.C:61 csgdemo.C:62 csgdemo.C:63 csgdemo.C:64 csgdemo.C:65 csgdemo.C:66 csgdemo.C:67 csgdemo.C:68 csgdemo.C:69 csgdemo.C:70 csgdemo.C:71 csgdemo.C:72 csgdemo.C:73 csgdemo.C:74 csgdemo.C:75 csgdemo.C:76 csgdemo.C:77 csgdemo.C:78 csgdemo.C:79 csgdemo.C:80 csgdemo.C:81 csgdemo.C:82 csgdemo.C:83 csgdemo.C:84 csgdemo.C:85 csgdemo.C:86 csgdemo.C:87 csgdemo.C:88 csgdemo.C:89 csgdemo.C:90 csgdemo.C:91 csgdemo.C:92 csgdemo.C:93 csgdemo.C:94 csgdemo.C:95 csgdemo.C:96 csgdemo.C:97 csgdemo.C:98 csgdemo.C:99 csgdemo.C:100 csgdemo.C:101 csgdemo.C:102 csgdemo.C:103 csgdemo.C:104 csgdemo.C:105 csgdemo.C:106 csgdemo.C:107 csgdemo.C:108 csgdemo.C:109 csgdemo.C:110 csgdemo.C:111 csgdemo.C:112 csgdemo.C:113 csgdemo.C:114 csgdemo.C:115 csgdemo.C:116 csgdemo.C:117 csgdemo.C:118 csgdemo.C:119 csgdemo.C:120 csgdemo.C:121 csgdemo.C:122 csgdemo.C:123 csgdemo.C:124 csgdemo.C:125 csgdemo.C:126 csgdemo.C:127 csgdemo.C:128 csgdemo.C:129 csgdemo.C:130 csgdemo.C:131 csgdemo.C:132 csgdemo.C:133 csgdemo.C:134 csgdemo.C:135 csgdemo.C:136 csgdemo.C:137 csgdemo.C:138 csgdemo.C:139 csgdemo.C:140 csgdemo.C:141 csgdemo.C:142 csgdemo.C:143 csgdemo.C:144 csgdemo.C:145 csgdemo.C:146 csgdemo.C:147 csgdemo.C:148 csgdemo.C:149 csgdemo.C:150 csgdemo.C:151 csgdemo.C:152 csgdemo.C:153 csgdemo.C:154 csgdemo.C:155 csgdemo.C:156 csgdemo.C:157 csgdemo.C:158 csgdemo.C:159 csgdemo.C:160 csgdemo.C:161 csgdemo.C:162 csgdemo.C:163 csgdemo.C:164 csgdemo.C:165 csgdemo.C:166 csgdemo.C:167 csgdemo.C:168 csgdemo.C:169 csgdemo.C:170 csgdemo.C:171 csgdemo.C:172 csgdemo.C:173 csgdemo.C:174 csgdemo.C:175 csgdemo.C:176 csgdemo.C:177 csgdemo.C:178 csgdemo.C:179 csgdemo.C:180 csgdemo.C:181 csgdemo.C:182 csgdemo.C:183 csgdemo.C:184 csgdemo.C:185 csgdemo.C:186 csgdemo.C:187 csgdemo.C:188 csgdemo.C:189 csgdemo.C:190 csgdemo.C:191 csgdemo.C:192 csgdemo.C:193 csgdemo.C:194 csgdemo.C:195 csgdemo.C:196 csgdemo.C:197 csgdemo.C:198 csgdemo.C:199 csgdemo.C:200 csgdemo.C:201 csgdemo.C:202 csgdemo.C:203 csgdemo.C:204 csgdemo.C:205 csgdemo.C:206 csgdemo.C:207 csgdemo.C:208 csgdemo.C:209 csgdemo.C:210 csgdemo.C:211 csgdemo.C:212 csgdemo.C:213 csgdemo.C:214 csgdemo.C:215 csgdemo.C:216 csgdemo.C:217 csgdemo.C:218 csgdemo.C:219 csgdemo.C:220 csgdemo.C:221 csgdemo.C:222 csgdemo.C:223 csgdemo.C:224 csgdemo.C:225 csgdemo.C:226 csgdemo.C:227 csgdemo.C:228 csgdemo.C:229 csgdemo.C:230 csgdemo.C:231 csgdemo.C:232 csgdemo.C:233 csgdemo.C:234 csgdemo.C:235 csgdemo.C:236 csgdemo.C:237 csgdemo.C:238 csgdemo.C:239 csgdemo.C:240 csgdemo.C:241 csgdemo.C:242 csgdemo.C:243 csgdemo.C:244 csgdemo.C:245 csgdemo.C:246 csgdemo.C:247 csgdemo.C:248 csgdemo.C:249 csgdemo.C:250 csgdemo.C:251 csgdemo.C:252 csgdemo.C:253 csgdemo.C:254 csgdemo.C:255 csgdemo.C:256 csgdemo.C:257 csgdemo.C:258 csgdemo.C:259 csgdemo.C:260 csgdemo.C:261 csgdemo.C:262 csgdemo.C:263 csgdemo.C:264 csgdemo.C:265 csgdemo.C:266 csgdemo.C:267 csgdemo.C:268 csgdemo.C:269 csgdemo.C:270 csgdemo.C:271 csgdemo.C:272 csgdemo.C:273 csgdemo.C:274 csgdemo.C:275 csgdemo.C:276 csgdemo.C:277 csgdemo.C:278 csgdemo.C:279 csgdemo.C:280 csgdemo.C:281 csgdemo.C:282 csgdemo.C:283 csgdemo.C:284 csgdemo.C:285 csgdemo.C:286 csgdemo.C:287 csgdemo.C:288 csgdemo.C:289 csgdemo.C:290 csgdemo.C:291 csgdemo.C:292 csgdemo.C:293 csgdemo.C:294 csgdemo.C:295 csgdemo.C:296 csgdemo.C:297 csgdemo.C:298 csgdemo.C:299 csgdemo.C:300 csgdemo.C:301 csgdemo.C:302 csgdemo.C:303 csgdemo.C:304 csgdemo.C:305 csgdemo.C:306 csgdemo.C:307 csgdemo.C:308 csgdemo.C:309 csgdemo.C:310 csgdemo.C:311 csgdemo.C:312 csgdemo.C:313 csgdemo.C:314 csgdemo.C:315 csgdemo.C:316 csgdemo.C:317 csgdemo.C:318 csgdemo.C:319 csgdemo.C:320 csgdemo.C:321 csgdemo.C:322 csgdemo.C:323 csgdemo.C:324 csgdemo.C:325 csgdemo.C:326 csgdemo.C:327 csgdemo.C:328 csgdemo.C:329 csgdemo.C:330 csgdemo.C:331 csgdemo.C:332 csgdemo.C:333 csgdemo.C:334 csgdemo.C:335 csgdemo.C:336 csgdemo.C:337 csgdemo.C:338 csgdemo.C:339 csgdemo.C:340 csgdemo.C:341 csgdemo.C:342 csgdemo.C:343 csgdemo.C:344 csgdemo.C:345 csgdemo.C:346 csgdemo.C:347 csgdemo.C:348 csgdemo.C:349 csgdemo.C:350 csgdemo.C:351 csgdemo.C:352 csgdemo.C:353 csgdemo.C:354 csgdemo.C:355 csgdemo.C:356 csgdemo.C:357 csgdemo.C:358 csgdemo.C:359 csgdemo.C:360 |
|