49 #include "HepPolyhedronProcessor.h"
67 fRequestedDepth (requestedDepth),
68 fUseFullExtent (useFullExtent),
72 fpCurrentMaterial (0),
73 fpCurrentTransform (0),
74 fCurtailDescent (
false),
76 fClippingMode (subtraction)
80 fType =
"G4PhysicalVolumeModel";
81 fTopPVName = fpTopPV -> GetName ();
82 fTopPVCopyNo = fpTopPV -> GetCopyNo ();
84 o << fpTopPV -> GetCopyNo ();
85 fGlobalTag = fpTopPV -> GetName () +
"." + o.str();
86 fGlobalDescription =
"G4PhysicalVolumeModel " + fGlobalTag;
140 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
144 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
152 VisitGeometryAndGetVisReps
155 startingTransformation,
162 fpCurrentMaterial = 0;
163 if (fFullPVPath.size() != fBaseFullPVPath.size()) {
166 (
"G4PhysicalVolumeModel::DescribeYourselfTo",
169 "Path at start of modeling not equal to base path. Something badly"
170 "\nwrong. Please contact visualisation coordinator.");
172 fDrawnPVPath.clear();
178 std::ostringstream o;
183 return "WARNING: NO CURRENT VOLUME - global tag is " +
fGlobalTag;
194 G4int requestedDepth,
211 if (!(pVPV -> IsReplicated ())) {
213 pSol = pLV -> GetSolid ();
214 pMaterial = pLV -> GetMaterial ();
215 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
216 theAT, sceneHandler);
225 pVPV -> GetReplicationData (axis, nReplicas, width, offset, consuming);
226 if (fCurrentDepth == 0) nReplicas = 1;
229 for (
int n = 0;
n < nReplicas;
n++) {
230 pSol = pP -> ComputeSolid (
n, pVPV);
231 pP -> ComputeTransformation (
n, pVPV);
232 pSol -> ComputeDimensions (pP,
n, pVPV);
233 pVPV -> SetCopyNo (
n);
238 pMaterial = pP -> ComputeMaterial (
n, pVPV, &parentTouchable);
239 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
240 theAT, sceneHandler);
265 pSol = pLV -> GetSolid ();
266 pMaterial = pLV -> GetMaterial ();
267 G4ThreeVector originalTranslation = pVPV -> GetTranslation ();
269 G4double originalRMin = 0., originalRMax = 0.;
271 originalRMin = ((
G4Tubs*)pSol)->GetInnerRadius();
272 originalRMax = ((
G4Tubs*)pSol)->GetOuterRadius();
274 G4bool visualisable =
true;
275 for (
int n = 0;
n < nReplicas;
n++) {
282 translation =
G4ThreeVector (-width*(nReplicas-1)*0.5+
n*width,0,0);
285 translation =
G4ThreeVector (0,-width*(nReplicas-1)*0.5+
n*width,0);
288 translation =
G4ThreeVector (0,0,-width*(nReplicas-1)*0.5+
n*width);
292 ((
G4Tubs*)pSol)->SetInnerRadius(width*
n+offset);
293 ((
G4Tubs*)pSol)->SetOuterRadius(width*(
n+1)+offset);
295 if (fpMP->IsWarning())
297 "G4PhysicalVolumeModel::VisitGeometryAndGetVisReps: WARNING:"
298 "\n built-in replicated volumes replicated in radius for "
300 "-type\n solids (your solid \""
302 "\") are not visualisable."
304 visualisable =
false;
308 rotation.rotateZ (-(offset+(
n+0.5)*width));
311 pRotation = &rotation;
314 pVPV -> SetTranslation (translation);
315 pVPV -> SetRotation (pRotation);
316 pVPV -> SetCopyNo (
n);
318 DescribeAndDescend (pVPV, requestedDepth, pLV, pSol, pMaterial,
319 theAT, sceneHandler);
323 pVPV -> SetTranslation (originalTranslation);
324 pVPV -> SetRotation (pOriginalRotation);
326 ((
G4Tubs*)pSol)->SetInnerRadius(originalRMin);
327 ((
G4Tubs*)pSol)->SetOuterRadius(originalRMax);
337 G4int requestedDepth,
347 fpCurrentMaterial = pMaterial;
350 const G4ThreeVector& translation = pVPV -> GetTranslation ();
361 if (fCurrentDepth != 0) theNewAT = theAT * theLT;
362 fpCurrentTransform = &theNewAT;
365 if (!pVisAttribs) pVisAttribs = fpMP->GetDefaultVisAttributes();
367 G4bool visAttsCreated =
false;
370 visAttsCreated =
true;
375 G4bool thisToBeDrawn =
true;
378 G4int copyNo = fpCurrentPV->GetCopyNo();
379 fFullPVPath.push_back
381 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform));
384 G4bool copyForVAM =
false;
389 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
390 fpMP->GetVisAttributesModifiers();
391 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
393 for (iModifier = vams.begin();
394 iModifier != vams.end();
397 iModifier->GetPVNameCopyNoPath();
398 if (vamPath.size() == fFullPVPath.size()) {
402 std::vector<G4PhysicalVolumeNodeID>::const_iterator iPVNodeId;
403 for (iVAMNameCopyNo = vamPath.begin(), iPVNodeId = fFullPVPath.begin();
404 iVAMNameCopyNo != vamPath.end();
405 ++iVAMNameCopyNo, ++iPVNodeId) {
413 iVAMNameCopyNo->GetName() ==
414 iPVNodeId->GetPhysicalVolume()->GetName() &&
415 iVAMNameCopyNo->GetCopyNo() ==
416 iPVNodeId->GetPhysicalVolume()->GetCopyNo()
421 if (iVAMNameCopyNo == vamPath.end()) {
425 pVisAttribs = pModifiedVisAtts;
429 switch (iModifier->GetVisAttributesSignifier()) {
475 G4bool culling = fpMP->IsCulling();
476 G4bool cullingInvisible = fpMP->IsCullingInvisible();
478 G4bool cullingLowDensity = fpMP->IsDensityCulling();
480 G4double densityCut = fpMP -> GetVisibleDensity ();
485 if (cullingInvisible) {
487 if (!markedVisible) thisToBeDrawn =
false;
490 if (cullingLowDensity) {
492 if (density < densityCut) thisToBeDrawn =
false;
497 fFullPVPath.back().SetDrawn(thisToBeDrawn);
502 fDrawnPVPath.push_back
504 (fpCurrentPV,copyNo,fCurrentDepth,*fpCurrentTransform,thisToBeDrawn));
506 if (fpMP->IsExplode() && fDrawnPVPath.size() == 1) {
513 centred.getDecomposition(oldScale, oldRotation, oldTranslation);
514 G4double explodeFactor = fpMP->GetExplodeFactor();
517 explodeFactor * oldTranslation.dy(),
518 explodeFactor * oldTranslation.dz());
519 theNewAT = centering * newTranslation * oldRotation * oldScale;
522 DescribeSolid (theNewAT, pSol, pVisAttribs, sceneHandler);
531 G4bool daughtersToBeDrawn =
true;
533 if (!nDaughters) daughtersToBeDrawn =
false;
535 else if (requestedDepth == 0) daughtersToBeDrawn =
false;
537 else if (fCurtailDescent) daughtersToBeDrawn =
false;
545 G4bool cullingCovered = fpMP->IsCullingCovered();
560 if (cullingInvisible) {
562 if (daughtersInvisible) daughtersToBeDrawn =
false;
565 if (cullingCovered) {
567 if (surfaceDrawing) {
571 if (opaque) daughtersToBeDrawn =
false;
580 delete pModifiedVisAtts;
581 pVisAttribs = pUnmodifiedVisAtts;
586 if (visAttsCreated)
delete pVisAttribs;
588 if (daughtersToBeDrawn) {
589 for (
G4int iDaughter = 0; iDaughter < nDaughters; iDaughter++) {
594 VisitGeometryAndGetVisReps
595 (pDaughterVPV, requestedDepth - 1, theNewAT, sceneHandler);
601 fCurtailDescent =
false;
604 fFullPVPath.pop_back();
606 fDrawnPVPath.pop_back();
618 G4VSolid* pSectionSolid = fpMP->GetSectionSolid();
619 G4VSolid* pCutawaySolid = fpMP->GetCutawaySolid();
621 if (!fpClippingSolid && !pSectionSolid && !pCutawaySolid) {
623 pSol -> DescribeYourselfTo (sceneHandler);
631 G4Polyhedron::SetNumberOfRotationSteps
634 G4Polyhedron::SetNumberOfRotationSteps(fpMP->GetNoOfSides());
636 G4Polyhedron::ResetNumberOfRotationSteps();
640 if (fpMP->IsWarning())
642 "WARNING: G4PhysicalVolumeModel::DescribeSolid: solid\n \""
644 "\" has no polyhedron. Cannot by clipped."
646 pSol -> DescribeYourselfTo (sceneHandler);
654 if (fpClippingSolid) {
655 switch (fClippingMode) {
659 (
"resultant_solid", pSol, fpClippingSolid, theAT.inverse());
663 (
"resultant_solid", pSol, fpClippingSolid, theAT.inverse());
670 (
"sectioned_solid", pSol, pSectionSolid, theAT.inverse());
675 (
"cutaway_solid", pSol, pCutawaySolid, theAT.inverse());
679 if (tmpResultant) resultant = *tmpResultant;
681 if (fpMP->IsWarning())
683 "WARNING: G4PhysicalVolumeModel::DescribeSolid: resultant polyhedron for"
684 "\n solid \"" << pSol->
GetName() <<
685 "\" not defined due to error during Boolean processing."
686 "\n Original will be drawn in red."
691 delete resultantSolid;
708 size_t nWorlds = transportationManager->
GetNoWorlds();
712 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
714 for (
size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
728 if (foundVolume !=
fpTopPV && warn) {
730 "G4PhysicalVolumeModel::Validate(): A volume of the same name and"
733 <<
") still exists and is being used."
734 "\n But it is not the same volume you originally specified"
735 "\n in /vis/scene/add/."
743 if (found)
return true;
747 "G4PhysicalVolumeModel::Validate(): No volume of name and"
760 std::map<G4String,G4AttDef>* store
764 G4AttDef(
"PVPath",
"Physical Volume Path",
"Physics",
"",
"G4String");
766 G4AttDef(
"LVol",
"Logical Volume",
"Physics",
"",
"G4String");
768 G4AttDef(
"Solid",
"Solid Name",
"Physics",
"",
"G4String");
770 G4AttDef(
"EType",
"Entity Type",
"Physics",
"",
"G4String");
772 G4AttDef(
"DmpSol",
"Dump of Solid properties",
"Physics",
"",
"G4String");
774 G4AttDef(
"Trans",
"Transformation of volume",
"Physics",
"",
"G4String");
775 (*store)[
"Material"] =
776 G4AttDef(
"Material",
"Material Name",
"Physics",
"",
"G4String");
777 (*store)[
"Density"] =
778 G4AttDef(
"Density",
"Material Density",
"Physics",
"G4BestUnit",
"G4double");
780 G4AttDef(
"State",
"Material State (enum undefined,solid,liquid,gas)",
"Physics",
"",
"G4String");
782 G4AttDef(
"Radlen",
"Material Radiation Length",
"Physics",
"G4BestUnit",
"G4double");
784 G4AttDef(
"Region",
"Cuts Region",
"Physics",
"",
"G4String");
785 (*store)[
"RootRegion"] =
786 G4AttDef(
"RootRegion",
"Root Region (0/1 = false/true)",
"Physics",
"",
"G4bool");
800 t.getDecomposition(sc, r, tl);
805 o << setw(w) << t.xx() << setw(w) << t.xy() << setw(w) << t.xz() << setw(w) << t.dx() << endl;
806 o << setw(w) << t.yx() << setw(w) << t.yy() << setw(w) << t.yz() << setw(w) << t.dy() << endl;
807 o << setw(w) << t.zx() << setw(w) << t.zy() << setw(w) << t.zz() << setw(w) << t.dz() << endl;
810 o <<
"= translation:" << endl;
811 o << setw(w) << tl.dx() << setw(w) << tl.dy() << setw(w) << tl.dz() << endl;
814 o <<
"* rotation:" << endl;
815 o << setw(w) << r.xx() << setw(w) << r.xy() << setw(w) << r.xz() << endl;
816 o << setw(w) << r.yx() << setw(w) << r.yy() << setw(w) << r.yz() << endl;
817 o << setw(w) << r.zx() << setw(w) << r.zy() << setw(w) << r.zz() << endl;
820 o <<
"* scale:" << endl;
821 o << setw(w) << sc.xx() << setw(w) << sc.yy() << setw(w) << sc.zz() << endl;
824 o <<
"Transformed axes:" << endl;
825 o <<
"x': " << r *
G4Vector3D(1., 0., 0.) << endl;
826 o <<
"y': " << r *
G4Vector3D(0., 1., 0.) << endl;
827 o <<
"z': " << r *
G4Vector3D(0., 0., 1.) << endl;
834 std::vector<G4AttValue>* values =
new std::vector<G4AttValue>;
835 std::ostringstream oss;
837 oss <<
fFullPVPath[i].GetPhysicalVolume()->GetName()
844 (
"G4PhysicalVolumeModel::CreateCurrentAttValues",
847 "Current logical volume not defined.");
851 values->push_back(
G4AttValue(
"PVPath", oss.str(),
""));
856 oss.str(
""); oss <<
'\n' << *pSol;
857 values->push_back(
G4AttValue(
"DmpSol", oss.str(),
""));
859 values->push_back(
G4AttValue(
"Trans", oss.str(),
""));
861 values->push_back(
G4AttValue(
"Material", matName,
""));
865 oss.str(
""); oss << matState;
866 values->push_back(
G4AttValue(
"State", oss.str(),
""));
871 values->push_back(
G4AttValue(
"Region", regionName,
""));
873 values->push_back(
G4AttValue(
"RootRegion", oss.str(),
""));
877 G4bool G4PhysicalVolumeModel::G4PhysicalVolumeNodeID::operator<
880 if (fpPV <
right.fpPV)
return true;
881 if (fpPV ==
right.fpPV) {
882 if (fCopyNo <
right.fCopyNo)
return true;
883 if (fCopyNo ==
right.fCopyNo)
884 return fNonCulledDepth <
right.fNonCulledDepth;
889 std::ostream&
operator<<
895 <<
':' << node.GetCopyNo()
896 <<
'[' << node.GetNonCulledDepth() <<
']'
897 <<
':' << node.GetTransform();
898 if (!node.GetDrawn()) os <<
" Not "; os <<
"drawn";
906 (
const std::vector<G4PhysicalVolumeNodeID>& fullPVPath):
907 fFullPVPath(fullPVPath) {}
913 G4Exception(
"G4PhysicalVolumeModelTouchable::GetTranslation",
916 "Index out of range. Asking for non-existent depth");
919 tempTranslation =
fFullPVPath[i].GetTransform().getTranslation();
920 return tempTranslation;
927 G4Exception(
"G4PhysicalVolumeModelTouchable::GetRotation",
930 "Index out of range. Asking for non-existent depth");
933 tempRotation =
fFullPVPath[i].GetTransform().getRotation();
934 return &tempRotation;
941 G4Exception(
"G4PhysicalVolumeModelTouchable::GetVolume",
944 "Index out of range. Asking for non-existent depth");
953 G4Exception(
"G4PhysicalVolumeModelTouchable::GetSolid",
956 "Index out of range. Asking for non-existent depth");
958 return fFullPVPath[i].GetPhysicalVolume()->GetLogicalVolume()->GetSolid();
965 G4Exception(
"G4PhysicalVolumeModelTouchable::GetReplicaNumber",
968 "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 &)