CMS 3D CMS Logo

Functions

CMSSW_4_4_3_patch1/src/Fireworks/Core/src/vis_macros.cc File Reference

#include <list>
#include <cmath>
#include <TEveElement.h>
#include <TEveGeoNode.h>
#include <TGeoNode.h>
#include "vis_macros.h"

Go to the source code of this file.

Functions

void expand_node (TEveElement *element)
const char * get_name (const TEveElement *element)
TGeoShape * get_shape (TEveElement *element)
const TGeoShape * get_shape (const TEveElement *element)
void hide_tracker_endcap (TEveElement *tracker)
bool is_leaf_node (const TEveElement *element)
void set_children_visibility (TEveElement *element, const std::string &node_name, const std::vector< std::string > &children_name, bool visibility)
void set_color (TEveElement *element, Color_t color, float alpha, unsigned int levels)
void set_tracker_endcap_visibility (TEveElement *tracker, bool visibility)
void show_tracker_endcap (TEveElement *tracker)

Function Documentation

void expand_node ( TEveElement *  element)

Definition at line 26 of file vis_macros.cc.

Referenced by node_filter(), and set_color().

{
   // force a TEveGeoNode to load all its children
   if (TEveGeoNode * node = dynamic_cast<TEveGeoNode *>( element )) {
      if (node->NumChildren() == 0 && node->GetNode()->GetVolume()->GetNdaughters() > 0) {
         TIter next(node->GetNode()->GetVolume()->GetNodes());
         TGeoNode* dnode;
         while ((dnode = (TGeoNode*) next()) != 0) {
            TEveGeoNode* node_re = new TEveGeoNode(dnode);
            node->AddElement(node_re);
         }
      }
      return;
   }
   // a TEveGeoShape is always exanded
   //if (TEveGeoShape * shape __attribute__ ((unused)) = dynamic_cast<TEveGeoShape *>( element )) {
   //  return;
   //}
   // a generic TEveElement has no knwledge on children expansion
   return;
}
const char* get_name ( const TEveElement *  element)

Definition at line 11 of file vis_macros.cc.

Referenced by apply_filter(), clone(), get_root_object(), and set_children_visibility().

                                                    {
   // try as a TEveGeoNode or TEveGeoShape
   if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element ))
      return node->GetName();
   if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element ))
      return shape->GetName();

   // try to access the element as a named thingy
   if (const TNamed * named = dynamic_cast<const TNamed *>( element ))
      return named->GetName();

   return 0;
}
TGeoShape* get_shape ( TEveElement *  element)

Definition at line 64 of file vis_macros.cc.

                                               {
   // a TEveGeoNode cannot modify its shape
   //if (const TEveGeoNode * node __attribute__ ((unused)) = dynamic_cast<const TEveGeoNode *>( element )) {
   //  return 0;
   //}
   // a TEveGeoShape owns its shape, and can modifiy it
   if (TEveGeoShape * shape = dynamic_cast<TEveGeoShape *>( element )) {
      return shape->GetShape();
   }
   // a TEveElement is too generic, no way to get a shape
   return 0;
}
const TGeoShape* get_shape ( const TEveElement *  element)

Definition at line 49 of file vis_macros.cc.

Referenced by clone().

                                                           {
   // a TEveGeoNode, can look into its TGeoNode and retrieve the shape
   if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element )) {
      return node->GetNode()->GetVolume()->GetShape();
   }
   // a TEveGeoShape owns its shape
   if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element )) {
      TEveGeoShape * nc_shape = const_cast<TEveGeoShape *>( shape );
      return const_cast<const TGeoShape *>( nc_shape->GetShape() );
   }
   // a TEveElement is too generic, no way to get a shape
   return 0;
}
void hide_tracker_endcap ( TEveElement *  tracker)

Definition at line 167 of file vis_macros.cc.

bool is_leaf_node ( const TEveElement *  element)

Definition at line 100 of file vis_macros.cc.

Referenced by set_children_visibility().

{
   // a TEveGeoNode can have unaccounted-for children
   if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element )) {
      return ((node->NumChildren() == 0) and (node->GetNode()->GetVolume()->GetNdaughters() == 0));
   }
   // a TEveGeoShape always knows its children
   if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element )) {
      return (shape->NumChildren() == 0);
   }
   // default implementation
   return (element->NumChildren() == 0);
}
void set_children_visibility ( TEveElement *  element,
const std::string &  node_name,
const std::vector< std::string > &  children_name,
bool  visibility 
)

Definition at line 116 of file vis_macros.cc.

Referenced by set_tracker_endcap_visibility().

{
   // try to access the element as a named thingy
   const char * name = get_name( element );
   if (not name or strncmp(name, node_name.c_str(), node_name.size()))
      // unnamed node, or wrong node
      return;

   for (std::list<TEveElement *>::iterator j = element->BeginChildren(); j != element->EndChildren(); ++j) {
      TEveElement * child = *j;
      name = get_name( child );
      if (not name)
         // unnamed node, ignore it
         continue;

      for (unsigned int i = 0; i < children_name.size(); ++i)
         if (not strncmp(name, children_name[i].c_str(), children_name[i].size())) {
            // change this child visibility
            if (is_leaf_node( child )) {
               child->SetRnrSelf( visibility );
               child->SetRnrChildren( false );
            } else {
               child->SetRnrSelf( false );
               child->SetRnrChildren( visibility );
            }
            break;
         }
   }
   // notify the element that is had changed
   element->ElementChanged(true, true);
}
void set_color ( TEveElement *  element,
Color_t  color,
float  alpha,
unsigned int  levels 
)

Definition at line 77 of file vis_macros.cc.

Referenced by set_color().

{
   if (not element)
      return;

   // set this node's color
   element->SetMainColor( color );
   if (alpha > 1.) alpha = 1.;
   if (alpha < 0.) alpha = 0.;
   unsigned char transparency = (unsigned char) roundf(100. - (alpha * 100.));
   element->SetMainTransparency( transparency );

   if (levels > 0) {
      // set the node's children's color
      expand_node( element );
      for (std::list<TEveElement*>::iterator i = element->BeginChildren(); i != element->EndChildren(); ++i)
         set_color( *i, color, alpha, levels - 1);
   }
   // notify the element that it has changed
   element->ElementChanged(true, true);
}
void set_tracker_endcap_visibility ( TEveElement *  tracker,
bool  visibility 
)

Definition at line 149 of file vis_macros.cc.

Referenced by hide_tracker_endcap(), and show_tracker_endcap().

{
   std::vector<std::string> endcap;
   endcap.push_back("tec:TEC");
   endcap.push_back("tidf:TIDF");
   endcap.push_back("tidb:TIDB");
   endcap.push_back("pixfwd:PixelForwardZPlus");
   endcap.push_back("pixfwd:PixelForwardZMinus");
   set_children_visibility( tracker, "tracker:Tracker", endcap, visibility );
}
void show_tracker_endcap ( TEveElement *  tracker)

Definition at line 161 of file vis_macros.cc.