Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ToolsSGViewer.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26// John Allison 6th October 2019
27
28#ifndef G4TOOLSSGVIEWER_HH
29#define G4TOOLSSGVIEWER_HH
30
31#include "G4VViewer.hh"
32
34#include "G4Scene.hh"
35#include "G4VVisCommand.hh"
36
37#include <tools/fpng>
38#include <tools/toojpeg>
39
40#include <tools/sg/device_interactor>
41#include <tools/sg/separator>
42#include <tools/sg/ortho>
43#include <tools/sg/perspective>
44#include <tools/sg/shade_model>
45#include <tools/sg/torche>
46#include <tools/sg/blend>
47#include <tools/sg/noderef>
48#include <tools/sg/keys>
49
50#include <tools/tokenize>
51#include <tools/sg/write_paper>
52
54public:
56 virtual ~G4ToolsSG_viewer() {}
57protected:
60public:
61 virtual void EmitWindowRender() {}
62};
63
64template <class SG_SESSION,class SG_VIEWER>
65class G4ToolsSGViewer : public G4VViewer, public G4ToolsSG_viewer, tools::sg::device_interactor {
66 typedef G4VViewer parent;
67 typedef G4ToolsSG_viewer parent_viewer;
68 typedef tools::sg::device_interactor parent_interactor;
69public: //tools::sg::device_interactor interface.
70 virtual void key_press(const tools::sg::key_down_event&) {}
71 virtual void key_release(const tools::sg::key_up_event&) {}
72 virtual void mouse_press(const tools::sg::mouse_down_event& a_event) {
73 fMousePressed = true;
74 fMousePressedX = a_event.x();
75 fMousePressedY = a_event.y();
76 }
77 virtual void mouse_release(const tools::sg::mouse_up_event&) {fMousePressed = false;}
78 virtual void mouse_move(const tools::sg::mouse_move_event& a_event) {
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
91 const G4double dxScene = dx*sceneRadius/scale;
92 const G4double dyScene = dy*sceneRadius/scale;
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();
102 newViewpointDirection += dx*x_prime/scale;
103 newViewpointDirection += dy*y_prime/scale;
104 fVP.SetViewpointDirection(newViewpointDirection.unit());
105
106 if (fVP.GetRotationStyle() == G4ViewParameters::freeRotation) {
107 G4Vector3D newUpVector = fVP.GetUpVector();
108 newUpVector += dx*x_prime/scale;
109 newUpVector += dy*y_prime/scale;
110 fVP.SetUpVector(newUpVector.unit());
111 }
112 }
113 }
114
115 SetView();
116 DrawView();
117 }
118 virtual void wheel_rotate(const tools::sg::wheel_rotate_event& a_event) {
119
120 ZoomFromMouseWheel(a_event.angle(), a_event.shift_modifier(), a_event.x(), a_event.y());
121
122 SetView();
123 DrawView();
124 }
125public:
126 G4ToolsSGViewer(SG_SESSION& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
127 :parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
128 ,fSGSession(a_session)
129 ,fSGSceneHandler(a_scene_handler)
130 ,fSGViewer(nullptr)
131 ,fMousePressed(false)
134 {
136 }
137
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 }
145protected:
147 :parent(a_from)
148 ,parent_viewer(a_from)
149 ,parent_interactor(a_from)
150 ,fSGSession(a_from.fSGSession)
152 ,fSGViewer(nullptr)
153 ,fMousePressed(false)
156 {}
158public:
159 virtual void Initialise() {
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 //////////////////////////////////////////////////////////
167 fSGViewer = new SG_VIEWER(fSGSession
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 }
180
181 virtual void SetView() {
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
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 :
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 {// 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;
225 if(GetRenderAreaSize(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 :
250 tools::sg::base_camera* _camera = nullptr;
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 }
258 tools::sg::ortho* ortho_camera = new tools::sg::ortho;
259 ortho_camera->height.value(float(top-bottom));
260 _camera = ortho_camera;
261 } else {
262 //G4cout << "debug : camera : perspec : heightAngle " << float(2*fVP.GetFieldHalfAngle()) << std::endl;
263 tools::sg::perspective* perspective_camera = new tools::sg::perspective;
264 perspective_camera->height_angle.value(2 * std::atan(std::tan(fVP.GetFieldHalfAngle()) / fVP.GetZoomFactor()));
265 _camera = perspective_camera;
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 }
289
290 virtual void ClearView() {}
291
292 virtual void DrawView() {
293
295 G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
296 ProcessView(); // Clears store and processes scene only if necessary.
297
298 if (kernelVisitWasNeeded) {
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 }
311
312 virtual void ShowView() {FinishView();}
313
314 virtual void FinishView() {
315 if(fSGViewer) {
316 fSGSceneHandler.TouchPlotters(fSGViewer->sg());
317 fSGViewer->show();
318 fSGViewer->win_render();
319 }
320 }
321
322public:
323 G4bool GetWindowSize(unsigned int& a_w,unsigned int& a_h) {
324 if(!fSGViewer) {a_w = 0; a_h = 0; return false;}
325 return fSGViewer->window_size(a_w,a_h);
326 }
327 G4bool GetRenderAreaSize(unsigned int& a_w, unsigned int& a_h) {
328 if (!fSGViewer) {a_w = 0; a_h = 0; return false;}
329 fSGViewer->render_area_size(a_w, a_h);
330 return true;
331 }
332 //SG_VIEWER* sg_viewer() {return fSGViewer;}
333
334 virtual void EmitWindowRender() {
335 if(!fSGViewer) return;
336 fSGViewer->emit_win_render();
337 }
338
339protected:
342 NeedKernelVisit (); // Sets fNeedKernelVisit.
343 }
344 }
345
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 ()) ||
371 fVP.GetDefaultVisAttributes()->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 }
425
427 if (vp.GetTimeParameters() != fVP.GetTimeParameters()) {
428 return fTransientsNeedRedrawing = true;
429 }
430 return false;
431 }
432
433protected:
434 void CreateSG(tools::sg::base_camera* a_camera,const G4Vector3D& a_light_dir) {
435 tools::sg::group& _parent = fSGViewer->sg();
436 _parent.clear();
437
438 ///////////////////////////////////////////////////
439 /// 2D scene graph: ///////////////////////////////
440 ///////////////////////////////////////////////////
441 tools::sg::separator* scene_2D = new tools::sg::separator;
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 ///////////////////////////////////////////////////
449 tools::sg::separator* scene_3D = new tools::sg::separator;
450 _parent.add(scene_3D);
451
452 scene_3D->add(a_camera);
453
454 {tools::sg::shade_model* shade_model = new tools::sg::shade_model;
455 shade_model->model = tools::sg::shade_smooth;
456 scene_3D->add(shade_model);}
457
458 {tools::sg::torche* light = new tools::sg::torche;
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
465 {tools::sg::blend* blend = new tools::sg::blend;
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 }
472
473 void Export(const G4String& a_format,const G4String& a_file,G4bool a_do_transparency) {
474 if(!fSGViewer) return;
475 const G4Colour& back_color = fVP.GetBackgroundColour();
476 bool top_to_bottom = false; //if using tools::fpng, tools::toojpeg.
477 if(!tools::sg::write_paper(G4cout,f_gl2ps_mgr,f_zb_mgr,
478 tools::fpng::write,tools::toojpeg::write,
479 float(back_color.GetRed()),float(back_color.GetGreen()),float(back_color.GetBlue()),float(back_color.GetAlpha()),
480 fSGViewer->sg(),fSGViewer->width(),fSGViewer->height(),
481 a_file,a_format,a_do_transparency,top_to_bottom,std::string(),std::string())) {
482 G4cout << "G4ToolsSGViewer::Export: write_paper() failed." << G4endl;
483 return;
484 }
485 }
486
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
498 G4double frontHalfHeight;
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 }
507
508protected:
509 class Messenger: public G4VVisCommand {
510 public:
511 static void Create() {static Messenger s_messenger;}
512 private:
513 Messenger() {
514 G4UIparameter* parameter;
515 //////////////////////////////////////////////////////////
516 /// /vis/tsg/export : ////////////////////////////////////
517 //////////////////////////////////////////////////////////
518 write_scene = new G4UIcommand("/vis/tsg/export", this);
519 write_scene->SetGuidance("Write the content of the current viewer in a file at various formats.");
520 write_scene->SetGuidance("Default file is out.eps and default format is gl2ps_eps.");
521 write_scene->SetGuidance("Available formats are:");
522 write_scene->SetGuidance("- gl2ps_eps: gl2ps producing eps");
523 write_scene->SetGuidance("- gl2ps_ps: gl2ps producing ps");
524 write_scene->SetGuidance("- gl2ps_pdf: gl2ps producing pdf");
525 write_scene->SetGuidance("- gl2ps_svg: gl2ps producing svg");
526 write_scene->SetGuidance("- gl2ps_tex: gl2ps producing tex");
527 write_scene->SetGuidance("- gl2ps_pgf: gl2ps producing pgf");
528 write_scene->SetGuidance("- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
529 write_scene->SetGuidance("- zb_png: tools::sg offscreen zbuffer put in a png file.");
530 write_scene->SetGuidance("- zb_jpeg: tools::sg offscreen zbuffer put in a jpeg file.");
531
532 parameter = new G4UIparameter("format",'s',true);
533 parameter->SetDefaultValue("gl2ps_eps");
534 write_scene->SetParameter(parameter);
535
536 parameter = new G4UIparameter("file",'s',true);
537 parameter->SetDefaultValue("out.eps");
538 write_scene->SetParameter(parameter);
539
540 parameter = new G4UIparameter ("do_transparency", 'b', true);
541 parameter->SetDefaultValue("true");
542 write_scene->SetParameter(parameter);
543
544 }
545 virtual ~Messenger() {
546 delete write_scene;
547 }
548 public:
549 virtual void SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
552 if (!viewer) {
553 if (verbosity >= G4VisManager::errors) G4cerr << "ERROR: No current viewer." << G4endl;
554 return;
555 }
556 G4ToolsSGViewer* tsg_viewer = dynamic_cast<G4ToolsSGViewer*>(viewer);
557 if(!tsg_viewer) {
558 G4cout << "G4ToolsSGViewer::Messenger::SetNewValue:"
559 << " current viewer is not a G4ToolsSGViewer." << G4endl;
560 return;
561 }
562 std::vector<std::string> args;
563 tools::double_quotes_tokenize(a_value,args);
564 if(args.size()!=a_cmd->GetParameterEntries()) return;
565 if(a_cmd==write_scene) {
566 G4bool do_transparency = G4UIcommand::ConvertToBool(args[2].c_str());
567 tsg_viewer->Export(args[0],args[1],do_transparency);
568 }
569 }
570 private:
571 G4UIcommand* write_scene;
572 };
573
574protected:
575 SG_SESSION& fSGSession;
577 SG_VIEWER* fSGViewer;
578 G4ViewParameters fLastVP; // Memory for making kernel visit decisions.
579
582
583 tools::sg::zb_manager f_zb_mgr;
584 tools::sg::gl2ps_manager f_gl2ps_mgr;
585
586};
587
588#endif
G4Colour G4Color
Definition G4Color.hh:41
HepGeom::Normal3D< G4double > G4Normal3D
Definition G4Normal3D.hh:34
HepGeom::Point3D< G4double > G4Point3D
Definition G4Point3D.hh:34
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
HepGeom::Vector3D< G4double > G4Vector3D
Definition G4Vector3D.hh:34
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
G4double GetBlue() const
Definition G4Colour.hh:172
G4double GetAlpha() const
Definition G4Colour.hh:173
G4double GetRed() const
Definition G4Colour.hh:170
G4double GetGreen() const
Definition G4Colour.hh:171
virtual void SetNewValue(G4UIcommand *a_cmd, G4String a_value)
virtual void ClearView()
G4bool GetRenderAreaSize(unsigned int &a_w, unsigned int &a_h)
virtual void ShowView()
virtual void mouse_move(const tools::sg::mouse_move_event &a_event)
virtual void mouse_press(const tools::sg::mouse_down_event &a_event)
G4bool GetWindowSize(unsigned int &a_w, unsigned int &a_h)
virtual void key_press(const tools::sg::key_down_event &)
virtual void wheel_rotate(const tools::sg::wheel_rotate_event &a_event)
virtual void FinishView()
G4bool CompareForTransientsRedraw(G4ViewParameters &vp)
G4double GetSceneNearWidth()
void Export(const G4String &a_format, const G4String &a_file, G4bool a_do_transparency)
void CreateSG(tools::sg::base_camera *a_camera, const G4Vector3D &a_light_dir)
virtual void mouse_release(const tools::sg::mouse_up_event &)
G4bool CompareForKernelVisit(G4ViewParameters &vp)
virtual void key_release(const tools::sg::key_up_event &)
G4ToolsSGViewer(const G4ToolsSGViewer &a_from)
G4ToolsSGViewer(SG_SESSION &a_session, G4ToolsSGSceneHandler &a_scene_handler, const G4String &a_name)
virtual void Initialise()
virtual void SetView()
G4ToolsSGViewer & operator=(const G4ToolsSGViewer &)
virtual ~G4ToolsSGViewer()
virtual void DrawView()
virtual void EmitWindowRender()
G4ToolsSG_viewer(const G4ToolsSG_viewer &)
virtual ~G4ToolsSG_viewer()
G4ToolsSG_viewer & operator=(const G4ToolsSG_viewer &)
virtual void EmitWindowRender()
std::size_t GetParameterEntries() const
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
static G4bool ConvertToBool(const char *st)
void SetDefaultValue(const char *theDefaultValue)
G4bool fNeedKernelVisit
Definition G4VViewer.hh:280
void ProcessView()
Definition G4VViewer.cc:112
G4VSceneHandler & fSceneHandler
Definition G4VViewer.hh:268
void ProcessTransients()
Definition G4VViewer.cc:133
G4String fName
Definition G4VViewer.hh:270
void NeedKernelVisit()
Definition G4VViewer.cc:85
G4ViewParameters fDefaultVP
Definition G4VViewer.hh:273
G4int fViewId
Definition G4VViewer.hh:269
G4bool fTransientsNeedRedrawing
Definition G4VViewer.hh:281
G4ViewParameters fVP
Definition G4VViewer.hh:272
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
Definition G4VViewer.cc:49
void ZoomFromMouseWheel(G4double delta, G4bool shift=false, G4double xPos=0, G4double yPos=0)
Definition G4VViewer.cc:144
static G4VisManager * GetVisManager()
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
const G4Vector3D & GetScaleFactor() const
G4int GetNoOfSides() const
G4bool IsSpecialMeshRendering() const
CutawayMode GetCutawayMode() const
G4double GetExplodeFactor() const
const G4ModelingParameters::TimeParameters & GetTimeParameters() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
G4bool IsCutaway() const
const G4Colour & GetBackgroundColour() const
G4bool IsSection() const
G4bool IsPicking() const
G4bool IsDotsSmooth() 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
G4int GetTransparencyByDepthOption() const
G4double GetGlobalMarkerScale() const
G4bool IsCullingInvisible() const
const G4VisAttributes * GetDefaultVisAttributes() const
const G4Planes & GetCutawayPlanes() const
G4bool IsDensityCulling() const
G4double GetVisibleDensity() const
SMROption GetSpecialMeshRenderingOption() const
G4double GetDotsSize() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
DrawingStyle GetDrawingStyle() const
G4double GetTransparencyByDepth() const
G4bool IsAuxEdgeVisible() const
const G4Colour & GetColour() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const