source: trunk/source/visualization/management/src/G4VSceneHandler.cc@ 912

Last change on this file since 912 was 850, checked in by garnier, 17 years ago

geant4.8.2 beta

  • Property svn:mime-type set to text/cpp
File size: 27.9 KB
RevLine 
[531]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//
[688]27// $Id: G4VSceneHandler.cc,v 1.83 2008/01/04 22:03:46 allison Exp $
[850]28// GEANT4 tag $Name: HEAD $
[531]29//
30//
31// John Allison 19th July 1996
32// Abstract interface class for graphics scenes.
33
34#include "G4VSceneHandler.hh"
35
36#include "G4ios.hh"
37#include <sstream>
38
39#include "G4VisManager.hh"
40#include "G4VGraphicsSystem.hh"
41#include "G4VViewer.hh"
42#include "G4VSolid.hh"
43#include "G4RotationMatrix.hh"
44#include "G4ThreeVector.hh"
45#include "G4VPhysicalVolume.hh"
46#include "G4Material.hh"
47#include "G4Polyline.hh"
48#include "G4Scale.hh"
49#include "G4Text.hh"
50#include "G4Circle.hh"
51#include "G4Square.hh"
52#include "G4Polymarker.hh"
53#include "G4Polyhedron.hh"
54#include "G4NURBS.hh"
55#include "G4Visible.hh"
56#include "G4VisAttributes.hh"
57#include "G4VModel.hh"
58#include "G4TrajectoriesModel.hh"
59#include "G4Box.hh"
60#include "G4Cons.hh"
61#include "G4Tubs.hh"
62#include "G4Trd.hh"
63#include "G4Trap.hh"
64#include "G4Sphere.hh"
65#include "G4Para.hh"
66#include "G4Torus.hh"
67#include "G4Polycone.hh"
68#include "G4Polyhedra.hh"
69#include "G4LogicalVolume.hh"
70#include "G4PhysicalVolumeModel.hh"
71#include "G4ModelingParameters.hh"
72#include "G4VTrajectory.hh"
[593]73#include "G4VTrajectoryPoint.hh"
74#include "G4HitsModel.hh"
[531]75#include "G4VHit.hh"
76#include "Randomize.hh"
77#include "G4StateManager.hh"
78#include "G4RunManager.hh"
79#include "G4Run.hh"
80#include "G4Transform3D.hh"
[593]81#include "G4AttHolder.hh"
82#include "G4AttDef.hh"
[531]83
84G4VSceneHandler::G4VSceneHandler (G4VGraphicsSystem& system, G4int id, const G4String& name):
85 fSystem (system),
86 fSceneHandlerId (id),
87 fViewCount (0),
88 fpViewer (0),
89 fpScene (0),
90 fMarkForClearingTransientStore (true), // Ready for first
91 // ClearTransientStoreIfMarked(),
92 // e.g., at end of run (see
93 // G4VisManager.cc).
94 fReadyForTransients (true), // Only false while processing scene.
95 fProcessingSolid (false),
96 fSecondPassRequested (false),
97 fSecondPass (false),
98 fpModel (0),
99 fpObjectTransformation (0),
100 fNestingDepth (0),
[593]101 fpVisAttribs (0)
[531]102{
103 G4VisManager* pVMan = G4VisManager::GetInstance ();
104 fpScene = pVMan -> GetCurrentScene ();
105 if (name == "") {
106 std::ostringstream ost;
107 ost << fSystem.GetName () << '-' << fSceneHandlerId;
108 fName = ost.str();
109 }
110 else {
111 fName = name;
112 }
113 fTransientsDrawnThisEvent = pVMan->GetTransientsDrawnThisEvent();
114 fTransientsDrawnThisRun = pVMan->GetTransientsDrawnThisRun();
115}
116
117G4VSceneHandler::~G4VSceneHandler () {
118 G4ViewerListIterator i;
119 for (i = fViewerList.begin(); i != fViewerList.end(); ++i) {
120 delete *i;
121 }
122}
123
124void G4VSceneHandler::PreAddSolid (const G4Transform3D& objectTransformation,
125 const G4VisAttributes& visAttribs) {
126 fpObjectTransformation = &objectTransformation;
127 fpVisAttribs = &visAttribs;
128 fProcessingSolid = true;
129}
130
131void G4VSceneHandler::PostAddSolid () {
132 fpObjectTransformation = 0;
133 fpVisAttribs = 0;
134 fProcessingSolid = false;
135 if (fReadyForTransients) {
136 fTransientsDrawnThisEvent = true;
137 fTransientsDrawnThisRun = true;
138 }
139}
140
141void G4VSceneHandler::BeginPrimitives
142(const G4Transform3D& objectTransformation) {
143 fNestingDepth++;
144 if (fNestingDepth > 1)
145 G4Exception("G4VSceneHandler::BeginPrimitives: Nesting detected."
146 "\n It is illegal to nest Begin/EndPrimitives.");
147 fpObjectTransformation = &objectTransformation;
148}
149
150void G4VSceneHandler::EndPrimitives () {
151 if (fNestingDepth <= 0)
152 G4Exception("G4VSceneHandler::EndPrimitives: Nesting error");
153 fNestingDepth--;
154 fpObjectTransformation = 0;
155 if (fReadyForTransients) {
156 fTransientsDrawnThisEvent = true;
157 fTransientsDrawnThisRun = true;
158 }
159}
160
[688]161void G4VSceneHandler::BeginPrimitives2D
162(const G4Transform3D& objectTransformation) {
[531]163 fNestingDepth++;
164 if (fNestingDepth > 1)
165 G4Exception("G4VSceneHandler::BeginPrimitives2D: Nesting detected."
166 "\n It is illegal to nest Begin/EndPrimitives.");
[688]167 fpObjectTransformation = &objectTransformation;
[531]168}
169
170void G4VSceneHandler::EndPrimitives2D () {
171 if (fNestingDepth <= 0)
172 G4Exception("G4VSceneHandler::EndPrimitives2D: Nesting error");
173 fNestingDepth--;
174 fpObjectTransformation = 0;
175 if (fReadyForTransients) {
176 fTransientsDrawnThisEvent = true;
177 fTransientsDrawnThisRun = true;
178 }
179}
180
181void G4VSceneHandler::BeginModeling () {
182}
183
184void G4VSceneHandler::EndModeling ()
185{
186 fpModel = 0;
187}
188
189void G4VSceneHandler::ClearStore () {
190 // if (fpViewer) fpViewer -> NeedKernelVisit (true);
191 // ?? Viewer is supposed to be smart enough to know when to visit
192 // kernel, but a problem in OpenGL Stored seems to require a forced
193 // kernel visit triggered by the above code. John Allison Aug 2001
194 // Feb 2005 - commented out. Let's fix OpenGL if necessary.
195}
196
197void G4VSceneHandler::ClearTransientStore () {
198}
199
200void G4VSceneHandler::AddSolid (const G4Box& box) {
201 RequestPrimitives (box);
202// If your graphics system is sophisticated enough to handle a
203// particular solid shape as a primitive, in your derived class write a
204// function to override this. (Note: some compilers warn that your
205// function "hides" this one. That's OK.)
206// Your function might look like this...
207// void G4MyScene::AddSolid (const G4Box& box) {
208// Get parameters of appropriate object, e.g.:
209// G4double dx = box.GetXHalfLength ();
210// G4double dy = box.GetYHalfLength ();
211// G4double dz = box.GetZHalfLength ();
212// and Draw or Store in your display List.
213}
214
215void G4VSceneHandler::AddSolid (const G4Tubs& tubs) {
216 RequestPrimitives (tubs);
217}
218
219void G4VSceneHandler::AddSolid (const G4Cons& cons) {
220 RequestPrimitives (cons);
221}
222
223void G4VSceneHandler::AddSolid (const G4Trd& trd) {
224 RequestPrimitives (trd);
225}
226
227void G4VSceneHandler::AddSolid (const G4Trap& trap) {
228 RequestPrimitives (trap);
229}
230
231void G4VSceneHandler::AddSolid (const G4Sphere& sphere) {
232 RequestPrimitives (sphere );
233}
234
235void G4VSceneHandler::AddSolid (const G4Para& para) {
236 RequestPrimitives (para);
237}
238
239void G4VSceneHandler::AddSolid (const G4Torus& torus) {
240 RequestPrimitives (torus);
241}
242
243void G4VSceneHandler::AddSolid (const G4Polycone& polycone) {
244 RequestPrimitives (polycone);
245}
246
247void G4VSceneHandler::AddSolid (const G4Polyhedra& polyhedra) {
248 RequestPrimitives (polyhedra);
249}
250
251void G4VSceneHandler::AddSolid (const G4VSolid& solid) {
252 RequestPrimitives (solid);
253}
254
255void G4VSceneHandler::AddCompound (const G4VTrajectory& traj) {
256 G4TrajectoriesModel* pTrModel =
257 dynamic_cast<G4TrajectoriesModel*>(fpModel);
258 if (!pTrModel) G4Exception
259 ("G4VSceneHandler::AddCompound(const G4VTrajectory&): Not a G4TrajectoriesModel.");
260 traj.DrawTrajectory(pTrModel->GetDrawingMode());
261}
262
263void G4VSceneHandler::AddCompound (const G4VHit& hit) {
264 ((G4VHit&)hit).Draw(); // Cast to non-const because Draw is non-const!!!!
265}
266
267void G4VSceneHandler::AddViewerToList (G4VViewer* pViewer) {
268 fViewerList.push_back (pViewer);
269}
270
271void G4VSceneHandler::AddPrimitive (const G4Scale& scale) {
272
273 const G4double margin(0.01);
274 // Fractional margin - ensures scale is comfortably inside viewing
275 // volume.
276 const G4double oneMinusMargin (1. - margin);
277
278 const G4VisExtent& sceneExtent = fpScene->GetExtent();
279
280 // Useful constants...
281 const G4double length(scale.GetLength());
282 const G4double halfLength(length / 2.);
283 const G4double tickLength(length / 20.);
284 const G4double piBy2(halfpi);
285
286 // Get size of scene...
287 const G4double xmin = sceneExtent.GetXmin();
288 const G4double xmax = sceneExtent.GetXmax();
289 const G4double ymin = sceneExtent.GetYmin();
290 const G4double ymax = sceneExtent.GetYmax();
291 const G4double zmin = sceneExtent.GetZmin();
292 const G4double zmax = sceneExtent.GetZmax();
293
294 // Create (empty) polylines having the same vis attributes...
295 G4Polyline scaleLine, tick11, tick12, tick21, tick22;
296 G4VisAttributes visAtts(*scale.GetVisAttributes()); // Long enough life.
297 scaleLine.SetVisAttributes(&visAtts);
298 tick11.SetVisAttributes(&visAtts);
299 tick12.SetVisAttributes(&visAtts);
300 tick21.SetVisAttributes(&visAtts);
301 tick22.SetVisAttributes(&visAtts);
302
303 // Add points to the polylines to represent an scale parallel to the
304 // x-axis centred on the origin...
305 G4Point3D r1(G4Point3D(-halfLength, 0., 0.));
306 G4Point3D r2(G4Point3D( halfLength, 0., 0.));
307 scaleLine.push_back(r1);
308 scaleLine.push_back(r2);
309 G4Point3D ticky(0., tickLength, 0.);
310 G4Point3D tickz(0., 0., tickLength);
311 tick11.push_back(r1 + ticky);
312 tick11.push_back(r1 - ticky);
313 tick12.push_back(r1 + tickz);
314 tick12.push_back(r1 - tickz);
315 tick21.push_back(r2 + ticky);
316 tick21.push_back(r2 - ticky);
317 tick22.push_back(r2 + tickz);
318 tick22.push_back(r2 - tickz);
319 G4Point3D textPosition(0., tickLength, 0.);
320
321 // Transform appropriately...
322
323 G4Transform3D transformation;
324 if (scale.GetAutoPlacing()) {
325 G4Transform3D rotation;
326 switch (scale.GetDirection()) {
327 case G4Scale::x:
328 break;
329 case G4Scale::y:
330 rotation = G4RotateZ3D(piBy2);
331 break;
332 case G4Scale::z:
333 rotation = G4RotateY3D(piBy2);
334 break;
335 }
336 G4double sxmid(scale.GetXmid());
337 G4double symid(scale.GetYmid());
338 G4double szmid(scale.GetZmid());
339 sxmid = xmin + oneMinusMargin * (xmax - xmin);
340 symid = ymin + margin * (ymax - ymin);
341 szmid = zmin + oneMinusMargin * (zmax - zmin);
342 switch (scale.GetDirection()) {
343 case G4Scale::x:
344 sxmid -= halfLength;
345 break;
346 case G4Scale::y:
347 symid += halfLength;
348 break;
349 case G4Scale::z:
350 szmid -= halfLength;
351 break;
352 }
353 G4Translate3D translation(sxmid, symid, szmid);
354 transformation = translation * rotation;
355 } else {
356 if (fpModel) transformation = fpModel->GetTransformation();
357 }
358
359 // Draw...
360 // We would like to call BeginPrimitives(transformation) here but
361 // calling BeginPrimitives from within an AddPrimitive is not
362 // allowed! So we have to do our own transformation...
363 AddPrimitive(scaleLine.transform(transformation));
364 AddPrimitive(tick11.transform(transformation));
365 AddPrimitive(tick12.transform(transformation));
366 AddPrimitive(tick21.transform(transformation));
367 AddPrimitive(tick22.transform(transformation));
368 G4Text text(scale.GetAnnotation(),textPosition.transform(transformation));
369 text.SetScreenSize(12.);
370 AddPrimitive(text);
371}
372
373void G4VSceneHandler::AddPrimitive (const G4Polymarker& polymarker) {
374 switch (polymarker.GetMarkerType()) {
375 default:
376 case G4Polymarker::dots:
377 {
378 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
379 G4Circle dot (polymarker);
380 dot.SetPosition (polymarker[iPoint]);
381 dot.SetWorldSize (0.);
382 dot.SetScreenSize (0.1); // Very small circle.
383 AddPrimitive (dot);
384 }
385 }
386 break;
387 case G4Polymarker::circles:
388 {
389 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
390 G4Circle circle (polymarker);
391 circle.SetPosition (polymarker[iPoint]);
392 AddPrimitive (circle);
393 }
394 }
395 break;
396 case G4Polymarker::squares:
397 {
398 for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
399 G4Square square (polymarker);
400 square.SetPosition (polymarker[iPoint]);
401 AddPrimitive (square);
402 }
403 }
404 break;
405 }
406}
407
408void G4VSceneHandler::RemoveViewerFromList (G4VViewer* pViewer) {
409 fViewerList.remove(pViewer);
410}
411
412void G4VSceneHandler::SetScene (G4Scene* pScene) {
413 fpScene = pScene;
414 // Notify all viewers that a kernel visit is required.
415 G4ViewerListIterator i;
416 for (i = fViewerList.begin(); i != fViewerList.end(); i++) {
417 (*i) -> SetNeedKernelVisit (true);
418 }
419}
420
421void G4VSceneHandler::RequestPrimitives (const G4VSolid& solid) {
422 BeginPrimitives (*fpObjectTransformation);
423 G4NURBS* pNURBS = 0;
424 G4Polyhedron* pPolyhedron = 0;
425 switch (fpViewer -> GetViewParameters () . GetRepStyle ()) {
426 case G4ViewParameters::nurbs:
427 pNURBS = solid.CreateNURBS ();
428 if (pNURBS) {
[593]429 pNURBS -> SetVisAttributes (fpVisAttribs);
[531]430 AddPrimitive (*pNURBS);
431 delete pNURBS;
432 break;
433 }
434 else {
435 G4VisManager::Verbosity verbosity =
436 G4VisManager::GetInstance()->GetVerbosity();
437 if (verbosity >= G4VisManager::errors) {
438 G4cout <<
439 "ERROR: G4VSceneHandler::RequestPrimitives"
440 "\n NURBS not available for "
441 << solid.GetName () << G4endl;
442 G4cout << "Trying polyhedron." << G4endl;
443 }
444 }
445 // Dropping through to polyhedron...
446 case G4ViewParameters::polyhedron:
447 default:
[593]448 G4Polyhedron::SetNumberOfRotationSteps (GetNoOfSides (fpVisAttribs));
[531]449 pPolyhedron = solid.GetPolyhedron ();
450 G4Polyhedron::ResetNumberOfRotationSteps ();
451 if (pPolyhedron) {
[593]452 pPolyhedron -> SetVisAttributes (fpVisAttribs);
[531]453 AddPrimitive (*pPolyhedron);
454 }
455 else {
456 G4VisManager::Verbosity verbosity =
457 G4VisManager::GetInstance()->GetVerbosity();
458 if (verbosity >= G4VisManager::errors) {
459 G4cout <<
460 "ERROR: G4VSceneHandler::RequestPrimitives"
461 "\n Polyhedron not available for " << solid.GetName () <<
462 ".\n This means it cannot be visualized on most systems."
463 "\n Contact the Visualization Coordinator." << G4endl;
464 }
465 }
466 break;
467 }
468 EndPrimitives ();
469}
470
471void G4VSceneHandler::ProcessScene (G4VViewer&) {
[593]472
[531]473 if (!fpScene) return;
474
475 G4VisManager* visManager = G4VisManager::GetInstance();
476
477 if (!visManager->GetConcreteInstance()) return;
478
479 G4VisManager::Verbosity verbosity = visManager->GetVerbosity();
480
481 fReadyForTransients = false;
482
483 // Clear stored scene, if any, i.e., display lists, scene graphs.
484 ClearStore ();
485
486 // Reset fMarkForClearingTransientStore. No need to clear transient
487 // store since it has just been cleared above. (Leaving
488 // fMarkForClearingTransientStore true causes problems with
489 // recomputing transients below.) Restore it again at end...
490 G4bool tmpMarkForClearingTransientStore = fMarkForClearingTransientStore;
491 fMarkForClearingTransientStore = false;
492
493 // Traverse geometry tree and send drawing primitives to window(s).
494
495 const std::vector<G4VModel*>& runDurationModelList =
496 fpScene -> GetRunDurationModelList ();
497
498 if (runDurationModelList.size ()) {
499 if (verbosity >= G4VisManager::confirmations) {
500 G4cout << "Traversing scene data..." << G4endl;
501 }
502
503 BeginModeling ();
504
505 // Create modeling parameters from view parameters...
506 G4ModelingParameters* pMP = CreateModelingParameters ();
507
508 for (size_t i = 0; i < runDurationModelList.size (); i++) {
509 G4VModel* pModel = runDurationModelList[i];
510 // Note: this is not the place to take action on
511 // pModel->GetTransformation(). The model must take care of
512 // this in pModel->DescribeYourselfTo(*this). See, for example,
513 // G4PhysicalVolumeModel and /vis/scene/add/logo.
514 pModel -> SetModelingParameters (pMP);
515 SetModel (pModel); // Store for use by derived class.
516 pModel -> DescribeYourselfTo (*this);
517 pModel -> SetModelingParameters (0);
518 }
519
520 // Repeat if required...
521 if (fSecondPassRequested) {
522 fSecondPass = true;
523 for (size_t i = 0; i < runDurationModelList.size (); i++) {
524 G4VModel* pModel = runDurationModelList[i];
525 pModel -> SetModelingParameters (pMP);
526 SetModel (pModel); // Store for use by derived class.
527 pModel -> DescribeYourselfTo (*this);
528 pModel -> SetModelingParameters (0);
529 }
530 fSecondPass = false;
531 fSecondPassRequested = false;
532 }
533
534 delete pMP;
535 EndModeling ();
536
537 }
538
539 fpViewer->FinishView(); // Flush streams and/or swap buffers.
540
541 fReadyForTransients = true;
542
543 // Refresh event from end-of-event model list. Allow only in Idle state...
544 G4StateManager* stateManager = G4StateManager::GetStateManager();
545 G4ApplicationState state = stateManager->GetCurrentState();
546 if (state == G4State_Idle) {
547
548 visManager->SetEventRefreshing(true);
549
[593]550 if (visManager->GetRequestedEvent()) {
551 DrawEvent(visManager->GetRequestedEvent());
[531]552
553 } else {
554
555 G4RunManager* runManager = G4RunManager::GetRunManager();
556 if (runManager) {
[593]557 const G4Run* run = runManager->GetCurrentRun();
558 const std::vector<const G4Event*>* events =
559 run? run->GetEventVector(): 0;
560 size_t nKeptEvents = 0;
561 if (events) nKeptEvents = events->size();
562 if (nKeptEvents) {
[531]563
[593]564 if (fpScene->GetRefreshAtEndOfEvent()) {
[531]565
[593]566 if (verbosity >= G4VisManager::confirmations) {
567 G4cout << "Refreshing event..." << G4endl;
568 }
569 const G4Event* event = 0;
570 if (events && events->size()) event = events->back();
[561]571 if (event) DrawEvent(event);
[531]572
[593]573 } else { // Accumulating events.
574
575 if (verbosity >= G4VisManager::confirmations) {
576 G4cout << "Refreshing events in run..." << G4endl;
[561]577 }
[593]578 for (size_t i = 0; i < nKeptEvents; ++i) {
579 const G4Event* event = (*events)[i];
580 if (event) DrawEvent(event);
581 }
582
583 if (!fpScene->GetRefreshAtEndOfRun()) {
584 if (verbosity >= G4VisManager::warnings) {
585 G4cout <<
586 "WARNING: Cannot refresh events accumulated over more"
587 "\n than one runs. Refreshed just the last run."
588 << G4endl;
589 }
590 }
[561]591 }
[531]592 }
593 }
[593]594 }
595 visManager->SetEventRefreshing(false);
596 }
[531]597
598 fMarkForClearingTransientStore = tmpMarkForClearingTransientStore;
599}
600
601void G4VSceneHandler::DrawEvent(const G4Event* event)
602{
603 const std::vector<G4VModel*>& EOEModelList =
604 fpScene -> GetEndOfEventModelList ();
605 size_t nModels = EOEModelList.size();
606 if (nModels) {
607 G4ModelingParameters* pMP = CreateModelingParameters();
608 pMP->SetEvent(event);
609 for (size_t i = 0; i < nModels; i++) {
610 G4VModel* pModel = EOEModelList [i];
611 pModel -> SetModelingParameters(pMP);
612 SetModel (pModel);
613 pModel -> DescribeYourselfTo (*this);
614 pModel -> SetModelingParameters(0);
615 }
616 delete pMP;
617 SetModel (0);
618 }
619}
620
621G4ModelingParameters* G4VSceneHandler::CreateModelingParameters ()
622{
623 // Create modeling parameters from View Parameters...
624 const G4ViewParameters& vp = fpViewer -> GetViewParameters ();
625
626 // Convert drawing styles...
627 G4ModelingParameters::DrawingStyle modelDrawingStyle =
628 G4ModelingParameters::wf;
629 switch (vp.GetDrawingStyle ()) {
630 default:
631 case G4ViewParameters::wireframe:
632 modelDrawingStyle = G4ModelingParameters::wf;
633 break;
634 case G4ViewParameters::hlr:
635 modelDrawingStyle = G4ModelingParameters::hlr;
636 break;
637 case G4ViewParameters::hsr:
638 modelDrawingStyle = G4ModelingParameters::hsr;
639 break;
640 case G4ViewParameters::hlhsr:
641 modelDrawingStyle = G4ModelingParameters::hlhsr;
642 break;
643 }
644
645 // Decide if covered daughters are really to be culled...
646 G4bool reallyCullCovered =
647 vp.IsCullingCovered() // Culling daughters depends also on...
648 && !vp.IsSection () // Sections (DCUT) not requested.
649 && !vp.IsCutaway () // Cutaways not requested.
650 ;
651
652 G4ModelingParameters* pModelingParams = new G4ModelingParameters
653 (vp.GetDefaultVisAttributes (),
654 modelDrawingStyle,
655 vp.IsCulling (),
656 vp.IsCullingInvisible (),
657 vp.IsDensityCulling (),
658 vp.GetVisibleDensity (),
659 reallyCullCovered,
660 vp.GetNoOfSides ()
661 );
662
663 pModelingParams->SetWarning
664 (G4VisManager::GetInstance()->GetVerbosity() >= G4VisManager::warnings);
665
666 pModelingParams->SetExplodeFactor(vp.GetExplodeFactor());
667 pModelingParams->SetExplodeCentre(vp.GetExplodeCentre());
668
669 pModelingParams->SetSectionPolyhedron(CreateSectionPolyhedron());
670 pModelingParams->SetCutawayPolyhedron(CreateCutawayPolyhedron());
671 // The polyhedron objects are deleted in the modeling parameters destructor.
672
673 return pModelingParams;
674}
675
676const G4Polyhedron* G4VSceneHandler::CreateSectionPolyhedron()
677{
678 /* Disable for now. Boolean processor not up to it.
679 const G4ViewParameters& vp = fpViewer->GetViewParameters();
680 if (vp.IsSection () ) {
681 G4double radius = fpScene->GetExtent().GetExtentRadius();
682 G4double safe = radius + fpScene->GetExtent().GetExtentCentre().mag();
683 G4Box sectionBox("clipper",
684 safe, safe, 1.e-5 * radius); // Thin in z-plane.
685 G4Polyhedron* sectioner = sectionBox.CreatePolyhedron();
686 const G4Plane3D& s = vp.GetSectionPlane ();
687 G4double a = s.a();
688 G4double b = s.b();
689 G4double c = s.c();
690 G4double d = s.d();
691 G4Transform3D transform = G4TranslateZ3D(-d);
692 const G4Normal3D normal(a,b,c);
693 if (normal != G4Normal3D(0,0,1)) {
694 const G4double angle = std::acos(normal.dot(G4Normal3D(0,0,1)));
695 const G4Vector3D axis = G4Normal3D(0,0,1).cross(normal);
696 transform = G4Rotate3D(angle, axis) * transform;
697 }
698 sectioner->Transform(transform);
699 return sectioner;
700 } else {
701 return 0;
702 }
703 */
704 return 0;
705}
706
707const G4Polyhedron* G4VSceneHandler::CreateCutawayPolyhedron()
708{
709 return 0;
710}
711
[593]712void G4VSceneHandler::LoadAtts(const G4Visible& visible, G4AttHolder* holder)
713{
714 // Load G4Atts from G4VisAttributes, if any...
715 const G4VisAttributes* va = visible.GetVisAttributes();
716 if (va) {
717 const std::map<G4String,G4AttDef>* vaDefs =
718 va->GetAttDefs();
719 if (vaDefs) {
720 holder->AddAtts(visible.GetVisAttributes()->CreateAttValues(), vaDefs);
721 }
722 }
723
724 G4PhysicalVolumeModel* pPVModel =
725 dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
726 if (pPVModel) {
727 // Load G4Atts from G4PhysicalVolumeModel...
728 const std::map<G4String,G4AttDef>* defs = pPVModel->GetAttDefs();
729 if (defs) {
730 holder->AddAtts(pPVModel->CreateCurrentAttValues(), defs);
731 }
732 }
733
734 G4TrajectoriesModel* trajModel = dynamic_cast<G4TrajectoriesModel*>(fpModel);
735 if (trajModel) {
736 // Load G4Atts from trajectory...
737 const G4VTrajectory* traj = trajModel->GetCurrentTrajectory();
738 const std::map<G4String,G4AttDef>* defs = traj->GetAttDefs();
739 if (defs) {
740 holder->AddAtts(traj->CreateAttValues(), defs);
741 }
742 G4int nPoints = traj->GetPointEntries();
743 for (G4int i = 0; i < nPoints; ++i) {
744 G4VTrajectoryPoint* trajPoint = traj->GetPoint(i);
745 const std::map<G4String,G4AttDef>* defs = trajPoint->GetAttDefs();
746 if (defs) {
747 holder->AddAtts(trajPoint->CreateAttValues(), defs);
748 }
749 }
750 }
751
752 G4HitsModel* hitsModel = dynamic_cast<G4HitsModel*>(fpModel);
753 if (hitsModel) {
754 // Load G4Atts from hit...
755 const G4VHit* hit = hitsModel->GetCurrentHit();
756 const std::map<G4String,G4AttDef>* defs = hit->GetAttDefs();
757 if (defs) {
758 holder->AddAtts(hit->CreateAttValues(), defs);
759 }
760 }
761}
762
[531]763const G4Colour& G4VSceneHandler::GetColour (const G4Visible& visible) {
764 // Colour is determined by the applicable vis attributes.
765 const G4Colour& colour = fpViewer ->
766 GetApplicableVisAttributes (visible.GetVisAttributes ()) -> GetColour ();
767 return colour;
768}
769
770const G4Colour& G4VSceneHandler::GetTextColour (const G4Text& text) {
771 const G4VisAttributes* pVA = text.GetVisAttributes ();
772 if (!pVA) {
773 pVA = fpViewer -> GetViewParameters (). GetDefaultTextVisAttributes ();
774 }
775 const G4Colour& colour = pVA -> GetColour ();
776 return colour;
777}
778
[593]779G4double G4VSceneHandler::GetLineWidth(const G4VisAttributes* pVisAttribs)
[531]780{
[593]781 G4double lineWidth = pVisAttribs->GetLineWidth();
[531]782 if (lineWidth < 1.) lineWidth = 1.;
783 lineWidth *= fpViewer -> GetViewParameters().GetGlobalLineWidthScale();
784 if (lineWidth < 1.) lineWidth = 1.;
785 return lineWidth;
786}
787
788G4ViewParameters::DrawingStyle G4VSceneHandler::GetDrawingStyle
789(const G4VisAttributes* pVisAttribs) {
790 // Drawing style is normally determined by the view parameters, but
791 // it can be overriddden by the ForceDrawingStyle flag in the vis
792 // attributes.
[593]793 G4ViewParameters::DrawingStyle style =
[531]794 fpViewer->GetViewParameters().GetDrawingStyle();
795 if (pVisAttribs -> IsForceDrawingStyle ()) {
796 G4VisAttributes::ForcedDrawingStyle forcedStyle =
797 pVisAttribs -> GetForcedDrawingStyle ();
798 // This is complicated because if hidden line and surface removal
799 // has been requested we wish to preserve this sometimes.
800 switch (forcedStyle) {
801 case (G4VisAttributes::solid):
802 switch (style) {
803 case (G4ViewParameters::hlr):
804 style = G4ViewParameters::hlhsr;
805 break;
806 case (G4ViewParameters::wireframe):
807 style = G4ViewParameters::hsr;
808 break;
809 case (G4ViewParameters::hlhsr):
810 case (G4ViewParameters::hsr):
811 default:
812 break;
813 }
814 break;
815 case (G4VisAttributes::wireframe):
816 default:
817 // But if forced style is wireframe, do it, because one of its
818 // main uses is in displaying the consituent solids of a Boolean
819 // solid and their surfaces overlap with the resulting Booean
820 // solid, making a mess if hlr is specified.
821 style = G4ViewParameters::wireframe;
822 break;
823 }
824 }
825 return style;
826}
827
828G4bool G4VSceneHandler::GetAuxEdgeVisible (const G4VisAttributes* pVisAttribs) {
829 G4bool isAuxEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible ();
830 if (pVisAttribs -> IsForceAuxEdgeVisible()) isAuxEdgeVisible = true;
831 return isAuxEdgeVisible;
832}
833
834G4double G4VSceneHandler::GetMarkerSize
835(const G4VMarker& marker,
836 G4VSceneHandler::MarkerSizeType& markerSizeType)
837{
838 G4bool userSpecified = marker.GetWorldSize() || marker.GetScreenSize();
839 const G4VMarker& defaultMarker =
840 fpViewer -> GetViewParameters().GetDefaultMarker();
841 G4double size = userSpecified ?
842 marker.GetWorldSize() : defaultMarker.GetWorldSize();
843 if (size) {
844 // Draw in world coordinates.
845 markerSizeType = world;
846 }
847 else {
848 size = userSpecified ?
849 marker.GetScreenSize() : defaultMarker.GetScreenSize();
850 // Draw in screen coordinates.
851 markerSizeType = screen;
852 }
853 if (size <= 1.) size = 1.;
854 size *= fpViewer -> GetViewParameters().GetGlobalMarkerScale();
855 if (size <= 1.) size = 1.;
856 return size;
857}
858
859G4int G4VSceneHandler::GetNoOfSides(const G4VisAttributes* pVisAttribs)
860{
861 // No. of sides (lines segments per circle) is normally determined
862 // by the view parameters, but it can be overriddden by the
863 // ForceLineSegmentsPerCircle in the vis attributes.
864 G4int lineSegmentsPerCircle = fpViewer->GetViewParameters().GetNoOfSides();
[593]865 if (pVisAttribs) {
866 if (pVisAttribs->IsForceLineSegmentsPerCircle())
867 lineSegmentsPerCircle = pVisAttribs->GetForcedLineSegmentsPerCircle();
868 const G4int nSegmentsMin = 12;
869 if (lineSegmentsPerCircle < nSegmentsMin) {
870 lineSegmentsPerCircle = nSegmentsMin;
871 G4cout <<
872 "G4VSceneHandler::GetNoOfSides: attempt to set the"
873 "\nnumber of line segements per circle < " << nSegmentsMin
874 << "; forced to " << lineSegmentsPerCircle << G4endl;
875 }
[531]876 }
877 return lineSegmentsPerCircle;
878}
879
880std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s) {
881
882 os << "Scene handler " << s.fName << " has "
883 << s.fViewerList.size () << " viewer(s):";
884 for (size_t i = 0; i < s.fViewerList.size (); i++) {
885 os << "\n " << *(s.fViewerList [i]);
886 }
887
888 if (s.fpScene) {
889 os << "\n " << *s.fpScene;
890 }
891 else {
892 os << "\n This scene handler currently has no scene.";
893 }
894
895 return os;
896}
Note: See TracBrowser for help on using the repository browser.