Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 // $Id: G4ModelingParameters.cc 101035 2016-11-04 08:48:17Z gcosmo $
28 //
29 //
30 // John Allison 31st December 1997.
31 // Parameters associated with the modeling of GEANT4 objects.
32 
33 #include "G4ModelingParameters.hh"
34 
35 #include "G4ios.hh"
36 #include "G4VisAttributes.hh"
37 #include "G4ExceptionSeverity.hh"
38 #include "G4SystemOfUnits.hh"
39 #include "G4VSolid.hh"
40 #include "G4VPhysicalVolume.hh"
41 #include "G4PhysicalVolumeModel.hh"
42 
44  fWarning (true),
45  fpDefaultVisAttributes (0),
46  fDrawingStyle (wf),
47  fCulling (false),
48  fCullInvisible (false),
49  fDensityCulling (false),
50  fVisibleDensity (0.01 * g / cm3),
51  fCullCovered (false),
52  fExplodeFactor (1.),
53  fNoOfSides (72),
54  fpSectionSolid (0),
55  fpCutawaySolid (0),
56  fpEvent (0)
57 {}
58 
60 (const G4VisAttributes* pDefaultVisAttributes,
62  G4bool isCulling,
63  G4bool isCullingInvisible,
64  G4bool isDensityCulling,
65  G4double visibleDensity,
66  G4bool isCullingCovered,
67  G4int noOfSides
68  ):
69  fWarning (true),
70  fpDefaultVisAttributes (pDefaultVisAttributes),
71  fDrawingStyle (drawingStyle),
72  fCulling (isCulling),
73  fCullInvisible (isCullingInvisible),
74  fDensityCulling (isDensityCulling),
75  fVisibleDensity (visibleDensity),
76  fCullCovered (isCullingCovered),
77  fExplodeFactor (1.),
78  fNoOfSides (noOfSides),
79  fpSectionSolid (0),
80  fpCutawaySolid (0),
81  fpEvent (0)
82 {}
83 
85 {
86  delete fpSectionSolid;
87  delete fpCutawaySolid;
88 }
89 
91 (const G4VisAttributes& visAtts,
93  const std::vector<G4PhysicalVolumeModel::G4PhysicalVolumeNodeID>& path):
94 fVisAtts(visAtts), fSignifier(signifier)
95 {
97  typedef std::vector<PVNodeID> PVPath;
98  typedef PVPath::const_iterator PVPathConstIterator;
99  PVPathConstIterator i;
100  for (i = path.begin();
101  i != path.end();
102  ++i) {
103  fPVNameCopyNoPath.push_back
104  (PVNameCopyNo
105  (i->GetPhysicalVolume()->GetName(),
106  i->GetCopyNo()));
107  }
108 }
109 
111  const G4double reasonableMaximum = 10.0 * g / cm3;
112  if (visibleDensity < 0 && fWarning) {
113  G4cout << "G4ModelingParameters::SetVisibleDensity: attempt to set negative "
114  "density - ignored." << G4endl;
115  }
116  else {
117  if (fVisibleDensity > reasonableMaximum && fWarning) {
118  G4cout << "G4ModelingParameters::SetVisibleDensity: density > "
119  << reasonableMaximum
120  << " g / cm3 - did you mean this?"
121  << G4endl;
122  }
123  fVisibleDensity = visibleDensity;
124  }
125 }
126 
128  const G4int nSidesMin = fpDefaultVisAttributes->GetMinLineSegmentsPerCircle();
129  if (nSides < nSidesMin) {
130  nSides = nSidesMin;
131  if (fWarning)
132  G4cout << "G4ModelingParameters::SetNoOfSides: attempt to set the"
133  "\nnumber of sides per circle < " << nSidesMin
134  << "; forced to" << nSides << G4endl;
135  }
136  fNoOfSides = nSides;
137  return fNoOfSides;
138 }
139 
141 (G4VSolid* pSectionSolid) {
142  delete fpSectionSolid;
143  fpSectionSolid = pSectionSolid;
144 }
145 
147 (G4VSolid* pCutawaySolid) {
148  delete fpCutawaySolid;
149  fpCutawaySolid = pCutawaySolid;
150 }
151 
152 std::ostream& operator << (std::ostream& os, const G4ModelingParameters& mp)
153 {
154  os << "Modeling parameters (warning ";
155  if (mp.fWarning) os << "true";
156  else os << "false";
157  os << "):";
158 
159  const G4VisAttributes* va = mp.fpDefaultVisAttributes;
160  os << "\n Default vis. attributes: ";
161  if (va) os << *va;
162  else os << "none";
163 
164  os << "\n Current requested drawing style: ";
165  switch (mp.fDrawingStyle) {
167  os << "wireframe"; break;
169  os << "hidden line removal (hlr)"; break;
171  os << "surface (hsr)"; break;
173  os << "surface and edges (hlhsr)"; break;
174  default: os << "unrecognised"; break;
175  }
176 
177  os << "\n Culling: ";
178  if (mp.fCulling) os << "on";
179  else os << "off";
180 
181  os << "\n Culling invisible objects: ";
182  if (mp.fCullInvisible) os << "on";
183  else os << "off";
184 
185  os << "\n Density culling: ";
186  if (mp.fDensityCulling) {
187  os << "on - invisible if density less than "
188  << mp.fVisibleDensity / (1. * g / cm3) << " g cm^-3";
189  }
190  else os << "off";
191 
192  os << "\n Culling daughters covered by opaque mothers: ";
193  if (mp.fCullCovered) os << "on";
194  else os << "off";
195 
196  os << "\n Explode factor: " << mp.fExplodeFactor
197  << " about centre: " << mp.fExplodeCentre;
198 
199  os << "\n No. of sides used in circle polygon approximation: "
200  << mp.fNoOfSides;
201 
202  os << "\n Section (DCUT) shape (G4VSolid) pointer: ";
203  if (!mp.fpSectionSolid) os << "non-";
204  os << "null";
205 
206  os << "\n Cutaway (DCUT) shape (G4VSolid) pointer: ";
207  if (!mp.fpCutawaySolid) os << "non-";
208  os << "null";
209 
210  os << "\n Event pointer: " << mp.fpEvent;
211 
212  os << "\n Vis attributes modifiers: ";
213  const std::vector<G4ModelingParameters::VisAttributesModifier>& vams =
214  mp.fVisAttributesModifiers;
215  if (vams.empty()) {
216  os << "None";
217  } else {
218  os << vams;
219  }
220 
221  return os;
222 }
223 
224 G4bool G4ModelingParameters::operator !=
225 (const G4ModelingParameters& mp) const {
226 
227  if (
228  (fWarning != mp.fWarning) ||
229  (*fpDefaultVisAttributes != *mp.fpDefaultVisAttributes) ||
230  (fCulling != mp.fCulling) ||
231  (fCullInvisible != mp.fCullInvisible) ||
232  (fDensityCulling != mp.fDensityCulling) ||
233  (fCullCovered != mp.fCullCovered) ||
234  (fExplodeFactor != mp.fExplodeFactor) ||
235  (fExplodeCentre != mp.fExplodeCentre) ||
236  (fNoOfSides != mp.fNoOfSides) ||
237  (fpSectionSolid != mp.fpSectionSolid) ||
238  (fpCutawaySolid != mp.fpCutawaySolid) ||
239  (fpEvent != mp.fpEvent)
240  )
241  return true;
242 
243  if (fDensityCulling &&
244  (fVisibleDensity != mp.fVisibleDensity)) return true;
245 
246  if (fVisAttributesModifiers != mp.fVisAttributesModifiers)
247  return true;
248 
249  return false;
250 }
251 
252 G4bool G4ModelingParameters::PVNameCopyNo::operator!=
254 {
255  if (fName != rhs.fName) return true;
256  if (fCopyNo != rhs.fCopyNo) return true;
257  return false;
258 }
259 
260 G4bool G4ModelingParameters::VisAttributesModifier::operator!=
262 {
263  if (fSignifier != rhs.fSignifier) return true;
264  if (fPVNameCopyNoPath != rhs.fPVNameCopyNoPath) return true;
265  switch (fSignifier) {
267  if (fVisAtts.IsVisible() != rhs.fVisAtts.IsVisible())
268  return true;
269  break;
271  if (fVisAtts.IsDaughtersInvisible() !=
272  rhs.fVisAtts.IsDaughtersInvisible())
273  return true;
274  break;
276  if (fVisAtts.GetColour() != rhs.fVisAtts.GetColour())
277  return true;
278  break;
280  if (fVisAtts.GetLineStyle() != rhs.fVisAtts.GetLineStyle())
281  return true;
282  break;
284  if (fVisAtts.GetLineWidth() != rhs.fVisAtts.GetLineWidth())
285  return true;
286  break;
288  if (fVisAtts.GetForcedDrawingStyle() !=
289  rhs.fVisAtts.GetForcedDrawingStyle())
290  return true;
291  break;
293  if (fVisAtts.GetForcedDrawingStyle() !=
294  rhs.fVisAtts.GetForcedDrawingStyle())
295  return true;
296  break;
298  if (fVisAtts.IsForceAuxEdgeVisible() !=
299  rhs.fVisAtts.IsForceAuxEdgeVisible() ||
300  fVisAtts.IsForcedAuxEdgeVisible() !=
301  rhs.fVisAtts.IsForcedAuxEdgeVisible())
302  return true;
303  break;
305  if (fVisAtts.GetForcedLineSegmentsPerCircle() !=
306  rhs.fVisAtts.GetForcedLineSegmentsPerCircle())
307  return true;
308  break;
309  }
310  return false;
311 }
312 
313 std::ostream& operator <<
314 (std::ostream& os, const G4ModelingParameters::PVNameCopyNoPath& path)
315 {
316  os << "Touchable path: physical-volume-name:copy-number pairs:\n ";
318  for (i = path.begin(); i != path.end(); ++i) {
319  if (i != path.begin()) {
320  os << ',';
321  }
322  os << i->GetName() << ':' << i->GetCopyNo();
323  }
324  return os;
325 }
326 
327 std::ostream& operator <<
328 (std::ostream& os,
329  const std::vector<G4ModelingParameters::VisAttributesModifier>& vams)
330 {
331  std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator
332  iModifier;
333  for (iModifier = vams.begin();
334  iModifier != vams.end();
335  ++iModifier) {
337  iModifier->GetPVNameCopyNoPath();
338  os << '\n' << vamPath;
339  const G4VisAttributes& vamVisAtts = iModifier->GetVisAttributes();
340  const G4Colour& c = vamVisAtts.GetColour();
341  switch (iModifier->GetVisAttributesSignifier()) {
343  os << " visibility ";
344  if (vamVisAtts.IsVisible()) {
345  os << "true";
346  } else {
347  os << "false";
348  }
349  break;
351  os << " daughtersInvisible ";
352  if (vamVisAtts.IsDaughtersInvisible()) {
353  os << "true";
354  } else {
355  os << "false";
356  }
357  break;
359  os << " colour " << c;
360  break;
362  os << " lineStyle ";
363  switch (vamVisAtts.GetLineStyle()) {
365  os << "unbroken";
366  break;
368  os << "dashed";
369  break;
371  os << "dotted";
372  }
373  break;
375  os << " lineWidth "
376  << vamVisAtts.GetLineWidth();
377  break;
380  os << " forceWireframe ";
381  if (vamVisAtts.IsForceDrawingStyle()) {
382  os << "true";
383  } else {
384  os << "false";
385  }
386  }
387  break;
389  if (vamVisAtts.GetForcedDrawingStyle() == G4VisAttributes::solid) {
390  os << " forceSolid ";
391  if (vamVisAtts.IsForceDrawingStyle()) {
392  os << "true";
393  } else {
394  os << "false";
395  }
396  }
397  break;
399  os << " forceAuxEdgeVisible: ";
400  if (!vamVisAtts.IsForceDrawingStyle()) {
401  os << "not ";
402  }
403  os << " forced";
404  if (vamVisAtts.IsForceAuxEdgeVisible()) {
405  os << ": ";
406  if (vamVisAtts.IsForcedAuxEdgeVisible()) {
407  os << "true";
408  } else {
409  os << "false";
410  }
411  }
412  break;
414  os << " lineSegmentsPerCircle "
415  << vamVisAtts.GetForcedLineSegmentsPerCircle();
416  break;
417  }
418  }
419 
420  return os;
421 }
422 
G4bool IsForceAuxEdgeVisible() const
G4String fName
Definition: G4AttUtils.hh:55
G4double GetLineWidth() const
void SetVisibleDensity(G4double)
G4bool IsVisible() const
const G4Colour & GetColour() const
int G4int
Definition: G4Types.hh:78
LineStyle GetLineStyle() const
void SetCutawaySolid(G4VSolid *pCutawaySolid)
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5205
G4GLOB_DLL std::ostream G4cout
static G4int GetMinLineSegmentsPerCircle()
G4bool IsDaughtersInvisible() const
bool G4bool
Definition: G4Types.hh:79
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
VisAttributesModifier(const G4VisAttributes &visAtts, VisAttributesSignifier signifier, const PVNameCopyNoPath &path)
std::vector< PVNodeID > PVPath
G4bool IsForcedAuxEdgeVisible() const
static constexpr double cm3
Definition: G4SIunits.hh:121
G4int GetForcedLineSegmentsPerCircle() const
void SetSectionSolid(G4VSolid *pSectionSolid)
std::vector< PVNameCopyNo > PVNameCopyNoPath
G4bool IsForceDrawingStyle() const
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
tuple c
Definition: test.py:13
ForcedDrawingStyle GetForcedDrawingStyle() const
PVNameCopyNoPath::const_iterator PVNameCopyNoPathConstIterator