28#ifndef G4TOOLSSGVIEWER_HH
29#define G4TOOLSSGVIEWER_HH
38#include <tools/toojpeg>
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/torche>
45#include <tools/sg/blend>
46#include <tools/sg/noderef>
47#include <tools/sg/keys>
49#include <tools/tokenize>
50#include <tools/sg/write_paper>
52template <
class SG_SESSION,
class SG_VIEWER>
55 typedef tools::sg::device_interactor parent_interactor;
57 virtual void key_press(
const tools::sg::key_down_event& a_event) {
59 fKeyShift = a_event.key() == tools::sg::key_shift()?
true:
false;
62 virtual void mouse_press(
const tools::sg::mouse_down_event& a_event) {
68 virtual void mouse_move(
const tools::sg::mouse_move_event& a_event) {
82 const G4double dxScene = dx*sceneRadius/scale;
83 const G4double dyScene = dy*sceneRadius/scale;
84 fVP.IncrementPan(-dxScene,dyScene);
89 const G4Vector3D& x_prime =
fVP.GetViewpointDirection().cross(
fVP.GetUpVector());
92 G4Vector3D newViewpointDirection =
fVP.GetViewpointDirection();
93 newViewpointDirection += dx*x_prime/scale;
94 newViewpointDirection += dy*y_prime/scale;
95 fVP.SetViewpointDirection(newViewpointDirection.
unit());
99 newUpVector += dx*x_prime/scale;
100 newUpVector += dy*y_prime/scale;
101 fVP.SetUpVector(newUpVector.
unit());
109 virtual void wheel_rotate(
const tools::sg::wheel_rotate_event& a_event) {
110 const G4double angleY = a_event.angle();
111 if (
fVP.GetFieldHalfAngle() == 0.) {
113 fVP.MultiplyZoomFactor(1.+angleY/scale);
116 fVP.SetDolly(
fVP.GetDolly()+angleY*delta);
123 :parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
147 ,parent_interactor(a_from)
161 fVP.SetAutoRefresh(
true);
168 ,
fVP.GetWindowAbsoluteLocationHintX(1440)
169 ,
fVP.GetWindowAbsoluteLocationHintY(900)
170 ,
fVP.GetWindowSizeHintX()
171 ,
fVP.GetWindowSizeHintY()
175 G4cerr <<
"G4ToolsSGViewer::Initialise : SG_VIEWER::has_window() failed." <<
G4endl;
184 fSGViewer->set_clear_color(0.3,0.3,0.3,1);
185 G4cerr <<
"G4ToolsSGViewer::SetView : no G4Scene.." <<
G4endl;
195 =
fSceneHandler.GetScene()->GetStandardTargetPoint() +
fVP.GetCurrentTargetPoint ();
197 if(radius<=0.) radius = 1.;
198 const G4double cameraDistance =
fVP.GetCameraDistance (radius);
199 const G4Point3D cameraPosition = targetPoint + cameraDistance *
fVP.GetViewpointDirection().unit();
201 const G4double pnear =
fVP.GetNearDistance (cameraDistance, radius);
202 const G4double pfar =
fVP.GetFarDistance (cameraDistance, pnear, radius);
205 const G4double top =
fVP.GetFrontHalfHeight (pnear, radius);
208 tools::vec3f dir(
float(targetPoint.
x()-cameraPosition.
x()),
209 float(targetPoint.
y()-cameraPosition.
y()),
210 float(targetPoint.
z()-cameraPosition.
z()));
212 fSGViewer->set_clear_color(0.3,0.3,0.3,1);
213 G4cerr <<
"G4ToolsSGViewer::SetView : null size viewer area." <<
G4endl;
234 tools::sg::base_camera* _camera =
nullptr;
235 if (
fVP.GetFieldHalfAngle() <= 0.) {
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;
242 tools::sg::ortho* ortho_camera =
new tools::sg::ortho;
243 ortho_camera->height.value(
float(top-bottom));
244 _camera = ortho_camera;
247 tools::sg::perspective* perspective_camera =
new tools::sg::perspective;
248 perspective_camera->height_angle.value(
float(2*
fVP.GetFieldHalfAngle()));
249 _camera = perspective_camera;
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));
259 _camera->look_at(dir,tools::vec3f(up.
x(),up.
y(),up.
z()));
268 CreateSG(_camera,
fVP.GetActualLightpointDirection());
270 {
G4Color background =
fVP.GetBackgroundColour ();
281 if (kernelVisitWasNeeded) {
343 fVP.GetCBDAlgorithmNumber()) ||
357 fVP.GetDefaultVisAttributes()->GetColour()) ||
359 fVP.GetDefaultTextVisAttributes()->GetColour()) ||
367 fVP.GetVisAttributesModifiers()) ||
369 fVP.IsSpecialMeshRendering()) ||
371 fVP.GetSpecialMeshRenderingOption())
391 fVP.GetCutawayPlanes ().size ())
return true;
417 tools::sg::group& _parent =
fSGViewer->sg();
423 tools::sg::separator* scene_2D =
new tools::sg::separator;
424 _parent.add(scene_2D);
425 scene_2D->add(
new tools::sg::noderef(
fSGSceneHandler.GetTransient2DObjects()));
426 scene_2D->add(
new tools::sg::noderef(
fSGSceneHandler.GetPersistent2DObjects()));
431 tools::sg::separator* scene_3D =
new tools::sg::separator;
432 _parent.add(scene_3D);
434 scene_3D->add(a_camera);
436 {tools::sg::torche* light =
new tools::sg::torche;
438 light->direction = tools::vec3f(-a_light_dir.
x(),-a_light_dir.
y(),-a_light_dir.
z());
439 light->ambient = tools::colorf(0.2f,0.2f,0.2f,1.0f);
440 light->color = tools::colorf(0.8f,0.8f,0.8f,1.0f);
441 scene_3D->add(light);}
443 {tools::sg::blend* blend =
new tools::sg::blend;
445 scene_3D->add(blend);}
447 scene_3D->add(
new tools::sg::noderef(
fSGSceneHandler.GetTransient3DObjects()));
448 scene_3D->add(
new tools::sg::noderef(
fSGSceneHandler.GetPersistent3DObjects()));
453 const G4Colour& back_color =
fVP.GetBackgroundColour();
454 bool top_to_bottom =
false;
456 tools::fpng::write,tools::toojpeg::write,
459 a_file,a_format,a_do_transparency,top_to_bottom,std::string(),std::string())) {
460 G4cout <<
"G4ToolsSGViewer::Export: write_paper() failed." <<
G4endl;
468 static void Create() {
static Messenger s_messenger;}
474 write_scene =
new G4UIcommand(
"/vis/tsg/export",
this);
475 write_scene->
SetGuidance(
"Write the content of the current viewer in a file at various formats.");
476 write_scene->
SetGuidance(
"Default file is out.eps and default format is gl2ps_eps.");
477 write_scene->
SetGuidance(
"Available formats are:");
478 write_scene->
SetGuidance(
"- gl2ps_eps: gl2ps producing eps");
479 write_scene->
SetGuidance(
"- gl2ps_ps: gl2ps producing ps");
480 write_scene->
SetGuidance(
"- gl2ps_pdf: gl2ps producing pdf");
481 write_scene->
SetGuidance(
"- gl2ps_svg: gl2ps producing svg");
482 write_scene->
SetGuidance(
"- gl2ps_tex: gl2ps producing tex");
483 write_scene->
SetGuidance(
"- gl2ps_pgf: gl2ps producing pgf");
484 write_scene->
SetGuidance(
"- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
485 write_scene->
SetGuidance(
"- zb_png: tools::sg offscreen zbuffer put in a png file.");
486 write_scene->
SetGuidance(
"- zb_jpeg: tools::sg offscreen zbuffer put in a jpeg file.");
496 parameter =
new G4UIparameter (
"do_transparency",
'b',
true);
501 virtual ~Messenger() {
514 G4cout <<
"G4ToolsSGViewer::SetNewValue:"
515 <<
" current viewer is not a G4ToolsSGViewer." <<
G4endl;
518 std::vector<std::string> args;
519 tools::double_quotes_tokenize(a_value,args);
521 if(a_cmd==write_scene) {
523 tsg_viewer->
Export(args[0],args[1],do_transparency);
HepGeom::Normal3D< G4double > G4Normal3D
HepGeom::Point3D< G4double > G4Point3D
HepGeom::Vector3D< G4double > G4Vector3D
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
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)
G4VSceneHandler & fSceneHandler
G4ViewParameters fDefaultVP
G4VViewer(G4VSceneHandler &, G4int id, const G4String &name="")
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
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
G4double GetGlobalLineWidthScale() const
const G4Colour & GetBackgroundColour() const
const G4VisAttributes * GetDefaultTextVisAttributes() 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
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
G4bool IsMultithreadedApplication()