]> git.uio.no Git - u/mrichter/AliRoot.git/blob - TGeant4/TG4VisManager.cxx
Possibility to define the magnetic field in the reconstruction (Yu.Belikov)
[u/mrichter/AliRoot.git] / TGeant4 / TG4VisManager.cxx
1 // $Id$
2 // Category: visualization
3 //
4 // According to visualization/management/include/MyVisManager.*
5 // John Allison 24th January 1998.
6 // I. Hrivnacova 12.5.98
7 //
8 // Renamed to TG4VisManager
9 // I. Hrivnacova, 3.9.99
10 //
11 // Added AliMC implementation
12 // A. Gheata, 22.2.00
13 //
14 // Added OpenGL*Win32, RayTracer (as replacement of RayX) drivers 
15 // based on G4 suggestions.
16 // I. Gonzalez, 4.4.2000
17 //
18 // Example Visualization Manager description:
19 //   Implements virtual function RegisterGraphicsSystems.  
20 //   Exploits C-pre-processor variables G4VIS_USE_DAWN, etc.,
21 //   which are set by the G4 makefiles if
22 //   environment variables of the same name are set.
23 //
24 // So all you have to do is set environment variables and compile and
25 //   instantiate this in your main().
26 //
27 // Alternatively, you can implement an empty function here and just
28 //   register the systems you want in your main(), e.g.:
29 //   G4VisManager* myVisManager = new MyVisManager;
30 //   myVisManager -> RegisterGraphicsSystem (new MyGraphicsSystem);
31
32
33 #ifdef G4VIS_USE
34
35 #include "TG4VisManager.h"
36 #include "TG4Globals.h"
37
38 #include <G4LogicalVolumeStore.hh>
39 #include <G4PhysicalVolumeStore.hh>
40 #include <G4TransportationManager.hh>
41 #include <G4Material.hh>
42 #include <G4PhysicalVolumeModel.hh>
43 #include <G4VVisManager.hh>
44
45 // Supported drivers...
46
47 #ifdef G4VIS_USE_DAWN
48 #include <G4FukuiRenderer.hh>
49 #endif
50
51 #ifdef G4VIS_USE_DAWNFILE
52 #include <G4DAWNFILE.hh>
53 #endif
54
55 #ifdef G4VIS_USE_OPACS
56 #include <G4Wo.hh>
57 #include <G4Xo.hh>
58 #endif
59
60 #ifdef G4VIS_USE_OPENGLX
61 #include <G4OpenGLImmediateX.hh>
62 #include <G4OpenGLStoredX.hh>
63 #endif
64
65 #ifdef G4VIS_USE_OPENGLXM
66 #include <G4OpenGLImmediateXm.hh>
67 #include <G4OpenGLStoredXm.hh>
68 #endif
69
70 #ifdef G4VIS_USE_OPENGLWIN32
71 #include "G4OpenGLImmediateWin32.hh"
72 #include "G4OpenGLStoredWin32.hh"
73 #endif
74
75 #ifdef G4VIS_USE_OIX
76 #include <G4OpenInventorX.hh>
77 #endif
78
79 #ifdef G4VIS_USE_OIWIN32
80 #include <G4OpenInventorWin32.hh>
81 #endif
82
83 #ifdef G4VIS_USE_RAYTRACER
84 #include "G4RayTracer.hh"
85 #endif
86
87 #ifdef G4VIS_USE_VRML
88 #include <G4VRML1.hh>
89 #include <G4VRML2.hh>
90 #endif
91
92 #ifdef G4VIS_USE_VRMLFILE
93 #include <G4VRML1File.hh>
94 #include <G4VRML2File.hh>
95 #endif
96
97 TG4VisManager::TG4VisManager(G4int verboseLevel) {
98 //  
99   fVerbose = verboseLevel; 
100   fColourFlag = true;
101 }
102
103 TG4VisManager::TG4VisManager(const TG4VisManager& right) {
104 // 
105   TG4Globals::Exception(
106     "Attempt to copy TG4VisManager singleton.");
107 }
108
109 TG4VisManager::~TG4VisManager() {
110 //
111 }  
112
113 // operators
114
115 TG4VisManager& TG4VisManager::operator=(const TG4VisManager& right) 
116 {
117   // check assignement to self
118   if (this == &right) return *this;
119
120   TG4Globals::Exception(
121     "Attempt to assign TG4VisManager singleton.");
122     
123   return *this;  
124 }    
125           
126 // private methods
127
128 void TG4VisManager::RegisterGraphicsSystems() 
129 {
130 // Registers the graphics systems.
131 // ---
132
133   // all created graphics system instances are
134   // deleted in G4VisManager::~G4VisManager()
135 #ifdef G4VIS_USE_DAWN
136   RegisterGraphicsSystem(new G4FukuiRenderer);
137 #endif
138
139 #ifdef G4VIS_USE_DAWNFILE
140   RegisterGraphicsSystem(new G4DAWNFILE);
141 #endif
142
143 #ifdef G4VIS_USE_OPACS
144   RegisterGraphicsSystem(new G4Wo);
145   RegisterGraphicsSystem(new G4Xo);
146 #endif
147
148 #ifdef G4VIS_USE_OPENGLX
149   RegisterGraphicsSystem(new G4OpenGLImmediateX);
150   RegisterGraphicsSystem(new G4OpenGLStoredX);
151 #endif
152
153 #ifdef G4VIS_USE_OPENGLXM
154   RegisterGraphicsSystem(new G4OpenGLImmediateXm);
155   RegisterGraphicsSystem(new G4OpenGLStoredXm);
156 #endif
157
158 #ifdef G4VIS_USE_OPENGLWIN32
159   RegisterGraphicsSystem (new G4OpenGLImmediateWin32);
160   RegisterGraphicsSystem (new G4OpenGLStoredWin32);
161 #endif
162
163 #ifdef G4VIS_USE_OIX
164   RegisterGraphicsSystem(new G4OpenInventorX);
165 #endif
166
167 #ifdef G4VIS_USE_OIWIN32
168   RegisterGraphicsSystem(new G4OpenInventorWin32);
169 #endif
170
171 #ifdef G4VIS_USE_RAYTRACER
172   RegisterGraphicsSystem (new G4RayTracer);
173 #endif
174
175 #ifdef G4VIS_USE_VRML
176   RegisterGraphicsSystem(new G4VRML1);
177   RegisterGraphicsSystem(new G4VRML2);
178 #endif
179
180 #ifdef G4VIS_USE_VRMLFILE
181   RegisterGraphicsSystem(new G4VRML1File);
182   RegisterGraphicsSystem(new G4VRML2File);
183 #endif
184
185   if (fVerbose > 0) {
186     G4cout <<
187       "\nYou have successfully chosen to use the following graphics systems."
188          << G4endl;
189     PrintAvailableGraphicsSystems();
190   }
191 }
192
193 //---------------------------------------------------------------
194 // private methods
195 //---------------------------------------------------------------
196
197
198 G4RWTPtrOrderedVector<G4LogicalVolume> TG4VisManager::GetLVList(G4String name)
199 {
200 // Get function returning the list of logical volumes
201 // associated to NAME; G4 built clones of a G3 volume (identified 
202 // with NAME_NUMBER will be added to the list)  
203 //  NAME can be the name of a logical or physical volume
204 // ---
205
206  G4RWTPtrOrderedVector <G4LogicalVolume> lvList;
207  G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
208  G4LogicalVolume* pLV = 0; 
209  if (pLVStore)
210  {
211    for (G4int i=0; i<pLVStore->entries(); i++)
212    {
213      pLV = pLVStore->at(i);  
214      if (CaseInsensitiveEqual(name,pLV->GetName())) 
215      {
216        if (!lvList.contains(pLV)) lvList.append(pLV);
217      }
218    }
219  }  
220  if (!lvList.isEmpty()) return lvList;
221  G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
222  G4VPhysicalVolume* pPV = 0;
223  if (pPVStore) 
224  {
225    for (G4int i=0; i<pPVStore->entries(); i++)
226    {
227      pPV = pPVStore->at(i); 
228      if (CaseInsensitiveEqual(name,pPV->GetName())) 
229      {
230        pLV = pPV->GetLogicalVolume();
231        if (!lvList.contains(pLV)) lvList.append(pLV);
232      }     
233    }
234  }  
235  return lvList;
236 }
237
238
239 G4RWTPtrOrderedVector<G4VPhysicalVolume> TG4VisManager::GetPVList(G4String name)
240 {
241 // Get function returning the physical volume pointer for NAME
242 // ---
243
244   G4RWTPtrOrderedVector <G4VPhysicalVolume> pvList;
245   G4PhysicalVolumeStore* pPVStore = G4PhysicalVolumeStore::GetInstance();
246   if (!pPVStore)
247   {
248     TG4Globals::Warning("TG4VisManager::Gdraw : No volume store !");
249     return pvList;
250   }
251   G4VPhysicalVolume* pPV = 0;
252   for (G4int i=0; i<pPVStore->entries(); i++)
253   {
254     pPV = pPVStore->at(i);
255     if (CaseInsensitiveEqual(name,pPV->GetName()))
256     {
257       if (!pvList.contains(pPV)) pvList.append(pPV);
258     }  
259   }
260   return pvList;
261 }
262
263
264 G4bool TG4VisManager::CaseInsensitiveEqual(const G4String string1,
265                                            const G4String string2)
266 {
267 // Case insensitive comparison of 2 strings
268 // ---
269
270   G4int i;
271   if (string1 == string2) return true;
272 //  if (string1.length() != string2.length()) return false;
273   for (i=0; i<string1.length(); i++)
274   {
275     G4int diff = abs((G4int)string1(i)-(G4int)string2(i));
276     if (diff && (diff!=32)) return false;
277   }
278   if (string2.length() > string1.length())
279   {
280     if (string2(i) == '_') return true;
281     return false;
282   }    
283   return true;
284 }
285  
286
287 void TG4VisManager::SetAtt4Daughters(G4LogicalVolume* const lv, 
288                                      const TG4G3Attribute att, const G4int val)
289 {
290 // Iterator for setting a visual attribute for all daughters
291 // ---
292
293   SetG4Attribute(lv,att,val);  
294   
295   G4String lvName = lv->GetName();
296   G4int nOfDaughters = lv->GetNoDaughters();
297   if (nOfDaughters>0)
298   {
299     G4String previousName = "";
300     for (G4int i=0; i<nOfDaughters; i++) 
301     { 
302       G4LogicalVolume* lvd = lv->GetDaughter(i)->GetLogicalVolume(); 
303       G4String currentName = lvd->GetName();
304       if (currentName != lvName && currentName != previousName)
305       {
306         SetAtt4Daughters(lvd, att, val);
307         previousName = currentName;
308       } 
309     }
310   }   
311 }
312
313
314 G4bool TG4VisManager::IsSharedVisAttributes(const G4LogicalVolume* pLV)
315 {
316 // Function seeking if the volume's visible attributes are shared with
317 //  other volumes
318 // ---
319
320   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
321   G4LogicalVolume* pLVCurrent = 0;
322   const G4VisAttributes* pVisAtt = pLV->GetVisAttributes();
323   if (!pVisAtt) return false;
324   for (G4int i=0; i<pLVStore->entries(); i++)
325   {
326     pLVCurrent = pLVStore->at(i);
327     if (pLVCurrent != pLV)
328     {
329       if (pLVCurrent->GetVisAttributes() == pVisAtt) 
330       {
331         return true;
332       }
333     }
334   }
335   return false;
336 }
337
338
339 void TG4VisManager::SetG4Attribute(G4LogicalVolume* const lv,
340                                    const TG4G3Attribute att, const G4int val)
341 {
342 // Set the G4 attribute fo volume LV accordingly to the G3 description
343 //  of (att- val)    
344 // --
345
346  if (!lv) return;
347  // Dupplicating old vis. attributes    
348  const G4VisAttributes* visAttributes = lv->GetVisAttributes();
349  G4VisAttributes* newVisAttributes;
350  if (!visAttributes)
351    newVisAttributes    = new G4VisAttributes(false);
352  else {
353    G4bool visibility = visAttributes->IsVisible();
354    G4Colour colour   = visAttributes->GetColour();
355    newVisAttributes = new G4VisAttributes(visibility, colour);
356  }
357
358  const G4int kAbsVal = abs(val);        // the functionality is given by the abs value
359
360  // Default visible attributes
361  G4double red(0),green(0),blue(0); // default is black
362  G4bool isVisible(false);
363  G4bool isDaughtersInvisible(false);
364  G4VisAttributes::LineStyle lineStyle = G4VisAttributes::unbroken;
365  G4double lineWidth = 1.0;
366  G4bool isForceDrawingStyle(false);
367  G4VisAttributes::ForcedDrawingStyle drawingStyle = G4VisAttributes::wireframe;
368  
369  // a 'hardcopy' of old vis attributes is needed because the copy constructor
370  // resets to defaults some of the data members of G4VisAttributes class
371  if (visAttributes)
372  {
373    isVisible          = visAttributes->IsVisible();
374    isDaughtersInvisible = visAttributes->IsDaughtersInvisible();
375    red   = visAttributes->GetColour().GetRed();
376    green = visAttributes->GetColour().GetGreen(); 
377    blue  = visAttributes->GetColour().GetBlue();        // old RGB components
378    lineStyle = visAttributes->GetLineStyle();
379    lineWidth = visAttributes->GetLineWidth();
380    isForceDrawingStyle = visAttributes->IsForceDrawingStyle();
381    if (isForceDrawingStyle) 
382        drawingStyle = visAttributes->GetForcedDrawingStyle();
383    
384  }
385  G4double luminosityBin(0.04),  // bin for luminosity 
386           luminosity(0);        // colour luminosity
387
388  // Delete old vis. attributes if they are not shared
389  if (visAttributes && !IsSharedVisAttributes(lv)) delete visAttributes;
390
391  // Set the required attribute
392  switch (att)
393  {
394   case kSEEN:
395    switch (val)
396    {
397     case  0:
398      isVisible = false; 
399      break;
400     case  1:
401      isVisible = true;  
402      break;
403     case -1:
404      isVisible = false; 
405      break;
406     case -2:
407      isVisible = false; 
408      break;
409     default:
410      isVisible = false; 
411    }       
412    break;
413   case kLSTY:
414    switch (kAbsVal)
415    {
416     case 1:
417      lineStyle = G4VisAttributes::unbroken; break;
418     case 2:
419      lineStyle = G4VisAttributes::dashed; break;
420     case 3:
421      lineStyle = G4VisAttributes::dotted; break;
422     default:
423      if (fVerbose > 0)
424       G4cout << "TG4VisManager::Gsatt() Usage of LSTY :" << G4endl
425              << "ATT = 1,2,3 means line unbroken, dashed or dotted" << G4endl
426              << "any other value resets to the default : unbroken" << G4endl;
427      lineStyle = G4VisAttributes::unbroken;
428    }       
429    break;
430   case kLWID:
431    lineWidth = kAbsVal;
432    if (lineWidth > 7) lineWidth = 7;
433    if (fVerbose > 0) 
434        G4cout << "TG4VisManager::Gsatt() Usage for LWID :" << G4endl
435               << "  The VAL you supply means the width of lines in pixels "
436               << "for the screen and in 0.1*mm for paper." << G4endl
437               << "  Negative values means the same, but for all daughters"
438               << G4endl;
439    break;
440   case kCOLO:
441    if (kAbsVal < 8)     // G3 base colours
442    {
443     switch (kAbsVal)
444     {
445      case 1:
446        red=0; green=0; blue=0;          //black
447        break;                   
448      case 2:
449        red=1; green=0; blue=0;          //red
450        break;                   
451      case 3:
452        red=0; green=1; blue=0;          //green
453        break;                   
454      case 4:
455        red=0; green=0; blue=1;          //blue
456        break;                   
457      case 5:
458        red=1; green=1; blue=0;          //yellow
459        break;                   
460      case 6:
461        red=1; green=0; blue=1;          //violet
462        break;                   
463      case 7:
464        red=0; green=1; blue=1;          //lightblue (almost !)
465     }
466     luminosity = 0.;
467    }
468    if (kAbsVal>=8 && kAbsVal<=16)
469    {
470      red=0; green=0; blue=0;
471      luminosity = (kAbsVal-7)*luminosityBin;
472    }
473    if (kAbsVal>=17 && kAbsVal<=41)
474    {
475      red=1; green=0; blue=0;
476      luminosity = (kAbsVal-16)*luminosityBin;
477    }
478    if (kAbsVal>=67 && kAbsVal<=91)
479    {
480      red=0; green=1; blue=0;
481      luminosity = (kAbsVal-66)*luminosityBin;
482    }
483    if (kAbsVal>=117 && kAbsVal<=141)
484    {
485      red=0; green=0; blue=1;
486      luminosity = (kAbsVal-116)*luminosityBin;
487    }
488    if (kAbsVal>=42 && kAbsVal<=66)
489    {
490      red=1; green=1; blue=0;
491      luminosity = (kAbsVal-41)*luminosityBin;
492    }
493    if (kAbsVal>=142 && kAbsVal<=166)
494    {
495      red=1; green=0; blue=1;
496      luminosity = (kAbsVal-141)*luminosityBin;
497    }
498    if (kAbsVal>=92 && kAbsVal<=116)
499    {
500      red=0; green=1; blue=1;
501      luminosity = (kAbsVal-91)*luminosityBin;
502    }
503    if (red < luminosityBin)     red += luminosity;
504    if (green < luminosityBin) green += luminosity;
505    if (blue < luminosityBin)   blue += luminosity;
506    break;
507   case kFILL:
508    isForceDrawingStyle = true;
509    switch (kAbsVal)
510    {
511     case 0:
512      drawingStyle = G4VisAttributes::wireframe;
513      break;
514     case 1:
515      drawingStyle = G4VisAttributes::solid;
516      break;
517     default:
518      if (fVerbose > 0)
519          G4cout << "TG4VisManager::Gsatt() FILL usage :" << G4endl
520                 << "  The FILL values you can supply are only :" << G4endl
521                 << "+/- 1 : forces wireframe drawing (default)" << G4endl
522                 << "+/- 2 : forces solid drawing" << G4endl
523                 << "other values sets the drawing style to solid"
524                 << G4endl;              
525      drawingStyle = G4VisAttributes::solid;
526    }      
527  }
528  // Register vis. attributes
529  newVisAttributes->SetVisibility(isVisible);
530  newVisAttributes->SetDaughtersInvisible(isDaughtersInvisible);
531  newVisAttributes->SetColour(red,green,blue);
532  newVisAttributes->SetLineStyle(lineStyle);
533  newVisAttributes->SetLineWidth(lineWidth);
534  if (drawingStyle == G4VisAttributes::wireframe) 
535        newVisAttributes->SetForceWireframe(isForceDrawingStyle);
536  if (drawingStyle == G4VisAttributes::solid) 
537        newVisAttributes->SetForceSolid(isForceDrawingStyle);
538  
539  lv->SetVisAttributes(newVisAttributes);
540
541   
542 //-----------------------------------------------------------------
543 // functions for drawing
544 //-----------------------------------------------------------------
545
546 void TG4VisManager::DrawOneSpec(const char* name)
547 {
548 // Function called when one double-clicks on a volume name
549 // in a TPaveLabel drawn by Gdtree
550 // ---
551
552  G4cout << "TG4VisManager::DrawOneSpec() Not yet implemented";
553 }
554
555
556 void TG4VisManager::SetColors()
557 {
558 // Function for setting default volume colours
559 // ---
560
561   G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
562   const G4LogicalVolume* pLV = 0; 
563   if (!pLVStore)
564   {
565     TG4Globals::Warning("TG4VisManager::SetColors : Ignored, geometry not built.");
566     return;
567   }
568   // parse the LV tree and set colours according to material density
569   for (G4int i=0; i<pLVStore->entries(); i++)
570   {
571     pLV = pLVStore->at(i);
572 //    G4cout << "VOLUME : " << pLV->GetName() << G4endl;
573     const G4Material* pMaterial = pLV->GetMaterial();
574     const G4State kState = pMaterial->GetState();
575     G4double density = (pMaterial->GetDensity())*cm3/g;
576     G4String nState = "Undefined";
577     G4int colour = 1;                   //black by default
578     G4double luminosity = 0.;
579     if (kState == kStateUndefined) 
580     {
581       nState = "Undefined";
582     }
583     if (kState == kStateSolid) 
584     {
585       nState = "Solid";
586       if (density < 2)
587       {
588         colour = 17;    //red
589         luminosity = 25 - 25*density/2;
590       }
591       else if (density < 3)
592       {
593         colour = 117;   //blue
594         luminosity = 25 - 25*(density-2);
595       }
596       else if (density < 10)
597       {
598         colour = 67;    //green
599         luminosity = 25 - 25*(density-5)/5;
600       }
601       else if (density < 15)
602       {
603         colour = 92;    //cyan
604         luminosity = 25 - 25*(density-10)/5;
605       }
606       else if (density < 20)
607       {
608         colour = 8;     //black
609         luminosity = 9 - 9*(density-15)/5;
610       }
611     }
612     if (kState == kStateLiquid) 
613     {
614       nState = "Liquid";
615       colour = 142;     //violet
616       luminosity = 25 - 25*density/2;
617     }
618     if (kState == kStateGas) 
619     {
620       nState = "Gas";
621       if (density < 0.001)  {colour = 42;}      //yellow
622       else if (density < 0.002) {colour = 27;}  //light red
623       else if (density < 0.003) {colour = 77;}  //light green
624       else {colour = 102;}                      //light cyan
625       luminosity = 0;
626     }
627     if (luminosity < 0) luminosity=0;
628     colour += (G4int)luminosity;
629     //  Setting the corresponding colour
630     Gsatt(pLV->GetName(),"COLO",colour);
631   }
632
633   
634
635 void TG4VisManager::Gsatt(const char* name, const char* att, Int_t val)
636 {
637 // Geant3 description :
638 //  
639 //    NAME   Volume name
640 //    IOPT   Name of the attribute to be set
641 //    IVAL   Value to which the attribute is to be set
642 //  
643 //    name= "*" stands for all the volumes.
644 //    iopt can be chosen among the following :
645 //    kWORK, kSEEN, kLSTY, kLWID, kCOLO, kFILL, kSET, kDET, kDTYP
646 // ---
647
648  G4int ival = val;
649  G4LogicalVolume* lv = 0; 
650  G4RWTPtrOrderedVector<G4LogicalVolume> lvList;
651  G4String sname(name),
652           satt(att);            
653
654  // seek for known attributes
655  TG4G3Attribute attribute = kUNKNOWN;
656  if (CaseInsensitiveEqual(att,"WORK"))
657  {
658    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
659    message += satt + " not used in G4";
660    TG4Globals::Warning(message);
661    return;
662  }
663  if (CaseInsensitiveEqual(att,"SEEN"))  attribute = kSEEN;  
664  if (CaseInsensitiveEqual(att,"LSTY"))  attribute = kLSTY;  
665  if (CaseInsensitiveEqual(att,"LWID"))  attribute = kLWID;
666  if (CaseInsensitiveEqual(att,"COLO"))  attribute = kCOLO;  
667  if (CaseInsensitiveEqual(att,"FILL"))  attribute = kFILL;  
668  if (CaseInsensitiveEqual(att,"SET"))
669  {
670    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
671    message += satt + " not used in G4";
672    TG4Globals::Warning(message);
673    return;
674  }
675  if (CaseInsensitiveEqual(att,"DET"))
676  {
677    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
678    message += satt + " not used in G4";
679    TG4Globals::Warning(message);
680    return;
681  }
682  if (CaseInsensitiveEqual(att,"DTYP"))
683  {
684    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
685    message += satt + " not used in G4";
686    TG4Globals::Warning(message);
687    return;
688  }
689  if (attribute == kUNKNOWN)
690  {
691    G4String message = "TG4VisManager::Gsatt: G3Attribute ";
692    message += satt + " unknown";
693    TG4Globals::Warning(message);
694    return;
695  }
696  G4bool  doForDaughters(false),         // tree iterator flag 
697          doForAll(false),               // activated if NAME is "*" 
698          topVisible(false);             // activated for kSEEN/-2
699  if (sname == "*")      doForAll = true;
700  if (val < 0 && sname!="*") doForDaughters = true;
701  if (attribute==kSEEN && val==-2) topVisible = true;
702  
703  // parse all the tree
704  if (doForAll)
705  {
706      G4LogicalVolumeStore* pLVStore = G4LogicalVolumeStore::GetInstance();
707      for (G4int i=0; i<pLVStore->entries(); i++)
708      {
709          lv = pLVStore->at(i);
710          SetG4Attribute(lv,attribute,ival);
711      }
712      return;
713  }
714
715  // get the logical volume pointer corresponding to NAME
716  lvList = GetLVList(name);
717  if (lvList.isEmpty())
718  {
719      G4String message = "TG4VisManager::Gsatt(): Ignored\n";
720      message += "    Logical volume " + sname + " has not been found.\n";
721      TG4Globals::Warning(message); 
722      return;
723  }
724 // set attribute for all descendents
725  if (doForDaughters)
726  {
727    for (G4int i=0; i<lvList.entries(); i++)
728    {
729      lv = lvList[i];
730      SetAtt4Daughters(lv,attribute,ival);
731    }     
732  }
733  else
734  {
735    for (G4int i=0; i<lvList.entries(); i++)
736    {
737      lv = lvList[i];
738      SetG4Attribute(lv,attribute,ival);
739    }     
740  }
741  if (topVisible) 
742  {
743    for (G4int i=0; i<lvList.entries(); i++)
744    {
745      lv = lvList[i];
746      SetG4Attribute(lv,attribute,1); 
747    }
748  }       
749
750
751
752 void TG4VisManager::Gdraw(const char *name,Float_t theta, Float_t phi, Float_t psi,
753                     Float_t u0,Float_t v0,Float_t ul,Float_t vl)
754
755 // Draw the physical volume NAME and all descendents;
756 // Mandatory : the graphics system, scene and view must be
757 //      initialized, e.g. "/vis~/create_view/new_graphics_system OGLSX";
758 //      Any call of Gdraw() will use the current graphics system and
759 //      the current window.
760 // The result will be a centered view drawing of the designated volume,
761 //      lights moving with camera, viewpoint direction given by theta/phi
762 //      and rotation on the screen given by psi;
763 // The u0, v0, ul, vl factors are ignored since the object will be 
764 //      automatically centered and will be confortable in the window
765 //      at any viewing angle.
766 //
767 // check if G4 graphics is ready for drawing
768 // ---
769
770   G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance();
771   if (!pVVisManager) { 
772     TG4Globals::Warning(
773        "TG4VisManager::Gdraw: Ignored - No graphics driver is built. ");
774     return;
775   }     
776   if (NeedSetColours())
777   {
778     SetColors();
779     SetColourFlag(false);
780   }
781   
782   const G4double kRad = M_PI/180.;
783   G4RWTPtrOrderedVector<G4VPhysicalVolume> pvList;
784   G4String sname(name);
785   G4bool  successful            = false;
786
787   pvList = GetPVList(name);
788   if (pvList.isEmpty())
789   {
790     G4String message = "TG4VisManager::Gdraw() :\n";
791     message += "Volume " + sname + " not found. Bailing out";
792     TG4Globals::Warning(message); 
793     return;
794   }
795
796   G4VPhysicalVolume *pPV = 0;
797
798   // clear the current scene if not empty
799   if (!fpScene->IsEmpty()) fpScene->Clear();
800
801   // create and add object's model list to the runtime-duration model 
802   // list and draw it
803   // (it is deleted in the VisManager destructor within 
804   // all the RWTPtrOrderedVectors of the scene)
805   for (G4int i=0; i<pvList.entries(); i++)
806   { 
807     pPV = pvList[i];
808     G4LogicalVolume* pLV = pPV->GetLogicalVolume();
809     G4VSolid* pSolid = pLV->GetSolid();
810     successful = fpScene->AddRunDurationModel(new G4PhysicalVolumeModel(pPV));
811     if (!successful) 
812     {
813       G4String message = "TG4VisManager::Gdraw() Could not add ";
814       message += pPV->GetName() + " to the drawing list. Probably ";
815       message += "it is already in the list.";
816       TG4Globals::Warning(message);
817     }  
818   }
819   // get the standard target point of the scene
820   const G4Point3D kTargetPoint = fpScene->GetStandardTargetPoint();
821
822   // set the viewpoint and the rotation on the screen
823   G4Vector3D viewpointDirection(sin(theta*kRad)*cos(phi*kRad), 
824                                 sin(theta*kRad)*sin(phi*kRad), cos(theta*kRad)); 
825   G4Vector3D upVector(sin(psi*kRad), cos(psi*kRad),0);                         
826
827   // set and register view parameters to the viewer
828   
829   fVP.SetLightsMoveWithCamera(true);
830   fVP.SetViewGeom();
831   fVP.UnsetViewHits();
832   fVP.UnsetViewDigis();
833   fVP.SetNoOfSides(48);
834   fVP.SetCurrentTargetPoint(kTargetPoint);
835   fVP.SetViewpointDirection(viewpointDirection);
836   fVP.SetUpVector(upVector);
837   fVP.SetDensityCulling(true);
838   fpViewer->SetViewParameters(fVP);
839
840   if (IsValidView())
841   {
842     fpSceneHandler->SetScene(fpScene);
843     fpSceneHandler->SetCurrentViewer(fpViewer);
844     fpViewer->DrawView();
845     fpViewer->ShowView();
846   }
847   else TG4Globals::Warning(
848          "TG4VisManager::Gdraw: Ignored - Failed to register volume"); 
849 }
850 #endif //G4VIS_USE