Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4XXXStoredSceneHandler.cc
이 파일의 문서화 페이지로 가기
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: G4XXXStoredSceneHandler.cc 66870 2013-01-14 23:38:59Z adotti $
28 //
29 //
30 // John Allison 7th March 2006
31 // A template for a graphics driver with a store/database.
32 //?? Lines beginning like this require specialisation for your driver.
33 
35 
36 #include "G4XXXStoredViewer.hh"
37 #include "G4PhysicalVolumeModel.hh"
38 #include "G4LogicalVolumeModel.hh"
39 #include "G4VPhysicalVolume.hh"
40 #include "G4LogicalVolume.hh"
41 #include "G4Box.hh"
42 #include "G4Polyline.hh"
43 #include "G4Text.hh"
44 #include "G4Circle.hh"
45 #include "G4Square.hh"
46 #include "G4Polyhedron.hh"
47 #include "G4UnitsTable.hh"
48 #include "G4AttDef.hh"
49 #include "G4AttValue.hh"
50 #include "G4AttCheck.hh"
51 
52 #include <sstream>
53 
55 // Counter for XXX scene handlers.
56 
58  const G4String& name):
59  G4VSceneHandler(system, fSceneIdCount++, name)
60 {}
61 
63 
64 #ifdef G4XXXStoredDEBUG
65 // Useful function...
66 void G4XXXStoredSceneHandler::PrintThings() {
67  G4cout <<
68  " with transformation "
69  << (void*)fpObjectTransformation;
70  if (fpModel) {
71  G4cout << " from " << fpModel->GetCurrentDescription()
72  << " (tag " << fpModel->GetCurrentTag()
73  << ')';
74  } else {
75  G4cout << "(not from a model)";
76  }
77  G4PhysicalVolumeModel* pPVModel =
78  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
79  if (pPVModel) {
80  G4cout <<
81  "\n current physical volume: "
82  << pPVModel->GetCurrentPV()->GetName() <<
83  "\n current logical volume: "
84 // There might be a problem with the LV pointer if this is a G4LogicalVolumeModel
85  << pPVModel->GetCurrentLV()->GetName() <<
86  "\n current depth of geometry tree: "
87  << pPVModel->GetCurrentDepth();
88  }
89  G4cout << G4endl;
90 }
91 #endif
92 
94 (const G4Transform3D& objectTransformation,
95  const G4VisAttributes& visAttribs)
96 {
97  G4VSceneHandler::PreAddSolid(objectTransformation, visAttribs);
98 
99  // Get user G4Atts...
100  const std::map<G4String,G4AttDef>* userAttDefs = visAttribs.GetAttDefs();
101  if (userAttDefs) {
102 #ifdef G4XXXStoredDEBUG
103  const std::vector<G4AttValue>* userAttValues =
104  visAttribs.CreateAttValues();
105  G4cout << "\nProvided G4Atts:\n"
106  << G4AttCheck(userAttValues, userAttDefs);
107  // Extra checks...
108  G4AttCheck attCheck(userAttValues, userAttDefs);
109  if (attCheck.Check()) G4cout << "Error" << G4endl;
110  else {
111  std::vector<G4AttValue> standardValues;
112  std::map<G4String,G4AttDef> standardDefinitions;
113  attCheck.Standard(&standardValues, &standardDefinitions);
114  G4cout << "\nStandard G4Atts:\n"
115  << G4AttCheck(&standardValues, &standardDefinitions);
116  }
117  // End of extra checks.
118  delete userAttValues; // (Must be deleted after use.)
119 #endif
120  }
121 
122  // Get solid's G4Atts created by G4PhysicalVolumeModel...
123  G4PhysicalVolumeModel* pPVModel =
124  dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
125  if (pPVModel) {
126  const std::map<G4String,G4AttDef>* solidAttDefs = pPVModel->GetAttDefs();
127  if (solidAttDefs) {
128 #ifdef G4XXXStoredDEBUG
129  std::vector<G4AttValue>* solidAttValues =
130  pPVModel->CreateCurrentAttValues();
131  G4cout << "\nProvided G4Atts:\n"
132  << G4AttCheck(solidAttValues, solidAttDefs);
133  // Extra checks...
134  G4AttCheck attCheck(solidAttValues,solidAttDefs);
135  if (attCheck.Check()) G4cout << "Error" << G4endl;
136  else {
137  std::vector<G4AttValue> standardValues;
138  std::map<G4String,G4AttDef> standardDefinitions;
139  attCheck.Standard(&standardValues, &standardDefinitions);
140  G4cout << "\nStandard G4Atts:\n"
141  << G4AttCheck(&standardValues, &standardDefinitions);
142  }
143  // End of extra checks.
144  delete solidAttValues; // (Must be deleted after use.)
145 #endif
146  }
147  }
148 
149  // Create a place for current solid...
150  fCurrentItem = fStore.insert(fStore.end(), G4String("\nPreAddSolid:\n"));
151  if (fReadyForTransients) {
152  fTransients.push_back(fCurrentItem);
153  } else {
154  fPermanents.push_back(fCurrentItem);
155  }
156 }
157 
159 {
160  *fCurrentItem += "\nEndSolid\n";
162 }
163 
165 (const G4Transform3D& objectTransformation)
166 {
167  G4VSceneHandler::BeginPrimitives(objectTransformation);
168 
169  // If thread of control has already passed through PreAddSolid,
170  // avoid opening a graphical data base component again.
171  if (!fProcessingSolid) {
172  // Create a place for current primitive...
173  fCurrentItem = fStore.insert(fStore.end(),
174  G4String("\nBeginPrimitives:\n"));
175  if (fReadyForTransients) {
176  fTransients.push_back(fCurrentItem);
177  } else {
178  fPermanents.push_back(fCurrentItem);
179  }
180  }
181 }
182 
184 {
185  if (!fProcessingSolid) { // Already done if so.
186  *fCurrentItem += "\nEndPrimitives\n";
187  }
189 }
190 
191 // Note: This function overrides G4VSceneHandler::AddSolid(const
192 // G4Box&). You may not want to do this, but this is how it's done if
193 // you do. Certain other specific solids may be treated this way -
194 // see G4VSceneHandler.hh. The simplest possible driver would *not*
195 // implement these polymorphic functions, with the effect that the
196 // default versions in G4VSceneHandler are used, which simply call
197 // G4VSceneHandler::RequestPrimitives to turn the solid into a
198 // G4Polyhedron usually.
199 // Don't forget, solids can be transients too (e.g., representing a hit).
201 #ifdef G4XXXStoredDEBUG
202  G4cout <<
203  "G4XXXStoredSceneHandler::AddSolid(const G4Box& box) called for "
204  << box.GetName()
205  << G4endl;
206 #endif
207  //?? Process your box...
208  std::ostringstream oss;
209  oss << "G4Box(" <<
210  G4String
211  (G4BestUnit
213  (box.GetXHalfLength(), box.GetYHalfLength(), box.GetZHalfLength()),
214  "Length")).strip() << ')';
215  *fCurrentItem += oss.str();
216 }
217 
219 #ifdef G4XXXStoredDEBUG
220  G4cout <<
221  "G4XXXStoredSceneHandler::AddPrimitive(const G4Polyline& polyline) called.\n"
222  << polyline
223  << G4endl;
224 #endif
225  // Get vis attributes - pick up defaults if none.
226  //const G4VisAttributes* pVA =
227  // fpViewer -> GetApplicableVisAttributes (polyline.GetVisAttributes ());
228  //?? Process polyline.
229  std::ostringstream oss;
230  oss << polyline;
231  *fCurrentItem += oss.str();
232 }
233 
235 #ifdef G4XXXStoredDEBUG
236  G4cout <<
237  "G4XXXStoredSceneHandler::AddPrimitive(const G4Text& text) called.|n"
238  << text
239  << G4endl;
240 #endif
241  // Get text colour - special method since default text colour is
242  // determined by the default text vis attributes, which may be
243  // specified independent of default vis attributes of other types of
244  // visible objects.
245  //const G4Colour& c = GetTextColour (text); // Picks up default if none.
246  //?? Process text.
247  std::ostringstream oss;
248  oss << text;
249  *fCurrentItem += oss.str();
250 }
251 
253 #ifdef G4XXXStoredDEBUG
254  G4cout <<
255  "G4XXXStoredSceneHandler::AddPrimitive(const G4Circle& circle) called.\n"
256  << circle
257  << G4endl;
258  MarkerSizeType sizeType;
259  G4double size = GetMarkerSize (circle, sizeType);
260  switch (sizeType) {
261  default:
262  case screen:
263  // Draw in screen coordinates.
264  G4cout << "screen";
265  break;
266  case world:
267  // Draw in world coordinates.
268  G4cout << "world";
269  break;
270  }
271  G4cout << " size: " << size << G4endl;
272 #endif
273  // Get vis attributes - pick up defaults if none.
274  //const G4VisAttributes* pVA =
275  // fpViewer -> GetApplicableVisAttributes (circle.GetVisAttributes ());
276  //?? Process circle.
277  std::ostringstream oss;
278  oss << circle;
279  *fCurrentItem += oss.str();
280 }
281 
283 #ifdef G4XXXStoredDEBUG
284  G4cout <<
285  "G4XXXStoredSceneHandler::AddPrimitive(const G4Square& square) called.\n"
286  << square
287  << G4endl;
288  MarkerSizeType sizeType;
289  G4double size = GetMarkerSize (square, sizeType);
290  switch (sizeType) {
291  default:
292  case screen:
293  // Draw in screen coordinates.
294  G4cout << "screen";
295  break;
296  case world:
297  // Draw in world coordinates.
298  G4cout << "world";
299  break;
300  }
301  G4cout << " size: " << size << G4endl;
302 #endif
303  // Get vis attributes - pick up defaults if none.
304  //const G4VisAttributes* pVA =
305  // fpViewer -> GetApplicableVisAttributes (square.GetVisAttributes ());
306  //?? Process square.
307  std::ostringstream oss;
308  oss << square;
309  *fCurrentItem += oss.str();
310 }
311 
313 #ifdef G4XXXStoredDEBUG
314  G4cout <<
315  "G4XXXStoredSceneHandler::AddPrimitive(const G4Polyhedron&) called.\n"
316  << polyhedron
317  << G4endl;
318 #endif
319  //?? Process polyhedron.
320  std::ostringstream oss;
321  oss << polyhedron;
322  *fCurrentItem += oss.str();
323 
324  //?? Or... here are some ideas for decomposing into polygons...
325  //Assume all facets are convex quadrilaterals.
326  //Draw each G4Facet individually
327 
328  //Get colour, etc..
329  if (polyhedron.GetNoFacets() == 0) return;
330 
331  // Get vis attributes - pick up defaults if none.
332  const G4VisAttributes* pVA =
333  fpViewer -> GetApplicableVisAttributes (polyhedron.GetVisAttributes ());
334 
335  // Get view parameters that the user can force through the vis
336  // attributes, thereby over-riding the current view parameter.
337  G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (pVA);
338  //G4bool isAuxEdgeVisible = GetAuxEdgeVisible (pVA);
339 
340  //Get colour, etc..
341  //const G4Colour& c = pVA -> GetColour ();
342 
343  // Initial action depending on drawing style.
344  switch (drawing_style) {
345  case (G4ViewParameters::hsr):
346  {
347  break;
348  }
349  case (G4ViewParameters::hlr):
350  {
351  break;
352  }
354  {
355  break;
356  }
357  default:
358  {
359  break;
360  }
361  }
362 
363  // Loop through all the facets...
364 
365  // Look at G4OpenGLSceneHandler::AddPrimitive(const G4Polyhedron&)
366  // for an example of how to get facets out of a G4Polyhedron,
367  // including how to cope with triangles if that's a problem.
368 }
369 
371 {
372  fStore.clear();
373  fPermanents.clear();
374  fTransients.clear();
375 }
376 
378 {
379  typedef std::vector<StoreIterator>::iterator StoreIteratorIterator;
380  for (StoreIteratorIterator i = fTransients.begin();
381  i != fTransients.end(); ++i) {
382  fStore.erase(*i);
383  }
384  fTransients.clear();
385 
386  // Make sure screen corresponds to graphical database...
387  if (fpViewer) {
388  fpViewer -> SetView ();
389  fpViewer -> ClearView ();
390  fpViewer -> DrawView ();
391  }
392 }
const XML_Char * name
Definition: expat.h:151
G4double GetYHalfLength() const
std::vector< StoreIterator > fPermanents
system("rm -rf microbeam.root")
virtual void BeginPrimitives(const G4Transform3D &objectTransformation)
#define G4endl
Definition: G4ios.hh:61
G4VViewer * fpViewer
void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
double G4double
Definition: G4Types.hh:76
const std::vector< G4AttValue > * CreateAttValues() const
Definition: G4Text.hh:73
const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual void PostAddSolid()
virtual G4String GetCurrentDescription() const
Definition: G4VModel.cc:54
std::vector< StoreIterator > fTransients
Definition: G4Box.hh:64
G4bool Standard(std::vector< G4AttValue > *standardValues, std::map< G4String, G4AttDef > *standardDefinitions) const
Definition: G4AttCheck.cc:351
void BeginPrimitives(const G4Transform3D &objectTransformation)
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4double GetXHalfLength() const
G4LogicalVolume * GetCurrentLV() const
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
virtual void PreAddSolid(const G4Transform3D &objectTransformation, const G4VisAttributes &)
int G4int
Definition: G4Types.hh:78
void AddPrimitive(const G4Polyline &)
G4VPhysicalVolume * GetCurrentPV() const
G4XXXStoredSceneHandler(G4VGraphicsSystem &system, const G4String &name)
G4String GetName() const
G4bool Check(const G4String &leader="") const
Definition: G4AttCheck.cc:123
G4GLOB_DLL std::ostream G4cout
virtual G4String GetCurrentTag() const
Definition: G4VModel.cc:49
G4double GetZHalfLength() const
std::vector< G4AttValue > * CreateCurrentAttValues() const
virtual void EndPrimitives()
const G4String & GetName() const
const G4String & GetName() const