Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ModelingParameters.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27//
28//
29// John Allison 31st December 1997.
30// Parameters associated with the modeling of GEANT4 objects.
31
33
34#include "G4ios.hh"
35#include "G4VisAttributes.hh"
37#include "G4SystemOfUnits.hh"
38#include "G4VSolid.hh"
39#include "G4DisplacedSolid.hh"
40#include "G4VPhysicalVolume.hh"
42#include "G4UnitsTable.hh"
43
44#define G4warn G4cout
45
47 fWarning (true),
48 fpDefaultVisAttributes (0),
49 fDrawingStyle (wf),
50 fNumberOfCloudPoints (10000),
51 fCulling (false),
52 fCullInvisible (false),
53 fDensityCulling (false),
54 fVisibleDensity (0.01 * g / cm3),
55 fCullCovered (false),
56 fCBDAlgorithmNumber (0),
57 fExplodeFactor (1.),
58 fNoOfSides (24),
59 fpSectionSolid (0),
60 fCutawayMode (cutawayUnion),
61 fpCutawaySolid (0),
62 fpEvent (0),
63 fSpecialMeshRendering (false),
64 fTransparencyByDepth (0.),
65 fTransparencyByDepthOption (1)
66{}
67
69(const G4VisAttributes* pDefaultVisAttributes,
71 G4bool isCulling,
72 G4bool isCullingInvisible,
73 G4bool isDensityCulling,
74 G4double visibleDensity,
75 G4bool isCullingCovered,
76 G4int noOfSides
77 ):
78 fWarning (true),
79 fpDefaultVisAttributes (pDefaultVisAttributes),
80 fDrawingStyle (drawingStyle),
81 fNumberOfCloudPoints (10000),
82 fCulling (isCulling),
83 fCullInvisible (isCullingInvisible),
84 fDensityCulling (isDensityCulling),
85 fVisibleDensity (visibleDensity),
86 fCullCovered (isCullingCovered),
87 fCBDAlgorithmNumber (0),
88 fExplodeFactor (1.),
89 fNoOfSides (noOfSides),
90 fpSectionSolid (0),
91 fCutawayMode (cutawayUnion),
92 fpCutawaySolid (0),
93 fpEvent (0),
94 fSpecialMeshRendering (false),
95 fTransparencyByDepth (0.),
96 fTransparencyByDepthOption (1)
97{}
98
100{
101 delete fpSectionSolid;
102 delete fpCutawaySolid;
103}
104
105//G4ModelingParameters::VisAttributesModifier::VisAttributesModifier
106//(const G4VisAttributes& visAtts,
107// G4ModelingParameters::VisAttributesSignifier signifier,
108// const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& path):
109//fVisAtts(visAtts), fSignifier(signifier)
110//{
111// typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
112// typedef std::vector<PVNodeID> PVPath;
113// typedef PVPath::const_iterator PVPathConstIterator;
114// PVPathConstIterator i;
115// for (i = path.begin();
116// i != path.end();
117// ++i) {
118// fPVNameCopyNoPath.push_back
119// (PVNameCopyNo
120// (i->GetPhysicalVolume()->GetName(),
121// i->GetCopyNo()));
122// }
123//}
124
126 const G4double reasonableMaximum = 10.0 * g / cm3;
127 if (visibleDensity < 0 && fWarning) {
128 G4warn << "G4ModelingParameters::SetVisibleDensity: attempt to set negative "
129 "density - ignored." << G4endl;
130 }
131 else {
132 if (fVisibleDensity > reasonableMaximum && fWarning) {
133 G4warn << "G4ModelingParameters::SetVisibleDensity: density > "
134 << reasonableMaximum
135 << " g / cm3 - did you mean this?"
136 << G4endl;
137 }
138 fVisibleDensity = visibleDensity;
139 }
140}
141
143 const G4int nSidesMin = fpDefaultVisAttributes->GetMinLineSegmentsPerCircle();
144 if (nSides < nSidesMin) {
145 nSides = nSidesMin;
146 if (fWarning)
147 G4warn << "G4ModelingParameters::SetNoOfSides: attempt to set the"
148 "\nnumber of sides per circle < " << nSidesMin
149 << "; forced to" << nSides << G4endl;
150 }
151 fNoOfSides = nSides;
152 return fNoOfSides;
153}
154
156(G4DisplacedSolid* pSectionSolid) {
157 delete fpSectionSolid;
158 fpSectionSolid = pSectionSolid;
159}
160
162(G4DisplacedSolid* pCutawaySolid) {
163 delete fpCutawaySolid;
164 fpCutawaySolid = pCutawaySolid;
165}
166
167std::ostream& operator << (std::ostream& os, const G4ModelingParameters& mp)
168{
169 os << "Modeling parameters (warning ";
170 if (mp.fWarning) os << "true";
171 else os << "false";
172 os << "):";
173
174 const G4VisAttributes* va = mp.fpDefaultVisAttributes;
175 os << "\n Default vis. attributes: ";
176 if (va) os << *va;
177 else os << "none";
178
179 os << "\n Current requested drawing style: ";
180 switch (mp.fDrawingStyle) {
182 os << "wireframe"; break;
184 os << "hidden line removal (hlr)"; break;
186 os << "surface (hsr)"; break;
188 os << "surface and edges (hlhsr)"; break;
190 os << "cloud"; break;
191 default: os << "unrecognised"; break;
192 }
193
194 os << "\n Number of cloud points: " << mp.fNumberOfCloudPoints;
195
196 os << "\n Culling: ";
197 if (mp.fCulling) os << "on";
198 else os << "off";
199
200 os << "\n Culling invisible objects: ";
201 if (mp.fCullInvisible) os << "on";
202 else os << "off";
203
204 os << "\n Density culling: ";
205 if (mp.fDensityCulling) {
206 os << "on - invisible if density less than "
207 << mp.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
208 }
209 else os << "off";
210
211 os << "\n Culling daughters covered by opaque mothers: ";
212 if (mp.fCullCovered) os << "on";
213 else os << "off";
214
215 os << "\n Colour by density: ";
216 if (mp.fCBDAlgorithmNumber <= 0) {
217 os << "inactive";
218 } else {
219 os << "Algorithm " << mp.fCBDAlgorithmNumber << ", Parameters:";
220 for (auto p: mp.fCBDParameters) {
221 os << ' ' << G4BestUnit(p,"Volumic Mass");
222 }
223 }
224
225 os << "\n Explode factor: " << mp.fExplodeFactor
226 << " about centre: " << mp.fExplodeCentre;
227
228 os << "\n No. of sides used in circle polygon approximation: "
229 << mp.fNoOfSides;
230
231 os << "\n Section (DCUT) shape (G4DisplacedSolid) pointer: ";
232 if (!mp.fpSectionSolid) os << "non-";
233 os << "null";
234
235 os << "\n Cutaway mode: ";
236 if (mp.GetCutawayMode() == G4ModelingParameters::cutawayUnion) os << "union";
237 else if (mp.GetCutawayMode() == G4ModelingParameters::cutawayIntersection) os << "intersection";
238
239 os << "\n Cutaway (DCUT) shape (G4DisplacedSolid) pointer: ";
240 if (!mp.fpCutawaySolid) os << "non-";
241 os << "null";
242
243 os << "\n Event pointer: " << mp.fpEvent;
244
245 os << "\n Vis attributes modifiers: ";
246 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
247 mp.fVisAttributesModifiers;
248 if (vams.empty()) {
249 os << "None";
250 } else {
251 os << vams;
252 }
253
254 os << "\n Special Mesh Rendering: ";
255 if (mp.fSpecialMeshRendering) {
256 os << "on: ";
257 if (mp.fSpecialMeshVolumes.empty()) {
258 os << "all meshes";
259 } else {
260 os << "selected meshes";
261 for (const auto& vol: mp.fSpecialMeshVolumes) {
262 os << "\n " << vol.GetName() << ':' << vol.GetCopyNo();
263 }
264 }
265 } else os << "off";
266
267 os << "\nTransparency by depth: " << mp.fTransparencyByDepth
268 << ", option: " << mp.fTransparencyByDepthOption;
269
270 return os;
271}
272
273G4bool G4ModelingParameters::operator !=
274(const G4ModelingParameters& mp) const {
275
276 if (
277 (fWarning != mp.fWarning) ||
278 (*fpDefaultVisAttributes != *mp.fpDefaultVisAttributes) ||
279 (fDrawingStyle != mp.fDrawingStyle) ||
280 (fNumberOfCloudPoints != mp.fNumberOfCloudPoints) ||
281 (fCulling != mp.fCulling) ||
282 (fCullInvisible != mp.fCullInvisible) ||
283 (fDensityCulling != mp.fDensityCulling) ||
284 (fCullCovered != mp.fCullCovered) ||
285 (fCBDAlgorithmNumber != mp.fCBDAlgorithmNumber) ||
286 (fExplodeFactor != mp.fExplodeFactor) ||
287 (fExplodeCentre != mp.fExplodeCentre) ||
288 (fNoOfSides != mp.fNoOfSides) ||
289 (fpSectionSolid != mp.fpSectionSolid) ||
290 (fCutawayMode != mp.fCutawayMode) ||
291 (fpCutawaySolid != mp.fpCutawaySolid) ||
292 (fpEvent != mp.fpEvent) ||
293 (fSpecialMeshRendering != mp.fSpecialMeshRendering) ||
294 (fTransparencyByDepth != mp.fTransparencyByDepth) ||
295 (fTransparencyByDepthOption != mp.fTransparencyByDepthOption)
296 )
297 return true;
298
299 if (fDensityCulling &&
300 (fVisibleDensity != mp.fVisibleDensity)) return true;
301
302 if (fCBDAlgorithmNumber > 0) {
303 if (fCBDParameters.size() != mp.fCBDParameters.size()) return true;
304 else if (fCBDParameters != mp.fCBDParameters) return true;
305 }
306
307 if (fVisAttributesModifiers != mp.fVisAttributesModifiers)
308 return true;
309
310 if (fSpecialMeshRendering) {
311 if (fSpecialMeshVolumes != mp.fSpecialMeshVolumes)
312 return true;;
313 }
314
315 return false;
316}
317
318G4bool G4ModelingParameters::VisAttributesModifier::operator!=
320{
321 if (fSignifier != rhs.fSignifier) return true;
322 if (fPVNameCopyNoPath != rhs.fPVNameCopyNoPath) return true;
323 switch (fSignifier) {
325 if (fVisAtts.IsVisible() != rhs.fVisAtts.IsVisible())
326 return true;
327 break;
329 if (fVisAtts.IsDaughtersInvisible() !=
330 rhs.fVisAtts.IsDaughtersInvisible())
331 return true;
332 break;
334 if (fVisAtts.GetColour() != rhs.fVisAtts.GetColour())
335 return true;
336 break;
338 if (fVisAtts.GetLineStyle() != rhs.fVisAtts.GetLineStyle())
339 return true;
340 break;
342 if (fVisAtts.GetLineWidth() != rhs.fVisAtts.GetLineWidth())
343 return true;
344 break;
348 if (fVisAtts.GetForcedDrawingStyle() !=
349 rhs.fVisAtts.GetForcedDrawingStyle())
350 return true;
351 break;
353 if (fVisAtts.GetForcedNumberOfCloudPoints() !=
354 rhs.fVisAtts.GetForcedNumberOfCloudPoints())
355 return true;
356 break;
358 if (fVisAtts.IsForceAuxEdgeVisible() !=
359 rhs.fVisAtts.IsForceAuxEdgeVisible() ||
360 fVisAtts.IsForcedAuxEdgeVisible() !=
361 rhs.fVisAtts.IsForcedAuxEdgeVisible())
362 return true;
363 break;
365 if (fVisAtts.GetForcedLineSegmentsPerCircle() !=
366 rhs.fVisAtts.GetForcedLineSegmentsPerCircle())
367 return true;
368 break;
369 }
370 return false;
371}
372
373G4bool G4ModelingParameters::PVNameCopyNo::operator!=
374(const G4ModelingParameters::PVNameCopyNo& rhs) const
375{
376 if (fName != rhs.fName) return true;
377 if (fCopyNo != rhs.fCopyNo) return true;
378 return false;
379}
380
381std::ostream& operator <<
382(std::ostream& os, const G4ModelingParameters::PVNameCopyNoPath& path)
383{
384 os << "Touchable path: ";
385 if (path.empty()) {
386 os << "empty";
387 } else {
388 os << "physical-volume-name:copy-number pairs:\n ";
390 for (i = path.begin(); i != path.end(); ++i) {
391 if (i != path.begin()) {
392 os << ',';
393 }
394 os << i->GetName() << ':' << i->GetCopyNo();
395 }
396 }
397 return os;
398}
399
401{
402 return fpPV->GetName();
403}
404
405G4bool G4ModelingParameters::PVPointerCopyNo::operator!=
407{
408 if (fpPV != rhs.fpPV) return true;
409 if (fCopyNo != rhs.fCopyNo) return true;
410 return false;
411}
412
413std::ostream& operator <<
414(std::ostream& os, const G4ModelingParameters::PVPointerCopyNoPath& path)
415{
416 os << "Touchable path: physical-volume-pointer:copy-number pairs:\n ";
418 for (i = path.begin(); i != path.end(); ++i) {
419 if (i != path.begin()) {
420 os << ',';
421 }
422 os << '(' << (void*)(i->GetPVPointer()) << ')' << i->GetName() << ':' << i->GetCopyNo();
423 }
424 return os;
425}
426
427std::ostream& operator <<
428(std::ostream& os,
429 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams)
430{
431 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
432 iModifier;
433 for (iModifier = vams.begin();
434 iModifier != vams.end();
435 ++iModifier) {
437 iModifier->GetPVNameCopyNoPath();
438 os << '\n' << vamPath;
439 const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
440 const G4Colour& c = vamVisAtts.GetColour();
441 switch (iModifier->GetVisAttributesSignifier()) {
443 os << " visibility ";
444 if (vamVisAtts.IsVisible()) {
445 os << "true";
446 } else {
447 os << "false";
448 }
449 break;
451 os << " daughtersInvisible ";
452 if (vamVisAtts.IsDaughtersInvisible()) {
453 os << "true";
454 } else {
455 os << "false";
456 }
457 break;
459 os << " colour " << c;
460 break;
462 os << " lineStyle ";
463 switch (vamVisAtts.GetLineStyle()) {
465 os << "unbroken";
466 break;
468 os << "dashed";
469 break;
471 os << "dotted";
472 }
473 break;
475 os << " lineWidth "
476 << vamVisAtts.GetLineWidth();
477 break;
480 os << " forceWireframe ";
481 if (vamVisAtts.IsForceDrawingStyle()) {
482 os << "true";
483 } else {
484 os << "false";
485 }
486 }
487 break;
489 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
490 os << " forceSolid ";
491 if (vamVisAtts.IsForceDrawingStyle()) {
492 os << "true";
493 } else {
494 os << "false";
495 }
496 }
497 break;
499 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::cloud) {
500 os << " forceCloud ";
501 if (vamVisAtts.IsForceDrawingStyle()) {
502 os << "true";
503 } else {
504 os << "false";
505 }
506 }
507 break;
509 os << " numberOfCloudPoints "
510 << vamVisAtts.GetForcedNumberOfCloudPoints();
511 break;
513 os << " forceAuxEdgeVisible: ";
514 if (!vamVisAtts.IsForceDrawingStyle()) {
515 os << "not ";
516 }
517 os << " forced";
518 if (vamVisAtts.IsForceAuxEdgeVisible()) {
519 os << ": ";
520 if (vamVisAtts.IsForcedAuxEdgeVisible()) {
521 os << "true";
522 } else {
523 os << "false";
524 }
525 }
526 break;
528 os << " lineSegmentsPerCircle "
529 << vamVisAtts.GetForcedLineSegmentsPerCircle();
530 break;
531 }
532 }
533
534 return os;
535}
536
std::ostream & operator<<(std::ostream &os, const G4ModelingParameters &mp)
#define G4warn
Definition G4Scene.cc:41
#define G4BestUnit(a, b)
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4DisplacedSolid is a solid that has been shifted from its original frame of reference to a new one....
CutawayMode GetCutawayMode() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
PVPointerCopyNoPath::const_iterator PVPointerCopyNoPathConstIterator
std::vector< PVNameCopyNo > PVNameCopyNoPath
std::vector< PVPointerCopyNo > PVPointerCopyNoPath
void SetCutawaySolid(G4DisplacedSolid *pCutawaySolid)
void SetSectionSolid(G4DisplacedSolid *pSectionSolid)
G4int GetForcedNumberOfCloudPoints() const
G4double GetLineWidth() const
G4bool IsDaughtersInvisible() const
G4int GetForcedLineSegmentsPerCircle() const
LineStyle GetLineStyle() const
const G4Colour & GetColour() const
G4bool IsVisible() const
G4bool IsForceAuxEdgeVisible() const
G4bool IsForcedAuxEdgeVisible() const
ForcedDrawingStyle GetForcedDrawingStyle() const
G4bool IsForceDrawingStyle() const