Geant4 11.1.1
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 fpCutawaySolid (0),
61 fpEvent (0),
62 fSpecialMeshRendering (false)
63{}
64
66(const G4VisAttributes* pDefaultVisAttributes,
68 G4bool isCulling,
69 G4bool isCullingInvisible,
70 G4bool isDensityCulling,
71 G4double visibleDensity,
72 G4bool isCullingCovered,
73 G4int noOfSides
74 ):
75 fWarning (true),
76 fpDefaultVisAttributes (pDefaultVisAttributes),
77 fDrawingStyle (drawingStyle),
78 fNumberOfCloudPoints (10000),
79 fCulling (isCulling),
80 fCullInvisible (isCullingInvisible),
81 fDensityCulling (isDensityCulling),
82 fVisibleDensity (visibleDensity),
83 fCullCovered (isCullingCovered),
84 fCBDAlgorithmNumber (0),
85 fExplodeFactor (1.),
86 fNoOfSides (noOfSides),
87 fpSectionSolid (0),
88 fpCutawaySolid (0),
89 fpEvent (0),
90 fSpecialMeshRendering (false)
91{}
92
94{
95 delete fpSectionSolid;
96 delete fpCutawaySolid;
97}
98
99//G4ModelingParameters::VisAttributesModifier::VisAttributesModifier
100//(const G4VisAttributes& visAtts,
101// G4ModelingParameters::VisAttributesSignifier signifier,
102// const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& path):
103//fVisAtts(visAtts), fSignifier(signifier)
104//{
105// typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
106// typedef std::vector<PVNodeID> PVPath;
107// typedef PVPath::const_iterator PVPathConstIterator;
108// PVPathConstIterator i;
109// for (i = path.begin();
110// i != path.end();
111// ++i) {
112// fPVNameCopyNoPath.push_back
113// (PVNameCopyNo
114// (i->GetPhysicalVolume()->GetName(),
115// i->GetCopyNo()));
116// }
117//}
118
120 const G4double reasonableMaximum = 10.0 * g / cm3;
121 if (visibleDensity < 0 && fWarning) {
122 G4warn << "G4ModelingParameters::SetVisibleDensity: attempt to set negative "
123 "density - ignored." << G4endl;
124 }
125 else {
126 if (fVisibleDensity > reasonableMaximum && fWarning) {
127 G4warn << "G4ModelingParameters::SetVisibleDensity: density > "
128 << reasonableMaximum
129 << " g / cm3 - did you mean this?"
130 << G4endl;
131 }
132 fVisibleDensity = visibleDensity;
133 }
134}
135
137 const G4int nSidesMin = fpDefaultVisAttributes->GetMinLineSegmentsPerCircle();
138 if (nSides < nSidesMin) {
139 nSides = nSidesMin;
140 if (fWarning)
141 G4warn << "G4ModelingParameters::SetNoOfSides: attempt to set the"
142 "\nnumber of sides per circle < " << nSidesMin
143 << "; forced to" << nSides << G4endl;
144 }
145 fNoOfSides = nSides;
146 return fNoOfSides;
147}
148
150(G4DisplacedSolid* pSectionSolid) {
151 delete fpSectionSolid;
152 fpSectionSolid = pSectionSolid;
153}
154
156(G4DisplacedSolid* pCutawaySolid) {
157 delete fpCutawaySolid;
158 fpCutawaySolid = pCutawaySolid;
159}
160
161std::ostream& operator << (std::ostream& os, const G4ModelingParameters& mp)
162{
163 os << "Modeling parameters (warning ";
164 if (mp.fWarning) os << "true";
165 else os << "false";
166 os << "):";
167
168 const G4VisAttributes* va = mp.fpDefaultVisAttributes;
169 os << "\n Default vis. attributes: ";
170 if (va) os << *va;
171 else os << "none";
172
173 os << "\n Current requested drawing style: ";
174 switch (mp.fDrawingStyle) {
176 os << "wireframe"; break;
178 os << "hidden line removal (hlr)"; break;
180 os << "surface (hsr)"; break;
182 os << "surface and edges (hlhsr)"; break;
184 os << "cloud"; break;
185 default: os << "unrecognised"; break;
186 }
187
188 os << "\n Number of cloud points: " << mp.fNumberOfCloudPoints;
189
190 os << "\n Culling: ";
191 if (mp.fCulling) os << "on";
192 else os << "off";
193
194 os << "\n Culling invisible objects: ";
195 if (mp.fCullInvisible) os << "on";
196 else os << "off";
197
198 os << "\n Density culling: ";
199 if (mp.fDensityCulling) {
200 os << "on - invisible if density less than "
201 << mp.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
202 }
203 else os << "off";
204
205 os << "\n Culling daughters covered by opaque mothers: ";
206 if (mp.fCullCovered) os << "on";
207 else os << "off";
208
209 os << "\n Colour by density: ";
210 if (mp.fCBDAlgorithmNumber <= 0) {
211 os << "inactive";
212 } else {
213 os << "Algorithm " << mp.fCBDAlgorithmNumber << ", Parameters:";
214 for (auto p: mp.fCBDParameters) {
215 os << ' ' << G4BestUnit(p,"Volumic Mass");
216 }
217 }
218
219 os << "\n Explode factor: " << mp.fExplodeFactor
220 << " about centre: " << mp.fExplodeCentre;
221
222 os << "\n No. of sides used in circle polygon approximation: "
223 << mp.fNoOfSides;
224
225 os << "\n Section (DCUT) shape (G4DisplacedSolid) pointer: ";
226 if (!mp.fpSectionSolid) os << "non-";
227 os << "null";
228
229 os << "\n Cutaway (DCUT) shape (G4DisplacedSolid) pointer: ";
230 if (!mp.fpCutawaySolid) os << "non-";
231 os << "null";
232
233 os << "\n Event pointer: " << mp.fpEvent;
234
235 os << "\n Vis attributes modifiers: ";
236 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
237 mp.fVisAttributesModifiers;
238 if (vams.empty()) {
239 os << "None";
240 } else {
241 os << vams;
242 }
243
244 os << "\n Special Mesh Rendering: ";
245 if (mp.fSpecialMeshRendering) {
246 os << "on: ";
247 if (mp.fSpecialMeshVolumes.empty()) {
248 os << "all meshes";
249 } else {
250 os << "selected meshes";
251 for (const auto& vol: mp.fSpecialMeshVolumes) {
252 os << "\n " << vol.GetName() << ':' << vol.GetCopyNo();
253 }
254 }
255 } else os << "off";
256
257 return os;
258}
259
260G4bool G4ModelingParameters::operator !=
261(const G4ModelingParameters& mp) const {
262
263 if (
264 (fWarning != mp.fWarning) ||
265 (*fpDefaultVisAttributes != *mp.fpDefaultVisAttributes) ||
266 (fDrawingStyle != mp.fDrawingStyle) ||
267 (fNumberOfCloudPoints != mp.fNumberOfCloudPoints) ||
268 (fCulling != mp.fCulling) ||
269 (fCullInvisible != mp.fCullInvisible) ||
270 (fDensityCulling != mp.fDensityCulling) ||
271 (fCullCovered != mp.fCullCovered) ||
272 (fCBDAlgorithmNumber != mp.fCBDAlgorithmNumber) ||
273 (fExplodeFactor != mp.fExplodeFactor) ||
274 (fExplodeCentre != mp.fExplodeCentre) ||
275 (fNoOfSides != mp.fNoOfSides) ||
276 (fpSectionSolid != mp.fpSectionSolid) ||
277 (fpCutawaySolid != mp.fpCutawaySolid) ||
278 (fpEvent != mp.fpEvent) ||
279 (fSpecialMeshRendering != mp.fSpecialMeshRendering)
280 )
281 return true;
282
283 if (fDensityCulling &&
284 (fVisibleDensity != mp.fVisibleDensity)) return true;
285
286 if (fCBDAlgorithmNumber > 0) {
287 if (fCBDParameters.size() != mp.fCBDParameters.size()) return true;
288 else if (fCBDParameters != mp.fCBDParameters) return true;
289 }
290
291 if (fVisAttributesModifiers != mp.fVisAttributesModifiers)
292 return true;
293
294 if (fSpecialMeshRendering) {
295 if (fSpecialMeshVolumes != mp.fSpecialMeshVolumes)
296 return true;;
297 }
298
299 return false;
300}
301
302G4bool G4ModelingParameters::VisAttributesModifier::operator!=
304{
305 if (fSignifier != rhs.fSignifier) return true;
306 if (fPVNameCopyNoPath != rhs.fPVNameCopyNoPath) return true;
307 switch (fSignifier) {
309 if (fVisAtts.IsVisible() != rhs.fVisAtts.IsVisible())
310 return true;
311 break;
313 if (fVisAtts.IsDaughtersInvisible() !=
314 rhs.fVisAtts.IsDaughtersInvisible())
315 return true;
316 break;
318 if (fVisAtts.GetColour() != rhs.fVisAtts.GetColour())
319 return true;
320 break;
322 if (fVisAtts.GetLineStyle() != rhs.fVisAtts.GetLineStyle())
323 return true;
324 break;
326 if (fVisAtts.GetLineWidth() != rhs.fVisAtts.GetLineWidth())
327 return true;
328 break;
332 if (fVisAtts.GetForcedDrawingStyle() !=
333 rhs.fVisAtts.GetForcedDrawingStyle())
334 return true;
335 break;
337 if (fVisAtts.GetForcedNumberOfCloudPoints() !=
338 rhs.fVisAtts.GetForcedNumberOfCloudPoints())
339 return true;
340 break;
342 if (fVisAtts.IsForceAuxEdgeVisible() !=
343 rhs.fVisAtts.IsForceAuxEdgeVisible() ||
344 fVisAtts.IsForcedAuxEdgeVisible() !=
345 rhs.fVisAtts.IsForcedAuxEdgeVisible())
346 return true;
347 break;
349 if (fVisAtts.GetForcedLineSegmentsPerCircle() !=
350 rhs.fVisAtts.GetForcedLineSegmentsPerCircle())
351 return true;
352 break;
353 }
354 return false;
355}
356
357G4bool G4ModelingParameters::PVNameCopyNo::operator!=
358(const G4ModelingParameters::PVNameCopyNo& rhs) const
359{
360 if (fName != rhs.fName) return true;
361 if (fCopyNo != rhs.fCopyNo) return true;
362 return false;
363}
364
365std::ostream& operator <<
366(std::ostream& os, const G4ModelingParameters::PVNameCopyNoPath& path)
367{
368 os << "Touchable path: ";
369 if (path.empty()) {
370 os << "empty";
371 } else {
372 os << "physical-volume-name:copy-number pairs:\n ";
374 for (i = path.begin(); i != path.end(); ++i) {
375 if (i != path.begin()) {
376 os << ',';
377 }
378 os << i->GetName() << ':' << i->GetCopyNo();
379 }
380 }
381 return os;
382}
383
385{
386 return fpPV->GetName();
387}
388
389G4bool G4ModelingParameters::PVPointerCopyNo::operator!=
391{
392 if (fpPV != rhs.fpPV) return true;
393 if (fCopyNo != rhs.fCopyNo) return true;
394 return false;
395}
396
397std::ostream& operator <<
398(std::ostream& os, const G4ModelingParameters::PVPointerCopyNoPath& path)
399{
400 os << "Touchable path: physical-volume-pointer:copy-number pairs:\n ";
402 for (i = path.begin(); i != path.end(); ++i) {
403 if (i != path.begin()) {
404 os << ',';
405 }
406 os << '(' << (void*)(i->GetPVPointer()) << ')' << i->GetName() << ':' << i->GetCopyNo();
407 }
408 return os;
409}
410
411std::ostream& operator <<
412(std::ostream& os,
413 const std::vector<G4ModelingParameters::VisAttributesModifier>& vams)
414{
415 std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
416 iModifier;
417 for (iModifier = vams.begin();
418 iModifier != vams.end();
419 ++iModifier) {
421 iModifier->GetPVNameCopyNoPath();
422 os << '\n' << vamPath;
423 const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
424 const G4Colour& c = vamVisAtts.GetColour();
425 switch (iModifier->GetVisAttributesSignifier()) {
427 os << " visibility ";
428 if (vamVisAtts.IsVisible()) {
429 os << "true";
430 } else {
431 os << "false";
432 }
433 break;
435 os << " daughtersInvisible ";
436 if (vamVisAtts.IsDaughtersInvisible()) {
437 os << "true";
438 } else {
439 os << "false";
440 }
441 break;
443 os << " colour " << c;
444 break;
446 os << " lineStyle ";
447 switch (vamVisAtts.GetLineStyle()) {
449 os << "unbroken";
450 break;
452 os << "dashed";
453 break;
455 os << "dotted";
456 }
457 break;
459 os << " lineWidth "
460 << vamVisAtts.GetLineWidth();
461 break;
464 os << " forceWireframe ";
465 if (vamVisAtts.IsForceDrawingStyle()) {
466 os << "true";
467 } else {
468 os << "false";
469 }
470 }
471 break;
473 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
474 os << " forceSolid ";
475 if (vamVisAtts.IsForceDrawingStyle()) {
476 os << "true";
477 } else {
478 os << "false";
479 }
480 }
481 break;
483 if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::cloud) {
484 os << " forceCloud ";
485 if (vamVisAtts.IsForceDrawingStyle()) {
486 os << "true";
487 } else {
488 os << "false";
489 }
490 }
491 break;
493 os << " numberOfCloudPoints "
494 << vamVisAtts.GetForcedNumberOfCloudPoints();
495 break;
497 os << " forceAuxEdgeVisible: ";
498 if (!vamVisAtts.IsForceDrawingStyle()) {
499 os << "not ";
500 }
501 os << " forced";
502 if (vamVisAtts.IsForceAuxEdgeVisible()) {
503 os << ": ";
504 if (vamVisAtts.IsForcedAuxEdgeVisible()) {
505 os << "true";
506 } else {
507 os << "false";
508 }
509 }
510 break;
512 os << " lineSegmentsPerCircle "
513 << vamVisAtts.GetForcedLineSegmentsPerCircle();
514 break;
515 }
516 }
517
518 return os;
519}
520
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:57
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator
PVPointerCopyNoPath::const_iterator PVPointerCopyNoPathConstIterator
std::vector< PVNameCopyNo > PVNameCopyNoPath
std::vector< PVPointerCopyNo > PVPointerCopyNoPath
void SetCutawaySolid(G4DisplacedSolid *pCutawaySolid)
void SetSectionSolid(G4DisplacedSolid *pSectionSolid)
void SetVisibleDensity(G4double)
const G4String & GetName() const
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
static G4int GetMinLineSegmentsPerCircle()
G4bool IsForceDrawingStyle() const