26#include "TGeoBoolNode.h"
27#include "TGeoCompositeShape.h"
28#include "TGeoMatrix.h"
32const char RootGM::BooleanSolid::fgkIntersectionChar =
'*';
33const char RootGM::BooleanSolid::fgkSubtractionChar =
'-';
34const char RootGM::BooleanSolid::fgkUnionChar =
'+';
35const char RootGM::BooleanSolid::fgkSeparator =
':';
40 TGeoMatrix* displacementB)
61 TGeoHMatrix displacement(
63 matrixA = matrixA * displacement;
72 TGeoHMatrix displacement(
74 matrixB = matrixB * displacement;
83 TGeoMatrix* newMatrixA = 0;
84 if (!matrixA.IsIdentity()) newMatrixA =
new TGeoHMatrix(matrixA);
86 TGeoMatrix* newMatrixB = displacementB;
87 if (!matrixB.IsIdentity())
88 newMatrixB =
new TGeoHMatrix(TGeoHMatrix(*displacementB) * matrixB);
90 TGeoBoolNode* boolNode = 0;
94 new TGeoIntersection(rootSolidA, rootSolidB, newMatrixA, newMatrixB);
98 new TGeoSubtraction(rootSolidA, rootSolidB, newMatrixA, newMatrixB);
101 boolNode =
new TGeoUnion(rootSolidA, rootSolidB, newMatrixA, newMatrixB);
105 std::cerr <<
" RootGM::BooleanSolid::BooleanSolid: " << std::endl;
106 std::cerr <<
" Unknown Boolean solid type" << std::endl;
107 std::cerr <<
"*** Error: Aborting execution ***" << std::endl;
111 fCompositeShape =
new TGeoCompositeShape(name.data(), boolNode);
119 VGM::IBooleanSolid(),
121 fCompositeShape(compositeShape)
130 :
VGM::ISolid(),
VGM::IBooleanSolid(),
BaseVGM::VBooleanSolid()
137 :
VGM::ISolid(rhs),
VGM::IBooleanSolid(rhs),
BaseVGM::VBooleanSolid(rhs)
158 return fCompositeShape->GetName();
167 TGeoBoolNode* boolNode = fCompositeShape->GetBoolNode();
169 if (boolNode->GetBooleanOperator() == TGeoBoolNode::kGeoIntersection)
172 if (boolNode->GetBooleanOperator() == TGeoBoolNode::kGeoSubtraction)
175 if (boolNode->GetBooleanOperator() == TGeoBoolNode::kGeoUnion)
187 TGeoBoolNode* boolNode = fCompositeShape->GetBoolNode();
189 TGeoShape* rootSolidA = boolNode->GetLeftShape();
201 TGeoBoolNode* boolNode = fCompositeShape->GetBoolNode();
203 TGeoShape* rootSolidB = boolNode->GetRightShape();
216 TGeoBoolNode* boolNode = fCompositeShape->GetBoolNode();
218 TGeoMatrix* matrixA = boolNode->GetLeftMatrix();
219 TGeoMatrix* matrixB = boolNode->GetRightMatrix();
221 TGeoHMatrix transformA(*matrixA);
222 TGeoHMatrix transformB(*matrixB);
228 TGeoHMatrix totalTransformA(transformA);
229 TGeoShape* shapeA = boolNode->GetLeftShape();
234 while (shapeA->IsComposite()) {
236 TGeoBoolNode* boolNodeAC = ((TGeoCompositeShape*)shapeA)->GetBoolNode();
238 TGeoShape* shapeAC = boolNodeAC->GetLeftShape();
241 TGeoMatrix* matrixAC = boolNodeAC->GetLeftMatrix();
242 TGeoHMatrix transformAC(*matrixAC);
244 totalTransformA = totalTransformA * transformAC;
252 TGeoHMatrix totalTransformB(transformB);
253 TGeoShape* shapeB = boolNode->GetRightShape();
257 while (shapeB->IsComposite()) {
259 TGeoBoolNode* boolNodeBC = ((TGeoCompositeShape*)shapeB)->GetBoolNode();
261 TGeoShape* shapeBC = boolNodeBC->GetLeftShape();
264 TGeoMatrix* matrixBC = boolNodeBC->GetLeftMatrix();
265 TGeoHMatrix transformBC(*matrixBC);
267 totalTransformB = totalTransformB * transformBC;
275 return Transform(totalTransformA.Inverse() * totalTransformB);
280 int index, TGeoCompositeShape* compositeShape)
284 TGeoBoolNode* boolNode = compositeShape->GetBoolNode();
287 return boolNode->GetLeftShape();
289 return boolNode->GetRightShape();
291 std::cerr <<
" RootGM::BooleanSolid::GetConstituentSolid: " << std::endl;
292 std::cerr <<
" Index out of scope <0, 1>" << std::endl;
293 std::cerr <<
"*** Error: Aborting execution ***" << std::endl;
VGM implementation for Root Boolean solid.
static TGeoShape * GetConstituentSolid(int index, TGeoCompositeShape *compositeShape)
virtual VGM::Transform Displacement() const
Return the 3D displacement of the second constituent solid with respect to the first one.
virtual VGM::ISolid * ConstituentSolidB() const
Return the second constituent solid.
virtual VGM::BooleanType BoolType() const
Return the Boolean type of this solid.
virtual VGM::ISolid * ConstituentSolidA() const
Return the first constituent solid.
virtual std::string Name() const
Return the name of this solid.
TGeoShape * GetSolid(VGM::ISolid *iSolid) const
void AddSolid(VGM::ISolid *, TGeoShape *)
static SolidMap * Instance()
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.
virtual SolidType Type() const =0
Return the type of this solid.
TGeoMatrix * CreateTransform(const VGM::Transform &transform)
VGM::Transform Transform(const TGeoMatrix &matrix)
std::vector< double > Transform