VGM Version 5.3
Loading...
Searching...
No Matches
VFactory.cxx
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The BaseVGM 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 VFactory
14// ---------------
15// The interface to geometry factory.
16//
17// Author: Ivana Hrivnacova; IPN Orsay
18
20#include "VGM/solids/IArb8.h"
22#include "VGM/solids/IBox.h"
23#include "VGM/solids/ICons.h"
24#include "VGM/solids/ICtubs.h"
29#include "VGM/solids/IHype.h"
31#include "VGM/solids/IPara.h"
36#include "VGM/solids/ISolid.h"
37#include "VGM/solids/ISphere.h"
39#include "VGM/solids/ITorus.h"
40#include "VGM/solids/ITrap.h"
41#include "VGM/solids/ITrd.h"
42#include "VGM/solids/ITubs.h"
44#include "VGM/volumes/IVolume.h"
45
49
50#include <cstdlib>
51
52namespace {
53
54//_____________________________________________________________________________
55void PrintVersion()
56{
58
59 std::cout << std::endl
60 << "============================================================="
61 << std::endl
62 << " Virtual Geometry Model " << std::endl
63 << " Version " << VGM_RELEASE << " ( " << VGM_RELEASE_DATE << " )"
64 << std::endl
65 << " WWW : https://vmc-project.github.io/vgm-documentation/"
66 << std::endl
67 << "============================================================="
68 << std::endl
69 << std::endl;
70}
71
72} // namespace
73
74//_____________________________________________________________________________
76 const std::string& name, VGM::IMaterialFactory* materialFactory)
77 : VGM::IFactory(),
78 fDebug(0),
79 fIgnore(false),
80 fBestMatch(false),
81 fSingleMode(false),
82 fDummyBoxDimensions(VGM::kDefaultDummyBoxDimensions),
83 fName(name),
84 fSolids(),
85 fVolumes(),
86 fMaterialFactory(materialFactory)
87{
89
90 // Print version info
91 static bool printVersion = true;
92 if (printVersion) {
93 PrintVersion();
94 printVersion = false;
95 }
96}
97
98//_____________________________________________________________________________
100{
102}
103
104//_____________________________________________________________________________
105BaseVGM::VFactory::VFactory(const VFactory& rhs) : VGM::IFactory(rhs)
106{
108}
109
110//_____________________________________________________________________________
112{
113 // Deletes all objects created by factory
114 // ---
115
116 // Delete solids
117 for (unsigned int i = 0; i < fSolids.size(); i++) {
118 delete fSolids[i];
119 }
120
121 // Delete volumes
122 for (unsigned int j = 0; j < fVolumes.size(); j++) {
123 delete fVolumes[j];
124 }
125
126 // Placements are deleted together with volumes
127
128 // Material factory
129 delete fMaterialFactory;
130}
131
132//
133// private functions
134//
135
136//_____________________________________________________________________________
137VGM::ISolid* BaseVGM::VFactory::ExportDisplacedSolid(
138 VGM::IDisplacedSolid* solid, VGM::IFactory* factory) const
139
140{
141 // Exports specified displaced solid to given factory
142 // ---
143
144 // Export constituent solids first
145 VGM::ISolid* constituentSolid =
146 ExportSolid(solid->ConstituentSolid(), factory);
147 // Can lead to a duplication of solids in case
148 // the solid has been already exported
149 // Should not harm, but will be better to be avoided
150
151 VGM::Transform transform = solid->Displacement();
152
153 VGM::ISolid* newSolid =
154 factory->CreateDisplacedSolid(solid->Name(), constituentSolid, transform);
155 return newSolid;
156}
157
158//_____________________________________________________________________________
159VGM::ISolid* BaseVGM::VFactory::ExportScaledSolid(
160 VGM::IScaledSolid* solid, VGM::IFactory* factory) const
161
162{
163 // Exports specific scaled solid to given factory
164 // ---
165
166 // Export constituent solids first
167 VGM::ISolid* constituentSolid =
168 ExportSolid(solid->ConstituentSolid(), factory);
169 // Can lead to a duplication of solids in case
170 // the solid has been already exported
171 // Should not harm, but will be better to be avoided
172
173 VGM::Transform transform = solid->Scale();
174
175 VGM::ISolid* newSolid =
176 factory->CreateScaledSolid(solid->Name(), constituentSolid, transform);
177 return newSolid;
178}
179
180//_____________________________________________________________________________
181VGM::ISolid* BaseVGM::VFactory::ExportBooleanSolid(
182 VGM::IBooleanSolid* solid, VGM::IFactory* factory) const
183
184{
185 // Exports specified Boolean solid to given factory
186 // ---
187
188 // Export constituent solids first
189 VGM::ISolid* solidA = ExportSolid(solid->ConstituentSolidA(), factory);
190 VGM::ISolid* solidB = ExportSolid(solid->ConstituentSolidB(), factory);
191 // Can lead to a duplication of solids in case
192 // the solid has been already exported
193 // Should not harm, but will be better to be avoided
194
195 VGM::BooleanType boolType = solid->BoolType();
196 VGM::Transform transform = solid->Displacement();
197
198 VGM::ISolid* newSolid = 0;
199 if (boolType == VGM::kIntersection) {
200 newSolid = factory->CreateIntersectionSolid(
201 solid->Name(), solidA, solidB, transform);
202 }
203 else if (boolType == VGM::kSubtraction) {
204 newSolid =
205 factory->CreateSubtractionSolid(solid->Name(), solidA, solidB, transform);
206 }
207 else if (boolType == VGM::kUnion) {
208 newSolid =
209 factory->CreateUnionSolid(solid->Name(), solidA, solidB, transform);
210 }
211
212 if (!newSolid) {
213 std::cerr << " BaseVGM::VFactory::ExportBooleanSolid:" << std::endl;
214 std::cerr << " Unknown Boolean type (solid \"" << solid->Name() << "\")"
215 << std::endl;
216 std::cerr << "*** Error: Aborting execution ***" << std::endl;
217 exit(1);
218 }
219
220 return newSolid;
221}
222
223//_____________________________________________________________________________
224VGM::ISolid* BaseVGM::VFactory::ExportMultiUnion(
225 VGM::IMultiUnion* solid, VGM::IFactory* factory) const
226{
227 // Exports specified Boolean solid to given factory
228 // ---
229
230 // Export constituent solids first
231 std::vector<VGM::ISolid*> newConstituents;
232 std::vector<VGM::Transform> newTransforms;
233 for (int i = 0; i < solid->NofSolids(); ++i) {
234 newConstituents.push_back(ExportSolid(solid->ConstituentSolid(i), factory));
235 newTransforms.push_back(solid->Transformation(i));
236 }
237 VGM::ISolid* newSolid =
238 factory->CreateMultiUnion(solid->Name(), newConstituents, newTransforms);
239
240 return newSolid;
241}
242
243//_____________________________________________________________________________
244VGM::ISolid* BaseVGM::VFactory::ExportSolid(
245 VGM::ISolid* solid, VGM::IFactory* factory) const
246{
247 // Exports specified solid to given factory
248 // ---
249
250 if (Debug() > 0) {
252 std::cout << " Exporting solid: ";
253 if (Debug() > 1) std::cout << solid;
254 std::cout << std::endl;
256 std::cout << " " << *solid << std::endl;
257 }
258
259 VGM::SolidType solidType = solid->Type();
260 if (solidType == VGM::kArb8) {
261 VGM::IArb8* arb8 = dynamic_cast<VGM::IArb8*>(solid);
262 std::vector<VGM::TwoVector> vertices;
263 for (int i = 0; i < arb8->NofVertices(); ++i)
264 vertices.push_back(arb8->Vertex(i));
265 return factory->CreateArb8(arb8->Name(), arb8->ZHalfLength(), vertices);
266 }
267 else if (solidType == VGM::kBox) {
268 VGM::IBox* box = dynamic_cast<VGM::IBox*>(solid);
269 return factory->CreateBox(
270 box->Name(), box->XHalfLength(), box->YHalfLength(), box->ZHalfLength());
271 }
272 else if (solidType == VGM::kCons) {
273 VGM::ICons* cons = dynamic_cast<VGM::ICons*>(solid);
274 return factory->CreateCons(cons->Name(), cons->InnerRadiusMinusZ(),
275 cons->OuterRadiusMinusZ(), cons->InnerRadiusPlusZ(),
276 cons->OuterRadiusPlusZ(), cons->ZHalfLength(), cons->StartPhi(),
277 cons->DeltaPhi());
278 }
279 else if (solidType == VGM::kCtubs) {
280 VGM::ICtubs* ctubs = dynamic_cast<VGM::ICtubs*>(solid);
281 return factory->CreateCtubs(ctubs->Name(), ctubs->InnerRadius(),
282 ctubs->OuterRadius(), ctubs->ZHalfLength(), ctubs->StartPhi(),
283 ctubs->DeltaPhi(), ctubs->NxLow(), ctubs->NyLow(), ctubs->NzLow(),
284 ctubs->NxHigh(), ctubs->NyHigh(), ctubs->NzHigh());
285 }
286 else if (solidType == VGM::kEllipsoid) {
287 VGM::IEllipsoid* ellipsoid = dynamic_cast<VGM::IEllipsoid*>(solid);
288 return factory->CreateEllipsoid(ellipsoid->Name(), ellipsoid->XSemiAxis(),
289 ellipsoid->YSemiAxis(), ellipsoid->ZSemiAxis(), ellipsoid->ZBottomCut(),
290 ellipsoid->ZTopCut());
291 }
292 else if (solidType == VGM::kEltu) {
293 VGM::IEllipticalTube* eltu = dynamic_cast<VGM::IEllipticalTube*>(solid);
294 return factory->CreateEllipticalTube(
295 eltu->Name(), eltu->Dx(), eltu->Dy(), eltu->ZHalfLength());
296 }
297 else if (solidType == VGM::kExtruded) {
298 VGM::IExtrudedSolid* xtru = dynamic_cast<VGM::IExtrudedSolid*>(solid);
299 std::vector<VGM::TwoVector> polygon;
300 for (int i = 0; i < xtru->NofVertices(); ++i)
301 polygon.push_back(xtru->Vertex(i));
302 std::vector<std::vector<double>> zsections;
303 for (int i = 0; i < xtru->NofZSections(); ++i) {
304 std::vector<double> zsection;
305 zsection.push_back(xtru->ZPosition(i));
306 zsection.push_back(xtru->Offset(i).first);
307 zsection.push_back(xtru->Offset(i).second);
308 zsection.push_back(xtru->Scale(i));
309 zsections.push_back(zsection);
310 }
311 return factory->CreateExtrudedSolid(xtru->Name(), polygon, zsections);
312 }
313 else if (solidType == VGM::kHype) {
314 VGM::IHype* hype = dynamic_cast<VGM::IHype*>(solid);
315 return factory->CreateHype(hype->Name(), hype->InnerRadius(),
316 hype->OuterRadius(), hype->InnerStereoAngle(), hype->OuterStereoAngle(),
317 hype->ZHalfLength());
318 }
319 else if (solidType == VGM::kPara) {
320 VGM::IPara* para = dynamic_cast<VGM::IPara*>(solid);
321 return factory->CreatePara(para->Name(), para->XHalfLength(),
322 para->YHalfLength(), para->ZHalfLength(), para->Alpha(), para->Theta(),
323 para->Phi());
324 }
325 else if (solidType == VGM::kParaboloid) {
326 VGM::IParaboloid* paraboloid = dynamic_cast<VGM::IParaboloid*>(solid);
327 return factory->CreateParaboloid(paraboloid->Name(),
328 paraboloid->RadiusMinusZ(), paraboloid->RadiusPlusZ(),
329 paraboloid->ZHalfLength());
330 }
331 else if (solidType == VGM::kPolycone) {
332 VGM::IPolycone* polycone = dynamic_cast<VGM::IPolycone*>(solid);
333 return factory->CreatePolycone(polycone->Name(), polycone->StartPhi(),
334 polycone->DeltaPhi(), polycone->NofZPlanes(), polycone->ZValues(),
335 polycone->InnerRadiusValues(), polycone->OuterRadiusValues());
336 }
337 else if (solidType == VGM::kPolyhedra) {
338 VGM::IPolyhedra* polyhedra = dynamic_cast<VGM::IPolyhedra*>(solid);
339 return factory->CreatePolyhedra(polyhedra->Name(), polyhedra->StartPhi(),
340 polyhedra->DeltaPhi(), polyhedra->NofSides(), polyhedra->NofZPlanes(),
341 polyhedra->ZValues(), polyhedra->InnerRadiusValues(),
342 polyhedra->OuterRadiusValues());
343 }
344 else if (solidType == VGM::kSphere) {
345 VGM::ISphere* sphere = dynamic_cast<VGM::ISphere*>(solid);
346 return factory->CreateSphere(sphere->Name(), sphere->InnerRadius(),
347 sphere->OuterRadius(), sphere->StartPhi(), sphere->DeltaPhi(),
348 sphere->StartTheta(), sphere->DeltaTheta());
349 }
350 else if (solidType == VGM::kTessellated) {
351 VGM::ITessellatedSolid* tessellated =
352 dynamic_cast<VGM::ITessellatedSolid*>(solid);
353
354 std::vector<std::vector<VGM::ThreeVector>> facets;
355 for (int i = 0; i < tessellated->NofFacets(); ++i) {
356 std::vector<VGM::ThreeVector> facet;
357 for (int j = 0; j < tessellated->NofVertices(i); ++j) {
358 facet.push_back(tessellated->Vertex(i, j));
359 }
360 facets.push_back(facet);
361 }
362 return factory->CreateTessellatedSolid(tessellated->Name(), facets);
363 }
364 else if (solidType == VGM::kTorus) {
365 VGM::ITorus* torus = dynamic_cast<VGM::ITorus*>(solid);
366 return factory->CreateTorus(torus->Name(), torus->InnerRadius(),
367 torus->OuterRadius(), torus->AxialRadius(), torus->StartPhi(),
368 torus->DeltaPhi());
369 }
370 else if (solidType == VGM::kTrap) {
371 VGM::ITrap* trap = dynamic_cast<VGM::ITrap*>(solid);
372 return factory->CreateTrap(trap->Name(), trap->ZHalfLength(), trap->Theta(),
373 trap->Phi(), trap->YHalfLengthMinusZ(), trap->XHalfLengthMinusZMinusY(),
374 trap->XHalfLengthMinusZPlusY(), trap->AlphaMinusZ(),
376 trap->XHalfLengthPlusZPlusY(), trap->AlphaPlusZ());
377 }
378 else if (solidType == VGM::kTrd) {
379 VGM::ITrd* trd = dynamic_cast<VGM::ITrd*>(solid);
380 return factory->CreateTrd(trd->Name(), trd->XHalfLengthMinusZ(),
381 trd->XHalfLengthPlusZ(), trd->YHalfLengthMinusZ(),
382 trd->YHalfLengthPlusZ(), trd->ZHalfLength());
383 }
384 else if (solidType == VGM::kTubs) {
385 VGM::ITubs* tubs = dynamic_cast<VGM::ITubs*>(solid);
386 return factory->CreateTubs(tubs->Name(), tubs->InnerRadius(),
387 tubs->OuterRadius(), tubs->ZHalfLength(), tubs->StartPhi(),
388 tubs->DeltaPhi());
389 }
390 else if (solidType == VGM::kDisplaced) {
391 VGM::IDisplacedSolid* displaced =
392 dynamic_cast<VGM::IDisplacedSolid*>(solid);
393 return ExportDisplacedSolid(displaced, factory);
394 }
395 else if (solidType == VGM::kScaled) {
396 VGM::IScaledSolid* scaled = dynamic_cast<VGM::IScaledSolid*>(solid);
397 return ExportScaledSolid(scaled, factory);
398 }
399 else if (solidType == VGM::kBoolean) {
400 VGM::IBooleanSolid* boolean = dynamic_cast<VGM::IBooleanSolid*>(solid);
401 return ExportBooleanSolid(boolean, factory);
402 }
403 else if (solidType == VGM::kMultiUnion) {
404 VGM::IMultiUnion* multiUnion = dynamic_cast<VGM::IMultiUnion*>(solid);
405 return ExportMultiUnion(multiUnion, factory);
406 }
407
408 std::cerr << " BaseVGM::VFactory::ExportSolid:" << std::endl;
409 std::cerr << " Unknown solid type (solid \"" << solid->Name() << "\")"
410 << std::endl;
411 std::cerr << "*** Error: Aborting execution ***" << std::endl;
412 exit(1);
413 return 0;
414}
415
416//_____________________________________________________________________________
417BaseVGM::VFactory::VolumeMap* BaseVGM::VFactory::ExportVolumeStore(
418 VGM::IFactory* factory) const
419{
420 // Exports all volumes.
421 // ---
422
423 if (Debug() > 0) {
425 std::cout << "Exporting volume store: " << std::endl;
426 }
427
428 VolumeMap* volumeMap = new VolumeMap();
429
430 for (unsigned int i = 0; i < Volumes().size(); i++) {
431
432 VGM::IVolume* volume = Volumes()[i];
433
434 // Export solid
435 VGM::ISolid* solid = ExportSolid(volume->Solid(), factory);
436
437 // Create factory's volume
438 VGM::IVolume* newVolume =
439 factory->CreateVolume(volume->Name(), solid, volume->MediumName());
440
441 // Map new volume to old volume
442 (*volumeMap)[volume] = newVolume;
443
444 // Debug info
445 //
446 if (Debug() > 0) {
448 std::cout << "Exporting volume: " << i << "th \"" << volume->Name();
449 std::cout << "\" "
450 << "material: \"" << volume->MaterialName() << "\"";
451 if (Debug() > 1)
452 std::cout << " "
453 << " oldVGM=" << volume << " newVGM=" << newVolume;
454 std::cout << std::endl;
455 }
456 }
457
458 return volumeMap;
459}
460
461//_____________________________________________________________________________
462VGM::IPlacement* BaseVGM::VFactory::ExportSimplePlacement(
463 VGM::IPlacement* placement, VGM::IFactory* factory,
464 VolumeMap* volumeMap) const
465{
466 // Export simple placement.
467 // ---
468
469#ifndef NEW_DEBUG
470 if (Debug() > 0) {
471 std::cout << " simple placement: " << placement->Name() << std::endl;
472 }
473#endif
474
475 VGM::IVolume* newVolume = (*volumeMap)[placement->Volume()];
476 VGM::IVolume* newMother = (*volumeMap)[placement->Mother()];
477
478 // If boolean or scaled solid that have to be reflected
480 VGM::Transform transform = placement->Transformation();
481 VGM::IBooleanSolid* booleanSolid =
482 dynamic_cast<VGM::IBooleanSolid*>(placement->Volume()->Solid());
483 VGM::IScaledSolid* scaledSolid =
484 dynamic_cast<VGM::IScaledSolid*>(placement->Volume()->Solid());
485 if ((booleanSolid && booleanSolid->ToBeReflected()) ||
486 (scaledSolid && scaledSolid->ToBeReflected())) {
487 transform[VGM::kReflZ] = 1;
488 }
489
490 VGM::IPlacement* newPlacement = factory->CreatePlacement(
491 placement->Name(), placement->CopyNo(), newVolume, newMother, transform);
492
493 return newPlacement;
494}
495
496//_____________________________________________________________________________
497VGM::IPlacement* BaseVGM::VFactory::ExportMultiplePlacement(
498 VGM::IPlacement* placement, VGM::IFactory* factory,
499 VolumeMap* volumeMap) const
500{
501 // Exports multiple placement.
502 // ---
503
504 VGM::IVolume* newVolume = (*volumeMap)[placement->Volume()];
505 VGM::IVolume* newMother = (*volumeMap)[placement->Mother()];
506
508 int nofItems = 0;
509 double width = 0.;
510 double offset = 0.;
511 double halfGap = 0.;
512 placement->MultiplePlacementData(axis, nofItems, width, offset, halfGap);
513
514#ifndef NEW_DEBUG
515 if (Debug() > 0) {
516 std::cout << " multiple placement - data: " << axis << ", " << nofItems
517 << ", " << width << ", " << offset << ", " << halfGap
518 << std::endl;
519 }
520#endif
521
522 VGM::IPlacement* newPlacement =
523 factory->CreateMultiplePlacement(placement->Name(), newVolume, newMother,
524 axis, nofItems, width, offset, halfGap);
525
526 return newPlacement;
527}
528
529//_____________________________________________________________________________
530VGM::IPlacement* BaseVGM::VFactory::ExportParameterisedPlacement(
531 VGM::IPlacement* placement, VGM::IFactory* factory,
532 VolumeMap* volumeMap) const
533{
534 // Exports parameterised placement.
535 // ---
536
537 // Get parameterised placement data
538 std::vector<VGM::Transform> transforms;
539 std::vector<VGM::IVolume*> volumes;
540 placement->ParameterisedPlacementData(transforms, volumes);
541
542#ifndef NEW_DEBUG
543 if (Debug() > 0) {
544 std::cout << " parameterised placement" << std::endl;
545 }
546#else
547 if (Debug() > 0) {
548 std::cout << " parameterised placement - transforms: " << std::endl;
549 for (VGM::Transform& tr : transforms) {
550 std::cout << " " << tr << std::endl;
551 }
552 }
553#endif
554
555 if (Debug() > 0) {
556 std::cout << " parameterised volumes: "
557 << std::endl;
558 int counter = 0;
559 for (auto& vol : volumes) {
560 std::cout << " Volume from element "
561 << counter++ << ": " << " " << vol->Name() << std::endl;
562 }
563 }
564
565 VGM::IVolume* newMother = (*volumeMap)[placement->Mother()];
566 std::vector<VGM::IVolume*> newVolumes;
567 for (auto volume : volumes) {
568 newVolumes.emplace_back((*volumeMap)[volume]);
569 }
570
571 return factory->CreateParameterisedPlacement(
572 placement->Name(), newMother, transforms, newVolumes);
573}
574
575//_____________________________________________________________________________
576void BaseVGM::VFactory::ExportPlacements(
577 VGM::IFactory* factory, VolumeMap* volumeMap) const
578{
579 // Exports all placements.
580 // ---
581
582#ifdef NEW_DEBUG
583 if (Debug() > 0) {
585 std::cout << "Exporting placements:" << std::endl;
586 }
587#endif
588
589 for (unsigned int i = 0; i < Volumes().size(); i++) {
590
591 VGM::IVolume* volume = Volumes()[i];
592
593#ifndef NEW_DEBUG
594 if (Debug() > 0) {
596 std::cout << "ExportPlacements for " << i << "th volume ";
597 if (Debug() > 1) std::cout << volume << " ";
598 std::cout << volume->Name() << std::endl;
599 }
600#endif
601
602 for (int id = 0; id < volume->NofDaughters(); id++) {
603
604 VGM::IPlacement* daughter = volume->Daughter(id);
605
606#ifndef NEW_DEBUG
607 if (Debug() > 0) {
609 std::cout << " " << id << "th daughter vol = ";
610 if (Debug() > 1) std::cout << daughter->Volume() << " ";
611 std::cout << daughter->Volume()->Name();
612 }
613#endif
614
615#ifdef NEW_DEBUG
616 if (Debug() > 0) {
618 std::cout << "Exporting placement: ";
619 if (Debug() > 1) std::cout << daughter;
620 std::cout << std::endl;
622 std::cout << " " << *daughter << std::endl;
623 }
624#endif
625
626 if (daughter->Type() == VGM::kSimplePlacement) {
627 ExportSimplePlacement(daughter, factory, volumeMap);
628 }
629 else if (daughter->Type() == VGM::kMultiplePlacement) {
630 ExportMultiplePlacement(daughter, factory, volumeMap);
631 }
632 else if (daughter->Type() == VGM::kParameterised) {
633 ExportParameterisedPlacement(daughter, factory, volumeMap);
634 }
635 else {
636 std::cout << std::endl;
637 std::cerr << " BaseVGM::VFactory::ExportPlacements:" << std::endl;
638 std::cerr << " Unknown placement type (placement \""
639 << daughter->Name() << "\")" << std::endl;
640 std::cerr << "*** Error: Aborting execution ***" << std::endl;
641 exit(1);
642 }
643 }
644 }
645
646 // Position the top volume
647 // (top volume has no mother volume that's why it must be placed
648 // explicitely)
649
650 VGM::IVolume* topVolume = (*volumeMap)[Top()->Volume()];
651
652 factory->CreatePlacement(
653 Top()->Name(), Top()->CopyNo(), topVolume, 0, Identity());
654
655 delete volumeMap;
656}
657
658//_____________________________________________________________________________
659VGM::Transform BaseVGM::VFactory::Identity() const
660{
661 //
662 VGM::Transform transform(VGM::kSize);
663 for (int i = 0; i < 7; i++) transform[i] = 0;
664
665 return transform;
666}
667
668//
669// public functions
670//
671
672//_____________________________________________________________________________
674{
676
677 // set the mode to destination factory
678 factory->SetSingleMode(SingleMode());
679
680 if (!SingleMode()) {
681 // Export materials
682 //
683 fMaterialFactory->Export(factory->MaterialFactory());
684
685 // Export volumes
686 //
687 VolumeMap* volumeMap = ExportVolumeStore(factory);
688 ExportPlacements(factory, volumeMap);
689
690 return true;
691 }
692 else {
693 // one solid mode
694
695 // Check if a solid was created/imported
696 if (!SingleSolid()) {
697 std::cerr << "++ Warning: ++ " << std::endl;
698 std::cerr << " BaseVGM::Export:" << std::endl;
699 std::cerr << " A solid must be created/imported first." << std::endl;
700
701 return false;
702 }
703
704 // Export solid
705 VGM::ISolid* solid = ExportSolid(SingleSolid(), factory);
706 factory->SetSolid(solid);
707
708 return (solid != 0);
709 }
710}
711
712//_____________________________________________________________________________
714{
715 // Print all solids.
716 // ---
717
718 std::cout << Name() << " factory solids store: " << std::endl;
719
720 const VGM::SolidStore& solids = Solids();
721
722 for (unsigned i = 0; i < solids.size(); i++) {
723 std::cout << " " << i << "th solid: " << *solids[i] << std::endl;
724 }
725}
726
727//_____________________________________________________________________________
729{
730 // Print all volumes.
731 // ---
732
733 std::cout << Name() << " factory volumes store: " << std::endl;
734
735 const VGM::VolumeStore& volumes = Volumes();
736
737 for (unsigned i = 0; i < volumes.size(); i++) {
738 std::cout << " " << i << "th: " << *volumes[i] << std::endl;
739 }
740}
741
742//_____________________________________________________________________________
744{
745 // Sets debug level; the same level is set to material factory.
746 // ---
747
748 fDebug = debug;
749 MaterialFactory()->SetDebug(debug);
750}
751
752//_____________________________________________________________________________
753void BaseVGM::VFactory::SetIgnore(bool ignore, double dummyBoxDimensions)
754{
755 fIgnore = ignore;
756 fDummyBoxDimensions = dummyBoxDimensions;
757}
The abstract base class to geometry factory.
Definition VFactory.h:43
virtual bool Export(VGM::IFactory *factory) const
Export geometry to the specified factory.
Definition VFactory.cxx:673
virtual void PrintSolids() const
Print all solids.
Definition VFactory.cxx:713
virtual void PrintVolumes() const
Print all volumes.
Definition VFactory.cxx:728
virtual ~VFactory()
Definition VFactory.cxx:111
virtual void SetDebug(int debug)
Set the debug level.
Definition VFactory.cxx:743
virtual void SetIgnore(bool ignore, double dummyBoxDimensions=VGM::kDefaultDummyBoxDimensions)
Set ignoring of unsupported features.
Definition VFactory.cxx:753
VGM Axis enumeration.
The VGM interface to Arb8 solids.
Definition IArb8.h:31
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual int NofVertices() const =0
Return the number of vertices.
virtual TwoVector Vertex(int index) const =0
Return the index-th vertex.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to Boolean solids.
virtual std::string Name() const =0
Return the name of this solid.
virtual ISolid * ConstituentSolidB() const =0
Return the second constituent solid.
virtual bool ToBeReflected() const =0
Return true if the solid has to be first reflected before being placed.
virtual ISolid * ConstituentSolidA() const =0
Return the first constituent solid.
virtual BooleanType BoolType() const =0
Return the Boolean type of this solid.
virtual Transform Displacement() const =0
Return the 3D displacement of the second constituent solid with respect to the first one.
The VGM interface to box solids.
Definition IBox.h:30
virtual std::string Name() const =0
Return the name of this solid.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLength() const =0
Return the half-length along the y axis in mm.
virtual double XHalfLength() const =0
Return the half-length along the x axis in mm.
The VGM interface to cons solids.
Definition ICons.h:30
virtual double DeltaPhi() const =0
Return the opening phi angle of the segment in deg.
virtual double OuterRadiusPlusZ() const =0
Return the outer radius at -z in mm.
virtual double OuterRadiusMinusZ() const =0
Return the outer radius at -z in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double InnerRadiusMinusZ() const =0
Return the innner radius at -z in mm.
virtual double InnerRadiusPlusZ() const =0
Return the innner radius at +z in mm.
virtual double StartPhi() const =0
Return the starting phi angle of the segment in deg.
The VGM interface to cut tubs solids.
Definition ICtubs.h:30
virtual double OuterRadius() const =0
Return the outside radius in mm.
virtual double NxHigh() const =0
X-component of the normal unit vector to the cut plane in +z.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in m.
virtual double DeltaPhi() const =0
Return the opening angle of the segment in deg.
virtual double NyLow() const =0
Y-component of the normal unit vector to the cut plane in -z.
virtual double NzLow() const =0
Z-component of the normal unit vector to the cut plane in -z.
virtual double NzHigh() const =0
Z-component of the normal unit vector to the cut plane in +z.
virtual std::string Name() const =0
Return the name of this solid.
virtual double InnerRadius() const =0
Return the inside radius in mm.
virtual double StartPhi() const =0
Return the starting angle of the segment in deg.
virtual double NxLow() const =0
X-component of the normal unit vector to the cut plane in -z.
virtual double NyHigh() const =0
Y-component of the normal unit vector to the cut plane in +z.
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.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to ellipsoid solids.
Definition IEllipsoid.h:30
virtual double ZBottomCut() const =0
Return the z bottom cut in mm.
virtual double ZSemiAxis() const =0
Return the semi-axis of the ellipse along z in mm.
virtual double ZTopCut() const =0
Return the z top cut in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double XSemiAxis() const =0
Return the semi-axis of the ellipse along x in mm.
virtual double YSemiAxis() const =0
Return the semi-axis of the ellipse along y in mm.
The VGM interface to elliptical tube solids.
virtual double Dx() const =0
Return the semi-axis of the ellipse along x in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double Dy() const =0
Return the semi-axis of the ellipse along y in mm.
The VGM interface to extruded solids.
virtual std::string Name() const =0
Return the name of this solid.
virtual TwoVector Offset(int iz) const =0
Return the polygon offset in iz-th side.
virtual int NofZSections() const =0
Return the number of planes perpendicular to the z axis.
virtual double ZPosition(int iz) const =0
Return the z position of the iz-th plane in mm.
virtual int NofVertices() const =0
Return the number of vertices of outline polygon.
virtual TwoVector Vertex(int index) const =0
Return the index-th vertex of outline polygon.
virtual double Scale(int iz) const =0
Return the polygon scale in iz-th side.
The VGM interface to geometry factory providing functions for geometry construction and conversions.
Definition IFactory.h:50
virtual IVolume * CreateVolume(const std::string &name, VGM::ISolid *solid, const std::string &mediumName)=0
Create the volume.
virtual ISolid * CreateTessellatedSolid(const std::string &name, std::vector< std::vector< VGM::ThreeVector > > facets)=0
Create tessellated solid = solid composed from triangular and rectangular facets.
virtual IMaterialFactory * MaterialFactory() const =0
Return the associated material factory.
virtual IPlacement * CreateMultiplePlacement(const std::string &name, VGM::IVolume *volume, VGM::IVolume *motherVolume, VGM::Axis axis, int nofItems, double width, double offset, double halfGap)=0
Create the multiple volume placement.
virtual ISolid * CreateScaledSolid(const std::string &name, VGM::ISolid *solid, const VGM::Transform &transform)=0
Create scaled solid.
virtual ISolid * CreateExtrudedSolid(const std::string &name, std::vector< TwoVector > polygon, std::vector< std::vector< double > > zsections)=0
Create the extruded solid.
virtual ISolid * CreateEllipsoid(const std::string &name, double dx, double dy, double dz, double zBottomCut, double zTopCut)=0
Create the ellipsoid solid.
virtual void SetSolid(VGM::ISolid *solid)=0
Set solid (in single mode)
virtual ISolid * CreateParaboloid(const std::string &name, double r1, double r2, double hz)=0
Create the paraboloid solid.
virtual IPlacement * CreatePlacement(const std::string &name, int copyNo, VGM::IVolume *volume, VGM::IVolume *motherVolume, const VGM::Transform &transform)=0
Create the simple volume placement.
virtual ISolid * CreateTorus(const std::string &name, double rin, double rout, double rax, double sphi, double dphi)=0
Create the torus solid = phi segment of a torus.
virtual ISolid * CreateCtubs(const std::string &name, double rin, double rout, double hz, double sphi, double dphi, double nxlow, double nylow, double nzlow, double nxhigh, double nyhigh, double nzhigh)=0
Create the cut tubs solid = phi segment of a tube cut with two planes.
virtual ISolid * CreateSphere(const std::string &name, double rin, double rout, double sphi, double dphi, double stheta, double dtheta)=0
Create the sphere solid = phi segment of a spherical shell.
virtual ISolid * CreatePolycone(const std::string &name, double sphi, double dphi, int nofZplanes, double *z, double *rin, double *rout)=0
Create the polycone solid = phi segment of a polycone.
virtual ISolid * CreateSubtractionSolid(const std::string &name, VGM::ISolid *solidA, VGM::ISolid *solidB, const VGM::Transform &transform)=0
Create the subtraction of two solids.
virtual ISolid * CreatePara(const std::string &name, double hx, double hy, double hz, double alpha, double theta, double phi)=0
Create the para solid = parallelepiped.
virtual ISolid * CreateTubs(const std::string &name, double rin, double rout, double hz, double sphi, double dphi)=0
Create the trd solid = phi segment of a tube.
virtual ISolid * CreateIntersectionSolid(const std::string &name, VGM::ISolid *solidA, VGM::ISolid *solidB, const VGM::Transform &transform)=0
Create the intersection of two solids.
virtual ISolid * CreatePolyhedra(const std::string &name, double sphi, double dphi, int nofSides, int nofZplanes, double *z, double *rin, double *rout)=0
Create the polyhedra solid = phi segment of a polyhedra (polygone)
virtual VGM::IPlacement * CreateParameterisedPlacement(const std::string &name, VGM::IVolume *motherVolume, const std::vector< VGM::Transform > &transforms, const std::vector< VGM::IVolume * > &volumes)=0
Create the parameterised volume placement.
virtual ISolid * CreateTrd(const std::string &name, double hx1, double hx2, double hy1, double hy2, double hz)=0
Create the trd solid = a trapezoid with the x and y dimensions varying along z.
virtual void SetSingleMode(bool value)=0
Set single mode option.
virtual ISolid * CreateTrap(const std::string &name, double hz, double theta, double phi, double dy1, double dx1, double dx2, double alpha1, double dy2, double dx3, double dx4, double alpha2)=0
Create the trap solid = general trapezoid ( Note that of the 11 parameters described below,...
virtual ISolid * CreateUnionSolid(const std::string &name, VGM::ISolid *solidA, VGM::ISolid *solidB, const VGM::Transform &transform)=0
Create the union of two solids.
virtual ISolid * CreateMultiUnion(const std::string &name, std::vector< VGM::ISolid * > constituents, std::vector< VGM::Transform > transforms)=0
Create the multi union of solids.
virtual ISolid * CreateDisplacedSolid(const std::string &name, VGM::ISolid *solid, const VGM::Transform &transform)=0
Create displaced solid.
virtual ISolid * CreateBox(const std::string &name, double hx, double hy, double hz)=0
Create the box solid.
virtual ISolid * CreateEllipticalTube(const std::string &name, double dx, double dy, double hz)=0
Create the elliptical tube solid.
virtual ISolid * CreateArb8(const std::string &name, double hz, std::vector< VGM::TwoVector > vertices)=0
Create the arbitrary trapezoid with 8 vertices standing on two paralel planes perpendicular to Z axis...
virtual ISolid * CreateHype(const std::string &name, double r1, double r2, double stereo1, double stereo2, double hz)=0
Create the hyperboloid solid.
virtual ISolid * CreateCons(const std::string &name, double rin1, double rout1, double rin2, double rout2, double hz, double sphi, double dphi)=0
Create the cons solid = phi segment of a conical tube.
The VGM interface to hyperboloid solids.
Definition IHype.h:30
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double OuterStereoAngle() const =0
Return the inner stereo angle.
virtual double OuterRadius() const =0
Return the outer radius in mm.
virtual double InnerStereoAngle() const =0
Return the inner stereo angle.
virtual std::string Name() const =0
Return the name of this solid.
virtual double InnerRadius() const =0
Return the inner radius in mm.
The VGM interface to material factory providing functions for material conversions.
The VGM interface to Boolean solids.
Definition IMultiUnion.h:31
virtual std::string Name() const =0
Return the name of this solid.
virtual Transform Transformation(int index) const =0
Return the displacement of the ith constituent solid.
virtual int NofSolids() const =0
Return the number of constituent solids.
virtual ISolid * ConstituentSolid(int index) const =0
Return the i-th constituent solid.
The VGM interface to para solids.
Definition IPara.h:30
virtual std::string Name() const =0
Return the name of this solid.
virtual double Alpha() const =0
Return angle formed by the y axis and by the plane joining the centre of the faces parallel to the z-...
virtual double Theta() const =0
Return polar angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double YHalfLength() const =0
Return half-length along the y axis in mm.
virtual double ZHalfLength() const =0
Return half-length along the z axis in mm.
virtual double XHalfLength() const =0
Return half-length along the x axis in mm.
virtual double Phi() const =0
Return azimuthal angle of the line joining the centres of the faces at -hz and +hz in deg.
The VGM interface to paraboloid solids.
Definition IParaboloid.h:30
virtual double RadiusMinusZ() const =0
Return the radius at -z in mm.
virtual double RadiusPlusZ() const =0
Return the radius at +z in mm.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to positions of volumes.
Definition IPlacement.h:44
virtual PlacementType Type() const =0
Return the type of this placement.
virtual Transform Transformation() const =0
Return the 3D transformation (if simple placement)
virtual bool MultiplePlacementData(VGM::Axis &axis, int &nofItems, double &width, double &offset, double &halfGap) const =0
Fill the multiple placement data if relevant and return true; return false if not multiple placement.
virtual bool ParameterisedPlacementData(std::vector< VGM::Transform > &transforms, std::vector< VGM::IVolume * > &volumes) const =0
Fill the parameterised placement data if relevant and return true; return false if not parameterised ...
virtual int CopyNo() const =0
Return the copy number of this placement.
virtual std::string Name() const =0
Return the name of this placement.
virtual IVolume * Volume() const =0
Return the associated volume.
virtual IVolume * Mother() const =0
Return the associated mother volume.
The VGM interface to polycone solids.
Definition IPolycone.h:30
virtual double StartPhi() const =0
Return starting phi angle of the segment in deg.
virtual int NofZPlanes() const =0
Return number of planes perpendicular to the z axis.
virtual double * ZValues() const =0
Return the array of z positions of the planes in mm.
virtual double DeltaPhi() const =0
Return opening phi angle of the segment in deg.
virtual double * InnerRadiusValues() const =0
Return the array of inner radius of the planes in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double * OuterRadiusValues() const =0
Return the array of outer radius of the planes in mm.
The VGM interface to polyhedra solids.
Definition IPolyhedra.h:30
virtual std::string Name() const =0
Return the name of this solid.
virtual double * OuterRadiusValues() const =0
Return the array of outer radius of the planes in mm.
virtual int NofSides() const =0
Return number of sides of the cross section between the given phi limits.
virtual double StartPhi() const =0
Return starting phi angle of the segment in deg.
virtual double * InnerRadiusValues() const =0
Return the array of innner radius of the planes in mm.
virtual double * ZValues() const =0
Return the array of z positions of the planes in mm.
virtual double DeltaPhi() const =0
Return opening phi angle of the segment in deg.
virtual int NofZPlanes() const =0
Return number of planes perpendicular to the z axis.
The VGM interface to Boolean solids.
virtual bool ToBeReflected() const =0
Return true if the solid has to be first reflected before being placed.
virtual Transform Scale() const =0
Return the 3D scale.
virtual ISolid * ConstituentSolid() const =0
Return the constituent solid.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to solids.
Definition ISolid.h:58
virtual SolidType Type() const =0
Return the type of this solid.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to sphere solids.
Definition ISphere.h:30
virtual double StartPhi() const =0
Return the starting azimuthal angle of the segment in deg.
virtual double DeltaPhi() const =0
Return the opening azimuthal angle of the segment in deg.
virtual double StartTheta() const =0
Return the starting polar angle of the segment in deg.
virtual double DeltaTheta() const =0
Return the opening polar angle of the segment in deg.
virtual std::string Name() const =0
Return the name of this solid.
virtual double OuterRadius() const =0
Return the outside radius of the shell in mm.
virtual double InnerRadius() const =0
Return the inside radius of the shell in mm.
The VGM interface to extruded solids.
virtual int NofVertices(int ifacet) const =0
Return the number of vertices in the the ifacet-th facet.
virtual ThreeVector Vertex(int ifacet, int index) const =0
Return the index-th vertex in the ifacet-th facet.
virtual std::string Name() const =0
Return the name of this solid.
virtual int NofFacets() const =0
Return the number of facets.
The VGM interface to torus solids.
Definition ITorus.h:30
virtual double OuterRadius() const =0
Return the outside radius of the torus in mm.
virtual double StartPhi() const =0
Return the starting phi angle of the segment in deg (with 0 being the +x axis)
virtual double AxialRadius() const =0
Return the axial (swept) radius of the torus in mm.
virtual double DeltaPhi() const =0
Return the opening phi angle of the segment in deg.
virtual double InnerRadius() const =0
Return the inside radius of the torus in mm.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to trap solids.
Definition ITrap.h:30
virtual double Phi() const =0
Return the azimuthal angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double XHalfLengthPlusZMinusY() const =0
Return the half-length along x of the side at -hy of the face at +hz in m.
virtual double AlphaPlusZ() const =0
Return the angle with respect to the y axis from the centre of the side at -hy to the centre at +hy o...
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLengthMinusZ() const =0
Return the half-length along y of the face at -hz in mm.
virtual double XHalfLengthMinusZMinusY() const =0
Return the half-length along x of the side at -hy of the face at -hz in mm.
virtual double YHalfLengthPlusZ() const =0
Return the half-length along y of the face at +hz in m.
virtual double XHalfLengthPlusZPlusY() const =0
Return the half-length along x of the side at +hy of the face at +hz in m.
virtual double Theta() const =0
Return the polar angle of the line joining the centres of the faces at -hz and +hz in deg.
virtual double AlphaMinusZ() const =0
Return the angle with respect to the y axis from the centre of the side at -hy to the centre at +hy o...
virtual double XHalfLengthMinusZPlusY() const =0
Return the half-length along x of the side at +hy of the face at +hz in mm.
virtual std::string Name() const =0
Return the name of this solid.
The VGM interface to trd solids.
Definition ITrd.h:30
virtual double XHalfLengthPlusZ() const =0
Return the half-length along x at the surface positioned at +hz in mm.
virtual double YHalfLengthPlusZ() const =0
Return thehalf-length along y at the surface positioned at +hz in mm.
virtual double XHalfLengthMinusZ() const =0
Return the half-length along x at the surface positioned at -hz in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double ZHalfLength() const =0
Return the half-length along the z axis in mm.
virtual double YHalfLengthMinusZ() const =0
Return the half-length along y at the surface positioned at -hz in mm.
The VGM interface to tubs solids.
Definition ITubs.h:30
virtual double ZHalfLength() const =0
Return the half-length along the z axis in m.
virtual double StartPhi() const =0
Return the starting angle of the segment in deg.
virtual double DeltaPhi() const =0
Return the opening angle of the segment in deg.
virtual double InnerRadius() const =0
Return the inside radius in mm.
virtual std::string Name() const =0
Return the name of this solid.
virtual double OuterRadius() const =0
Return the outside radius in mm.
The VGM interface to volumes.
Definition IVolume.h:32
virtual ISolid * Solid() const =0
Return the associated solid.
virtual std::string MaterialName() const =0
Return the name of the associated material.
virtual std::string Name() const =0
Return the name of this volume.
virtual std::string MediumName() const =0
Return the name of the associated medium.
#define VGM_RELEASE
BaseVGM version.
Definition version.h:21
void DebugInfo()
Debug printing.
Definition utilities.cxx:27
VGM::Transform Identity()
Definition transform.cxx:98
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40
@ kIntersection
@ kSubtraction
std::vector< IVolume * > VolumeStore
Definition IFactory.h:43
@ kUnknownAxis
Definition Axis.h:42
@ kSize
Definition Transform.h:51
@ kReflZ
Definition Transform.h:50
std::vector< ISolid * > SolidStore
Definition IFactory.h:42
@ kParameterised
Definition IPlacement.h:35
@ kSimplePlacement
Definition IPlacement.h:33
@ kMultiplePlacement
Definition IPlacement.h:34
SolidType
Definition ISolid.h:29
@ kTessellated
Definition ISolid.h:43
@ kEllipsoid
Definition ISolid.h:34
@ kScaled
Definition ISolid.h:51
@ kTorus
Definition ISolid.h:44
@ kTrd
Definition ISolid.h:46
@ kCons
Definition ISolid.h:32
@ kTubs
Definition ISolid.h:47
@ kExtruded
Definition ISolid.h:36
@ kPara
Definition ISolid.h:38
@ kSphere
Definition ISolid.h:42
@ kPolycone
Definition ISolid.h:40
@ kTrap
Definition ISolid.h:45
@ kMultiUnion
Definition ISolid.h:50
@ kPolyhedra
Definition ISolid.h:41
@ kEltu
Definition ISolid.h:35
@ kParaboloid
Definition ISolid.h:39
@ kHype
Definition ISolid.h:37
@ kBoolean
Definition ISolid.h:48
@ kArb8
Definition ISolid.h:30
@ kCtubs
Definition ISolid.h:33
@ kBox
Definition ISolid.h:31
@ kDisplaced
Definition ISolid.h:49
#define VGM_RELEASE_DATE
Definition version.h:22