CMS 3D CMS Logo

VisG4VolumeTwig.cc

Go to the documentation of this file.
00001 //<<<<<< INCLUDES                                                       >>>>>>
00002 
00003 #include "VisGeant4/VisG4Volumes/interface/VisG4VolumeTwig.h"
00004 #include "VisGeant4/VisG4Volumes/interface/VisG4Navigator.h"
00005 #include "VisGeant4/VisG4Volumes/interface/VisG4VolumePicker.h"
00006 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialFilter.h"
00007 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialCacheFilter.h"
00008 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialMiscFilter.h"
00009 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialDensityFilter.h"
00010 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialFalseColorFilter.h"
00011 #include "VisGeant4/VisG4Volumes/interface/VisG4Filter.h"
00012 #include "VisGeant4/VisG4Volumes/interface/VisG4FilterCache.h"
00013 #include "VisGeant4/VisG4Volumes/interface/VisG4MaterialNameFilter.h"
00014 #include "VisGeant4/VisG4Volumes/interface/xtypeinfo.h"
00015 #include "VisGeant4/VisG4Core/interface/VisG4Path.h"
00016 #include "VisGeant4/VisG4Core/interface/VisG4VisSceneHandler.h"
00017 #include "Iguana/GLModels/interface/IgCommon3DReps.h"
00018 #include "Iguana/GLModels/interface/Ig3DModel.h"
00019 #include "Iguana/GLModels/interface/Ig3DRep.h"
00020 #include "Iguana/GLModels/interface/IgRPhiModel.h"
00021 #include "Iguana/GLModels/interface/IgRPhiRep.h"
00022 #include "Iguana/GLModels/interface/IgRZModel.h"
00023 #include "Iguana/GLModels/interface/IgRZRep.h"
00024 #include "Iguana/GLModels/interface/xtypeinfo.h"
00025 #include "Iguana/Models/interface/IgTextModel.h"
00026 #include "Iguana/Models/interface/IgSimpleTextRep.h"
00027 #include "Iguana/Models/interface/xtypeinfo.h"
00028 #include "Iguana/Framework/interface/IgRepContext.h"
00029 #include "Iguana/Framework/interface/IgRepSet.h"
00030 #include "Iguana/Framework/interface/IgBrowserMethods.h"
00031 #include "Iguana/Framework/interface/xtypeinfo.h"
00032 #include <classlib/utils/DebugAids.h>
00033 #include <classlib/utils/Log.h>
00034 
00035 #include <Inventor/nodes/SoMaterial.h>
00036 
00037 #include <G4ModelingParameters.hh>
00038 #include <G4VPhysicalVolume.hh>
00039 #include <G4LogicalVolume.hh>
00040 #include <G4VisAttributes.hh>
00041 #include <G4Material.hh>
00042 #include <G4VSensitiveDetector.hh>
00043 #include <G4VSolid.hh>
00044 #include <G4Box.hh>
00045 #include <G4Cons.hh>
00046 #include <G4Polycone.hh>
00047 #include <G4Polyhedra.hh>
00048 #include <G4Torus.hh>
00049 #include <G4Trap.hh>
00050 #include <G4Trd.hh>
00051 #include <G4Tubs.hh>
00052 
00053 #include <sstream>
00054 
00055 //<<<<<< PRIVATE DEFINES                                                >>>>>>
00056 //<<<<<< PRIVATE CONSTANTS                                              >>>>>>
00057 //<<<<<< PRIVATE TYPES                                                  >>>>>>
00058 //<<<<<< PRIVATE VARIABLE DEFINITIONS                                   >>>>>>
00059 
00060 extern lat::logflag LFG4vis;
00061 
00062 //<<<<<< PUBLIC VARIABLE DEFINITIONS                                    >>>>>>
00063 //<<<<<< CLASS STRUCTURE INITIALIZATION                                 >>>>>>
00064 //<<<<<< PRIVATE FUNCTION DEFINITIONS                                   >>>>>>
00065 //<<<<<< PUBLIC FUNCTION DEFINITIONS                                    >>>>>>
00066 //<<<<<< MEMBER FUNCTION DEFINITIONS                                    >>>>>>
00067 
00068 VisG4VolumeTwig::VisG4VolumeTwig (IgTwig          *parent,
00069                                 G4VPhysicalVolume *volume,
00070                                 bool              traverse /* = false */,
00071                                 bool              visible /* = false */,
00072                                 bool              open /* = false */,
00073                                 bool              logic /* = true */)
00074     : IgCompoundTwig (parent),
00075       m_volume (volume)
00076 {
00077     ASSERT (parent);
00078     ASSERT (m_volume);
00079     
00080     selfTraverse (traverse);
00081     selfVisible (visible);
00082     cascade (open);
00083     logical (logic);
00084     if (m_materialFilter == 0)
00085     {
00086         m_materialFilter = new VisG4MaterialCacheFilter (true);
00087         VisG4MaterialFilter *currentFilter = m_materialFilter;
00088 
00089         VisG4MaterialFilter *tmpFilter;
00090         
00091         if (! getenv ("DISABLE_LUT_FILTER"))
00092         {
00093             tmpFilter = new VisG4MaterialLUTFilter (true);         
00094             currentFilter->appendFilter (tmpFilter);
00095             currentFilter = tmpFilter;
00096         }
00097         
00098         if (getenv ("ENABLE_DENSITY_FILTER"))
00099         {
00100             tmpFilter = new VisG4MaterialDensityFilter (true);
00101             currentFilter->appendFilter (tmpFilter);
00102             currentFilter = tmpFilter;
00103         }
00104         
00105         if (getenv ("ENABLE_FALSE_COLOR_FILTER"))
00106         {
00107             tmpFilter = new VisG4MaterialFalseColorFilter (true);
00108             currentFilter->appendFilter (tmpFilter);
00109             currentFilter = tmpFilter;
00110         }
00111     } 
00112 }
00113 
00114 VisG4MaterialFilter *VisG4VolumeTwig::m_materialFilter = 0;
00115 VisG4Filter *VisG4VolumeTwig::m_visualizationFilter = 0;
00116 
00117 std::string
00118 VisG4VolumeTwig::name (void) const
00119 { return m_volume->GetLogicalVolume ()->GetName (); }
00120 
00121 void
00122 VisG4VolumeTwig::name (const std::string &)
00123 { ASSERT (false); }
00124 
00125 bool
00126 VisG4VolumeTwig::expand (void)
00127 {
00128     if (IgCompoundTwig::expand ())
00129         return true;
00130 
00131     VisG4Navigator::build (1, m_volume, this);
00132     return false;
00133 }
00134 
00135 #if 0
00136 VisG4Path
00137 VisG4VolumeTwig::path (void) const
00138 {
00139     if (const IgTwig *p = parent ())
00140         return VisG4Path (p->path (), p->indexOf (this), 0);
00141     else
00142         return VisG4Path ();
00143 }
00144 #endif
00145 
00146 VisG4VolumeTwig *
00147 VisG4VolumeTwig::select (const VisG4Path &path, bool autoexpand /* = false */)
00148 {
00149     if (path.empty ())
00150         return this;
00151 
00152     VisG4VolumeTwig *c = select (path.prefix (), autoexpand);
00153 
00154     if (! c->children () && autoexpand)
00155         c->expand ();
00156 
00157     unsigned n = path.daughter ();
00158     if (n < c->children ())
00159     {
00160         IgTwig          *sub = c->child (n);
00161         VisG4VolumeTwig *subvol = static_cast<VisG4VolumeTwig *> (sub);
00162         ASSERT (dynamic_cast<VisG4VolumeTwig *> (sub));
00163         return subvol;
00164     }
00165     else
00166         return 0;
00167 }
00168 
00169 G4VPhysicalVolume *
00170 VisG4VolumeTwig::volume (void) const
00171 { return m_volume; }
00172 
00173 bool
00174 VisG4VolumeTwig::selfTraverse (void) const
00175 { return flag (TRAVERSE); }
00176 
00177 void
00178 VisG4VolumeTwig::selfTraverse (bool value)
00179 { flag (TRAVERSE, value); }
00180 
00181 bool
00182 VisG4VolumeTwig::selfVisible (void) const
00183 { return flag (VISIBLE); }
00184 
00185 void
00186 VisG4VolumeTwig::selfVisible (bool value)
00187 { flag (VISIBLE, value); }
00188 
00189 bool
00190 VisG4VolumeTwig::cascade (void) const
00191 { return flag (CASCADE); }
00192 
00193 void
00194 VisG4VolumeTwig::cascade (bool value)
00195 { flag (CASCADE, value); }
00196 
00197 // FIXME: Do these inherit?
00198 bool
00199 VisG4VolumeTwig::logical (void) const
00200 { return flag (LOGICAL); }
00201 
00202 void
00203 VisG4VolumeTwig::logical (bool value)
00204 {
00205     if (flag (LOGICAL) != value)
00206     {
00207         // Flip representation
00208         destroy ();
00209         flag (LOGICAL, value);
00210         flag (EXPANDED, false);
00211     }
00212 }
00213 
00215 unsigned
00216 VisG4VolumeTwig::physicalChildren (void)
00217 {
00218     if (! logical ())
00219         return children ();
00220     else if (flag (EXPANDED))
00221         return m_volume->GetLogicalVolume ()->GetNoDaughters ();
00222     else
00223         return 0;
00224 }
00225 
00226 IgTwig *
00227 VisG4VolumeTwig::physicalChild (unsigned index)
00228 { return child (logical () ? VisG4Navigator::findLogical (m_volume, index)
00229                 : index); }
00230 
00232 unsigned
00233 VisG4VolumeTwig::paths (void)
00234 {
00235     if (m_paths.empty ())
00236     {
00237         // We haven't yet computed the paths.  Do so now.
00238         if (VisG4VolumeTwig *p = dynamic_cast<VisG4VolumeTwig *> (parent ()))
00239         {
00240             // Parent is a volume twig.  Expand on paths assigned to it.
00241             G4VPhysicalVolume   *pvol = p->volume ();
00242             int                 nreps = 1;
00243 
00244             if (m_volume->IsReplicated ())
00245             {
00246                 EAxis    axis;
00247                 G4double width, offset;
00248                 G4bool   consuming;
00249                 m_volume->GetReplicationData (axis, nreps, width,
00250                                               offset, consuming);
00251             }
00252 
00253             if (p->logical ())
00254                 // Logical.  Push all subpaths with equal physical
00255                 // volume, using G4 daughter volume index (each
00256                 // replica).
00257                 for (unsigned i = 0; i < p->paths (); ++i)
00258                 {
00259                     VisG4Path           prefix = p->path (i);
00260                     G4LogicalVolume     *mother = pvol->GetLogicalVolume ();
00261                     G4LogicalVolume     *me = m_volume->GetLogicalVolume ();
00262 
00263                     for (int i = 0; i < mother->GetNoDaughters (); ++i)
00264                         if (mother->GetDaughter (i)->GetLogicalVolume () == me)
00265                             for (int j = 0; j < nreps; ++j)
00266                                 m_paths.push_back (VisG4Path (prefix, i, j));
00267                 }
00268 
00269             else
00270                 // Physical.  Push index of the G4 daughter volume
00271                 // (each replica).
00272                 for (unsigned i = 0, me = p->indexOf(this); i < p->paths();++i)
00273                     for (int j = 0; j < nreps; ++j)
00274                         m_paths.push_back (VisG4Path (p->path (i), me, j));
00275         }
00276         else
00277             m_paths.push_back (VisG4Path ());
00278     }
00279 
00280     // OK, now return the number of paths we have
00281     return m_paths.size ();
00282 }
00283 
00284 VisG4Path
00285 VisG4VolumeTwig::path (unsigned index)
00286 {
00287     ASSERT (m_paths.size () > index);
00288     return m_paths [index];
00289 }
00290 
00294 void
00295 drawSolidParts (VisG4VisSceneHandler *handler, G4VSolid *solid, int depth = 0)
00296 {
00297     G4VSolid *b0, *b1;
00298 
00299     if ((b0 = solid->GetConstituentSolid (0)))
00300     {
00301         VERIFY (b1 = solid->GetConstituentSolid (1));
00302         drawSolidParts (handler, b0, depth+1);
00303         drawSolidParts (handler, b1, depth+1);
00304     }
00305 
00306     if (depth > 0)
00307         solid->DescribeYourselfTo (*handler);
00308 }
00309 
00310 void
00311 drawVolumeTwig (VisG4VolumeTwig *twig, Ig3DRep *rep)
00312 {
00313 
00314     // Process each path assigned to the twig.  We create exactly one
00315     // SoSeparator for each path so it is easy to correlate the two
00316     // later on.  Note that the volume has a separate path for each
00317     // replica associated with it, not just path for every physical
00318     // volume copy.
00319 
00320     // Render the twig.  We create a temporary volume model and render
00321     // that to our special scene handler.  FIXME: Check that G4 thread
00322     // is available!  NB: This is executed in the GUI thread.
00323 
00324     // Zap any existing representations
00325     rep->clear ();
00326 
00327     // Dig out some common variables.
00328     VisG4VolumeTwig     *root = twig;
00329     while (VisG4VolumeTwig *x = dynamic_cast<VisG4VolumeTwig *> (root->parent()))
00330         root = x;
00331 
00332     VisG4VisSceneHandler        *handler = VisG4VisSceneHandler::instance ();
00333     G4VPhysicalVolume   *volume = root->volume ();
00334 
00335     ASSERT (handler);
00336     ASSERT (volume);
00337     ASSERT (root);
00338 
00339     // FIXME: This isn't really true -- there could be something else
00340     // in the view volume beyond the volumes.  At the moment we need
00341     // this only for G4Scale and markers, neither of which are likely
00342     // to be used, so this isn't a catastrophy.  Need to rethink this
00343     // part entirely.  (FIXME: Move to geometry update?)
00344     handler->defineBounds (volume->GetLogicalVolume ()
00345                            ->GetSolid ()->GetExtent ());
00346 
00347     for (unsigned i = 0; i < twig->paths (); ++i)
00348     {
00349         bool                    replica = false;
00350         G4VPhysicalVolume       *pv = volume;
00351         G4LogicalVolume         *lv = 0;
00352         G4VSolid                *solid = 0;
00353         G4Transform3D           pos;
00354 
00355         VisG4VolumePicker::apply (twig->path (i), pv, lv, solid, pos, replica);
00356 
00357         ASSERT (solid);
00358         ASSERT (pv);
00359         ASSERT (lv);
00360 
00361         // Create a VisSoMaterialDetails structure which describes the current twig
00362         VisSoMaterialDetails details;
00363         details << VisG4MaterialDetails (lv->GetMaterial ());
00364         details << VisG4PVDetails (pv);
00365         details << VisG4PathDetails (twig->fullName ());        
00366 
00367         // Skip if the filter rejects
00368         if (VisG4VolumeTwig::m_visualizationFilter
00369             && ! VisG4VolumeTwig::m_visualizationFilter->compute (details))
00370             continue;
00371 
00372         SoSeparator *sep = new SoSeparator;
00373         rep->node ()->addChild (sep);
00374 
00375         // Set object context.
00376         handler->beginObject (sep, replica ? 0 : pv);
00377 
00378         // Add transformation for this object.
00379         handler->addTransform (pos);
00380 
00381         // To show boolean constituents in white wireframe:
00382         //   handler->AddStyle (G4ViewParameters::wireframe);
00383         //   handler->AddMaterial (G4Colour (1., 1., 1., 1.));
00384         //   drawSolidParts (handler, solid);
00385     
00386         // Add colour and styles.  (FIXME: Move to and use a real
00387         // visualisation preferences service, and make it cache
00388         // materials and other style information as much as possible
00389         // -- switching materials is very bad for render performance,
00390         // and what's worse, we tend to reuse the same material lot.)
00391         handler->addStyle (lv->GetVisAttributes ());
00392 
00393         // Get the G4 material and check if there is a SoMaterial already in the cache. 
00394         handler->addMaterial (VisG4VolumeTwig::m_materialFilter->getSoMaterial (details, 0));   
00395 
00396         // Draw the solid itself.
00397         solid->DescribeYourselfTo (*handler);
00398         
00399         // Quit object context.
00400         handler->endObject ();
00401     }
00402 }
00403 
00404 void
00405 drawVolumeTwig (VisG4VolumeTwig *twig, IgRPhiRep *rep)
00406 {
00407 
00408     // Process each path assigned to the twig.  We create exactly one
00409     // SoSeparator for each path so it is easy to correlate the two
00410     // later on.  Note that the volume has a separate path for each
00411     // replica associated with it, not just path for every physical
00412     // volume copy.
00413 
00414     // Render the twig.  We create a temporary volume model and render
00415     // that to our special scene handler.  FIXME: Check that G4 thread
00416     // is available!  NB: This is executed in the GUI thread.
00417 
00418     // Zap any existing representations
00419     rep->clear ();
00420 
00421     // Dig out some common variables.
00422     VisG4VolumeTwig     *root = twig;
00423     while (VisG4VolumeTwig *x = dynamic_cast<VisG4VolumeTwig *> (root->parent()))
00424         root = x;
00425 
00426     VisG4VisSceneHandler        *handler = VisG4VisSceneHandler::instance ();
00427     G4VPhysicalVolume   *volume = root->volume ();
00428 
00429     ASSERT (handler);
00430     ASSERT (volume);
00431     ASSERT (root);
00432 
00433     // FIXME: This isn't really true -- there could be something else
00434     // in the view volume beyond the volumes.  At the moment we need
00435     // this only for G4Scale and markers, neither of which are likely
00436     // to be used, so this isn't a catastrophy.  Need to rethink this
00437     // part entirely.  (FIXME: Move to geometry update?)
00438     handler->defineBounds (volume->GetLogicalVolume ()
00439                            ->GetSolid ()->GetExtent ());
00440 
00441     for (unsigned i = 0; i < twig->paths (); ++i)
00442     {
00443         bool                    replica = false;
00444         G4VPhysicalVolume       *pv = volume;
00445         G4LogicalVolume         *lv = 0;
00446         G4VSolid                *solid = 0;
00447         G4Transform3D           pos;
00448 
00449         VisG4VolumePicker::apply (twig->path (i), pv, lv, solid, pos, replica);
00450 
00451         ASSERT (solid);
00452         ASSERT (pv);
00453         ASSERT (lv);
00454 
00455         // Create a VisSoMaterialDetails structure which describes the current twig
00456         VisSoMaterialDetails details;
00457         details << VisG4MaterialDetails (lv->GetMaterial ());
00458         details << VisG4PVDetails (pv);
00459         details << VisG4PathDetails (twig->fullName ());        
00460 
00461         // Skip if the filter rejects
00462         if (VisG4VolumeTwig::m_visualizationFilter
00463             && ! VisG4VolumeTwig::m_visualizationFilter->compute (details))
00464             continue;
00465 
00466         SoSeparator *sep = new SoSeparator;
00467         rep->node ()->addChild (sep);
00468 
00469         // Set object context.
00470         handler->beginObject (sep, replica ? 0 : pv);
00471 
00472         // Add transformation for this object.
00473         handler->addTransform (pos);
00474 
00475         // To show boolean constituents in white wireframe:
00476         //   handler->AddStyle (G4ViewParameters::wireframe);
00477         //   handler->AddMaterial (G4Colour (1., 1., 1., 1.));
00478         //   drawSolidParts (handler, solid);
00479     
00480         // Add colour and styles.  (FIXME: Move to and use a real
00481         // visualisation preferences service, and make it cache
00482         // materials and other style information as much as possible
00483         // -- switching materials is very bad for render performance,
00484         // and what's worse, we tend to reuse the same material lot.)
00485         handler->addStyle (lv->GetVisAttributes ());
00486 
00487         // Get the G4 material and check if there is a SoMaterial already in the cache. 
00488         handler->addMaterial (VisG4VolumeTwig::m_materialFilter->getSoMaterial (details, 0));   
00489 
00490         // Draw the solid itself.
00491         solid->DescribeYourselfTo (*handler);
00492         
00493         // Quit object context.
00494         handler->endObject ();
00495     }
00496 }
00497 
00498 void
00499 drawVolumeTwig (VisG4VolumeTwig *twig, IgRZRep *rep)
00500 {
00501 
00502     // Process each path assigned to the twig.  We create exactly one
00503     // SoSeparator for each path so it is easy to correlate the two
00504     // later on.  Note that the volume has a separate path for each
00505     // replica associated with it, not just path for every physical
00506     // volume copy.
00507 
00508     // Render the twig.  We create a temporary volume model and render
00509     // that to our special scene handler.  FIXME: Check that G4 thread
00510     // is available!  NB: This is executed in the GUI thread.
00511 
00512     // Zap any existing representations
00513     rep->clear ();
00514 
00515     // Dig out some common variables.
00516     VisG4VolumeTwig     *root = twig;
00517     while (VisG4VolumeTwig *x = dynamic_cast<VisG4VolumeTwig *> (root->parent()))
00518         root = x;
00519 
00520     VisG4VisSceneHandler        *handler = VisG4VisSceneHandler::instance ();
00521     G4VPhysicalVolume   *volume = root->volume ();
00522 
00523     ASSERT (handler);
00524     ASSERT (volume);
00525     ASSERT (root);
00526 
00527     // FIXME: This isn't really true -- there could be something else
00528     // in the view volume beyond the volumes.  At the moment we need
00529     // this only for G4Scale and markers, neither of which are likely
00530     // to be used, so this isn't a catastrophy.  Need to rethink this
00531     // part entirely.  (FIXME: Move to geometry update?)
00532     handler->defineBounds (volume->GetLogicalVolume ()
00533                            ->GetSolid ()->GetExtent ());
00534 
00535     for (unsigned i = 0; i < twig->paths (); ++i)
00536     {
00537         bool                    replica = false;
00538         G4VPhysicalVolume       *pv = volume;
00539         G4LogicalVolume         *lv = 0;
00540         G4VSolid                *solid = 0;
00541         G4Transform3D           pos;
00542 
00543         VisG4VolumePicker::apply (twig->path (i), pv, lv, solid, pos, replica);
00544 
00545         ASSERT (solid);
00546         ASSERT (pv);
00547         ASSERT (lv);
00548 
00549         // Create a VisSoMaterialDetails structure which describes the current twig
00550         VisSoMaterialDetails details;
00551         details << VisG4MaterialDetails (lv->GetMaterial ());
00552         details << VisG4PVDetails (pv);
00553         details << VisG4PathDetails (twig->fullName ());        
00554 
00555         // Skip if the filter rejects
00556         if (VisG4VolumeTwig::m_visualizationFilter
00557             && ! VisG4VolumeTwig::m_visualizationFilter->compute (details))
00558             continue;
00559 
00560         SoSeparator *sep = new SoSeparator;
00561         rep->node ()->addChild (sep);
00562 
00563         // Set object context.
00564         handler->beginObject (sep, replica ? 0 : pv);
00565 
00566         // Add transformation for this object.
00567         handler->addTransform (pos);
00568 
00569         // To show boolean constituents in white wireframe:
00570         //   handler->AddStyle (G4ViewParameters::wireframe);
00571         //   handler->AddMaterial (G4Colour (1., 1., 1., 1.));
00572         //   drawSolidParts (handler, solid);
00573     
00574         // Add colour and styles.  (FIXME: Move to and use a real
00575         // visualisation preferences service, and make it cache
00576         // materials and other style information as much as possible
00577         // -- switching materials is very bad for render performance,
00578         // and what's worse, we tend to reuse the same material lot.)
00579         handler->addStyle (lv->GetVisAttributes ());
00580 
00581         // Get the G4 material and check if there is a SoMaterial already in the cache. 
00582         handler->addMaterial (VisG4VolumeTwig::m_materialFilter->getSoMaterial (details, 0));   
00583 
00584         // Draw the solid itself.
00585         solid->DescribeYourselfTo (*handler);
00586         
00587         // Quit object context.
00588         handler->endObject ();
00589     }
00590 }
00591 
00592 MMM_DEFUN_FUNC(void,IgBrowserMethods::,doUpdate,
00593                (VisG4VolumeTwig *twig, Ig3DRep *rep, unsigned mask))
00594 {
00595     // Do most of the hard work in the base class implementation.
00596     mmm_doUpdate ((IgTwig *) twig, rep, mask);
00597 
00598     // Skip the update if possible.  We only render if the object is
00599     // visible, and either SELF_MASK is set (object was changed), or
00600     // if FLAGS_MASK is set and the rep has no content (either never
00601     // created or zapped).
00602     if (twig->visible () &&
00603         (((mask & IgTwig::FLAGS_MASK)
00604           && rep->node ()->getNumChildren () == 0)
00605          || (mask & IgTwig::SELF_MASK)))
00606         drawVolumeTwig (twig, rep);
00607 }
00608 
00609 MMM_DEFUN_FUNC(void,IgBrowserMethods::,doUpdate,
00610                (VisG4VolumeTwig *twig, IgRPhiRep *rep, unsigned mask))
00611 {
00612     // Do most of the hard work in the base class implementation.
00613     mmm_doUpdate ((IgTwig *) twig, rep, mask);
00614 
00615     // Skip the update if possible.  We only render if the object is
00616     // visible, and either SELF_MASK is set (object was changed), or
00617     // if FLAGS_MASK is set and the rep has no content (either never
00618     // created or zapped).
00619     if (twig->visible () &&
00620         (((mask & IgTwig::FLAGS_MASK)
00621           && rep->node ()->getNumChildren () == 0)
00622          || (mask & IgTwig::SELF_MASK)))
00623         drawVolumeTwig (twig, rep);
00624 }
00625 
00626 MMM_DEFUN_FUNC(void,IgBrowserMethods::,doUpdate,
00627                (VisG4VolumeTwig *twig, IgRZRep *rep, unsigned mask))
00628 {
00629     // Do most of the hard work in the base class implementation.
00630     mmm_doUpdate ((IgTwig *) twig, rep, mask);
00631 
00632     // Skip the update if possible.  We only render if the object is
00633     // visible, and either SELF_MASK is set (object was changed), or
00634     // if FLAGS_MASK is set and the rep has no content (either never
00635     // created or zapped).
00636     if (twig->visible () &&
00637         (((mask & IgTwig::FLAGS_MASK)
00638           && rep->node ()->getNumChildren () == 0)
00639          || (mask & IgTwig::SELF_MASK)))
00640         drawVolumeTwig (twig, rep);
00641 }
00642 
00643 MMM_DEFUN_FUNC(void,IgBrowserMethods::,doUpdate,
00644                (VisG4VolumeTwig *twig, IgTextRep *rep, unsigned))
00645 {
00646     // FIXME: HTML-quote text!
00647     // FIXME: Add physical volume information
00648     G4LogicalVolume     *lv = twig->volume ()->GetLogicalVolume ();
00649     G4VSolid            *solid = lv->GetSolid ();
00650     G4Material          *material = lv->GetMaterial ();
00651     G4RotationMatrix    *r = twig->volume ()->GetRotation ();
00652     G4ThreeVector       t = twig->volume ()->GetTranslation ();
00653 
00654     std::ostringstream text;
00655 
00656     text << "<table width='100%'><tr><td>Name</td><td>"
00657          << lv->GetName ()
00658          << "</td><tr><td>Copy #</td><td>"
00659          << twig->volume ()->GetCopyNo ()
00660          << "</td><tr><td>Replicated</td><td>"
00661          << (twig->volume ()->IsReplicated () ? "Yes" : "No")
00662         // FIXME: show parametrisation info
00663 
00664          << "</td><tr><td>Position</td><td>"
00665          << "(" << t.x () << ", " << t.y () << ", " << t.z () << ")"
00666          << "</td><tr><td>Rotation</td><td>";
00667 
00668     if (r)
00669         r->print (text);
00670     else
00671         text << "(None)";
00672 
00673     text << "</td><tr><td>Material</td><td>"
00674          << (material ? material->GetName () : G4String ("(None)"))
00675          << "</td></tr><tr><td>Density</td><td>"
00676          << (material ? material->GetDensity () / g*cm*cm*cm : 0.)
00677          << "</td></tr><tr><td>Sensitive</td><td>"
00678          << (lv->GetSensitiveDetector ()
00679              ? lv->GetSensitiveDetector ()->GetFullPathName ()
00680              : G4String ("(not sensitive)"))
00681          << "</td></tr><tr><td>Solid Type</td><td>"
00682          << solid->GetEntityType ()
00683          << "</td></tr><tr><td>Solid Name</td><td>"
00684          << solid->GetName ()
00685          << "</td></tr><tr><td>Solid Parameters</td><td>&nbsp;</td></tr>";
00686 
00687     // FIXME: This should be encapsulated, and use something like
00688     // Martin Liendl's SolidAnalyser or (why not?) a multimethod.
00689     if (G4Box *box = dynamic_cast<G4Box *> (solid))
00690         text << "<tr><td>&nbsp;&nbsp;x/2</td><td>"
00691              << box->GetXHalfLength () << "</td></tr>"
00692              << "<tr><td>&nbsp;&nbsp;y/2</td><td>"
00693              << box->GetYHalfLength () << "</td></tr>"
00694              << "<tr><td>&nbsp;&nbsp;z/2</td><td>"
00695              << box->GetZHalfLength () << "</td></tr>";
00696     else if (G4Cons *cons = dynamic_cast<G4Cons *> (solid))
00697         text << "<tr><td>&nbsp;&nbsp;z/2</td><td>"
00698              << cons->GetZHalfLength () << "</td></tr>"
00699              << "<tr><td>&nbsp;&nbsp;rInZ-</td><td>"
00700              << cons->GetInnerRadiusMinusZ () << "</td></tr>"
00701              << "<tr><td>&nbsp;&nbsp;rInZ+</td><td>"
00702              << cons->GetInnerRadiusPlusZ () << "</td></tr>"
00703              << "<tr><td>&nbsp;&nbsp;rOutZ-</td><td>"
00704              << cons->GetOuterRadiusMinusZ () << "</td></tr>"
00705              << "<tr><td>&nbsp;&nbsp;rOutZ+</td><td>"
00706              << cons->GetOuterRadiusPlusZ () << "</td></tr>"
00707              << "<tr><td>&nbsp;&nbsp;startPhi</td><td>"
00708              << cons->GetStartPhiAngle () << "</td></tr>"
00709              << "<tr><td>&nbsp;&nbsp;deltaPhi</td><td>"
00710              << cons->GetDeltaPhiAngle () << "</td></tr>";
00711     else if (G4Polycone *pcon = dynamic_cast<G4Polycone *> (solid))
00712     {
00713         int nr = pcon->GetNumRZCorner();   
00714         text << "<tr><td>&nbsp;&nbsp;startPhi</td><td>"
00715              << pcon->GetStartPhi () << "</td></tr>"
00716              << "<tr><td>&nbsp;&nbsp;endPhi</td><td>"
00717              << pcon->GetEndPhi () << "</td></tr>"
00718              << "<tr><td>&nbsp;&nbsp;nrRZ</td><td>"
00719              << nr << "</td></tr>";
00720 
00721         for (int i = 0; i < nr; ++i)
00722             text << "<tr><td>&nbsp;&nbsp;z" << i << "</td><td>"
00723                  << pcon->GetCorner (i).z << "</td></tr>"
00724                  << "<tr><td>&nbsp;&nbsp;r" << i << "</td><td>"
00725                  << pcon->GetCorner (i).r << "</td></tr>";
00726     }
00727     else if (G4Polyhedra *phed = dynamic_cast<G4Polyhedra *> (solid))
00728     {
00729         int nr = phed->GetNumRZCorner();   
00730         text << "<tr><td>&nbsp;&nbsp;startPhi</td><td>"
00731              << phed->GetStartPhi () << "</td></tr>"
00732              << "<tr><td>&nbsp;&nbsp;endPhi</td><td>"
00733              << phed->GetEndPhi () << "</td></tr>"
00734              << "<tr><td>&nbsp;&nbsp;sides</td><td>"
00735              << phed->GetNumSide () << "</td></tr>"
00736              << "<tr><td>&nbsp;&nbsp;nrRZ</td><td>"
00737              << nr << "</td></tr>";
00738 
00739         for (int i = 0; i < nr; ++i)
00740             text << "<tr><td>&nbsp;&nbsp;z" << i << "</td><td>"
00741                  << phed->GetCorner (i).z << "</td></tr>"
00742                  << "<tr><td>&nbsp;&nbsp;r" << i << "</td><td>"
00743                  << phed->GetCorner (i).r << "</td></tr>";
00744     }
00745     else if (G4Torus *torus = dynamic_cast<G4Torus *> (solid))
00746         text << "<tr><td>&nbsp;&nbsp;R min</td><td>"
00747              << torus->GetRmin () << "</td></tr>"
00748              << "<tr><td>&nbsp;&nbsp;R max</td><td>"
00749              << torus->GetRmax () << "</td></tr>"
00750              << "<tr><td>&nbsp;&nbsp;R tor</td><td>"
00751              << torus->GetRtor () << "</td></tr>"
00752              << "<tr><td>&nbsp;&nbsp;start Phi (radians)</td><td>"
00753              << torus->GetSPhi () << "</td></tr>"
00754              << "<tr><td>&nbsp;&nbsp;Delta angle of the segment (radians)</td><td>"
00755              << torus->GetDPhi () << "</td></tr>";
00756     else if (G4Trap *trap = dynamic_cast<G4Trap *> (solid))
00757         text << "<tr><td>&nbsp;&nbsp;z/2</td><td>"
00758              << trap->GetZHalfLength () << "</td></tr>"
00759              << "<tr><td>&nbsp;&nbsp;x1/2</td><td>"
00760              << trap->GetXHalfLength1 () << "</td></tr>"
00761              << "<tr><td>&nbsp;&nbsp;x2/2</td><td>"
00762              << trap->GetXHalfLength2 () << "</td></tr>"
00763              << "<tr><td>&nbsp;&nbsp;y1/2</td><td>"
00764              << trap->GetYHalfLength1 () << "</td></tr>"
00765              << "<tr><td>&nbsp;&nbsp;tanAlpha_1</td><td>"
00766              << trap->GetTanAlpha1 () << "</td></tr>"
00767              << "<tr><td>&nbsp;&nbsp;x3/2</td><td>"
00768              << trap->GetXHalfLength3 () << "</td></tr>"
00769              << "<tr><td>&nbsp;&nbsp;x4/2</td><td>"
00770              << trap->GetXHalfLength4 () << "</td></tr>"
00771              << "<tr><td>&nbsp;&nbsp;y2/2</td><td>"
00772              << trap->GetYHalfLength2 () << "</td></tr>"
00773              << "<tr><td>&nbsp;&nbsp;tanAlpha_2</td><td>"
00774              << trap->GetTanAlpha2 () << "</td></tr>";
00775     else if (G4Trd *trd = dynamic_cast<G4Trd *> (solid))
00776         text << "<tr><td>&nbsp;&nbsp;z/2</td><td>"
00777              << trd->GetZHalfLength () << "</td></tr>"
00778 
00779              << "<tr><td>&nbsp;&nbsp;x1/2</td><td>"
00780              << trd->GetXHalfLength1 () << "</td></tr>"
00781              << "<tr><td>&nbsp;&nbsp;x2/2</td><td>"
00782              << trd->GetXHalfLength2 () << "</td></tr>"
00783              << "<tr><td>&nbsp;&nbsp;y1/2</td><td>"
00784              << trd->GetYHalfLength1 () << "</td></tr>"
00785              << "<tr><td>&nbsp;&nbsp;y2/2</td><td>"
00786              << trd->GetYHalfLength2 () << "</td></tr>";
00787     else if (G4Tubs *tubs = dynamic_cast<G4Tubs *> (solid))
00788         text << "<tr><td>&nbsp;&nbsp;z/2</td><td>"
00789              << tubs->GetZHalfLength () << "</td></tr>"
00790              << "<tr><td>&nbsp;&nbsp;rIn</td><td>"
00791              << tubs->GetInnerRadius () << "</td></tr>"
00792              << "<tr><td>&nbsp;&nbsp;rOut</td><td>"
00793              << tubs->GetOuterRadius () << "</td></tr>"
00794              << "<tr><td>&nbsp;&nbsp;startPhi</td><td>"
00795              << tubs->GetStartPhiAngle () << "</td></tr>"
00796              << "<tr><td>&nbsp;&nbsp;deltaPhi</td><td>"
00797              << tubs->GetDeltaPhiAngle () << "</td></tr>";
00798     else
00799         text << "<tr><td>&nbsp;&nbsp;(not known)</td><td>&nbsp;</td></tr>";
00800 
00801     text << "</table>";
00802 
00803     rep->setText (text.str ());
00804 }

Generated on Tue Jun 9 17:50:07 2009 for CMSSW by  doxygen 1.5.4