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();
392 pVisAttribs = &defaultVisAttribs;
398 G4bool thisToBeDrawn =
true;
401 G4int copyNo = fpCurrentPV->GetCopyNo();
402 fFullPVPath.push_back
404 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform));
407 const auto& vams = fpMP->GetVisAttributesModifiers();
410 for (
const auto& vam: vams) {
411 const auto& vamPath = vam.GetPVNameCopyNoPath();
412 if (vamPath.size() == fFullPVPath.size()) {
415 auto iVAMNameCopyNo = vamPath.begin();
416 auto iPVNodeId = fFullPVPath.begin();
417 for (; iVAMNameCopyNo != vamPath.end(); ++iVAMNameCopyNo, ++iPVNodeId) {
419 iVAMNameCopyNo->GetName() ==
420 iPVNodeId->GetPhysicalVolume()->GetName() &&
421 iVAMNameCopyNo->GetCopyNo() ==
422 iPVNodeId->GetPhysicalVolume()->GetCopyNo()
428 if (iVAMNameCopyNo == vamPath.end()) {
434 modifiedVisAtts = *pVisAttribs;
435 pVisAttribs = &modifiedVisAtts;
437 switch (vam.GetVisAttributesSignifier()) {
488 G4bool culling = fpMP->IsCulling();
489 G4bool cullingInvisible = fpMP->IsCullingInvisible();
491 G4bool cullingLowDensity = fpMP->IsDensityCulling();
493 G4double densityCut = fpMP -> GetVisibleDensity ();
498 if (cullingInvisible) {
500 if (!markedVisible) thisToBeDrawn =
false;
503 if (cullingLowDensity) {
505 if (density < densityCut) thisToBeDrawn =
false;
509 if (fAbort) thisToBeDrawn =
false;
512 fFullPVPath.back().SetDrawn(thisToBeDrawn);
517 fDrawnPVPath.push_back
519 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform,thisToBeDrawn));
521 if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) {
529 G4double explodeFactor = fpMP->GetExplodeFactor();
532 explodeFactor * oldTranslation.
dy(),
533 explodeFactor * oldTranslation.
dz());
534 theNewAT = centering * newTranslation * oldRotation * oldScale;
537 DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler);
546 G4bool daughtersToBeDrawn =
true;
548 if (!nDaughters) daughtersToBeDrawn =
false;
550 else if (requestedDepth == 0) daughtersToBeDrawn =
false;
552 else if (fAbort) daughtersToBeDrawn =
false;
554 else if (fCurtailDescent) daughtersToBeDrawn =
false;
562 G4bool cullingCovered = fpMP->IsCullingCovered();
577 if (cullingInvisible) {
579 if (daughtersInvisible) daughtersToBeDrawn =
false;
582 if (cullingCovered) {
584 if (surfaceDrawing) {
588 if (opaque) daughtersToBeDrawn =
false;
595 if (daughtersToBeDrawn) {
596 for (
G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
601 VisitGeometryAndGetVisReps
602 (pDaughterVPV, requestedDepth - 1, theNewAT, sceneHandler);
608 fCurtailDescent =
false;
611 fFullPVPath.pop_back();
613 fDrawnPVPath.pop_back();
625 G4VSolid* pSectionSolid = fpMP->GetSectionSolid();
626 G4VSolid* pCutawaySolid = fpMP->GetCutawaySolid();
628 if (!fpClippingSolid && !pSectionSolid && !pCutawaySolid) {
630 pSol -> DescribeYourselfTo (sceneHandler);
647 if (fpMP->IsWarning())
649 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \""
651 "\" has no polyhedron. Cannot by clipped."
653 pSol -> DescribeYourselfTo (sceneHandler);
661 if (fpClippingSolid) {
662 switch (fClippingMode) {
666 (
"resultant_solid", pSol, fpClippingSolid, theAT.
inverse());
670 (
"resultant_solid", pSol, fpClippingSolid, theAT.
inverse());
677 (
"sectioned_solid", pSol, pSectionSolid, theAT.
inverse());
682 (
"cutaway_solid", pSol, pCutawaySolid, theAT.
inverse());
686 if (tmpResultant) resultant = *tmpResultant;
688 if (fpMP->IsWarning())
690 "WARNING: G4PhysicalVolumeModel::DescribeSolid: resultant polyhedron for"
691 "\n solid \"" << pSol->
GetName() <<
692 "\" not defined due to error during Boolean processing."
693 "\n Original will be drawn in red."
698 delete resultantSolid;
715 size_t nWorlds = transportationManager->
GetNoWorlds();
719 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
721 for (
size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
735 if (foundVolume !=
fpTopPV && warn) {
737 "G4PhysicalVolumeModel::Validate(): A volume of the same name and"
740 <<
") still exists and is being used."
741 "\n But it is not the same volume you originally specified"
742 "\n in /vis/scene/add/."
750 if (found)
return true;
754 "G4PhysicalVolumeModel::Validate(): No volume of name and"
767 std::map<G4String,G4AttDef>* store
771 G4AttDef(
"PVPath",
"Physical Volume Path",
"Physics",
"",
"G4String");
773 G4AttDef(
"LVol",
"Logical Volume",
"Physics",
"",
"G4String");
775 G4AttDef(
"Solid",
"Solid Name",
"Physics",
"",
"G4String");
777 G4AttDef(
"EType",
"Entity Type",
"Physics",
"",
"G4String");
779 G4AttDef(
"DmpSol",
"Dump of Solid properties",
"Physics",
"",
"G4String");
780 (*store)[
"LocalTrans"] =
781 G4AttDef(
"LocalTrans",
"Local transformation of volume",
"Physics",
"",
"G4String");
782 (*store)[
"GlobalTrans"] =
783 G4AttDef(
"GlobalTrans",
"Global transformation of volume",
"Physics",
"",
"G4String");
784 (*store)[
"Material"] =
785 G4AttDef(
"Material",
"Material Name",
"Physics",
"",
"G4String");
786 (*store)[
"Density"] =
787 G4AttDef(
"Density",
"Material Density",
"Physics",
"G4BestUnit",
"G4double");
789 G4AttDef(
"State",
"Material State (enum undefined,solid,liquid,gas)",
"Physics",
"",
"G4String");
791 G4AttDef(
"Radlen",
"Material Radiation Length",
"Physics",
"G4BestUnit",
"G4double");
793 G4AttDef(
"Region",
"Cuts Region",
"Physics",
"",
"G4String");
794 (*store)[
"RootRegion"] =
795 G4AttDef(
"RootRegion",
"Root Region (0/1 = false/true)",
"Physics",
"",
"G4bool");
814 o << setw(w) << t.
xx() << setw(w) << t.
xy() << setw(w) << t.
xz() << setw(w) << t.
dx() << endl;
815 o << setw(w) << t.
yx() << setw(w) << t.
yy() << setw(w) << t.
yz() << setw(w) << t.
dy() << endl;
816 o << setw(w) << t.
zx() << setw(w) << t.
zy() << setw(w) << t.
zz() << setw(w) << t.
dz() << endl;
819 o <<
"= translation:" << endl;
820 o << setw(w) << tl.dx() << setw(w) << tl.dy() << setw(w) << tl.dz() << endl;
823 o <<
"* rotation:" << endl;
824 o << setw(w) << r.xx() << setw(w) << r.xy() << setw(w) << r.xz() << endl;
825 o << setw(w) << r.yx() << setw(w) << r.yy() << setw(w) << r.yz() << endl;
826 o << setw(w) << r.zx() << setw(w) << r.zy() << setw(w) << r.zz() << endl;
829 o <<
"* scale:" << endl;
830 o << setw(w) << sc.xx() << setw(w) << sc.yy() << setw(w) << sc.zz() << endl;
833 o <<
"Transformed axes:" << endl;
834 o <<
"x': " << r *
G4Vector3D(1., 0., 0.) << endl;
835 o <<
"y': " << r *
G4Vector3D(0., 1., 0.) << endl;
836 o <<
"z': " << r *
G4Vector3D(0., 0., 1.) << endl;
843 std::vector<G4AttValue>* values =
new std::vector<G4AttValue>;
844 std::ostringstream oss;
846 oss <<
fFullPVPath[i].GetPhysicalVolume()->GetName()
853 (
"G4PhysicalVolumeModel::CreateCurrentAttValues",
856 "Current logical volume not defined.");
860 values->push_back(
G4AttValue(
"PVPath", oss.str(),
""));
865 oss.str(
""); oss <<
'\n' << *pSol;
866 values->push_back(
G4AttValue(
"DmpSol", oss.str(),
""));
869 oss.str(
""); oss <<
'\n' <<
G4Transform3D(localRotation,localTranslation);
870 values->push_back(
G4AttValue(
"LocalTrans", oss.str(),
""));
872 values->push_back(
G4AttValue(
"GlobalTrans", oss.str(),
""));
874 values->push_back(
G4AttValue(
"Material", matName,
""));
878 oss.str(
""); oss << matState;
879 values->push_back(
G4AttValue(
"State", oss.str(),
""));
884 values->push_back(
G4AttValue(
"Region", regionName,
""));
886 values->push_back(
G4AttValue(
"RootRegion", oss.str(),
""));
890 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<
893 if (fpPV < right.fpPV)
return true;
894 if (fpPV == right.fpPV) {
895 if (fCopyNo < right.fCopyNo)
return true;
896 if (fCopyNo == right.fCopyNo)
897 return fNonCulledDepth < right.fNonCulledDepth;
902 std::ostream&
operator<<
908 <<
' ' << node.GetCopyNo()
916 os <<
" (Null node)";
921 std::ostream&
operator<<
922 (std::ostream& os,
const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& path)
924 for (
const auto& nodeID: path) {
931 (
const std::vector<G4PhysicalVolumeNodeID>& fullPVPath):
932 fFullPVPath(fullPVPath) {}
936 size_t i = fFullPVPath.size() - depth - 1;
937 if (i >= fFullPVPath.size()) {
938 G4Exception(
"G4PhysicalVolumeModelTouchable::GetTranslation",
941 "Index out of range. Asking for non-existent depth");
944 tempTranslation = fFullPVPath[i].GetTransform().getTranslation();
945 return tempTranslation;
952 G4Exception(
"G4PhysicalVolumeModelTouchable::GetRotation",
955 "Index out of range. Asking for non-existent depth");
958 tempRotation =
fFullPVPath[i].GetTransform().getRotation();
959 return &tempRotation;
966 G4Exception(
"G4PhysicalVolumeModelTouchable::GetVolume",
969 "Index out of range. Asking for non-existent depth");
978 G4Exception(
"G4PhysicalVolumeModelTouchable::GetSolid",
981 "Index out of range. Asking for non-existent depth");
983 return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
990 G4Exception(
"G4PhysicalVolumeModelTouchable::GetReplicaNumber",
993 "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
const std::map< G4String, G4AttDef > * GetAttDefs() const
CLHEP::Hep3Vector G4ThreeVector
const G4VisAttributes * GetDefaultVisAttributes() const
G4double GetLineWidth() const
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
const G4String & GetName() const
void SetLineStyle(LineStyle)
void SetLineWidth(G4double)
const G4ThreeVector & GetTranslation(G4int depth) const
G4double GetDensity() const
const G4Colour & GetColour() const
G4VSolid * GetSolid() const
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4int GetReplicaNumber(G4int depth) const
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
virtual G4GeometryType GetEntityType() const =0
const G4VisExtent & GetExtent() const
void SetModelingParameters(const G4ModelingParameters *)
G4VPhysicalVolume * fpCurrentPV
void SetForceSolid(G4bool=true)
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
void SetVisibility(G4bool=true)
G4bool IsRootRegion() const
G4RotationMatrix GetObjectRotationValue() const
G4Material * fpCurrentMaterial
const G4VisAttributes * GetVisAttributes() const
G4LogicalVolume * fpCurrentLV
const G4ModelingParameters * fpMP
G4String GetCurrentDescription() const
G4bool IsForcedAuxEdgeVisible() const
virtual void DescribeSolid(const G4Transform3D &theAT, G4VSolid *pSol, const G4VisAttributes *pVisAttribs, G4VGraphicsScene &sceneHandler)
G4double GetRadlen() const
G4int GetNoDaughters() const
void SetDaughtersInvisible(G4bool=true)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void SetVisAttributes(const G4VisAttributes *)
static G4TransportationManager * GetTransportationManager()
const G4ThreeVector & GetTranslation() const
G4int GetForcedLineSegmentsPerCircle() const
G4VPhysicalVolume * fpTopPV
G4VSolid * fpClippingSolid
G4PhysicalVolumeModelTouchable(const std::vector< G4PhysicalVolumeNodeID > &fullPVPath)
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
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
G4double GetRadius() const
HepRotation & rotateZ(double delta)
G4String GetCurrentTag() const
size_t GetNoWorlds() const
void SetForceAuxEdgeVisible(G4bool=true)
G4PhysicalVolumeModel(G4VPhysicalVolume *=0, G4int requestedDepth=UNLIMITED, const G4Transform3D &modelTransformation=G4Transform3D(), const G4ModelingParameters *=0, G4bool useFullExtent=false)
virtual void EndPrimitives()=0
static void SetNumberOfRotationSteps(G4int n)
std::map< G4String, G4AttDef > * GetInstance(const G4String &storeKey, G4bool &isNew)
const G4String & GetName() const
void VisitGeometryAndGetVisReps(G4VPhysicalVolume *, G4int requestedDepth, const G4Transform3D &, G4VGraphicsScene &)
void SetDefaultVisAttributes(const G4VisAttributes *pDefaultVisAttributes)
G4bool IsForceLineSegmentsPerCircle() const
void SetForceWireframe(G4bool=true)
void DescribeAndDescend(G4VPhysicalVolume *, G4int requestedDepth, G4LogicalVolume *, G4VSolid *, G4Material *, const G4Transform3D &, G4VGraphicsScene &)
ForcedDrawingStyle GetForcedDrawingStyle() const
const G4RotationMatrix * GetRotation(G4int depth) const
void SetForceLineSegmentsPerCircle(G4int nSegments)
static void ResetNumberOfRotationSteps()
void DescribeYourselfTo(G4VGraphicsScene &)