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