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;
93 newViewpointDirection += dx*x_prime/scale;
94 newViewpointDirection += dy*y_prime/scale;
99 newUpVector += dx*x_prime/scale;
100 newUpVector += dy*y_prime/scale;
109 virtual void wheel_rotate(
const tools::sg::wheel_rotate_event& a_event) {
110 const G4double angleY = a_event.angle();
123 :
parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
147 ,parent_interactor(a_from)
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;
197 if(radius<=0.) radius = 1.;
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;
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;
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()));
281 if (kernelVisitWasNeeded) {
299#ifdef G4MULTITHREADED
300 virtual void SwitchToVisSubThread() {}
302 virtual void SwitchToMasterThread() {
419 tools::sg::group& _parent =
fSGViewer->sg();
425 tools::sg::separator* scene_2D =
new tools::sg::separator;
426 _parent.add(scene_2D);
433 tools::sg::separator* scene_3D =
new tools::sg::separator;
434 _parent.add(scene_3D);
436 scene_3D->add(a_camera);
438 {tools::sg::torche* light =
new tools::sg::torche;
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);
442 light->color = tools::colorf(0.8f,0.8f,0.8f,1.0f);
443 scene_3D->add(light);}
445 {tools::sg::blend* blend =
new tools::sg::blend;
447 scene_3D->add(blend);}
456 bool top_to_bottom =
false;
458 tools::fpng::write,tools::toojpeg::write,
461 a_file,a_format,a_do_transparency,top_to_bottom,std::string(),std::string())) {
462 G4cout <<
"G4ToolsSGViewer::Export: write_paper() failed." <<
G4endl;
476 write_scene =
new G4UIcommand(
"/vis/tsg/export",
this);
477 write_scene->
SetGuidance(
"Write the content of the current viewer in a file at various formats.");
478 write_scene->
SetGuidance(
"Default file is out.eps and default format is gl2ps_eps.");
479 write_scene->
SetGuidance(
"Available formats are:");
480 write_scene->
SetGuidance(
"- gl2ps_eps: gl2ps producing eps");
481 write_scene->
SetGuidance(
"- gl2ps_ps: gl2ps producing ps");
482 write_scene->
SetGuidance(
"- gl2ps_pdf: gl2ps producing pdf");
483 write_scene->
SetGuidance(
"- gl2ps_svg: gl2ps producing svg");
484 write_scene->
SetGuidance(
"- gl2ps_tex: gl2ps producing tex");
485 write_scene->
SetGuidance(
"- gl2ps_pgf: gl2ps producing pgf");
486 write_scene->
SetGuidance(
"- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
487 write_scene->
SetGuidance(
"- zb_png: tools::sg offscreen zbuffer put in a png file.");
488 write_scene->
SetGuidance(
"- zb_jpeg: tools::sg offscreen zbuffer put in a jpeg file.");
498 parameter =
new G4UIparameter (
"do_transparency",
'b',
true);
503 virtual ~Messenger() {
516 G4cout <<
"G4ToolsSGViewer::SetNewValue:"
517 <<
" current viewer is not a G4ToolsSGViewer." <<
G4endl;
520 std::vector<std::string> args;
521 tools::double_quotes_tokenize(a_value,args);
523 if(a_cmd==write_scene) {
525 tsg_viewer->
Export(args[0],args[1],do_transparency);
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
G4double GetAlpha() const
G4double GetGreen() const
const G4VisExtent & GetExtent() const
const G4Point3D & GetStandardTargetPoint() const
const std::vector< Model > & GetEndOfEventModelList() 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)
G4Scene * GetScene() const
virtual const G4VisExtent & GetExtent() const
G4VSceneHandler & fSceneHandler
G4ViewParameters fDefaultVP
static G4VisManager * GetVisManager()
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
const std::vector< G4ModelingParameters::VisAttributesModifier > & GetVisAttributesModifiers() const
const G4Vector3D & GetScaleFactor() const
void SetAutoRefresh(G4bool)
G4int GetNoOfSides() const
G4bool IsSpecialMeshRendering() const
G4int GetWindowAbsoluteLocationHintY(G4int) const
CutawayMode GetCutawayMode() const
G4double GetCameraDistance(G4double radius) const
G4double GetExplodeFactor() const
G4int GetNumberOfCloudPoints() const
G4bool IsMarkerNotHidden() const
unsigned int GetWindowSizeHintX() const
G4double GetGlobalLineWidthScale() const
G4Vector3D & GetActualLightpointDirection()
const G4Colour & GetBackgroundColour() const
const G4Vector3D & GetViewpointDirection() const
const G4Point3D & GetCurrentTargetPoint() const
G4double GetFarDistance(G4double cameraDistance, G4double nearDistance, G4double radius) const
G4double GetFieldHalfAngle() const
G4double GetFrontHalfHeight(G4double nearDistance, G4double radius) const
const G4VisAttributes * GetDefaultTextVisAttributes() const
void SetDolly(G4double dolly)
G4int GetWindowAbsoluteLocationHintX(G4int) const
void IncrementPan(G4double right, G4double up)
const G4Vector3D & GetUpVector() 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
void SetUpVector(const G4Vector3D &upVector)
const G4Planes & GetCutawayPlanes() const
RotationStyle GetRotationStyle() const
G4bool IsDensityCulling() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
G4double GetVisibleDensity() const
SMROption GetSpecialMeshRenderingOption() const
unsigned int GetWindowSizeHintY() const
G4bool IsCullingCovered() const
const G4Plane3D & GetSectionPlane() const
G4double GetNearDistance(G4double cameraDistance, G4double radius) const
DrawingStyle GetDrawingStyle() const
G4bool IsAuxEdgeVisible() const
G4double GetDolly() const
const G4Colour & GetColour() const
G4double GetExtentRadius() const
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
BasicVector3D< T > cross(const BasicVector3D< T > &v) const
BasicVector3D< T > unit() const
G4bool IsMultithreadedApplication()