Go to the documentation of this file.00001 #include <list>
00002 #include <cmath>
00003
00004 #include <TEveElement.h>
00005 #include <TEveGeoNode.h>
00006 #include <TGeoNode.h>
00007
00008 #include "vis_macros.h"
00009
00010
00011 const char* get_name( const TEveElement * element ) {
00012
00013 if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element ))
00014 return node->GetName();
00015 if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element ))
00016 return shape->GetName();
00017
00018
00019 if (const TNamed * named = dynamic_cast<const TNamed *>( element ))
00020 return named->GetName();
00021
00022 return 0;
00023 }
00024
00025
00026 void expand_node( TEveElement * element )
00027 {
00028
00029 if (TEveGeoNode * node = dynamic_cast<TEveGeoNode *>( element )) {
00030 if (node->NumChildren() == 0 && node->GetNode()->GetVolume()->GetNdaughters() > 0) {
00031 TIter next(node->GetNode()->GetVolume()->GetNodes());
00032 TGeoNode* dnode;
00033 while ((dnode = (TGeoNode*) next()) != 0) {
00034 TEveGeoNode* node_re = new TEveGeoNode(dnode);
00035 node->AddElement(node_re);
00036 }
00037 }
00038 return;
00039 }
00040
00041
00042
00043
00044
00045 return;
00046 }
00047
00048
00049 const TGeoShape * get_shape( const TEveElement * element ) {
00050
00051 if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element )) {
00052 return node->GetNode()->GetVolume()->GetShape();
00053 }
00054
00055 if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element )) {
00056 TEveGeoShape * nc_shape = const_cast<TEveGeoShape *>( shape );
00057 return const_cast<const TGeoShape *>( nc_shape->GetShape() );
00058 }
00059
00060 return 0;
00061 }
00062
00063
00064 TGeoShape * get_shape( TEveElement * element ) {
00065
00066
00067
00068
00069
00070 if (TEveGeoShape * shape = dynamic_cast<TEveGeoShape *>( element )) {
00071 return shape->GetShape();
00072 }
00073
00074 return 0;
00075 }
00076
00077 void set_color( TEveElement * element, Color_t color, float alpha, unsigned int levels )
00078 {
00079 if (not element)
00080 return;
00081
00082
00083 element->SetMainColor( color );
00084 if (alpha > 1.) alpha = 1.;
00085 if (alpha < 0.) alpha = 0.;
00086 unsigned char transparency = (unsigned char) roundf(100. - (alpha * 100.));
00087 element->SetMainTransparency( transparency );
00088
00089 if (levels > 0) {
00090
00091 expand_node( element );
00092 for (std::list<TEveElement*>::iterator i = element->BeginChildren(); i != element->EndChildren(); ++i)
00093 set_color( *i, color, alpha, levels - 1);
00094 }
00095
00096 element->ElementChanged(true, true);
00097 }
00098
00099
00100 bool is_leaf_node( const TEveElement * element )
00101 {
00102
00103 if (const TEveGeoNode * node = dynamic_cast<const TEveGeoNode *>( element )) {
00104 return ((node->NumChildren() == 0) and (node->GetNode()->GetVolume()->GetNdaughters() == 0));
00105 }
00106
00107 if (const TEveGeoShape * shape = dynamic_cast<const TEveGeoShape *>( element )) {
00108 return (shape->NumChildren() == 0);
00109 }
00110
00111 return (element->NumChildren() == 0);
00112 }
00113
00114
00115
00116 void set_children_visibility( TEveElement * element, const std::string & node_name, const std::vector<std::string> & children_name, bool visibility )
00117 {
00118
00119 const char * name = get_name( element );
00120 if (not name or strncmp(name, node_name.c_str(), node_name.size()))
00121
00122 return;
00123
00124 for (std::list<TEveElement *>::iterator j = element->BeginChildren(); j != element->EndChildren(); ++j) {
00125 TEveElement * child = *j;
00126 name = get_name( child );
00127 if (not name)
00128
00129 continue;
00130
00131 for (unsigned int i = 0; i < children_name.size(); ++i)
00132 if (not strncmp(name, children_name[i].c_str(), children_name[i].size())) {
00133
00134 if (is_leaf_node( child )) {
00135 child->SetRnrSelf( visibility );
00136 child->SetRnrChildren( false );
00137 } else {
00138 child->SetRnrSelf( false );
00139 child->SetRnrChildren( visibility );
00140 }
00141 break;
00142 }
00143 }
00144
00145 element->ElementChanged(true, true);
00146 }
00147
00148
00149 void set_tracker_endcap_visibility( TEveElement * tracker, bool visibility )
00150 {
00151 std::vector<std::string> endcap;
00152 endcap.push_back("tec:TEC");
00153 endcap.push_back("tidf:TIDF");
00154 endcap.push_back("tidb:TIDB");
00155 endcap.push_back("pixfwd:PixelForwardZPlus");
00156 endcap.push_back("pixfwd:PixelForwardZMinus");
00157 set_children_visibility( tracker, "tracker:Tracker", endcap, visibility );
00158 }
00159
00160
00161 void show_tracker_endcap( TEveElement * tracker )
00162 {
00163 set_tracker_endcap_visibility( tracker, true );
00164 }
00165
00166
00167 void hide_tracker_endcap( TEveElement * tracker )
00168 {
00169 set_tracker_endcap_visibility( tracker, false );
00170 }
00171