#include "TEveGeoNode.h"
#include "TEveManager.h"
#include "TEvePolygonSetProjected.h"
#include "TEveGeoShapeExtract.h"
#include "TROOT.h"
#include "TPad.h"
#include "TBuffer3D.h"
#include "TVirtualViewer3D.h"
#include "TColor.h"
#include "TFile.h"
#include "TGeoShape.h"
#include "TGeoVolume.h"
#include "TGeoNode.h"
#include "TGeoShapeAssembly.h"
#include "TGeoManager.h"
#include "TGeoMatrix.h"
#include "TVirtualGeoPainter.h"
ClassImp(TEveGeoNode);
TEveGeoNode::TEveGeoNode(TGeoNode* node) :
TEveElement(),
TObject(),
fNode(node)
{
char* l = (char*) dynamic_cast<TAttLine*>(node->GetVolume());
SetMainColorPtr((Color_t*)(l + sizeof(void*)));
SetMainTransparency((UChar_t) fNode->GetVolume()->GetTransparency());
fRnrSelf = fNode->TGeoAtt::IsVisible();
}
const Text_t* TEveGeoNode::GetName() const
{
return fNode->GetName();
}
const Text_t* TEveGeoNode::GetTitle() const
{
return fNode->GetTitle();
}
const Text_t* TEveGeoNode::GetElementName() const
{
return fNode->GetName();
}
const Text_t* TEveGeoNode::GetElementTitle() const
{
return fNode->GetTitle();
}
void TEveGeoNode::ExpandIntoListTree(TGListTree* ltree,
TGListTreeItem* parent)
{
if (fChildren.empty() && fNode->GetVolume()->GetNdaughters() > 0) {
TIter next(fNode->GetVolume()->GetNodes());
TGeoNode* dnode;
while ((dnode = (TGeoNode*) next()) != 0) {
TEveGeoNode* node_re = new TEveGeoNode(dnode);
AddElement(node_re);
}
}
TEveElement::ExpandIntoListTree(ltree, parent);
}
void TEveGeoNode::AddStamp(UChar_t bits)
{
TEveElement::AddStamp(bits);
if (bits & kCBVisibility)
{
fNode->SetVisibility(fRnrSelf);
fNode->VisibleDaughters(fRnrChildren);
}
}
Bool_t TEveGeoNode::CanEditMainColor() const
{
return ! fNode->GetVolume()->IsAssembly();
}
void TEveGeoNode::SetMainColor(Color_t color)
{
TEveElement::SetMainColor(color);
fNode->GetVolume()->SetLineColor(color);
}
Bool_t TEveGeoNode::CanEditMainTransparency() const
{
return ! fNode->GetVolume()->IsAssembly();
}
UChar_t TEveGeoNode::GetMainTransparency() const
{
UChar_t t = (UChar_t) fNode->GetVolume()->GetTransparency();
if (fMainTransparency != t)
{
TEveGeoNode* ncthis = const_cast<TEveGeoNode*>(this);
ncthis->SetMainTransparency(t);
}
return t;
}
void TEveGeoNode::SetMainTransparency(UChar_t t)
{
TEveElement::SetMainTransparency(t);
fNode->GetVolume()->SetTransparency((Char_t) t);
}
void TEveGeoNode::UpdateNode(TGeoNode* node)
{
static const TEveException eH("TEveGeoNode::UpdateNode ");
if (fNode == node)
StampColorSelection();
for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
((TEveGeoNode*)(*i))->UpdateNode(node);
}
}
void TEveGeoNode::UpdateVolume(TGeoVolume* volume)
{
static const TEveException eH("TEveGeoNode::UpdateVolume ");
if(fNode->GetVolume() == volume)
StampColorSelection();
for(List_i i=fChildren.begin(); i!=fChildren.end(); ++i) {
((TEveGeoNode*)(*i))->UpdateVolume(volume);
}
}
void TEveGeoNode::Draw(Option_t* option)
{
TString opt("SAME");
opt += option;
fNode->GetVolume()->Draw(opt);
}
void TEveGeoNode::Save(const char* file, const char* name)
{
TEveGeoShapeExtract* gse = DumpShapeTree(this, 0, 0);
TFile f(file, "RECREATE");
gse->Write(name);
f.Close();
}
TEveGeoShapeExtract* TEveGeoNode::DumpShapeTree(TEveGeoNode* geon, TEveGeoShapeExtract* parent, Int_t level)
{
static const TEveException eh("TEveGeoNode::DumpShapeTree ");
printf("dump_shape_tree %s \n", geon->GetName());
TGeoNode* tnode = 0;
TGeoVolume* tvolume = 0;
TGeoShape* tshape = 0;
tnode = geon->GetNode();
if (tnode == 0)
{
Info(eh, "Null TGeoNode for TEveGeoNode '%s': assuming it's a holder and descending.", geon->GetName());
}
else
{
tvolume = tnode->GetVolume();
if (tvolume == 0) {
Warning(eh, "Null TGeoVolume for TEveGeoNode '%s'; skipping its sub-tree.\n", geon->GetName());
return 0;
}
tshape = tvolume->GetShape();
}
TEveTrans trans;
if (parent) if (parent) trans.SetFromArray(parent->GetTrans());
TGeoMatrix* gm = tnode->GetMatrix();
const Double_t* rm = gm->GetRotationMatrix();
const Double_t* tv = gm->GetTranslation();
TEveTrans t;
t(1,1) = rm[0]; t(1,2) = rm[1]; t(1,3) = rm[2];
t(2,1) = rm[3]; t(2,2) = rm[4]; t(2,3) = rm[5];
t(3,1) = rm[6]; t(3,2) = rm[7]; t(3,3) = rm[8];
t(1,4) = tv[0]; t(2,4) = tv[1]; t(3,4) = tv[2];
trans *= t;
TEveGeoShapeExtract* gse = new TEveGeoShapeExtract(geon->GetName(), geon->GetTitle());
gse->SetTrans(trans.Array());
Int_t ci = 0;
if (tvolume) ci = tvolume->GetLineColor();
TColor* c = gROOT->GetColor(ci);
Float_t rgba[4] = {1, 0, 0, 1};
if (c) {
rgba[0] = c->GetRed();
rgba[1] = c->GetGreen();
rgba[2] = c->GetBlue();
}
gse->SetRGBA(rgba);
Bool_t rnr = geon->GetRnrSelf();
if (level > gGeoManager->GetVisLevel())
rnr = kFALSE;
gse->SetRnrSelf(rnr);
gse->SetRnrElements(geon->GetRnrChildren());
if (dynamic_cast<TGeoShapeAssembly*>(tshape)) {
Info(eh, "TGeoShapeAssembly name='%s' encountered in traversal. This is not supported.", tshape->GetName());
tshape = 0;
}
gse->SetShape(tshape);
++level;
if (geon->HasChildren())
{
TList* ele = new TList();
gse->SetElements(ele);
gse->GetElements()->SetOwner(true);
TEveElement::List_i i = geon->BeginChildren();
while (i != geon->EndChildren())
{
TEveGeoNode* l = dynamic_cast<TEveGeoNode*>(*i);
DumpShapeTree(l, gse, level+1);
++i;
}
}
if (parent)
parent->GetElements()->Add(gse);
return gse;
}
ClassImp(TEveGeoTopNode);
TEveGeoTopNode::TEveGeoTopNode(TGeoManager* manager, TGeoNode* node,
Int_t visopt, Int_t vislvl, Int_t maxvisnds) :
TEveGeoNode (node),
fManager (manager),
fVisOption (visopt),
fVisLevel (vislvl),
fMaxVisNodes (maxvisnds)
{
InitMainTrans();
fRnrSelf = kTRUE;
}
void TEveGeoTopNode::UseNodeTrans()
{
RefMainTrans().SetFrom(*fNode->GetMatrix());
}
void TEveGeoTopNode::AddStamp(UChar_t bits)
{
TEveElement::AddStamp(bits);
}
void TEveGeoTopNode::Draw(Option_t* option)
{
AppendPad(option);
}
void TEveGeoTopNode::Paint(Option_t* option)
{
if (fRnrSelf) {
gGeoManager = fManager;
TVirtualPad* pad = gPad;
gPad = 0;
TGeoVolume* top_volume = fManager->GetTopVolume();
fManager->SetVisOption(fVisOption);
if (fVisLevel > 0)
fManager->SetVisLevel(fVisLevel);
else
fManager->SetMaxVisNodes(fMaxVisNodes);
fManager->SetTopVolume(fNode->GetVolume());
gPad = pad;
TVirtualGeoPainter* vgp = fManager->GetGeomPainter();
if(vgp != 0) {
TGeoHMatrix geomat;
if (HasMainTrans()) RefMainTrans().SetGeoHMatrix(geomat);
vgp->PaintNode(fNode, option, &geomat);
}
fManager->SetTopVolume(top_volume);
}
}
void TEveGeoTopNode::VolumeVisChanged(TGeoVolume* volume)
{
static const TEveException eh("TEveGeoTopNode::VolumeVisChanged ");
printf("%s volume %s %p\n", eh.Data(), volume->GetName(), (void*)volume);
UpdateVolume(volume);
}
void TEveGeoTopNode::VolumeColChanged(TGeoVolume* volume)
{
static const TEveException eh("TEveGeoTopNode::VolumeColChanged ");
printf("%s volume %s %p\n", eh.Data(), volume->GetName(), (void*)volume);
UpdateVolume(volume);
}
void TEveGeoTopNode::NodeVisChanged(TGeoNode* node)
{
static const TEveException eh("TEveGeoTopNode::NodeVisChanged ");
printf("%s node %s %p\n", eh.Data(), node->GetName(), (void*)node);
UpdateNode(node);
}
namespace
{
TGeoManager* init_geo_mangeur()
{
TGeoManager* old = gGeoManager;
gGeoManager = 0;
TGeoManager* mgr = new TGeoManager();
mgr->SetNameTitle("TEveGeoShape::fgGeoMangeur",
"Static geo manager used for wrapped TGeoShapes.");
gGeoManager = old;
return mgr;
}
}
ClassImp(TEveGeoShape);
TGeoManager* TEveGeoShape::fgGeoMangeur = init_geo_mangeur();
TGeoManager* TEveGeoShape::GetGeoMangeur()
{
return fgGeoMangeur;
}
TEveGeoShape::TEveGeoShape(const Text_t* name, const Text_t* title) :
TEveElement (fColor),
TNamed (name, title),
fColor (0),
fNSegments (0),
fShape (0)
{
InitMainTrans();
}
TEveGeoShape::~TEveGeoShape()
{
SetShape(0);
}
void TEveGeoShape::SetShape(TGeoShape* s)
{
TEveGeoManagerHolder gmgr(fgGeoMangeur);
if (fShape) {
fShape->SetUniqueID(fShape->GetUniqueID() - 1);
if (fShape->GetUniqueID() == 0)
delete fShape;
}
fShape = s;
if (fShape) {
fShape->SetUniqueID(fShape->GetUniqueID() + 1);
}
}
void TEveGeoShape::Paint(Option_t* )
{
static const TEveException eh("TEveGeoShape::Paint ");
if (fShape == 0)
return;
TEveGeoManagerHolder gmgr(fgGeoMangeur, fNSegments);
TBuffer3D& buff = (TBuffer3D&) fShape->GetBuffer3D
(TBuffer3D::kCore, kFALSE);
buff.fID = this;
buff.fColor = GetMainColor();
buff.fTransparency = GetMainTransparency();
RefMainTrans().SetBuffer3D(buff);
buff.fLocalFrame = kTRUE;
Int_t sections = TBuffer3D::kBoundingBox | TBuffer3D::kShapeSpecific;
if (fNSegments > 2)
sections |= TBuffer3D::kRawSizes | TBuffer3D::kRaw;
fShape->GetBuffer3D(sections, kTRUE);
Int_t reqSec = gPad->GetViewer3D()->AddObject(buff);
if (reqSec != TBuffer3D::kNone) {
if (reqSec & TBuffer3D::kCore)
Warning(eh, "Core section required again for shape='%s'. This shouldn't happen.", GetName());
fShape->GetBuffer3D(reqSec, kTRUE);
reqSec = gPad->GetViewer3D()->AddObject(buff);
}
if (reqSec != TBuffer3D::kNone)
Warning(eh, "Extra section required: reqSec=%d, shape=%s.", reqSec, GetName());
}
void TEveGeoShape::Save(const char* file, const char* name)
{
TEveGeoShapeExtract* gse = DumpShapeTree(this, 0);
TFile f(file, "RECREATE");
gse->Write(name);
f.Close();
}
TEveGeoShapeExtract* TEveGeoShape::DumpShapeTree(TEveGeoShape* gsre,
TEveGeoShapeExtract* parent)
{
TEveGeoShapeExtract* she = new TEveGeoShapeExtract(gsre->GetName(), gsre->GetTitle());
she->SetTrans(gsre->RefMainTrans().Array());
Int_t ci = gsre->GetColor();
TColor* c = gROOT->GetColor(ci);
Float_t rgba[4] = {1, 0, 0, 1 - gsre->GetMainTransparency()/100.};
if (c)
{
rgba[0] = c->GetRed();
rgba[1] = c->GetGreen();
rgba[2] = c->GetBlue();
}
she->SetRGBA(rgba);
she->SetRnrSelf(gsre->GetRnrSelf());
she->SetRnrElements(gsre->GetRnrChildren());
she->SetShape(gsre->GetShape());
if (gsre->HasChildren())
{
TList* ele = new TList();
she->SetElements(ele);
she->GetElements()->SetOwner(true);
TEveElement::List_i i = gsre->BeginChildren();
while (i != gsre->EndChildren()) {
TEveGeoShape* l = dynamic_cast<TEveGeoShape*>(*i);
DumpShapeTree(l, she);
i++;
}
}
if (parent)
parent->GetElements()->Add(she);
return she;
}
TEveGeoShape* TEveGeoShape::ImportShapeExtract(TEveGeoShapeExtract* gse,
TEveElement* parent)
{
TEveGeoManagerHolder gmgr(fgGeoMangeur);
TEveManager::TRedrawDisabler redrawOff(gEve);
TEveGeoShape* gsre = SubImportShapeExtract(gse, parent);
gsre->ElementChanged();
return gsre;
}
TEveGeoShape* TEveGeoShape::SubImportShapeExtract(TEveGeoShapeExtract* gse,
TEveElement* parent)
{
TEveGeoShape* gsre = new TEveGeoShape(gse->GetName(), gse->GetTitle());
gsre->RefMainTrans().SetFromArray(gse->GetTrans());
const Float_t* rgba = gse->GetRGBA();
gsre->SetMainColorRGB(rgba[0], rgba[1], rgba[2]);
gsre->SetMainAlpha(rgba[3]);
gsre->SetRnrSelf(gse->GetRnrSelf());
gsre->SetRnrChildren(gse->GetRnrElements());
gsre->SetShape(gse->GetShape());
if (parent)
parent->AddElement(gsre);
if (gse->HasElements())
{
TIter next(gse->GetElements());
TEveGeoShapeExtract* chld;
while ((chld = (TEveGeoShapeExtract*) next()) != 0)
SubImportShapeExtract(chld, gsre);
}
return gsre;
}
TClass* TEveGeoShape::ProjectedClass() const
{
return TEvePolygonSetProjected::Class();
}
TBuffer3D* TEveGeoShape::MakeBuffer3D()
{
if (fShape == 0) return 0;
if (dynamic_cast<TGeoShapeAssembly*>(fShape)) {
return 0;
}
TEveGeoManagerHolder gmgr(fgGeoMangeur, fNSegments);
TBuffer3D* buff = fShape->MakeBuffer3D();
TEveTrans& mx = RefMainTrans();
if (mx.GetUseTrans())
{
Int_t n = buff->NbPnts();
Double_t* pnts = buff->fPnts;
for(Int_t k = 0; k < n; ++k)
{
mx.MultiplyIP(&pnts[3*k]);
}
}
return buff;
}
Last change: Mon Nov 24 08:18:37 2008
Last generated: 2008-11-24 08:18
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.