49 #include "HepPolyhedronProcessor.h"
60 ,
G4int requestedDepth
64 :
G4VModel (modelTransformation, pMP)
67 , fRequestedDepth (requestedDepth)
68 , fUseFullExtent (useFullExtent)
72 , fpCurrentMaterial (0)
73 , fpCurrentTransform (0)
75 , fCurtailDescent (
false)
77 , fClippingMode (subtraction)
79 fType =
"G4PhysicalVolumeModel";
94 fGlobalDescription =
"G4PhysicalVolumeModel " + fGlobalTag;
98 fTopPVName = fpTopPV -> GetName ();
99 fTopPVCopyNo = fpTopPV -> GetCopyNo ();
100 std::ostringstream o;
101 o << fpTopPV -> GetCopyNo ();
102 fGlobalTag = fpTopPV -> GetName () +
"." + o.str();
103 fGlobalDescription =
"G4PhysicalVolumeModel " + fGlobalTag;
105 fpCurrentPV = fpTopPV;
106 if (fpCurrentPV) fpCurrentLV = fpCurrentPV->GetLogicalVolume();
107 if (fpCurrentLV) fpCurrentMaterial = fpCurrentLV->GetMaterial();
108 fpCurrentTransform =
const_cast<G4Transform3D*
>(&modelTransformation);
162 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
166 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
174 VisitGeometryAndGetVisReps
177 startingTransformation,
184 fpCurrentMaterial = 0;
185 if (fFullPVPath.size() != fBaseFullPVPath.size()) {
188 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
191 "Path at start of modeling not equal to base path. Something badly"
192 "\nwrong. Please contact visualisation coordinator.");
194 fDrawnPVPath.clear();
196 fCurtailDescent =
false;
202 std::ostringstream o;
207 return "WARNING: NO CURRENT VOLUME - global tag is " +
fGlobalTag;
218 G4int requestedDepth,
235 if (!(pVPV -> IsReplicated ())) {
237 pSol = pLV -> GetSolid ();
238 pMaterial = pLV -> GetMaterial ();
239 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
240 theAT, sceneHandler);
249 pVPV -> GetReplicationData (axis, nReplicas, width, offset, consuming);
250 if (fCurrentDepth == 0) nReplicas = 1;
253 for (
int n = 0;
n < nReplicas;
n++) {
254 pSol = pP -> ComputeSolid (
n, pVPV);
255 pP -> ComputeTransformation (
n, pVPV);
256 pSol -> ComputeDimensions (pP,
n, pVPV);
257 pVPV -> SetCopyNo (
n);
262 pMaterial = pP -> ComputeMaterial (
n, pVPV, &parentTouchable);
263 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
264 theAT, sceneHandler);
289 pSol = pLV -> GetSolid ();
290 pMaterial = pLV -> GetMaterial ();
291 G4ThreeVector originalTranslation = pVPV -> GetTranslation ();
293 G4double originalRMin = 0., originalRMax = 0.;
295 originalRMin = ((
G4Tubs*)pSol)->GetInnerRadius();
296 originalRMax = ((
G4Tubs*)pSol)->GetOuterRadius();
298 G4bool visualisable =
true;
299 for (
int n = 0;
n < nReplicas;
n++) {
306 translation =
G4ThreeVector (-width*(nReplicas-1)*0.5+
n*width,0,0);
309 translation =
G4ThreeVector (0,-width*(nReplicas-1)*0.5+
n*width,0);
312 translation =
G4ThreeVector (0,0,-width*(nReplicas-1)*0.5+
n*width);
316 ((
G4Tubs*)pSol)->SetInnerRadius(width*
n+offset);
317 ((
G4Tubs*)pSol)->SetOuterRadius(width*(
n+1)+offset);
319 if (fpMP->IsWarning())
321 "G4PhysicalVolumeModel::VisitGeometryAndGetVisReps: WARNING:"
322 "\n built-in replicated volumes replicated in radius for "
324 "-type\n solids (your solid \""
326 "\") are not visualisable."
328 visualisable =
false;
332 rotation.rotateZ (-(offset+(
n+0.5)*width));
335 pRotation = &rotation;
338 pVPV -> SetTranslation (translation);
339 pVPV -> SetRotation (pRotation);
340 pVPV -> SetCopyNo (
n);
342 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
343 theAT, sceneHandler);
347 pVPV -> SetTranslation (originalTranslation);
348 pVPV -> SetRotation (pOriginalRotation);
350 ((
G4Tubs*)pSol)->SetInnerRadius(originalRMin);
351 ((
G4Tubs*)pSol)->SetOuterRadius(originalRMax);
359 G4int requestedDepth,
369 fpCurrentMaterial = pMaterial;
372 const G4ThreeVector& translation = pVPV -> GetTranslation ();
383 if (fCurrentDepth != 0) theNewAT = theAT * theLT;
384 fpCurrentTransform = &theNewAT;
387 if (!pVisAttribs) pVisAttribs = fpMP->GetDefaultVisAttributes();
389 G4bool visAttsCreated =
false;
392 visAttsCreated =
true;
397 G4bool thisToBeDrawn =
true;
400 G4int copyNo = fpCurrentPV->GetCopyNo();
401 fFullPVPath.push_back
403 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform));
406 G4bool copyForVAM =
false;
411 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
412 fpMP->GetVisAttributesModifiers();
413 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
415 for (iModifier = vams.begin();
416 iModifier != vams.end();
419 iModifier->GetPVNameCopyNoPath();
420 if (vamPath.size() == fFullPVPath.size()) {
424 std::vector<G4PhysicalVolumeNodeID>::const_iterator iPVNodeId;
425 for (iVAMNameCopyNo = vamPath.begin(), iPVNodeId = fFullPVPath.begin();
426 iVAMNameCopyNo != vamPath.end();
427 ++iVAMNameCopyNo, ++iPVNodeId) {
435 iVAMNameCopyNo->GetName() ==
436 iPVNodeId->GetPhysicalVolume()->GetName() &&
437 iVAMNameCopyNo->GetCopyNo() ==
438 iPVNodeId->GetPhysicalVolume()->GetCopyNo()
443 if (iVAMNameCopyNo == vamPath.end()) {
447 pVisAttribs = pModifiedVisAtts;
451 switch (iModifier->GetVisAttributesSignifier()) {
497 G4bool culling = fpMP->IsCulling();
498 G4bool cullingInvisible = fpMP->IsCullingInvisible();
500 G4bool cullingLowDensity = fpMP->IsDensityCulling();
502 G4double densityCut = fpMP -> GetVisibleDensity ();
507 if (cullingInvisible) {
509 if (!markedVisible) thisToBeDrawn =
false;
512 if (cullingLowDensity) {
514 if (density < densityCut) thisToBeDrawn =
false;
518 if (fAbort) thisToBeDrawn =
false;
521 fFullPVPath.back().SetDrawn(thisToBeDrawn);
526 fDrawnPVPath.push_back
528 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform,thisToBeDrawn));
530 if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) {
537 centred.getDecomposition(oldScale, oldRotation, oldTranslation);
538 G4double explodeFactor = fpMP->GetExplodeFactor();
541 explodeFactor * oldTranslation.dy(),
542 explodeFactor * oldTranslation.dz());
543 theNewAT = centering * newTranslation * oldRotation * oldScale;
546 DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler);
555 G4bool daughtersToBeDrawn =
true;
557 if (!nDaughters) daughtersToBeDrawn =
false;
559 else if (requestedDepth == 0) daughtersToBeDrawn =
false;
561 else if (fAbort) daughtersToBeDrawn =
false;
563 else if (fCurtailDescent) daughtersToBeDrawn =
false;
571 G4bool cullingCovered = fpMP->IsCullingCovered();
586 if (cullingInvisible) {
588 if (daughtersInvisible) daughtersToBeDrawn =
false;
591 if (cullingCovered) {
593 if (surfaceDrawing) {
597 if (opaque) daughtersToBeDrawn =
false;
606 delete pModifiedVisAtts;
607 pVisAttribs = pUnmodifiedVisAtts;
612 if (visAttsCreated)
delete pVisAttribs;
614 if (daughtersToBeDrawn) {
615 for (
G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
620 VisitGeometryAndGetVisReps
621 (pDaughterVPV, requestedDepth - 1, theNewAT, sceneHandler);
627 fCurtailDescent =
false;
630 fFullPVPath.pop_back();
632 fDrawnPVPath.pop_back();
644 G4VSolid* pSectionSolid = fpMP->GetSectionSolid();
645 G4VSolid* pCutawaySolid = fpMP->GetCutawaySolid();
647 if (!fpClippingSolid && !pSectionSolid && !pCutawaySolid) {
649 pSol -> DescribeYourselfTo (sceneHandler);
657 G4Polyhedron::SetNumberOfRotationSteps
660 G4Polyhedron::SetNumberOfRotationSteps(fpMP->GetNoOfSides());
662 G4Polyhedron::ResetNumberOfRotationSteps();
666 if (fpMP->IsWarning())
668 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \""
670 "\" has no polyhedron. Cannot by clipped."
672 pSol -> DescribeYourselfTo (sceneHandler);
680 if (fpClippingSolid) {
681 switch (fClippingMode) {
685 (
"resultant_solid", pSol, fpClippingSolid, theAT.inverse());
689 (
"resultant_solid", pSol, fpClippingSolid, theAT.inverse());
696 (
"sectioned_solid", pSol, pSectionSolid, theAT.inverse());
701 (
"cutaway_solid", pSol, pCutawaySolid, theAT.inverse());
705 if (tmpResultant) resultant = *tmpResultant;
707 if (fpMP->IsWarning())
709 "WARNING: G4PhysicalVolumeModel::DescribeSolid: resultant polyhedron for"
710 "\n solid \"" << pSol->
GetName() <<
711 "\" not defined due to error during Boolean processing."
712 "\n Original will be drawn in red."
717 delete resultantSolid;
734 size_t nWorlds = transportationManager->
GetNoWorlds();
738 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
740 for (
size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
754 if (foundVolume !=
fpTopPV && warn) {
756 "G4PhysicalVolumeModel::Validate(): A volume of the same name and"
759 <<
") still exists and is being used."
760 "\n But it is not the same volume you originally specified"
761 "\n in /vis/scene/add/."
769 if (found)
return true;
773 "G4PhysicalVolumeModel::Validate(): No volume of name and"
786 std::map<G4String,G4AttDef>* store
790 G4AttDef(
"PVPath",
"Physical Volume Path",
"Physics",
"",
"G4String");
792 G4AttDef(
"LVol",
"Logical Volume",
"Physics",
"",
"G4String");
794 G4AttDef(
"Solid",
"Solid Name",
"Physics",
"",
"G4String");
796 G4AttDef(
"EType",
"Entity Type",
"Physics",
"",
"G4String");
798 G4AttDef(
"DmpSol",
"Dump of Solid properties",
"Physics",
"",
"G4String");
800 G4AttDef(
"Trans",
"Transformation of volume",
"Physics",
"",
"G4String");
801 (*store)[
"Material"] =
802 G4AttDef(
"Material",
"Material Name",
"Physics",
"",
"G4String");
803 (*store)[
"Density"] =
804 G4AttDef(
"Density",
"Material Density",
"Physics",
"G4BestUnit",
"G4double");
806 G4AttDef(
"State",
"Material State (enum undefined,solid,liquid,gas)",
"Physics",
"",
"G4String");
808 G4AttDef(
"Radlen",
"Material Radiation Length",
"Physics",
"G4BestUnit",
"G4double");
810 G4AttDef(
"Region",
"Cuts Region",
"Physics",
"",
"G4String");
811 (*store)[
"RootRegion"] =
812 G4AttDef(
"RootRegion",
"Root Region (0/1 = false/true)",
"Physics",
"",
"G4bool");
826 t.getDecomposition(sc, r, tl);
831 o << setw(w) << t.xx() << setw(w) << t.xy() << setw(w) << t.xz() << setw(w) << t.dx() << endl;
832 o << setw(w) << t.yx() << setw(w) << t.yy() << setw(w) << t.yz() << setw(w) << t.dy() << endl;
833 o << setw(w) << t.zx() << setw(w) << t.zy() << setw(w) << t.zz() << setw(w) << t.dz() << endl;
836 o <<
"= translation:" << endl;
837 o << setw(w) << tl.dx() << setw(w) << tl.dy() << setw(w) << tl.dz() << endl;
840 o <<
"* rotation:" << endl;
841 o << setw(w) << r.xx() << setw(w) << r.xy() << setw(w) << r.xz() << endl;
842 o << setw(w) << r.yx() << setw(w) << r.yy() << setw(w) << r.yz() << endl;
843 o << setw(w) << r.zx() << setw(w) << r.zy() << setw(w) << r.zz() << endl;
846 o <<
"* scale:" << endl;
847 o << setw(w) << sc.xx() << setw(w) << sc.yy() << setw(w) << sc.zz() << endl;
850 o <<
"Transformed axes:" << endl;
851 o <<
"x': " << r *
G4Vector3D(1., 0., 0.) << endl;
852 o <<
"y': " << r *
G4Vector3D(0., 1., 0.) << endl;
853 o <<
"z': " << r *
G4Vector3D(0., 0., 1.) << endl;
860 std::vector<G4AttValue>* values =
new std::vector<G4AttValue>;
861 std::ostringstream oss;
863 oss <<
fFullPVPath[i].GetPhysicalVolume()->GetName()
870 (
"G4PhysicalVolumeModel::CreateCurrentAttValues",
873 "Current logical volume not defined.");
877 values->push_back(
G4AttValue(
"PVPath", oss.str(),
""));
882 oss.str(
""); oss <<
'\n' << *pSol;
883 values->push_back(
G4AttValue(
"DmpSol", oss.str(),
""));
885 values->push_back(
G4AttValue(
"Trans", oss.str(),
""));
887 values->push_back(
G4AttValue(
"Material", matName,
""));
891 oss.str(
""); oss << matState;
892 values->push_back(
G4AttValue(
"State", oss.str(),
""));
897 values->push_back(
G4AttValue(
"Region", regionName,
""));
899 values->push_back(
G4AttValue(
"RootRegion", oss.str(),
""));
903 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<
906 if (fpPV <
right.fpPV)
return true;
907 if (fpPV ==
right.fpPV) {
908 if (fCopyNo <
right.fCopyNo)
return true;
909 if (fCopyNo ==
right.fCopyNo)
910 return fNonCulledDepth <
right.fNonCulledDepth;
915 std::ostream&
operator<<
921 <<
':' << node.GetCopyNo()
922 <<
'[' << node.GetNonCulledDepth() <<
']'
923 <<
':' << node.GetTransform();
924 if (!node.GetDrawn()) os <<
" Not "; os <<
"drawn";
932 (
const std::vector<G4PhysicalVolumeNodeID>& fullPVPath):
933 fFullPVPath(fullPVPath) {}
939 G4Exception(
"G4PhysicalVolumeModelTouchable::GetTranslation",
942 "Index out of range. Asking for non-existent depth");
945 tempTranslation =
fFullPVPath[i].GetTransform().getTranslation();
946 return tempTranslation;
953 G4Exception(
"G4PhysicalVolumeModelTouchable::GetRotation",
956 "Index out of range. Asking for non-existent depth");
959 tempRotation =
fFullPVPath[i].GetTransform().getRotation();
960 return &tempRotation;
967 G4Exception(
"G4PhysicalVolumeModelTouchable::GetVolume",
970 "Index out of range. Asking for non-existent depth");
979 G4Exception(
"G4PhysicalVolumeModelTouchable::GetSolid",
982 "Index out of range. Asking for non-existent depth");
984 return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
991 G4Exception(
"G4PhysicalVolumeModelTouchable::GetReplicaNumber",
994 "Index out of range. Asking for non-existent depth");
virtual void PostAddSolid()=0
virtual G4Polyhedron * GetPolyhedron() const
G4bool IsForceAuxEdgeVisible() const
void SetColour(const G4Colour &)
const G4String & GetName() const
G4double GetAlpha() const
void SetForceWireframe(G4bool)
const std::map< G4String, G4AttDef > * GetAttDefs() const
CLHEP::Hep3Vector G4ThreeVector
const std::vector< G4PhysicalVolumeNodeID > & fFullPVPath
const G4VisAttributes * GetDefaultVisAttributes() const
CLHEP::HepRotation G4RotationMatrix
G4double GetLineWidth() const
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
const G4String & GetName() const
void SetLineStyle(LineStyle)
void SetLineWidth(G4double)
void SetVisibility(G4bool)
const G4ThreeVector & GetTranslation(G4int depth) const
G4double GetDensity() const
const G4Colour & GetColour() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4int GetReplicaNumber(G4int depth) const
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
G4bool Validate(G4bool warn)
const G4Point3D & GetCentre() const
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
G4Region * GetRegion() const
G4Transform3D * fpCurrentTransform
void SetForceSolid(G4bool)
virtual G4GeometryType GetEntityType() const =0
const G4VisExtent & GetExtent() const
static std::ostream & operator<<(std::ostream &o, const G4Transform3D t)
void SetModelingParameters(const G4ModelingParameters *)
G4VPhysicalVolume * fpCurrentPV
LineStyle GetLineStyle() const
virtual ~G4PhysicalVolumeModel()
virtual void AddPrimitive(const G4Polyline &)=0
std::vector< G4PhysicalVolumeNodeID > fFullPVPath
G4GLOB_DLL std::ostream G4cout
G4VPhysicalVolume * GetVolume(G4int depth) const
const G4String & GetName() const
G4bool IsDaughtersInvisible() const
G4bool IsRootRegion() const
G4Material * fpCurrentMaterial
const G4VisAttributes * GetVisAttributes() const
G4LogicalVolume * fpCurrentLV
const G4ModelingParameters * fpMP
G4String GetCurrentDescription() const
virtual void DescribeSolid(const G4Transform3D &theAT, G4VSolid *pSol, const G4VisAttributes *pVisAttribs, G4VGraphicsScene &sceneHandler)
G4double GetRadlen() const
G4int GetNoDaughters() const
void SetForceAuxEdgeVisible(G4bool)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void SetVisAttributes(const G4VisAttributes *)
static G4TransportationManager * GetTransportationManager()
G4int GetForcedLineSegmentsPerCircle() const
G4VPhysicalVolume * fpTopPV
G4VSolid * fpClippingSolid
G4PhysicalVolumeModelTouchable(const std::vector< G4PhysicalVolumeNodeID > &fullPVPath)
std::vector< PVNameCopyNo > PVNameCopyNoPath
G4VSolid * GetSolid(G4int depth) const
std::vector< G4AttValue > * CreateCurrentAttValues() const
G4bool IsForceDrawingStyle() const
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &visAttribs)=0
G4VPhysicalVolume * GetFoundVolume() const
G4double GetRadius() const
G4String GetCurrentTag() const
size_t GetNoWorlds() const
G4PhysicalVolumeModel(G4VPhysicalVolume *=0, G4int requestedDepth=UNLIMITED, const G4Transform3D &modelTransformation=G4Transform3D(), const G4ModelingParameters *=0, G4bool useFullExtent=false)
virtual void EndPrimitives()=0
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
void VisitGeometryAndGetVisReps(G4VPhysicalVolume *, G4int requestedDepth, const G4Transform3D &, G4VGraphicsScene &)
void SetDefaultVisAttributes(const G4VisAttributes *pDefaultVisAttributes)
G4bool IsForceLineSegmentsPerCircle() const
void SetDaughtersInvisible(G4bool)
void DescribeAndDescend(G4VPhysicalVolume *, G4int requestedDepth, G4LogicalVolume *, G4VSolid *, G4Material *, const G4Transform3D &, G4VGraphicsScene &)
ForcedDrawingStyle GetForcedDrawingStyle() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
G4VSolid * GetSolid() const
const G4RotationMatrix * GetRotation(G4int depth) const
void SetForceLineSegmentsPerCircle(G4int nSegments)
void DescribeYourselfTo(G4VGraphicsScene &)