Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ToolsSGViewer< SG_SESSION, SG_VIEWER > Class Template Reference

#include <G4ToolsSGViewer.hh>

Inheritance diagram for G4ToolsSGViewer< SG_SESSION, SG_VIEWER >:

Classes

class  Messenger

Public Member Functions

virtual void key_press (const tools::sg::key_down_event &)
virtual void key_release (const tools::sg::key_up_event &)
virtual void mouse_press (const tools::sg::mouse_down_event &a_event)
virtual void mouse_release (const tools::sg::mouse_up_event &)
virtual void mouse_move (const tools::sg::mouse_move_event &a_event)
virtual void wheel_rotate (const tools::sg::wheel_rotate_event &a_event)
 G4ToolsSGViewer (SG_SESSION &a_session, G4ToolsSGSceneHandler &a_scene_handler, const G4String &a_name)
virtual ~G4ToolsSGViewer ()
virtual void Initialise ()
virtual void SetView ()
virtual void ClearView ()
virtual void DrawView ()
virtual void ShowView ()
virtual void FinishView ()
G4bool GetWindowSize (unsigned int &a_w, unsigned int &a_h)
G4bool GetRenderAreaSize (unsigned int &a_w, unsigned int &a_h)
virtual void EmitWindowRender ()
Public Member Functions inherited from G4VViewer
 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
virtual ~G4VViewer ()
virtual void ResetView ()
void RefreshView ()
virtual G4bool ReadyToDraw ()
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
virtual void DoneWithMasterThread ()
virtual void MovingToVisSubThread ()
virtual void SwitchToVisSubThread ()
virtual void DoneWithVisSubThread ()
virtual void MovingToMasterThread ()
virtual void SwitchToMasterThread ()
void InsertModelInSceneTree (G4VModel *)
const G4SceneTreeItemGetSceneTree ()
G4SceneTreeItemAccessSceneTree ()
void UpdateGUISceneTree ()
void UpdateGUIControlWidgets ()
void UpdateGUIDrawingStyle ()
void UpdateGUIProjectionStyle ()
void UpdateGUITransparencySlider ()
const G4StringGetName () const
const G4StringGetShortName () const
void SetName (const G4String &)
G4int GetViewId () const
G4VSceneHandlerGetSceneHandler () const
const G4ViewParametersGetViewParameters () const
const G4ViewParametersGetDefaultViewParameters () const
G4double GetKernelVisitElapsedTimeSeconds () const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers () const
void SetViewParameters (const G4ViewParameters &vp)
void SetDefaultViewParameters (const G4ViewParameters &vp)
const G4VisAttributesGetApplicableVisAttributes (const G4VisAttributes *) const
void SetNeedKernelVisit (G4bool need)
void NeedKernelVisit ()
void ProcessView ()
void ProcessTransients ()
void ZoomFromMouseWheel (G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
Public Member Functions inherited from G4ToolsSG_viewer
 G4ToolsSG_viewer ()
virtual ~G4ToolsSG_viewer ()

Protected Member Functions

 G4ToolsSGViewer (const G4ToolsSGViewer &a_from)
G4ToolsSGVieweroperator= (const G4ToolsSGViewer &)
void KernelVisitDecision ()
G4bool CompareForKernelVisit (G4ViewParameters &vp)
G4bool CompareForTransientsRedraw (G4ViewParameters &vp)
void CreateSG (tools::sg::base_camera *a_camera, const G4Vector3D &a_light_dir)
void Export (const G4String &a_format, const G4String &a_file, G4bool a_do_transparency)
G4double GetSceneNearWidth ()
Protected Member Functions inherited from G4VViewer
void SetTouchable (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath)
void TouchableSetVisibility (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, G4bool visibility)
void TouchableSetColour (const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > &fullPath, const G4Colour &)
Protected Member Functions inherited from G4ToolsSG_viewer
 G4ToolsSG_viewer (const G4ToolsSG_viewer &)
G4ToolsSG_vieweroperator= (const G4ToolsSG_viewer &)

Protected Attributes

SG_SESSION & fSGSession
G4ToolsSGSceneHandlerfSGSceneHandler
SG_VIEWER * fSGViewer
G4ViewParameters fLastVP
G4bool fMousePressed
G4double fMousePressedX
G4double fMousePressedY
tools::sg::zb_manager f_zb_mgr
tools::sg::gl2ps_manager f_gl2ps_mgr
Protected Attributes inherited from G4VViewer
G4VSceneHandlerfSceneHandler
G4int fViewId
G4String fName
G4String fShortName
G4ViewParameters fVP
G4ViewParameters fDefaultVP
G4double fKernelVisitElapsedTimeSeconds = 999.
G4SceneTreeItem fSceneTree
G4bool fNeedKernelVisit
G4bool fTransientsNeedRedrawing

Additional Inherited Members

Public Attributes inherited from G4VViewer
const G4int fMaxAllTouchables = 10000
G4bool fCurtailDescent = false

Detailed Description

template<class SG_SESSION, class SG_VIEWER>
class G4ToolsSGViewer< SG_SESSION, SG_VIEWER >

Definition at line 65 of file G4ToolsSGViewer.hh.

Constructor & Destructor Documentation

◆ G4ToolsSGViewer() [1/2]

template<class SG_SESSION, class SG_VIEWER>
G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::G4ToolsSGViewer ( SG_SESSION & a_session,
G4ToolsSGSceneHandler & a_scene_handler,
const G4String & a_name )
inline

Definition at line 126 of file G4ToolsSGViewer.hh.

127 :parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
130 ,fSGViewer(nullptr)
131 ,fMousePressed(false)
134 {
136 }
SG_SESSION & fSGSession
G4ToolsSGSceneHandler & fSGSceneHandler
SG_VIEWER * fSGViewer

Referenced by G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Messenger::SetNewValue().

◆ ~G4ToolsSGViewer()

template<class SG_SESSION, class SG_VIEWER>
virtual G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::~G4ToolsSGViewer ( )
inlinevirtual

Definition at line 138 of file G4ToolsSGViewer.hh.

138 {
139 //::printf("debug : G4ToolsSGViewer::~G4ToolsSGViewer: %lu\n",this);
140 //WARNING : nodes may refer f_gl2ps_mgr, f_zb_mgr (to handle gstos (for GPU) or textures), then
141 // we have to delete them first.
142 fSGViewer->sg().clear();
143 delete fSGViewer;
144 }

◆ G4ToolsSGViewer() [2/2]

template<class SG_SESSION, class SG_VIEWER>
G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::G4ToolsSGViewer ( const G4ToolsSGViewer< SG_SESSION, SG_VIEWER > & a_from)
inlineprotected

Definition at line 146 of file G4ToolsSGViewer.hh.

147 :parent(a_from)
148 ,parent_viewer(a_from)
149 ,parent_interactor(a_from)
152 ,fSGViewer(nullptr)
153 ,fMousePressed(false)
156 {}

Member Function Documentation

◆ ClearView()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::ClearView ( void )
inlinevirtual

Implements G4VViewer.

Reimplemented in G4ToolsSGOffscreenViewer.

Definition at line 290 of file G4ToolsSGViewer.hh.

290{}

◆ CompareForKernelVisit()

template<class SG_SESSION, class SG_VIEWER>
G4bool G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::CompareForKernelVisit ( G4ViewParameters & vp)
inlineprotected

Definition at line 346 of file G4ToolsSGViewer.hh.

346 {
347 // Typical comparison. Taken from OpenInventor.
348 if (
349 (vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
350 (vp.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
351 (vp.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
352 (vp.IsCulling () != fVP.IsCulling ()) ||
353 (vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
354 (vp.IsDensityCulling () != fVP.IsDensityCulling ()) ||
355 (vp.IsCullingCovered () != fVP.IsCullingCovered ()) ||
356 (vp.GetCBDAlgorithmNumber() !=
357 fVP.GetCBDAlgorithmNumber()) ||
358 (vp.IsSection () != fVP.IsSection ()) ||
359 (vp.IsCutaway () != fVP.IsCutaway ()) ||
360 // This assumes use of generic clipping (sectioning, slicing,
361 // DCUT, cutaway). If a decision is made to implement locally,
362 // this will need changing. See G4OpenGLViewer::SetView,
363 // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
364 // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
365 (vp.IsExplode () != fVP.IsExplode ()) ||
366 (vp.GetNoOfSides () != fVP.GetNoOfSides ()) ||
367 (vp.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
368 (vp.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
369 (vp.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
370 (vp.GetDefaultVisAttributes()->GetColour() !=
371 fVP.GetDefaultVisAttributes()->GetColour()) ||
372 (vp.GetDefaultTextVisAttributes()->GetColour() !=
373 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
374 (vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
375 (vp.IsPicking () != fVP.IsPicking ()) ||
376 // Scaling for ToolsSG is done by the scene handler so it
377 // needs a kernel visit. (In this respect, it differs from the
378 // OpenGL drivers, where it's done in SetView.)
379 (vp.GetScaleFactor () != fVP.GetScaleFactor ()) ||
380 (vp.GetVisAttributesModifiers() != fVP.GetVisAttributesModifiers()) ||
381 (vp.IsSpecialMeshRendering() != fVP.IsSpecialMeshRendering()) ||
382 (vp.GetSpecialMeshRenderingOption()!= fVP.GetSpecialMeshRenderingOption())||
383 (vp.GetTransparencyByDepth() != fVP.GetTransparencyByDepth()) ||
384 (vp.IsDotsSmooth() != fVP.IsDotsSmooth()) ||
385 (vp.GetDotsSize() != fVP.GetDotsSize())
386 )
387 return true;
388
389 if (vp.IsDensityCulling () &&
390 (vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
391 return true;
392
393 if (vp.GetCBDAlgorithmNumber() > 0) {
394 if (vp.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
395 else if (vp.GetCBDParameters() != fVP.GetCBDParameters()) return true;
396 }
397
398 if (vp.IsSection () &&
399 (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
400 return true;
401
402 if (vp.IsCutaway ()) {
403 if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
404 if (vp.GetCutawayPlanes ().size () !=
405 fVP.GetCutawayPlanes ().size ()) return true;
406 for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
407 if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
408 return true;
409 }
410
411 if (vp.IsExplode () &&
412 (vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
413 return true;
414
415 if (vp.IsSpecialMeshRendering() &&
416 (vp.GetSpecialMeshVolumes() != fVP.GetSpecialMeshVolumes()))
417 return true;
418
419 if (vp.GetTransparencyByDepth() > 0. &&
420 vp.GetTransparencyByDepthOption() != fVP.GetTransparencyByDepthOption())
421 return true;
422
423 return false;
424 }
G4ViewParameters fVP
Definition G4VViewer.hh:272

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::KernelVisitDecision().

◆ CompareForTransientsRedraw()

template<class SG_SESSION, class SG_VIEWER>
G4bool G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::CompareForTransientsRedraw ( G4ViewParameters & vp)
inlineprotected

Definition at line 426 of file G4ToolsSGViewer.hh.

426 {
427 if (vp.GetTimeParameters() != fVP.GetTimeParameters()) {
428 return fTransientsNeedRedrawing = true;
429 }
430 return false;
431 }
G4bool fTransientsNeedRedrawing
Definition G4VViewer.hh:281

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::DrawView().

◆ CreateSG()

template<class SG_SESSION, class SG_VIEWER>
void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::CreateSG ( tools::sg::base_camera * a_camera,
const G4Vector3D & a_light_dir )
inlineprotected

2D scene graph: ///////////////////////////////

3D scene graph: ///////////////////////////////

Definition at line 434 of file G4ToolsSGViewer.hh.

434 {
436 _parent.clear();
437
438 ///////////////////////////////////////////////////
439 /// 2D scene graph: ///////////////////////////////
440 ///////////////////////////////////////////////////
442 _parent.add(scene_2D);
443 scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient2DObjects()));
444 scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent2DObjects()));
445
446 ///////////////////////////////////////////////////
447 /// 3D scene graph: ///////////////////////////////
448 ///////////////////////////////////////////////////
450 _parent.add(scene_3D);
451
452 scene_3D->add(a_camera);
453
456 scene_3D->add(shade_model);}
457
459 light->on = true;
460 light->direction = tools::vec3f(-a_light_dir.x(),-a_light_dir.y(),-a_light_dir.z());
461 light->ambient = tools::colorf(0.2f,0.2f,0.2f,1.0f); //same as in G4OpenGLViewer.cc glLight(GL_LIGHT0,GL_AMBIENT and GL_DIFFUSE).
462 light->color = tools::colorf(0.8f,0.8f,0.8f,1.0f); //idem.
463 scene_3D->add(light);}
464
466 blend->on = true; //to handle transparency.
467 scene_3D->add(blend);}
468
469 scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient3DObjects()));
470 scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent3DObjects()));
471 }

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::SetView().

◆ DrawView()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::DrawView ( )
inlinevirtual

Implements G4VViewer.

Reimplemented in G4ToolsSGOffscreenViewer.

Definition at line 292 of file G4ToolsSGViewer.hh.

292 {
293
295 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
296 ProcessView(); // Clears store and processes scene only if necessary.
297
299 // We might need to do something if the kernel was visited.
300 } else { // Or even if it was not!
304 }
305 }
306
307 FinishView (); // Flush streams and/or swap buffers.
308
309 fLastVP = fVP;
310 }
virtual void FinishView()
G4bool CompareForTransientsRedraw(G4ViewParameters &vp)
G4ViewParameters fLastVP
G4bool fNeedKernelVisit
Definition G4VViewer.hh:280
void ProcessView()
Definition G4VViewer.cc:112
void ProcessTransients()
Definition G4VViewer.cc:133

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::mouse_move(), and G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::wheel_rotate().

◆ EmitWindowRender()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::EmitWindowRender ( )
inlinevirtual

Reimplemented from G4ToolsSG_viewer.

Definition at line 334 of file G4ToolsSGViewer.hh.

334 {
335 if(!fSGViewer) return;
336 fSGViewer->emit_win_render();
337 }

◆ Export()

template<class SG_SESSION, class SG_VIEWER>
void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Export ( const G4String & a_format,
const G4String & a_file,
G4bool a_do_transparency )
inlineprotected

Definition at line 473 of file G4ToolsSGViewer.hh.

473 {
474 if(!fSGViewer) return;
475 const G4Colour& back_color = fVP.GetBackgroundColour();
476 bool top_to_bottom = false; //if using tools::fpng, tools::toojpeg.
479 float(back_color.GetRed()),float(back_color.GetGreen()),float(back_color.GetBlue()),float(back_color.GetAlpha()),
480 fSGViewer->sg(),fSGViewer->width(),fSGViewer->height(),
482 G4cout << "G4ToolsSGViewer::Export: write_paper() failed." << G4endl;
483 return;
484 }
485 }
tools::sg::gl2ps_manager f_gl2ps_mgr
tools::sg::zb_manager f_zb_mgr

Referenced by G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Messenger::SetNewValue().

◆ FinishView()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::FinishView ( void )
inlinevirtual

Reimplemented from G4VViewer.

Reimplemented in G4ToolsSGOffscreenViewer.

Definition at line 314 of file G4ToolsSGViewer.hh.

314 {
315 if(fSGViewer) {
316 fSGSceneHandler.TouchPlotters(fSGViewer->sg());
317 fSGViewer->show();
318 fSGViewer->win_render();
319 }
320 }

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::DrawView(), and G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::ShowView().

◆ GetRenderAreaSize()

template<class SG_SESSION, class SG_VIEWER>
G4bool G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::GetRenderAreaSize ( unsigned int & a_w,
unsigned int & a_h )
inline

Definition at line 327 of file G4ToolsSGViewer.hh.

327 {
328 if (!fSGViewer) {a_w = 0; a_h = 0; return false;}
329 fSGViewer->render_area_size(a_w, a_h);
330 return true;
331 }

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::SetView().

◆ GetSceneNearWidth()

template<class SG_SESSION, class SG_VIEWER>
G4double G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::GetSceneNearWidth ( )
inlineprotectedvirtual

Reimplemented from G4VViewer.

Definition at line 487 of file G4ToolsSGViewer.hh.

487 {
488 if (!fSGSceneHandler.GetScene()) {
489 return 0;
490 }
491 const G4Point3D targetPoint =
492 fSGSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint();
493 G4double radius = fSGSceneHandler.GetScene()->GetExtent().GetExtentRadius();
494 if (radius <= 0.) radius = 1.;
495 const G4double cameraDistance = fVP.GetCameraDistance(radius);
496 const G4double pnear = fVP.GetNearDistance(cameraDistance, radius);
497
499 if (fVP.GetFieldHalfAngle() == 0.) {
500 frontHalfHeight = radius / fVP.GetZoomFactor();
501 } else {
502 // Code from G4ViewParameters adapted to the different zoom behavior in TSG (angle)
503 frontHalfHeight = pnear * std::tan(fVP.GetFieldHalfAngle() / fVP.GetZoomFactor());
504 }
505 return 2 * frontHalfHeight;
506 }

◆ GetWindowSize()

template<class SG_SESSION, class SG_VIEWER>
G4bool G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::GetWindowSize ( unsigned int & a_w,
unsigned int & a_h )
inlinevirtual

Reimplemented from G4VViewer.

Definition at line 323 of file G4ToolsSGViewer.hh.

323 {
324 if(!fSGViewer) {a_w = 0; a_h = 0; return false;}
325 return fSGViewer->window_size(a_w,a_h);
326 }

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::SetView().

◆ Initialise()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::Initialise ( )
inlinevirtual

create the viewer, set the scene graph ///////////////

Reimplemented from G4VViewer.

Reimplemented in G4ToolsSGOffscreenViewer, G4ToolsSGQtGLESViewer, and G4ToolsSGQtZBViewer.

Definition at line 159 of file G4ToolsSGViewer.hh.

159 {
160 if(fSGViewer) return; //done.
161 fVP.SetAutoRefresh(true);
162 fDefaultVP.SetAutoRefresh(true);
163 //::printf("debug : G4ToolsSGViewer::Initialise\n");
164 //////////////////////////////////////////////////////////
165 /// create the viewer, set the scene graph ///////////////
166 //////////////////////////////////////////////////////////
168 ,fVP.GetWindowAbsoluteLocationHintX(1440)
169 ,fVP.GetWindowAbsoluteLocationHintY(900)
170 ,fVP.GetWindowSizeHintX()
171 ,fVP.GetWindowSizeHintY()
172 ,fName);
173 if(!fSGViewer->has_window()) {
174 fViewId = -1; // This flags an error.
175 G4cerr << "G4ToolsSGViewer::Initialise : SG_VIEWER::has_window() failed." << G4endl;
176 return;
177 }
178 fSGViewer->set_device_interactor(this);
179 }
G4String fName
Definition G4VViewer.hh:270
G4ViewParameters fDefaultVP
Definition G4VViewer.hh:273
G4int fViewId
Definition G4VViewer.hh:269

◆ KernelVisitDecision()

template<class SG_SESSION, class SG_VIEWER>
void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::KernelVisitDecision ( )
inlineprotected

Definition at line 340 of file G4ToolsSGViewer.hh.

340 {
342 NeedKernelVisit (); // Sets fNeedKernelVisit.
343 }
344 }
G4bool CompareForKernelVisit(G4ViewParameters &vp)
void NeedKernelVisit()
Definition G4VViewer.cc:85

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::DrawView().

◆ key_press()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::key_press ( const tools::sg::key_down_event & )
inlinevirtual

Definition at line 70 of file G4ToolsSGViewer.hh.

70{}

◆ key_release()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::key_release ( const tools::sg::key_up_event & )
inlinevirtual

Definition at line 71 of file G4ToolsSGViewer.hh.

71{}

◆ mouse_move()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::mouse_move ( const tools::sg::mouse_move_event & a_event)
inlinevirtual

Definition at line 78 of file G4ToolsSGViewer.hh.

78 {
79 G4double x = a_event.x();
80 G4double y = a_event.y();
85
86 if (fMousePressed) {
87
88 if (a_event.shift_modifier()) { // Translation (pan)
89 const G4double sceneRadius = fSGSceneHandler.GetScene()->GetExtent().GetExtentRadius();
90 const G4double scale = 300; // Roughly pixels per window, empirically chosen
93 fVP.IncrementPan(-dxScene,dyScene);
94
95 } else { // Rotation
96
97 // Simple ad-hoc algorithms
98 const G4Vector3D& x_prime = fVP.GetViewpointDirection().cross(fVP.GetUpVector());
99 const G4Vector3D& y_prime = x_prime.cross(fVP.GetViewpointDirection());
100 const G4double scale = 200; // Roughly pixels per window, empirically chosen
101 G4Vector3D newViewpointDirection = fVP.GetViewpointDirection();
104 fVP.SetViewpointDirection(newViewpointDirection.unit());
105
106 if (fVP.GetRotationStyle() == G4ViewParameters::freeRotation) {
107 G4Vector3D newUpVector = fVP.GetUpVector();
110 fVP.SetUpVector(newUpVector.unit());
111 }
112 }
113 }
114
115 SetView();
116 DrawView();
117 }
virtual void SetView()
virtual void DrawView()

◆ mouse_press()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::mouse_press ( const tools::sg::mouse_down_event & a_event)
inlinevirtual

Definition at line 72 of file G4ToolsSGViewer.hh.

72 {
73 fMousePressed = true;
76 }

◆ mouse_release()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::mouse_release ( const tools::sg::mouse_up_event & )
inlinevirtual

Definition at line 77 of file G4ToolsSGViewer.hh.

77{fMousePressed = false;}

◆ operator=()

template<class SG_SESSION, class SG_VIEWER>
G4ToolsSGViewer & G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::operator= ( const G4ToolsSGViewer< SG_SESSION, SG_VIEWER > & )
inlineprotected

Definition at line 157 of file G4ToolsSGViewer.hh.

157{return *this;}

◆ SetView()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::SetView ( )
inlinevirtual

create scene graph ///////////////////////////////////

Implements G4VViewer.

Definition at line 181 of file G4ToolsSGViewer.hh.

181 {
182 //::printf("debug : G4ToolsSGViewer::SetView\n");
183 if(!fSceneHandler.GetScene()) {
184 fSGViewer->set_clear_color(0.3,0.3,0.3,1); //some grey color to signal the user that something is wrong.
185 G4cerr << "G4ToolsSGViewer::SetView : no G4Scene.." << G4endl;
186 return;
187 }
188
189 //////////////////////////////////////////////////////////
190 //////////////////////////////////////////////////////////
191 //////////////////////////////////////////////////////////
192 // Get radius of scene, etc.
193 // Note that this procedure properly takes into account zoom, dolly and pan.
195 = fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint ();
196 G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
197 if(radius<=0.) radius = 1.;
198 const G4double cameraDistance = fVP.GetCameraDistance (radius);
199 const G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
200 const G4Normal3D& up = fVP.GetUpVector ();
201 const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
202 const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
203 //const G4double right = fVP.GetFrontHalfHeight (pnear, radius);
204 //const G4double left = -right;
205 const G4double top = fVP.GetFrontHalfHeight (pnear, radius);
206 const G4double bottom = -top;
207 // sanity check :
209 float(targetPoint.y()-cameraPosition.y()),
210 float(targetPoint.z()-cameraPosition.z()));
211 if(!dir.length()) {
212 fSGViewer->set_clear_color(0.3,0.3,0.3,1);
213 G4cerr << "G4ToolsSGViewer::SetView : null size viewer area." << G4endl;
214 return;
215 }
216
217 {// With Qt/Cocoa/OpenGL, Qt/Windows/OpenGL, the received size in
218 // tools::sg::glarea::resizeGL is the QWidget::[width(),height()] multiplied by the "devicePixelRatio"
219 // (with a value of 2 seen on a MacBookPro and 1.5 seen on a Windows laptop).
220 // In general it does not pose problem, except when rendering 2D texts.
221 // In order to have similar sizes than other drivers, we adapt their scale accordingly.
222 unsigned int ww,wh;
223 if(GetWindowSize(ww,wh)) {
224 unsigned int raw,rah;
226 if(ww!=0) {
227 double width_ratio = double(raw)/double(ww);
228 fSGSceneHandler.SetMarkerScale(width_ratio);
229 }
230 }
231 }}
232
233 //////////////////////////////////////////////////////////
234 //////////////////////////////////////////////////////////
235 //////////////////////////////////////////////////////////
236 /*
237 G4cout << "debug : 0002 : radius " << radius << std::endl;
238 G4cout << "debug : cameraDistance : " << cameraDistance << std::endl;
239 G4cout << "debug : fieldHalfAngle : " << fVP.GetFieldHalfAngle() << std::endl;
240 G4cout << "debug : zoomFactor : " << fVP.GetZoomFactor() << std::endl;
241 G4cout << "debug : up : " << up.x() << " " << up.y() << " " << up.z() << std::endl;
242 G4cout << "debug : targetPoint : " << targetPoint.x() << " " << targetPoint.y() << " " << targetPoint.z() << std::endl;
243 G4cout << "debug : cameraPosition : " << cameraPosition.x() << " " << cameraPosition.y() << " " << cameraPosition.z() << std::endl;
244 G4cout << "debug : camera : znear " << pnear << ", zfar " << pfar << std::endl;
245 */
246 //////////////////////////////////////////////////////////
247 /// create scene graph ///////////////////////////////////
248 //////////////////////////////////////////////////////////
249 // Set projection, then create the tools::sg camera node :
251 if (fVP.GetFieldHalfAngle() <= 0.) {
252 //G4cout << "debug : camera : ortho : top " << top << " bottom " << bottom << " top-bottom " << top-bottom << std::endl;
253 if((top-bottom)<=0) {
254 fSGViewer->set_clear_color(0.3,0.3,0.3,1);
255 G4cerr << "G4ToolsSGViewer::SetView : for ortho camera, (top-bottom)<=0." << G4endl;
256 return;
257 }
259 ortho_camera->height.value(float(top-bottom));
261 } else {
262 //G4cout << "debug : camera : perspec : heightAngle " << float(2*fVP.GetFieldHalfAngle()) << std::endl;
264 perspective_camera->height_angle.value(2 * std::atan(std::tan(fVP.GetFieldHalfAngle()) / fVP.GetZoomFactor()));
266 }
267
268 _camera->position.value
269 (tools::vec3f(float(cameraPosition.x()),
270 float(cameraPosition.y()),
271 float(cameraPosition.z())));
272 _camera->znear.value(float(pnear));
273 _camera->zfar.value(float(pfar));
274
275 _camera->look_at(dir,tools::vec3f(up.x(),up.y(),up.z())); //same logic as in G4OpenInventorViewer.
276
277 /*
278 const G4Vector3D& lightDirection = fVP.GetLightpointDirection();
279 G4cout << "debug : lightDirection : " << lightDirection.x() << " " << lightDirection.y() << " " << lightDirection.z() << std::endl;
280 const G4Vector3D& actualLightDirection = fVP.GetActualLightpointDirection();
281 G4cout << "debug : actualLightDirection : " << actualLightDirection.x() << " " << actualLightDirection.y() << " " << actualLightDirection.z() << std::endl;
282 */
283
284 CreateSG(_camera,fVP.GetActualLightpointDirection());
285
286 {G4Color background = fVP.GetBackgroundColour ();
287 fSGViewer->set_clear_color(float(background.GetRed()),float(background.GetGreen()),float(background.GetBlue()),1);}
288 }
G4bool GetRenderAreaSize(unsigned int &a_w, unsigned int &a_h)
G4bool GetWindowSize(unsigned int &a_w, unsigned int &a_h)
void CreateSG(tools::sg::base_camera *a_camera, const G4Vector3D &a_light_dir)
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:268

Referenced by G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::mouse_move(), and G4ToolsSGViewer< tools::offscreen::session, tools::offscreen::sg_viewer >::wheel_rotate().

◆ ShowView()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::ShowView ( void )
inlinevirtual

Reimplemented from G4VViewer.

Reimplemented in G4ToolsSGOffscreenViewer.

Definition at line 312 of file G4ToolsSGViewer.hh.

312{FinishView();}

◆ wheel_rotate()

template<class SG_SESSION, class SG_VIEWER>
virtual void G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::wheel_rotate ( const tools::sg::wheel_rotate_event & a_event)
inlinevirtual

Definition at line 118 of file G4ToolsSGViewer.hh.

118 {
119
120 ZoomFromMouseWheel(a_event.angle(), a_event.shift_modifier(), a_event.x(), a_event.y());
121
122 SetView();
123 DrawView();
124 }
void ZoomFromMouseWheel(G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
Definition G4VViewer.cc:144

Member Data Documentation

◆ f_gl2ps_mgr

template<class SG_SESSION, class SG_VIEWER>
tools::sg::gl2ps_manager G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::f_gl2ps_mgr
protected

Definition at line 584 of file G4ToolsSGViewer.hh.

◆ f_zb_mgr

template<class SG_SESSION, class SG_VIEWER>
tools::sg::zb_manager G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::f_zb_mgr
protected

Definition at line 583 of file G4ToolsSGViewer.hh.

◆ fLastVP

template<class SG_SESSION, class SG_VIEWER>
G4ViewParameters G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fLastVP
protected

Definition at line 578 of file G4ToolsSGViewer.hh.

◆ fMousePressed

template<class SG_SESSION, class SG_VIEWER>
G4bool G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fMousePressed
protected

Definition at line 580 of file G4ToolsSGViewer.hh.

◆ fMousePressedX

template<class SG_SESSION, class SG_VIEWER>
G4double G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fMousePressedX
protected

Definition at line 581 of file G4ToolsSGViewer.hh.

◆ fMousePressedY

template<class SG_SESSION, class SG_VIEWER>
G4double G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fMousePressedY
protected

Definition at line 581 of file G4ToolsSGViewer.hh.

◆ fSGSceneHandler

template<class SG_SESSION, class SG_VIEWER>
G4ToolsSGSceneHandler& G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fSGSceneHandler
protected

Definition at line 576 of file G4ToolsSGViewer.hh.

◆ fSGSession

template<class SG_SESSION, class SG_VIEWER>
SG_SESSION& G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fSGSession
protected

Definition at line 575 of file G4ToolsSGViewer.hh.

◆ fSGViewer

template<class SG_SESSION, class SG_VIEWER>
SG_VIEWER* G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::fSGViewer
protected

Definition at line 577 of file G4ToolsSGViewer.hh.


The documentation for this class was generated from the following file: