47 fFileName(fgkUndefinedFileName),
50 fMaps(writer->GetNumPrecision(), writer->AngleUnit(), writer->LengthUnit())
61 fFileName(fgkUndefinedFileName),
68 std::cerr <<
" XmlVGM::VExporter::VExporter:" << std::endl;
69 std::cerr <<
" Not allowed constructor." << std::endl;
70 std::cerr <<
"*** Error: Aborting execution +++" << std::endl;
77 fFileName(fgkUndefinedFileName),
84 std::cerr <<
" XmlVGM::VExporter::VExporter:" << std::endl;
85 std::cerr <<
" Copy constructor not implemented." << std::endl;
86 std::cerr <<
"** Exception: Aborting execution **" << std::endl;
107 if (
this == &right)
return *
this;
109 std::cerr <<
" XmlVGM::VExporter::operator=:" << std::endl;
110 std::cerr <<
" Assignement operator not implemented." << std::endl;
111 std::cerr <<
"** Exception: Aborting execution **" << std::endl;
122void XmlVGM::VExporter::ProcessPositions(
VGM::IVolume* volume)
126 std::string volumeName = volume->
Name();
129 fVolumeNames.insert(fVolumeNames.begin(), volumeName);
133 if (nofDaughters > 0) {
134 for (
int i = 0; i < nofDaughters; i++) {
142 std::string name = fMaps.AddPosition(transform);
144 if (name !=
"") fWriter->WritePosition(name, transform);
152 std::vector<VGM::Transform> transforms;
153 std::vector<VGM::IVolume*> volumes;
157 for (
size_t i=0; i<transforms.size(); ++i) {
158 auto transform = transforms[i];
159 std::string name = fMaps.AddPosition(transform);
160 if (name !=
"") fWriter->WritePosition(name, transform);
169 ProcessPositionsInTessellated(dSolid);
176 ProcessPositionsInMultiUnion(dSolid);
188 std::string dVolumeName = dPlacement->
Volume()->
Name();
189 if (fVolumeNames.find(dVolumeName) == fVolumeNames.end()) {
191 ProcessPositions(dPlacement->
Volume());
198void XmlVGM::VExporter::ProcessPositionsInBoolean(
VGM::ISolid* solid)
208 std::string name = fMaps.AddPosition(transform);
222void XmlVGM::VExporter::ProcessPositionsInTessellated(
VGM::ISolid* solid)
232 for (
int i = 0; i < tessellatedSolid->
NofFacets(); ++i) {
233 for (
int j = 0; j < tessellatedSolid->
NofVertices(i); ++j) {
236 std::string name = fMaps.AddPosition(vertex);
238 if (name !=
"") fWriter->WritePosition(name, vertex);
244void XmlVGM::VExporter::ProcessPositionsInMultiUnion(
VGM::ISolid* solid)
252 for (
int i = 0; i < multiUnion->
NofSolids(); ++i) {
253 std::string posName = fMaps.AddPosition(multiUnion->
Transformation(i));
260void XmlVGM::VExporter::ProcessRotations(
VGM::IVolume* volume)
265 std::string volumeName = volume->
Name();
268 fVolumeNames.insert(fVolumeNames.begin(), volumeName);
272 if (nofDaughters > 0) {
273 for (
int i = 0; i < nofDaughters; i++) {
281 std::string name = fMaps.AddRotation(transform);
283 if (name !=
"") fWriter->WriteRotation(name, transform);
288 std::vector<VGM::Transform> transforms;
289 std::vector<VGM::IVolume*> volumes;
292 for (
auto transform : transforms) {
293 std::string name = fMaps.AddRotation(transform);
294 if (name !=
"") fWriter->WriteRotation(name, transform);
312 ProcessRotationsInMultiUnion(dSolid);
315 std::string dVolumeName = dPlacement->
Volume()->
Name();
316 if (fVolumeNames.find(dVolumeName) == fVolumeNames.end()) {
318 ProcessRotations(dPlacement->
Volume());
325void XmlVGM::VExporter::ProcessRotationsInBoolean(
VGM::ISolid* solid)
335 std::string name = fMaps.AddRotation(transform);
349void XmlVGM::VExporter::ProcessRotationsInMultiUnion(
VGM::ISolid* solid)
357 for (
int i = 0; i < multiUnion->
NofSolids(); ++i) {
358 std::string rotName = fMaps.AddRotation(multiUnion->
Transformation(i));
365void XmlVGM::VExporter::ProcessMaterials(
VGM::IVolume* volume)
369 std::string volumeName = volume->
Name();
373 fFactory->MaterialFactory()->Material(volume->
MaterialName());
375 if (!volumeMaterial) {
376 std::cerr <<
"XmlVGM::VExporter::ProcessMaterials: " << std::endl;
377 std::cerr <<
" Material " << volume->
MaterialName() <<
"not found."
382 const VGM::IMaterial* material = fMaps.AddMaterial(volumeMaterial);
386 for (
int j = 0; j < int(material->
NofElements()); j++) {
388 fMaps.AddElement(element);
391 for (
int k = 0; k < int(element->
NofIsotopes()); k++)
392 fMaps.AddIsotope(element->
Isotope(k));
397 fVolumeNames.insert(fVolumeNames.begin(), volumeName);
401 if (nofDaughters > 0) {
402 for (
int i = 0; i < nofDaughters; i++) {
406 std::string dVolumeName = dPlacement->
Volume()->
Name();
407 if (fVolumeNames.find(dVolumeName) == fVolumeNames.end()) {
409 ProcessMaterials(dPlacement->
Volume());
416void XmlVGM::VExporter::ProcessMedia(
VGM::IVolume* volume)
420 std::string volumeName = volume->
Name();
424 fFactory->MaterialFactory()->Medium(volume->
MediumName());
427 std::cerr <<
"XmlVGM::VExporter::ProcessMedia: " << std::endl;
428 std::cerr <<
" Medium " << volume->
MediumName() <<
" not found."
433 fMaps.AddMedium(volumeMedium);
436 fVolumeNames.insert(fVolumeNames.begin(), volumeName);
440 if (nofDaughters > 0) {
441 for (
int i = 0; i < nofDaughters; i++) {
445 std::string dVolumeName = dPlacement->
Volume()->
Name();
446 if (fVolumeNames.find(dVolumeName) == fVolumeNames.end()) {
448 ProcessMedia(dPlacement->
Volume());
455void XmlVGM::VExporter::ProcessSolids(
VGM::IVolume* volume)
460 std::string volumeName = volume->
Name();
461 std::string mediumName = volume->
MediumName();
462 fWriter->WriteSolid(volumeName, solid, mediumName);
465 fVolumeNames.insert(fVolumeNames.begin(), volumeName);
469 if (nofDaughters > 0) {
470 for (
int i = 0; i < nofDaughters; i++) {
473 std::cout <<
"processing " << i <<
"th daughter of " << volume->
Name()
478 std::string dVolumeName = dVolume->
Name();
480 if (fVolumeNames.find(dVolumeName) == fVolumeNames.end()) {
482 ProcessSolids(dVolume);
487 std::vector<VGM::Transform> transforms;
488 std::vector<VGM::IVolume*> volumes;
491 for (
size_t i=0; i<volumes.size(); ++i) {
492 std::string iVolumeName = volumes[i]->Name();
493 if (fVolumeNames.find(iVolumeName) == fVolumeNames.end()) {
494 ProcessSolids(volumes[i]);
513 fWriter->OpenPositions();
520 ProcessPositions(volume);
524 fWriter->ClosePositions();
525 fWriter->WriteEmptyLine();
535 fWriter->OpenRotations();
542 ProcessRotations(volume);
546 fWriter->WriteEmptyLine();
547 std::string name0 =
"scale_0";
548 fWriter->WriteScale(name0);
551 fWriter->CloseRotations();
552 fWriter->WriteEmptyLine();
562 fWriter->OpenMaterials();
565 ProcessMaterials(volume);
568 fMaps.WriteAllIsotopes(fWriter);
571 fWriter->WriteEmptyLine();
574 fMaps.WriteAllElements(fWriter);
577 fWriter->WriteEmptyLine();
580 fMaps.WriteAllMaterials(fWriter);
582 fWriter->WriteEmptyLine();
586 fWriter->CloseMaterials();
587 fWriter->WriteEmptyLine();
597 fWriter->OpenMedia();
599 if (fFactory->MaterialFactory()->Media().size() > 0) {
601 ProcessMedia(volume);
604 fMaps.WriteAllMedia(fWriter);
608 fMaps.WriteAllMediaFromMaterials(fWriter);
612 fWriter->WriteEmptyLine();
616 fWriter->CloseMedia();
617 fWriter->WriteEmptyLine();
626 fWriter->OpenSolids();
627 ProcessSolids(volume);
628 fWriter->CloseSolids();
629 fWriter->WriteEmptyLine();
638 fVolumeNames.erase(fVolumeNames.begin(), fVolumeNames.end());
650 GenerateGeometry(fFactory->Top()->Volume());
661 for (
unsigned int i = 0; i < volumeStore.size(); i++) {
663 if (volume->
Name() == volumeName) {
666 GenerateGeometry(volume);
669 fMaps.ClearAllMaps();
675 std::cerr <<
"++ Warning: ++ " << std::endl;
676 std::cerr <<
" XmlVGM::VExporter::GenerateXMLGeometry:" << std::endl;
677 std::cerr <<
" Logical volume " << volumeName <<
" does not exist."
686 fWriter->SetNumWidth(width);
694 fWriter->SetNumPrecision(precision);
695 fMaps.SetNumPrecision(precision);
The VGM interface to Boolean solids.
virtual ISolid * ConstituentSolidB() const =0
Return the second constituent solid.
virtual ISolid * ConstituentSolidA() const =0
Return the first constituent 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 elements.
virtual IIsotope * Isotope(int i) const =0
Return the i-th isotope constituing this element.
virtual int NofIsotopes() const =0
Return the number of isotopes constituing this element.
The VGM interface to geometry factory providing functions for geometry construction and conversions.
The VGM interface to materials.
virtual IElement * Element(int iel) const =0
Return the i-th element constituing this material.
virtual int NofElements() const =0
Return the number of elements constituing this material.
The VGM interface to tracking medium.
The VGM interface to Boolean solids.
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.
The VGM interface to positions of volumes.
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 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 IVolume * Volume() const =0
Return the associated volume.
The VGM interface to solids.
virtual SolidType Type() const =0
Return the type of this solid.
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 int NofFacets() const =0
Return the number of facets.
The VGM interface to volumes.
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 IPlacement * Daughter(int i) const =0
Return the i-th daughter.
virtual std::string MediumName() const =0
Return the name of the associated medium.
virtual int NofDaughters() const =0
Return the number of volume daughters.
The interface for the XML writer that writes VGM geometry objects to XML:
Class for generation of geometry data files in XML, the XML format is independent from the geometry o...
void GenerateXMLGeometry()
void GenerateMedia(VGM::IVolume *volume)
void GeneratePositions(VGM::IVolume *volume)
void SetNumPrecision(int precision)
void GenerateMaterials(VGM::IVolume *volume)
void SetNumWidth(int width)
VExporter & operator=(const VExporter &)
void GenerateRotations(VGM::IVolume *volume)
void GenerateSolids(VGM::IVolume *volume)
static const std::string fgkUndefinedFileName
VGM::Transform Identity()
std::vector< double > Transform
std::vector< IVolume * > VolumeStore
std::vector< double > ThreeVector