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