Geant4 11.1.1
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 &a_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 ()
 
- Public Member Functions inherited from G4VViewer
 G4VViewer (G4VSceneHandler &, G4int id, const G4String &name="")
 
virtual ~G4VViewer ()
 
virtual void Initialise ()
 
virtual void ResetView ()
 
virtual void SetView ()=0
 
virtual void ClearView ()=0
 
virtual void DrawView ()=0
 
void RefreshView ()
 
virtual void ShowView ()
 
virtual void FinishView ()
 
std::vector< G4ThreeVectorComputeFlyThrough (G4Vector3D *)
 
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 ()
 

Protected Member Functions

 G4ToolsSGViewer (const G4ToolsSGViewer &a_from)
 
G4ToolsSGVieweroperator= (const G4ToolsSGViewer &)
 
void KernelVisitDecision ()
 
G4bool CompareForKernelVisit (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)
 
- 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 Attributes

SG_SESSION & fSGSession
 
G4ToolsSGSceneHandlerfSGSceneHandler
 
SG_VIEWER * fSGViewer
 
G4ViewParameters fLastVP
 
G4bool fKeyPressed
 
G4bool fKeyShift
 
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.
 
G4bool fNeedKernelVisit
 

Detailed Description

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

Definition at line 53 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 122 of file G4ToolsSGViewer.hh.

123 :parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
124 ,fSGSession(a_session)
125 ,fSGSceneHandler(a_scene_handler)
126 ,fSGViewer(nullptr)
127 ,fKeyPressed(false)
128 ,fKeyShift(false)
129 ,fMousePressed(false)
132 {
133 //::printf("debug : G4ToolsSGViewer::G4ToolsSGViewer: %lu, %s\n",this,a_name.c_str());
135 }
SG_SESSION & fSGSession
G4ToolsSGSceneHandler & fSGSceneHandler
SG_VIEWER * fSGViewer
G4int IncrementViewCount()

◆ ~G4ToolsSGViewer()

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

Definition at line 137 of file G4ToolsSGViewer.hh.

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

◆ 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 145 of file G4ToolsSGViewer.hh.

146 :parent(a_from)
147 ,parent_interactor(a_from)
148 ,fSGSession(a_from.fSGSession)
150 ,fSGViewer(nullptr)
151 ,fKeyPressed(false)
152 ,fKeyShift(false)
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 274 of file G4ToolsSGViewer.hh.

274{}

◆ CompareForKernelVisit()

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

Definition at line 334 of file G4ToolsSGViewer.hh.

334 {
335 // Typical comparison. Taken from OpenInventor.
336 if (
337 (vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
339 (vp.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
340 (vp.IsCulling () != fVP.IsCulling ()) ||
342 (vp.IsDensityCulling () != fVP.IsDensityCulling ()) ||
343 (vp.IsCullingCovered () != fVP.IsCullingCovered ()) ||
344 (vp.GetCBDAlgorithmNumber() !=
346 (vp.IsSection () != fVP.IsSection ()) ||
347 (vp.IsCutaway () != fVP.IsCutaway ()) ||
348 // This assumes use of generic clipping (sectioning, slicing,
349 // DCUT, cutaway). If a decision is made to implement locally,
350 // this will need changing. See G4OpenGLViewer::SetView,
351 // G4OpenGLStoredViewer.cc::CompareForKernelVisit and
352 // G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
353 (vp.IsExplode () != fVP.IsExplode ()) ||
354 (vp.GetNoOfSides () != fVP.GetNoOfSides ()) ||
363 (vp.IsPicking () != fVP.IsPicking ()) ||
364 // Scaling for Open Inventor is done by the scene handler so it
365 // needs a kernel visit. (In this respect, it differs from the
366 // OpenGL drivers, where it's done in SetView.)
367 (vp.GetScaleFactor () != fVP.GetScaleFactor ()) ||
374 )
375 return true;
376
377 if (vp.IsDensityCulling () &&
379 return true;
380
381 if (vp.GetCBDAlgorithmNumber() > 0) {
382 if (vp.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
383 else if (vp.GetCBDParameters() != fVP.GetCBDParameters()) return true;
384 }
385
386 if (vp.IsSection () &&
387 (vp.GetSectionPlane () != fVP.GetSectionPlane ()))
388 return true;
389
390 if (vp.IsCutaway ()) {
391 if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
392 if (vp.GetCutawayPlanes ().size () !=
393 fVP.GetCutawayPlanes ().size ()) return true;
394 for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
395 if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
396 return true;
397 }
398
399 if (vp.IsExplode () &&
401 return true;
402
403 if (vp.IsSpecialMeshRendering() &&
405 return true;
406
407 return false;
408 }
G4ViewParameters fVP
Definition: G4VViewer.hh:220
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
G4bool IsSpecialMeshRendering() const
CutawayMode GetCutawayMode() const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
G4bool IsCutaway() const
const G4Colour & GetBackgroundColour() const
G4bool IsSection() const
G4bool IsPicking() const
G4bool IsCulling() const
const G4VisAttributes * GetDefaultTextVisAttributes() const
G4bool IsExplode() const
const std::vector< G4double > & GetCBDParameters() const
G4int GetCBDAlgorithmNumber() const
const std::vector< G4ModelingParameters::PVNameCopyNo > & GetSpecialMeshVolumes() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
const G4Planes & GetCutawayPlanes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
SMROption GetSpecialMeshRenderingOption() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const

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

◆ 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 418 of file G4ToolsSGViewer.hh.

418 {
419 tools::sg::group& _parent = fSGViewer->sg();
420 _parent.clear();
421
422 ///////////////////////////////////////////////////
423 /// 2D scene graph: ///////////////////////////////
424 ///////////////////////////////////////////////////
425 tools::sg::separator* scene_2D = new tools::sg::separator;
426 _parent.add(scene_2D);
427 scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient2DObjects()));
428 scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent2DObjects()));
429
430 ///////////////////////////////////////////////////
431 /// 3D scene graph: ///////////////////////////////
432 ///////////////////////////////////////////////////
433 tools::sg::separator* scene_3D = new tools::sg::separator;
434 _parent.add(scene_3D);
435
436 scene_3D->add(a_camera);
437
438 {tools::sg::torche* light = new tools::sg::torche;
439 light->on = true;
440 light->direction = tools::vec3f(-a_light_dir.x(),-a_light_dir.y(),-a_light_dir.z());
441 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).
442 light->color = tools::colorf(0.8f,0.8f,0.8f,1.0f); //idem.
443 scene_3D->add(light);}
444
445 {tools::sg::blend* blend = new tools::sg::blend;
446 blend->on = true; //to handle transparency.
447 scene_3D->add(blend);}
448
449 scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient3DObjects()));
450 scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent3DObjects()));
451 }
tools::sg::separator & GetTransient3DObjects()
tools::sg::separator & GetTransient2DObjects()
tools::sg::separator & GetPersistent3DObjects()
tools::sg::separator & GetPersistent2DObjects()

Referenced by G4ToolsSGViewer< SG_SESSION, 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 276 of file G4ToolsSGViewer.hh.

276 {
278 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
279 fLastVP = fVP;
280 ProcessView(); // Clears store and processes scene only if necessary.
281 if (kernelVisitWasNeeded) {
282 // We might need to do something if the kernel was visited.
283 } else {
284 }
285 FinishView (); // Flush streams and/or swap buffers.
286 }
bool G4bool
Definition: G4Types.hh:86
virtual void FinishView()
G4ViewParameters fLastVP
G4bool fNeedKernelVisit
Definition: G4VViewer.hh:227
void ProcessView()
Definition: G4VViewer.cc:107

Referenced by G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::mouse_move(), and G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::wheel_rotate().

◆ 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 453 of file G4ToolsSGViewer.hh.

453 {
454 if(!fSGViewer) return;
455 const G4Colour& back_color = fVP.GetBackgroundColour();
456 bool top_to_bottom = false; //if using tools::fpng, tools::toojpeg.
457 if(!tools::sg::write_paper(G4cout,f_gl2ps_mgr,f_zb_mgr,
458 tools::fpng::write,tools::toojpeg::write,
459 float(back_color.GetRed()),float(back_color.GetGreen()),float(back_color.GetBlue()),float(back_color.GetAlpha()),
460 fSGViewer->sg(),fSGViewer->width(),fSGViewer->height(),
461 a_file,a_format,a_do_transparency,top_to_bottom,std::string(),std::string())) {
462 G4cout << "G4ToolsSGViewer::Export: write_paper() failed." << G4endl;
463 return;
464 }
465 }
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4double GetBlue() const
Definition: G4Colour.hh:154
G4double GetAlpha() const
Definition: G4Colour.hh:155
G4double GetRed() const
Definition: G4Colour.hh:152
G4double GetGreen() const
Definition: G4Colour.hh:153
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 290 of file G4ToolsSGViewer.hh.

290 {
291 if(fSGViewer) {
293 fSGViewer->show();
294 fSGViewer->win_render();
295 fSGSession.sync();
296 }
297 }
void TouchPlotters(tools::sg::node &)

Referenced by G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::DrawView(), and G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::ShowView().

◆ 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, and G4ToolsSGQtViewer.

Definition at line 159 of file G4ToolsSGViewer.hh.

159 {
160 if(fSGViewer) return; //done.
161 fVP.SetAutoRefresh(true);
163 //::printf("debug : G4ToolsSGViewer::Initialise\n");
164 //////////////////////////////////////////////////////////
165 /// create the viewer, set the scene graph ///////////////
166 //////////////////////////////////////////////////////////
167 fSGViewer = new SG_VIEWER(fSGSession
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 }
G4GLOB_DLL std::ostream G4cerr
G4String fName
Definition: G4VViewer.hh:218
G4ViewParameters fDefaultVP
Definition: G4VViewer.hh:221
G4int fViewId
Definition: G4VViewer.hh:217
void SetAutoRefresh(G4bool)
G4int GetWindowAbsoluteLocationHintY(G4int) const
unsigned int GetWindowSizeHintX() const
G4int GetWindowAbsoluteLocationHintX(G4int) const
unsigned int GetWindowSizeHintY() const

◆ KernelVisitDecision()

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

Definition at line 328 of file G4ToolsSGViewer.hh.

328 {
330 NeedKernelVisit (); // Sets fNeedKernelVisit.
331 }
332 }
G4bool CompareForKernelVisit(G4ViewParameters &vp)
void NeedKernelVisit()
Definition: G4VViewer.cc:80

Referenced by G4ToolsSGViewer< SG_SESSION, 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 &  a_event)
inlinevirtual

Definition at line 57 of file G4ToolsSGViewer.hh.

57 {
58 fKeyPressed = true;
59 fKeyShift = a_event.key() == tools::sg::key_shift()?true:false;
60 }

◆ 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 61 of file G4ToolsSGViewer.hh.

61{fKeyPressed = false;}

◆ 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 68 of file G4ToolsSGViewer.hh.

68 {
69 G4double x = a_event.x();
70 G4double y = a_event.y();
75
76 if (fMousePressed) {
77
78 if (fKeyPressed && fKeyShift) { // Translation (pan)
79
81 const G4double scale = 300; // Roughly pixels per window, empirically chosen
82 const G4double dxScene = dx*sceneRadius/scale;
83 const G4double dyScene = dy*sceneRadius/scale;
84 fVP.IncrementPan(-dxScene,dyScene);
85
86 } else { // Rotation
87
88 // Simple ad-hoc algorithms
90 const G4Vector3D& y_prime = x_prime.cross(fVP.GetViewpointDirection());
91 const G4double scale = 200; // Roughly pixels per window, empirically chosen
92 G4Vector3D newViewpointDirection = fVP.GetViewpointDirection();
93 newViewpointDirection += dx*x_prime/scale;
94 newViewpointDirection += dy*y_prime/scale;
95 fVP.SetViewpointDirection(newViewpointDirection.unit());
96
98 G4Vector3D newUpVector = fVP.GetUpVector();
99 newUpVector += dx*x_prime/scale;
100 newUpVector += dy*y_prime/scale;
101 fVP.SetUpVector(newUpVector.unit());
102 }
103 }
104 }
105
106 SetView();
107 DrawView();
108 }
double G4double
Definition: G4Types.hh:83
const G4VisExtent & GetExtent() const
virtual void SetView()
virtual void DrawView()
G4Scene * GetScene() const
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
const G4Vector3D & GetViewpointDirection() const
void IncrementPan(G4double right, G4double up)
const G4Vector3D & GetUpVector() const
void SetUpVector(const G4Vector3D &upVector)
RotationStyle GetRotationStyle() const
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:75
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const

◆ 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 62 of file G4ToolsSGViewer.hh.

62 {
63 fMousePressed = true;
64 fMousePressedX = a_event.x();
65 fMousePressedY = a_event.y();
66 }

◆ 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 67 of file G4ToolsSGViewer.hh.

67{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.

Reimplemented in G4ToolsSGOffscreenViewer, and G4ToolsSGQtViewer.

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.
194 const G4Point3D targetPoint
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 :
208 tools::vec3f dir(float(targetPoint.x()-cameraPosition.x()),
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 //////////////////////////////////////////////////////////
218 //////////////////////////////////////////////////////////
219 //////////////////////////////////////////////////////////
220 /*
221 G4cout << "debug : 0002 : radius " << radius << std::endl;
222 G4cout << "debug : cameraDistance : " << cameraDistance << std::endl;
223 G4cout << "debug : fieldHalfAngle : " << fVP.GetFieldHalfAngle() << std::endl;
224 G4cout << "debug : zoomFactor : " << fVP.GetZoomFactor() << std::endl;
225 G4cout << "debug : up : " << up.x() << " " << up.y() << " " << up.z() << std::endl;
226 G4cout << "debug : targetPoint : " << targetPoint.x() << " " << targetPoint.y() << " " << targetPoint.z() << std::endl;
227 G4cout << "debug : cameraPosition : " << cameraPosition.x() << " " << cameraPosition.y() << " " << cameraPosition.z() << std::endl;
228 G4cout << "debug : camera : znear " << pnear << ", zfar " << pfar << std::endl;
229 */
230 //////////////////////////////////////////////////////////
231 /// create scene graph ///////////////////////////////////
232 //////////////////////////////////////////////////////////
233 // Set projection, then create the tools::sg camera node :
234 tools::sg::base_camera* _camera = nullptr;
235 if (fVP.GetFieldHalfAngle() <= 0.) {
236 //G4cout << "debug : camera : ortho : top " << top << " bottom " << bottom << " top-bottom " << top-bottom << std::endl;
237 if((top-bottom)<=0) {
238 fSGViewer->set_clear_color(0.3,0.3,0.3,1);
239 G4cerr << "G4ToolsSGViewer::SetView : for ortho camera, (top-bottom)<=0." << G4endl;
240 return;
241 }
242 tools::sg::ortho* ortho_camera = new tools::sg::ortho;
243 ortho_camera->height.value(float(top-bottom));
244 _camera = ortho_camera;
245 } else {
246 //G4cout << "debug : camera : perspec : heightAngle " << float(2*fVP.GetFieldHalfAngle()) << std::endl;
247 tools::sg::perspective* perspective_camera = new tools::sg::perspective;
248 perspective_camera->height_angle.value(float(2*fVP.GetFieldHalfAngle()));
249 _camera = perspective_camera;
250 }
251
252 _camera->position.value
253 (tools::vec3f(float(cameraPosition.x()),
254 float(cameraPosition.y()),
255 float(cameraPosition.z())));
256 _camera->znear.value(float(pnear));
257 _camera->zfar.value(float(pfar));
258
259 _camera->look_at(dir,tools::vec3f(up.x(),up.y(),up.z())); //same logic as in G4OpenInventorViewer.
260
261 /*
262 const G4Vector3D& lightDirection = fVP.GetLightpointDirection();
263 G4cout << "debug : lightDirection : " << lightDirection.x() << " " << lightDirection.y() << " " << lightDirection.z() << std::endl;
264 const G4Vector3D& actualLightDirection = fVP.GetActualLightpointDirection();
265 G4cout << "debug : actualLightDirection : " << actualLightDirection.x() << " " << actualLightDirection.y() << " " << actualLightDirection.z() << std::endl;
266 */
267
269
270 {G4Color background = fVP.GetBackgroundColour ();
271 fSGViewer->set_clear_color(float(background.GetRed()),float(background.GetGreen()),float(background.GetBlue()),1);}
272 }
const G4Point3D & GetStandardTargetPoint() const
void CreateSG(tools::sg::base_camera *a_camera, const G4Vector3D &a_light_dir)
G4VSceneHandler & fSceneHandler
Definition: G4VViewer.hh:216
G4double GetCameraDistance(G4double radius) const
G4Vector3D & GetActualLightpointDirection()
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFarDistance(G4double cameraDistance, G4double nearDistance, G4double radius) const
G4double GetFieldHalfAngle() const
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
G4double GetNearDistance(G4double cameraDistance, G4double radius) const

Referenced by G4ToolsSGViewer< SG_SESSION, SG_VIEWER >::mouse_move(), and G4ToolsSGViewer< SG_SESSION, 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 288 of file G4ToolsSGViewer.hh.

288{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 109 of file G4ToolsSGViewer.hh.

109 {
110 const G4double angleY = a_event.angle();
111 if (fVP.GetFieldHalfAngle() == 0.) { // Orthographic projection
112 const G4double scale = 500; // Empirically chosen
113 fVP.MultiplyZoomFactor(1.+angleY/scale);
114 } else { // Perspective projection
115 const G4double delta = fSceneHandler.GetExtent().GetExtentRadius()/200.; // Empirical
116 fVP.SetDolly(fVP.GetDolly()+angleY*delta);
117 }
118 SetView();
119 DrawView();
120 }
virtual const G4VisExtent & GetExtent() const
void SetDolly(G4double dolly)
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
G4double GetDolly() const

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

◆ f_zb_mgr

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

◆ fKeyPressed

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

◆ fKeyShift

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

◆ fLastVP

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

◆ fMousePressed

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

◆ fMousePressedX

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

◆ fMousePressedY

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

◆ fSGSceneHandler

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

◆ fSGSession

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

◆ fSGViewer


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