VGM Version 5.3
Loading...
Searching...
No Matches
MultiUnion.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The RootGM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
12//
13// Class MultiUnion
14// ---------------------
15// VGM implementation for Root Boolean solid
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
21
25
26#include "TGeoBoolNode.h"
27#include "TGeoCompositeShape.h"
28#include "TString.h"
29
30#include <cstdlib>
31
32const char RootGM::MultiUnion::fgkUnionChar = '+';
33const char RootGM::MultiUnion::fgkSeparator = ':';
34
35//_____________________________________________________________________________
36RootGM::MultiUnion::MultiUnion(const std::string& name,
37 std::vector<VGM::ISolid*> constituents, std::vector<TGeoMatrix*> transforms)
38 : VGM::ISolid(),
39 VGM::IMultiUnion(),
40 BaseVGM::VMultiUnion(),
41 fCompositeShape(0),
42 fConstituents(constituents),
43 fTransforms(transforms)
44{
48
49 TString formula;
50
51 for (size_t i = 0; i < constituents.size(); ++i) {
52 // Get solid displacement, if present, and update transformation
53 // which will be used in Root node
54 //
55 VGM::ISolid* iConstSolid = constituents[i];
56 TGeoHMatrix imatrix(*transforms[i]);
57
58 // Get solid displacement, if present, and update transformation
59 // which will be used in Root node
60 if (iConstSolid->Type() == VGM::kDisplaced) {
61 VGM::IDisplacedSolid* displacedSolid =
62 dynamic_cast<VGM::IDisplacedSolid*>(iConstSolid);
63 TGeoHMatrix displacement(
64 *RootGM::CreateTransform(displacedSolid->Displacement()));
65 iConstSolid = displacedSolid->ConstituentSolid();
66 imatrix = imatrix * displacement;
67 }
68
69 // Get Root solid
70 TGeoShape* irootSolid = RootGM::SolidMap::Instance()->GetSolid(iConstSolid);
71 TString irootSolidName = irootSolid->GetName();
72 // CHECK
73 // The Root factory should attribute unique name
74 if (i > 0) {
75 formula += fgkUnionChar;
76 }
77 formula += irootSolidName;
78
79 TGeoMatrix* inewMatrix = 0;
80 if (!imatrix.IsIdentity()) {
81 inewMatrix = new TGeoCombiTrans(imatrix);
82 // set matrix name
83 TString tname = "t";
84 tname += i;
85 inewMatrix->SetName(tname);
86 inewMatrix->RegisterYourself();
87 // add transformation to formula
88 formula += fgkSeparator;
89 formula += tname;
90 }
91 }
92
93 // std::cout << "RootGM::MultiUnion::MultiUnion formula: " << formula <<
94 // std::endl;
95 fCompositeShape = new TGeoCompositeShape(name.data(), formula.Data());
96 RootGM::SolidMap::Instance()->AddSolid(this, fCompositeShape);
97}
98
99//_____________________________________________________________________________
101 : VGM::ISolid(), VGM::IMultiUnion(), BaseVGM::VMultiUnion()
102{
104}
105
106//_____________________________________________________________________________
108 : VGM::ISolid(rhs), VGM::IMultiUnion(rhs), BaseVGM::VMultiUnion(rhs)
109{
111}
112
113//_____________________________________________________________________________
118
119//
120// public methods
121//
122
123//_____________________________________________________________________________
124std::string RootGM::MultiUnion::Name() const
125{
126 // Returns the Boolean solid name
127 // ---
128
129 return fCompositeShape->GetName();
130}
131
132//_____________________________________________________________________________
134{
135 // Returns the Boolean solid name
136 // ---
137
138 return int(fConstituents.size());
139}
140
141//_____________________________________________________________________________
143{
144 // Returns the index-th constituent solid.
145 // ---
146
147 return fConstituents[index];
148}
149
150//_____________________________________________________________________________
152{
153 // Returns the displacement of the index-th constituent solid
154 // ---
155
156 return Transform(*fTransforms[index]);
157}
VGM implementation for Root Boolean solid.
Definition MultiUnion.h:36
virtual std::string Name() const
Return the name of this solid.
virtual int NofSolids() const
Return the number of constituent solids.
virtual ISolid * ConstituentSolid(int index) const
Return the i-th constituent solid.
virtual VGM::Transform Transformation(int index) const
Return the displacement of the ith constituent solid.
TGeoShape * GetSolid(VGM::ISolid *iSolid) const
Definition SolidMap.cxx:86
void AddSolid(VGM::ISolid *, TGeoShape *)
Definition SolidMap.cxx:59
static SolidMap * Instance()
Definition SolidMap.cxx:28
The VGM interface to displaced solids.
virtual ISolid * ConstituentSolid() const =0
Return the constituent solid.
virtual Transform Displacement() const =0
Return the 3D displacement of the constituent solid.
The VGM interface to solids.
Definition ISolid.h:58
virtual SolidType Type() const =0
Return the type of this solid.
BaseVGM utilities.
Definition utilities.h:23
TGeoMatrix * CreateTransform(const VGM::Transform &transform)
VGM::Transform Transform(const TGeoMatrix &matrix)
Definition transform.cxx:37
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40
@ kDisplaced
Definition ISolid.h:49