Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -28,20 +28,24 @@ CPPFLAGS += -I$(G4BASE)/geometry/solids/specific/include
|
||||
CPPFLAGS += -I$(G4BASE)/tracking/include
|
||||
CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
|
||||
|
||||
# Locally adjust source list before including common.gmk
|
||||
sources := src/G4ToolsSGSceneHandler.cc
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
sources += src/G4ToolsSGX11GLES.cc
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
sources += src/G4ToolsSGWindowsGLES.cc
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
sources += src/G4ToolsSGXtGLES.cc
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
sources += src/G4ToolsSGQtGLES.cc src/G4ToolsSGQtViewer.cc
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/moc.gmk
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
|
||||
@@ -20,7 +20,107 @@ History file for visualization ToolsSG category - a vis driver based on
|
||||
g4tools scene graph logic. See geant4/source/analysis/g4tools/tools.license
|
||||
------------------------------------------------
|
||||
|
||||
07 June 2021 John Allison (vis_toolsg-V10-07-05)
|
||||
13 November 2021 - John Allison (vis_toolssg-V10-07-16)
|
||||
- G4ToolsSGSceneHandler.cc: Bug fix:
|
||||
- In AddPrimitive, use preferred GetColour(a_polyline) instead of GetColour().
|
||||
- Similarly for a_polymarker and a_polyhedron.
|
||||
- If the vis attributes pointer is not up to date, GetColour() picks up
|
||||
the colour of the previous object!
|
||||
- GetColour() will probably be deprecated in future! It's use is
|
||||
misleading - see visman-V10-07-27.
|
||||
|
||||
12 November 2021 - Ben Morgan (vis_toolssg-V10-07-15)
|
||||
- Retire G4VIS_... preprocessor symbols in toolkit build, only required
|
||||
by obsolete GNUmake system
|
||||
|
||||
8 November 2021 - Ben Morgan (vis_toolssg-V10-07-14)
|
||||
- Retire G4UI/G4INTY_... preprocessor symbols in toolkit build, only required
|
||||
by obsolete GNUmake system
|
||||
|
||||
05 November 2021 Guy Barrand (vis_toolssg-V10-07-13)
|
||||
- G4ToolsSGSceneHandler: SetPlotterHistograms(): revisit
|
||||
in order that, from an int histogram hid given by a user (and
|
||||
passed to a G4Plotter), the address of the tools::histo, managed by G4/analysis,
|
||||
is retrieved by using a /analysis/h/get command so that the
|
||||
histo is copied in a tools::sg::plottable managed by a tools::sg::plotter.
|
||||
This way of doing secures the relationship tools::sg::plotter, managed by G4/vis
|
||||
relative to the histo, managed by G4/analysis.
|
||||
This overall way of doing permits to have the commands:
|
||||
/vis/plotter/add/h1,h2
|
||||
managed back in G4/vis, and then avoids to instrument
|
||||
G4/examples and user code with the templated G4VisPlotMessenger
|
||||
which is no more needed.
|
||||
|
||||
03 November 2021 Guy Barrand (vis_toolssg-V10-07-12)
|
||||
- G4ToolsSGSceneHandler: changes to deal with the changes
|
||||
in management/G4PlotterManager that handles a local list of styles.
|
||||
|
||||
25 October 2021 Guy Barrand (vis_toolssg-V10-07-11)
|
||||
- src/G4ToolsSGQtViewer.cc, sources.cmake: Linux: it permits to have cmake doing the
|
||||
"mocing" of G4ToolsSGQtViewer.hh. (Strangely not needed on my mac).
|
||||
- include/G4ToolsSGQtViewer.hh: handle a Qt "destroy" signal/slot to properly
|
||||
delete the G4ToolsSGViewer from the G4ToolsSGSceneHandler in case a user
|
||||
delete the viewer QWidget in the G4UIQt tab container widget.
|
||||
- include/G4ToolsSGViewer.hh: FinishView: handle the update of plotters
|
||||
(tools::sg::plots nodes) if any in the scene graph. Done by using
|
||||
fSGSceneHandler.TouchPlotters()
|
||||
- remove G4ToolsSGExport.hh. Now done by using tools/sg/write_paper.
|
||||
- G4ToolsSGSceneHandler.hh,.cc: have a /vis/tsg/plotter/printParameters. To
|
||||
print available style parameters of the tools::sg::plotter node.
|
||||
- G4ToolsSGSceneHandler.hh,.cc: plotting logic. Mainly implement AddPrimitive(G4Plotter)
|
||||
by handling a tools::sg::plots node in the scene graph. Have code to attach histograms
|
||||
and setup styles
|
||||
|
||||
22 October 2021 Guy Barrand (vis_toolssg-V10-07-10)
|
||||
- ToolsSG/History: change vis_toolsg to vis_toolssg in tags.
|
||||
- include/G4ToolsSGQtViewer.hh: remove ShowView, FinishView: the below modification
|
||||
permits to rely on the parent ShowView, FinishView. (No more need to have code
|
||||
to handle the "in tab" case).
|
||||
- include/G4ToolsSGQtViewer.hh/Initialise: enforce a Qt show() to be able
|
||||
to retreive the true QGLWidget size at startup.
|
||||
- include/G4ToolsSGQtViewer.hh: __APPLE__: implement a SetView to enforce a
|
||||
fVP.SetGlobalMarkerScale(2);
|
||||
so that 2D text have a similar size than other drivers and platforms.
|
||||
- include/G4ToolsSGViewer.hh: handle a /vis/tsg/export command to
|
||||
produce "paper" output files.
|
||||
- include/G4ToolsSGViewer.hh: ShowView calls FinishView.
|
||||
- include/G4ToolsSGViewer.hh: handle a scene graph so that camera and lighting nodes
|
||||
belong to the viewer.
|
||||
- G4ToolsSGSceneHandler.cc: AddPrimitives : use G4VSceneHandler::GetColour(), GetTextColour()
|
||||
instead of the viewer vis attributs ones.
|
||||
- G4ToolsSGSceneHandler.hh,.cc: revisit the scene graph logic so that camera and lighting
|
||||
nodes be handled by G4ToolsSGViewer.
|
||||
|
||||
13 October 2021 Guy Barrand (vis_toolssg-V10-07-09)
|
||||
- Following g4tools-V10-07-07.
|
||||
- for 2D text with freetype; have a mechanism to handle embedded fonts.
|
||||
Have the font lato_regular.ttf embedded in the C++ file:
|
||||
tools/sg/font/lato_regular_ttf
|
||||
The embedding of a .ttf file is done by using 'xxd -i' on a UNIX.
|
||||
With this in place, usage of the env variable TOOLS_FONT_PATH is no more
|
||||
needed for 2D freetype text to find the lato_regular font at run time.
|
||||
- handle G4/vis lightening. Use a tools::sg::torche.
|
||||
- for 2D: handle mouse resize of the viewer (Qt,Xt,X11,Windows).
|
||||
- handle transparency. Cowork with modifs in:
|
||||
tools/sg[GL_viewer,atb_vertices,render_action]
|
||||
- G4ToolsSGViewer, G4ToolsSGSceneHandler: revisit the scene graph organization
|
||||
to handle 2D text
|
||||
- handle 2D graphics. Cowork with modifs in:
|
||||
tools/sg/[text_freetype_marker,text_hershey_marker] to avoid text squashing.
|
||||
|
||||
12 October 2021 Ben Morgan (vis_toolssg-V10-07-08)
|
||||
- Xt backend does not depend on Xm
|
||||
|
||||
01 September 2021 John Allison (vis_toolssg-V10-07-07)
|
||||
- Store default background in view parameters.
|
||||
|
||||
30 June 2021 John Allison (vis_toolssg-V10-07-06)
|
||||
- Requires greps-V10-07-09, modeling-V10-07-11 and visman-V10-07-11.
|
||||
- Revise vis models. See visualization/modeling/History for more details.
|
||||
- Consequent changes:
|
||||
o AddPrimitive(const G4Scale&) has been removed from all scene handlers.
|
||||
|
||||
07 June 2021 John Allison (vis_toolssg-V10-07-05)
|
||||
- Requires greps-V10-07-07 (new method AddCompound (const G4Mesh&)).
|
||||
- Requires modeling-V10-07-09 (new class G4Mesh).
|
||||
- Requires visman-V10-07-10 (new default method and new commands).
|
||||
@@ -30,24 +130,24 @@ g4tools scene graph logic. See geant4/source/analysis/g4tools/tools.license
|
||||
28 May 2021 Ben Morgan (vis_toolssg-V10-07-04)
|
||||
- Migrate to modular CMake build
|
||||
|
||||
27 May 2021 John Allison (vis_toolsg-V10-07-03)
|
||||
27 May 2021 John Allison (vis_toolssg-V10-07-03)
|
||||
- AddPrimitive(const G4Polyhedron&):
|
||||
o Minor improvement to error message in the case of unexpected number
|
||||
of edges.
|
||||
|
||||
23 May 2021 John Allison (vis_toolsg-V10-07-02)
|
||||
23 May 2021 John Allison (vis_toolssg-V10-07-02)
|
||||
- Corrections to cmake files for freetype fonts:
|
||||
o Move freetype setup from CMakeLists.txt to sources.cmake.
|
||||
- G4ToolsSGSceneHandler.cc: Remove redundant comments.
|
||||
|
||||
14 May 2021 Guy Barrand (vis_toolsg-V10-07-01)
|
||||
14 May 2021 Guy Barrand (vis_toolssg-V10-07-01)
|
||||
- cosmetic/style improvements:
|
||||
o 0 => nullptr.
|
||||
o have '= default' for some destructors.
|
||||
o G4ToolsSGNode.hh : have public cpstor and operator=.
|
||||
o G4ToolsSGViewer.hh : rm #ifdef G4TOOLSSG_DEBUG code.
|
||||
|
||||
05 May 2021 Guy Barrand (vis_toolsg-V10-07-00)
|
||||
05 May 2021 Guy Barrand (vis_toolssg-V10-07-00)
|
||||
- Requires cmake-V10-07-15, visman-V10-07-06 and externals-V10-07-02.
|
||||
- First committal of a tools_sg driver (Guy Barrand).
|
||||
o Four (mutually exclusive) options:
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// John Allison, 6th October 2020
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_DRIVER) || defined (G4VIS_USE_TOOLSSG)
|
||||
|
||||
#ifndef G4TOOLSSGNODE_HH
|
||||
#define G4TOOLSSGNODE_HH
|
||||
|
||||
@@ -56,5 +54,3 @@ private:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER) || defined (G4VIS_USE_TOOLSSG_QT_GLES)
|
||||
|
||||
#ifndef G4TOOLSSGQTGLES_HH
|
||||
#define G4TOOLSSGQTGLES_HH
|
||||
|
||||
@@ -53,5 +51,3 @@ protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,36 +25,56 @@
|
||||
//
|
||||
// Guy Barrand 8th April 2021
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER) || defined (G4VIS_USE_TOOLSSG_QT_GLES)
|
||||
|
||||
#ifndef G4TOOLSSGQTVIEWER_HH
|
||||
#define G4TOOLSSGQTVIEWER_HH
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
|
||||
#include <tools/Qt/sg_viewer>
|
||||
|
||||
#include "G4Qt.hh"
|
||||
#include "G4UIQt.hh"
|
||||
#include "G4UImanager.hh"
|
||||
|
||||
#include <tools/Qt/sg_viewer>
|
||||
|
||||
#include <qmainwindow.h>
|
||||
|
||||
class G4ToolsSGQtDestroyCallback : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
G4ToolsSGQtDestroyCallback(G4VViewer* a_viewer):fViewer(a_viewer) {}
|
||||
virtual ~G4ToolsSGQtDestroyCallback() {}
|
||||
private:
|
||||
G4ToolsSGQtDestroyCallback(const G4ToolsSGQtDestroyCallback&);
|
||||
G4ToolsSGQtDestroyCallback& operator=(const G4ToolsSGQtDestroyCallback&);
|
||||
public slots:
|
||||
void execute(){
|
||||
//::printf("debug : G4ToolsSGQtDestroyCallback::execute\n");
|
||||
delete fViewer;
|
||||
}
|
||||
private:
|
||||
G4VViewer* fViewer;
|
||||
};
|
||||
|
||||
class G4ToolsSGQtViewer : public G4ToolsSGViewer<tools::Qt::session,tools::Qt::sg_viewer> {
|
||||
typedef G4ToolsSGViewer<tools::Qt::session,tools::Qt::sg_viewer> parent;
|
||||
public:
|
||||
G4ToolsSGQtViewer(tools::Qt::session& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
|
||||
:parent(a_session,a_scene_handler,a_name)
|
||||
,fInTab(false)
|
||||
,fSGQWidget(nullptr)
|
||||
{}
|
||||
virtual ~G4ToolsSGQtViewer() = default;
|
||||
,fDestroyCallback(0)
|
||||
{
|
||||
fDestroyCallback = new G4ToolsSGQtDestroyCallback(this);
|
||||
}
|
||||
virtual ~G4ToolsSGQtViewer() {
|
||||
delete fDestroyCallback; //it will remove the below signal/slot connection.
|
||||
}
|
||||
protected:
|
||||
G4ToolsSGQtViewer(const G4ToolsSGQtViewer& a_from):parent(a_from),fInTab(false){}
|
||||
G4ToolsSGQtViewer(const G4ToolsSGQtViewer& a_from):parent(a_from){}
|
||||
G4ToolsSGQtViewer& operator=(const G4ToolsSGQtViewer&) {return *this;}
|
||||
public:
|
||||
virtual void Initialise() {
|
||||
if(fSGQWidget) return; //done.
|
||||
parent::Initialise();
|
||||
fInTab = false;
|
||||
if(!fSGViewer) {
|
||||
G4cerr << "G4ToolsSGQtViewer::Initialise: ERROR: G4ToolsSGQtViewer has no tools::Qt::sg_viewer." << G4endl;
|
||||
return;
|
||||
@@ -64,45 +84,48 @@ public:
|
||||
G4cerr << "G4ToolsSGQtViewer::Initialise: ERROR: tools::Qt::sg_viewer has no QWidget shell." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
{G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
G4UIsession* session = ui->GetG4UIWindow();
|
||||
G4UIQt* uiQt = session? dynamic_cast<G4UIQt*>(session) :nullptr;
|
||||
if(uiQt) {
|
||||
G4Qt* interactorManager = G4Qt::getInstance ();
|
||||
if (!interactorManager->IsExternalApp()) {
|
||||
uiQt->AddTabWidget(fSGQWidget,QString(GetName()));
|
||||
fInTab = true;
|
||||
fSGViewer->set_own_shell(false);
|
||||
uiQt->AddTabWidget(fSGQWidget,QString(GetName()));
|
||||
QObject::connect(fSGQWidget,SIGNAL(destroyed()),fDestroyCallback,SLOT(execute()));
|
||||
|
||||
QMainWindow* main_window = uiQt->GetMainWindow();
|
||||
if(main_window) {
|
||||
main_window->show();
|
||||
interactorManager->FlushAndWaitExecution();
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
fSGViewer->enable_keyboard_focus();
|
||||
}
|
||||
virtual void ShowView() {
|
||||
if(fInTab) {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
} else {
|
||||
parent::ShowView();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void FinishView() {
|
||||
if(fInTab) {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
} else {
|
||||
parent::FinishView();
|
||||
|
||||
virtual void SetView() {
|
||||
#ifdef __APPLE__
|
||||
if(fSGQWidget && fSGViewer) {
|
||||
if( (2*fSGQWidget->width() == int(fSGViewer->width())) &&
|
||||
(2*fSGQWidget->height() == int(fSGViewer->height())) ){
|
||||
// With Qt/Cocoa, the received size in
|
||||
// tools::sg::glarea::resizeGL is twice the QWidget::[width(),height()]!
|
||||
// In general it does not pose problem, except when rendering 2D texts.
|
||||
// In order to have similar sizes than other platforms, we have to double
|
||||
// their pixel heights.
|
||||
fVP.SetGlobalMarkerScale(2);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
parent::SetView();
|
||||
}
|
||||
|
||||
protected:
|
||||
bool fInTab;
|
||||
QWidget* fSGQWidget;
|
||||
G4ToolsSGQtDestroyCallback* fDestroyCallback;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,66 +25,91 @@
|
||||
//
|
||||
// John Allison 6th October 2020
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_DRIVER) || defined (G4VIS_USE_TOOLSSG)
|
||||
|
||||
#ifndef G4TOOLSSGSCENEHANDLER_HH
|
||||
#define G4TOOLSSGSCENEHANDLER_HH
|
||||
|
||||
#include "G4VSceneHandler.hh"
|
||||
|
||||
#include "G4VVisCommand.hh"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace tools {namespace sg {class separator;}}
|
||||
#include <tools/sg/separator>
|
||||
|
||||
namespace tools {namespace sg {class base_freetype;}}
|
||||
namespace tools {namespace sg {class plots;}}
|
||||
|
||||
class G4ToolsSGNode;
|
||||
|
||||
class G4ToolsSGSceneHandler: public G4VSceneHandler {
|
||||
typedef G4VSceneHandler parent;
|
||||
public:
|
||||
G4ToolsSGSceneHandler(G4VGraphicsSystem& system,const G4String& name);
|
||||
virtual ~G4ToolsSGSceneHandler();
|
||||
protected:
|
||||
//G4ToolsSGSceneHandler(const G4ToolsSGSceneHandler& a_from):parent(a_from){}
|
||||
G4ToolsSGSceneHandler& operator=(const G4ToolsSGSceneHandler&){return *this;}
|
||||
public:
|
||||
|
||||
void PreAddSolid(const G4Transform3D& objectTransformation,
|
||||
const G4VisAttributes&);
|
||||
void PostAddSolid();
|
||||
|
||||
void BeginPrimitives2D(const G4Transform3D& objectTransformation);
|
||||
void EndPrimitives2D();
|
||||
|
||||
void BeginPrimitives(const G4Transform3D& objectTransformation);
|
||||
void EndPrimitives();
|
||||
|
||||
virtual void AddPrimitive(const G4Polyline&);
|
||||
virtual void AddPrimitive(const G4Scale&);
|
||||
virtual void AddPrimitive(const G4Text&);
|
||||
virtual void AddPrimitive(const G4Circle&);
|
||||
virtual void AddPrimitive(const G4Square&);
|
||||
virtual void AddPrimitive(const G4Polymarker&);
|
||||
virtual void AddPrimitive(const G4Polyhedron&);
|
||||
|
||||
void ClearStore ();
|
||||
void ClearTransientStore ();
|
||||
virtual void AddPrimitive(const G4Plotter&);
|
||||
|
||||
public:
|
||||
tools::sg::separator* ToolsSGScene() {return fpToolsSGScene;}
|
||||
virtual void ClearStore ();
|
||||
virtual void ClearTransientStore ();
|
||||
|
||||
G4ToolsSGSceneHandler(G4VGraphicsSystem& system,const G4String& name);
|
||||
virtual ~G4ToolsSGSceneHandler();
|
||||
|
||||
tools::sg::separator& GetTransient2DObjects() {return fpTransient2DObjects;}
|
||||
tools::sg::separator& GetPersistent2DObjects() {return fpPersistent2DObjects;}
|
||||
tools::sg::separator& GetTransient3DObjects() {return fpTransient3DObjects;}
|
||||
tools::sg::separator& GetPersistent3DObjects() {return fpPersistent3DObjects;}
|
||||
|
||||
void TouchPlotters(tools::sg::node&);
|
||||
|
||||
protected:
|
||||
G4ToolsSGSceneHandler(const G4ToolsSGSceneHandler&);
|
||||
G4ToolsSGSceneHandler& operator=(const G4ToolsSGSceneHandler&){return *this;}
|
||||
|
||||
protected:
|
||||
|
||||
void CreateSG();
|
||||
void EstablishBaseNodes();
|
||||
|
||||
tools::sg::separator* GetOrCreateNode(); // For next solid or primitive
|
||||
|
||||
static G4int fSceneIdCount; // Counter for Qt3D scene handlers.
|
||||
void SetPlotterHistograms(tools::sg::plots&);
|
||||
|
||||
static G4int fSceneIdCount;
|
||||
|
||||
tools::sg::separator fpTransient2DObjects;
|
||||
tools::sg::separator fpPersistent2DObjects;
|
||||
|
||||
tools::sg::separator fpTransient3DObjects;
|
||||
tools::sg::separator fpPersistent3DObjects;
|
||||
|
||||
tools::sg::separator* fpToolsSGScene;
|
||||
tools::sg::separator* fpTransientObjects;
|
||||
tools::sg::separator* fpPersistentObjects;
|
||||
std::vector<G4ToolsSGNode*> fpPhysicalVolumeObjects; // Multiple worlds
|
||||
|
||||
tools::sg::base_freetype* fFreetypeNode;
|
||||
|
||||
using Region_h1 = std::pair<unsigned int,int>;
|
||||
using Region_h2 = std::pair<unsigned int,int>;
|
||||
std::vector<Region_h1> fRegionH1s;
|
||||
std::vector<Region_h2> fRegionH2s;
|
||||
|
||||
class Messenger: public G4VVisCommand {
|
||||
public:
|
||||
static void Create() {static Messenger s_messenger;}
|
||||
virtual void SetNewValue(G4UIcommand*,G4String);
|
||||
private:
|
||||
Messenger() {
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
print_plotter_params = new G4UIcommand("/vis/tsg/plotter/printParameters", this);
|
||||
print_plotter_params->SetGuidance("Print available tools::sg::plotter parameters.");
|
||||
}
|
||||
virtual ~Messenger() {
|
||||
delete print_plotter_params;
|
||||
}
|
||||
G4UIcommand* print_plotter_params;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// John Allison 6th October 2019
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_DRIVER) || defined (G4VIS_USE_TOOLSSG)
|
||||
|
||||
#ifndef G4TOOLSSGVIEWER_HH
|
||||
#define G4TOOLSSGVIEWER_HH
|
||||
|
||||
@@ -34,16 +32,20 @@
|
||||
|
||||
#include "G4ToolsSGSceneHandler.hh"
|
||||
#include "G4Scene.hh"
|
||||
#include "G4VVisCommand.hh"
|
||||
|
||||
#include <tools/sg/device_interactor>
|
||||
#include <tools/sg/separator>
|
||||
#include <tools/sg/head_light>
|
||||
#include <tools/sg/ortho>
|
||||
#include <tools/sg/perspective>
|
||||
#include <tools/sg/torche>
|
||||
#include <tools/sg/blend>
|
||||
#include <tools/sg/noderef>
|
||||
#include <tools/sg/keys>
|
||||
|
||||
#include <tools/tokenize>
|
||||
#include <tools/sg/write_paper>
|
||||
|
||||
template <class SG_SESSION,class SG_VIEWER>
|
||||
class G4ToolsSGViewer : public G4VViewer, tools::sg::device_interactor {
|
||||
typedef G4VViewer parent;
|
||||
@@ -125,12 +127,16 @@ public:
|
||||
,fMousePressedX(0)
|
||||
,fMousePressedY(0)
|
||||
{
|
||||
//::printf("debug : G4ToolsSGViewer::G4ToolsSGViewer.\n");
|
||||
//::printf("debug : G4ToolsSGViewer::G4ToolsSGViewer: %lu, %s\n",this,a_name.c_str());
|
||||
Messenger::Create();
|
||||
}
|
||||
|
||||
virtual ~G4ToolsSGViewer() {
|
||||
//::printf("debug : G4ToolsSGViewer::~G4ToolsSGViewer: %lu\n",this);
|
||||
//WARNING : nodes may refer f_gl2ps_mgr, f_zb_mgr (to handle gstos (for GPU) or textures), then
|
||||
// we have to delete them first.
|
||||
fSGViewer->sg().clear();
|
||||
delete fSGViewer;
|
||||
//::printf("debug : G4ToolsSGViewer::~G4ToolsSGViewer.\n");
|
||||
}
|
||||
protected:
|
||||
G4ToolsSGViewer(const G4ToolsSGViewer& a_from)
|
||||
@@ -166,8 +172,6 @@ public:
|
||||
G4cerr << "G4ToolsSGViewer::Initialise : SG_VIEWER::has_window() failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
fSGViewer->set_clear_color(0.3,0.3,0.3,1);
|
||||
fSGViewer->set_device_interactor(this);
|
||||
}
|
||||
|
||||
@@ -178,7 +182,7 @@ public:
|
||||
G4cerr << "G4ToolsSGViewer::SetView : no G4Scene.." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
@@ -206,16 +210,27 @@ public:
|
||||
G4cerr << "G4ToolsSGViewer::SetView : null size viewer area." << G4endl;
|
||||
return;
|
||||
}
|
||||
//::printf("debug : GB : SetView : 1-001 : %g %g %g : %g %g %g : h %g : %g %g\n",
|
||||
// targetPoint.x(),targetPoint.y(),targetPoint.z(),
|
||||
// cameraPosition.x(),cameraPosition.y(),cameraPosition.z(),top-bottom,pnear,pfar);
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
/*
|
||||
G4cout << "debug : 0002 : radius " << radius << std::endl;
|
||||
G4cout << "debug : cameraDistance : " << cameraDistance << std::endl;
|
||||
G4cout << "debug : fieldHalfAngle : " << fVP.GetFieldHalfAngle() << std::endl;
|
||||
G4cout << "debug : zoomFactor : " << fVP.GetZoomFactor() << std::endl;
|
||||
G4cout << "debug : up : " << up.x() << " " << up.y() << " " << up.z() << std::endl;
|
||||
G4cout << "debug : targetPoint : " << targetPoint.x() << " " << targetPoint.y() << " " << targetPoint.z() << std::endl;
|
||||
G4cout << "debug : cameraPosition : " << cameraPosition.x() << " " << cameraPosition.y() << " " << cameraPosition.z() << std::endl;
|
||||
G4cout << "debug : camera : znear " << pnear << ", zfar " << pfar << std::endl;
|
||||
*/
|
||||
//////////////////////////////////////////////////////////
|
||||
/// create scene graph ///////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
// Set projection, then create the tools::sg camera node :
|
||||
tools::sg::base_camera* _camera = nullptr;
|
||||
if (fVP.GetFieldHalfAngle() <= 0.) {
|
||||
//G4cout << "debug : camera : ortho : top " << top << " bottom " << bottom << " top-bottom " << top-bottom << std::endl;
|
||||
if((top-bottom)<=0) {
|
||||
fSGViewer->set_clear_color(0.3,0.3,0.3,1);
|
||||
G4cerr << "G4ToolsSGViewer::SetView : for ortho camera, (top-bottom)<=0." << G4endl;
|
||||
@@ -225,6 +240,7 @@ public:
|
||||
ortho_camera->height.value(float(top-bottom));
|
||||
_camera = ortho_camera;
|
||||
} else {
|
||||
//G4cout << "debug : camera : perspec : heightAngle " << float(2*fVP.GetFieldHalfAngle()) << std::endl;
|
||||
tools::sg::perspective* perspective_camera = new tools::sg::perspective;
|
||||
perspective_camera->height_angle.value(float(2*fVP.GetFieldHalfAngle()));
|
||||
_camera = perspective_camera;
|
||||
@@ -238,24 +254,15 @@ public:
|
||||
_camera->zfar.value(float(pfar));
|
||||
|
||||
_camera->look_at(dir,tools::vec3f(up.x(),up.y(),up.z())); //same logic as in G4OpenInventorViewer.
|
||||
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
sep->add(_camera);
|
||||
|
||||
{tools::sg::head_light* light = new tools::sg::head_light;
|
||||
//light->direction = tools::vec3f(1,-1,-10);
|
||||
light->direction = tools::vec3f(0,0,-1);
|
||||
light->on = true;
|
||||
sep->add(light);}
|
||||
/*
|
||||
const G4Vector3D& lightDirection = fVP.GetLightpointDirection();
|
||||
G4cout << "debug : lightDirection : " << lightDirection.x() << " " << lightDirection.y() << " " << lightDirection.z() << std::endl;
|
||||
const G4Vector3D& actualLightDirection = fVP.GetActualLightpointDirection();
|
||||
G4cout << "debug : actualLightDirection : " << actualLightDirection.x() << " " << actualLightDirection.y() << " " << actualLightDirection.z() << std::endl;
|
||||
*/
|
||||
|
||||
{tools::sg::blend* blend = new tools::sg::blend;
|
||||
blend->on = true; //to handle transparency.
|
||||
sep->add(blend);}
|
||||
|
||||
sep->add(new tools::sg::noderef(*fSGSceneHandler.ToolsSGScene()));
|
||||
|
||||
fSGViewer->sg().clear();
|
||||
fSGViewer->sg().add(sep); //give sep ownership to the viewer.
|
||||
CreateSG(_camera,fVP.GetActualLightpointDirection());
|
||||
|
||||
{G4Color background = fVP.GetBackgroundColour ();
|
||||
fSGViewer->set_clear_color(float(background.GetRed()),float(background.GetBlue()),float(background.GetBlue()),1);}
|
||||
@@ -275,21 +282,17 @@ public:
|
||||
FinishView (); // Flush streams and/or swap buffers.
|
||||
}
|
||||
|
||||
virtual void ShowView() {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->show();
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
}
|
||||
virtual void ShowView() {FinishView();}
|
||||
|
||||
virtual void FinishView() {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->show();
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
if(fSGViewer) {
|
||||
fSGSceneHandler.TouchPlotters(fSGViewer->sg());
|
||||
fSGViewer->show();
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
virtual void SwitchToVisSubThread() {}
|
||||
|
||||
@@ -380,6 +383,109 @@ protected:
|
||||
// void mouseReleaseEvent (MouseEvent*);
|
||||
// void wheelEvent (WheelEvent*);
|
||||
|
||||
protected:
|
||||
void CreateSG(tools::sg::base_camera* a_camera,const G4Vector3D& a_light_dir) {
|
||||
tools::sg::group& _parent = fSGViewer->sg();
|
||||
_parent.clear();
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
/// 2D scene graph: ///////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
tools::sg::separator* scene_2D = new tools::sg::separator;
|
||||
_parent.add(scene_2D);
|
||||
scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient2DObjects()));
|
||||
scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent2DObjects()));
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
/// 3D scene graph: ///////////////////////////////
|
||||
///////////////////////////////////////////////////
|
||||
tools::sg::separator* scene_3D = new tools::sg::separator;
|
||||
_parent.add(scene_3D);
|
||||
|
||||
scene_3D->add(a_camera);
|
||||
|
||||
{tools::sg::torche* light = new tools::sg::torche;
|
||||
light->on = true;
|
||||
light->direction = tools::vec3f(-a_light_dir.x(),-a_light_dir.y(),-a_light_dir.z());
|
||||
scene_3D->add(light);}
|
||||
|
||||
{tools::sg::blend* blend = new tools::sg::blend;
|
||||
blend->on = true; //to handle transparency.
|
||||
scene_3D->add(blend);}
|
||||
|
||||
scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient3DObjects()));
|
||||
scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent3DObjects()));
|
||||
}
|
||||
|
||||
void Export(const G4String& a_format,const G4String& a_file) {
|
||||
if(!fSGViewer) return;
|
||||
const G4Colour& back_color = fVP.GetBackgroundColour();
|
||||
if(!write_paper(G4cout,f_gl2ps_mgr,f_zb_mgr,0,0,
|
||||
float(back_color.GetRed()),float(back_color.GetGreen()),float(back_color.GetBlue()),float(back_color.GetAlpha()),
|
||||
fSGViewer->sg(),
|
||||
fSGViewer->width(),fSGViewer->height(),a_file,a_format)) {
|
||||
G4cout << "G4ToolsSGViewer::Export: write_paper() failed." << G4endl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
class Messenger: public G4VVisCommand {
|
||||
public:
|
||||
static void Create() {static Messenger s_messenger;}
|
||||
private:
|
||||
Messenger() {
|
||||
G4UIparameter* parameter;
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
write_scene = new G4UIcommand("/vis/tsg/export", this);
|
||||
write_scene->SetGuidance("Write the content of the current viewer in a file at various formats.");
|
||||
write_scene->SetGuidance("Default file is out.eps and default format is gl2ps_eps.");
|
||||
write_scene->SetGuidance("Available formats are:");
|
||||
write_scene->SetGuidance("- gl2ps_eps: gl2ps producing eps");
|
||||
write_scene->SetGuidance("- gl2ps_ps: gl2ps producing ps");
|
||||
write_scene->SetGuidance("- gl2ps_pdf: gl2ps producing pdf");
|
||||
write_scene->SetGuidance("- gl2ps_svg: gl2ps producing svg");
|
||||
write_scene->SetGuidance("- gl2ps_tex: gl2ps producing tex");
|
||||
write_scene->SetGuidance("- gl2ps_pgf: gl2ps producing pgf");
|
||||
write_scene->SetGuidance("- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
|
||||
|
||||
parameter = new G4UIparameter("format",'s',true);
|
||||
parameter->SetDefaultValue("gl2ps_eps");
|
||||
write_scene->SetParameter (parameter);
|
||||
|
||||
parameter = new G4UIparameter("file",'s',true);
|
||||
parameter->SetDefaultValue("out.eps");
|
||||
write_scene->SetParameter (parameter);
|
||||
}
|
||||
virtual ~Messenger() {
|
||||
delete write_scene;
|
||||
}
|
||||
public:
|
||||
virtual void SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
|
||||
G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
||||
G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
|
||||
if (!viewer) {
|
||||
if (verbosity >= G4VisManager::errors) G4cerr << "ERROR: No current viewer." << G4endl;
|
||||
return;
|
||||
}
|
||||
G4ToolsSGViewer* tsg_viewer = dynamic_cast<G4ToolsSGViewer*>(viewer);
|
||||
if(!tsg_viewer) {
|
||||
G4cout << "G4ToolsSGViewer::SetNewValue:"
|
||||
<< " current viewer is not a G4ToolsSGViewer." << G4endl;
|
||||
return;
|
||||
}
|
||||
std::vector<std::string> args;
|
||||
tools::double_quotes_tokenize(a_value,args);
|
||||
if(args.size()!=a_cmd->GetParameterEntries()) return;
|
||||
if(a_cmd==write_scene) {
|
||||
tsg_viewer->Export(args[0],args[1]);
|
||||
}
|
||||
}
|
||||
private:
|
||||
G4UIcommand* write_scene;
|
||||
};
|
||||
|
||||
protected:
|
||||
SG_SESSION& fSGSession;
|
||||
G4ToolsSGSceneHandler& fSGSceneHandler;
|
||||
@@ -390,8 +496,10 @@ protected:
|
||||
G4bool fKeyShift;
|
||||
G4bool fMousePressed;
|
||||
G4double fMousePressedX, fMousePressedY;
|
||||
|
||||
tools::sg::zb_manager f_zb_mgr;
|
||||
tools::sg::gl2ps_manager f_gl2ps_mgr;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 6th March 2021
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER) || defined (G4VIS_USE_TOOLSSG_WINDOWS_GLES)
|
||||
|
||||
#ifndef G4TOOLSSGWINDOWSGLES_HH
|
||||
#define G4TOOLSSGWINDOWSGLES_HH
|
||||
|
||||
@@ -53,5 +51,3 @@ protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER) || defined (G4VIS_USE_TOOLSSG_X11_GLES)
|
||||
|
||||
#ifndef G4TOOLSSGX11GLES_HH
|
||||
#define G4TOOLSSGX11GLES_HH
|
||||
|
||||
@@ -53,5 +51,3 @@ protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER) || defined (G4VIS_USE_TOOLSSG_XT_GLES)
|
||||
|
||||
#ifndef G4TOOLSSGXTGLES_HH
|
||||
#define G4TOOLSSGXTGLES_HH
|
||||
|
||||
@@ -53,5 +51,3 @@ protected:
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
@@ -12,8 +12,6 @@ set(G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
G4ToolsSGSceneHandler.cc
|
||||
)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_DRIVER)
|
||||
|
||||
# X11 sources/links if selected
|
||||
if(GEANT4_USE_TOOLSSG_X11_GLES)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_HEADERS
|
||||
@@ -24,8 +22,6 @@ if(GEANT4_USE_TOOLSSG_X11_GLES)
|
||||
G4ToolsSGX11GLES.cc
|
||||
)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu)
|
||||
if(APPLE)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES XQuartzGL::GL)
|
||||
@@ -46,11 +42,7 @@ if(GEANT4_USE_TOOLSSG_XT_GLES)
|
||||
|
||||
add_definitions(-DTOOLS_USE_GL_GL_H)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER)
|
||||
|
||||
add_definitions(-DG4INTY_BUILD_XT)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES Motif::Xm X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu ${G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES})
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu ${G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES})
|
||||
if(APPLE)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES XQuartzGL::GL)
|
||||
else()
|
||||
@@ -67,12 +59,9 @@ if(GEANT4_USE_TOOLSSG_QT_GLES)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
G4ToolsSGQtGLES.cc
|
||||
G4ToolsSGQtViewer.cc
|
||||
)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER)
|
||||
|
||||
add_definitions(-DG4INTY_BUILD_QT -DG4UI_BUILD_QT_SESSION)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES Qt5::OpenGL Qt5::Gui Qt5::PrintSupport Qt5::Widgets OpenGL::GL)
|
||||
endif()
|
||||
|
||||
@@ -87,8 +76,6 @@ if(GEANT4_USE_TOOLSSG_WINDOWS_GLES)
|
||||
G4ToolsSGWindowsGLES.cc
|
||||
)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGQtGLES.hh"
|
||||
|
||||
//
|
||||
@@ -127,5 +125,3 @@ G4bool G4ToolsSGQtGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
#include "G4ToolsSGQtViewer.hh"
|
||||
#include "moc_G4ToolsSGQtViewer.cpp"
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
//
|
||||
// John Allison 6th October 2020
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_DRIVER
|
||||
|
||||
#include "G4ToolsSGSceneHandler.hh"
|
||||
|
||||
#include "G4ToolsSGNode.hh"
|
||||
|
||||
#include "G4TransportationManager.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Polymarker.hh"
|
||||
@@ -36,8 +36,7 @@
|
||||
#include "G4Square.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Text.hh"
|
||||
|
||||
//#define G4TOOLSSG_DEBUG
|
||||
#include "G4PlotterManager.hh"
|
||||
|
||||
#include <tools/sg/separator>
|
||||
#include <tools/sg/matrix>
|
||||
@@ -46,13 +45,28 @@
|
||||
#include <tools/sg/atb_vertices>
|
||||
#include <tools/sg/markers>
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
#include <tools/sg/text_freetype_marker>
|
||||
#include <tools/sg/text_freetype>
|
||||
#include <tools/sg/strings>
|
||||
#include <tools/font/lato_regular_ttf>
|
||||
#include <tools/font/roboto_bold_ttf>
|
||||
#include <tools/sg/text_freetype_marker>
|
||||
#else
|
||||
#include <tools/sg/dummy_freetype>
|
||||
#include <tools/sg/text_hershey_marker>
|
||||
#endif
|
||||
|
||||
#include "G4ToolsSGNode.hh"
|
||||
//for plotting:
|
||||
#include <tools/sg/dummy_freetype>
|
||||
#include <tools/sg/light_off>
|
||||
#include <tools/sg/plots>
|
||||
#include <tools/sg/h2plot_cp>
|
||||
#include <tools/sg/plotter_style>
|
||||
#include <tools/sg/event_dispatcher>
|
||||
#include <tools/sg/path>
|
||||
#include <tools/sg/search>
|
||||
#include <tools/histo/h1d>
|
||||
#include <tools/histo/h2d>
|
||||
#include <tools/sg/plotter_some_styles>
|
||||
|
||||
#include <utility>
|
||||
|
||||
@@ -61,27 +75,35 @@ G4int G4ToolsSGSceneHandler::fSceneIdCount = 0;
|
||||
G4ToolsSGSceneHandler::G4ToolsSGSceneHandler
|
||||
(G4VGraphicsSystem& system, const G4String& name)
|
||||
:parent(system, fSceneIdCount++, name)
|
||||
,fFreetypeNode(0)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "G4ToolsSGSceneHandler::G4ToolsSGSceneHandler called" << G4endl;
|
||||
#endif
|
||||
fpToolsSGScene = new tools::sg::separator;
|
||||
//::printf("debug : G4ToolsSGSceneHandler : %lu, %s\n",this,name.c_str());
|
||||
EstablishBaseNodes();
|
||||
#if defined(TOOLS_USE_FREETYPE)
|
||||
fFreetypeNode = new tools::sg::text_freetype();
|
||||
fFreetypeNode->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
|
||||
fFreetypeNode->add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
|
||||
#else
|
||||
fFreetypeNode = new tools::sg::dummy_freetype();
|
||||
#endif
|
||||
Messenger::Create();
|
||||
}
|
||||
|
||||
G4ToolsSGSceneHandler::~G4ToolsSGSceneHandler()
|
||||
{
|
||||
delete fpToolsSGScene;
|
||||
//::printf("debug : ~G4ToolsSGSceneHandler : %lu\n",this);
|
||||
//WARNING : nodes may refer graphics managers (as tools/sg/[GL_manager,gl2ps_manager,zb_manager]
|
||||
// used by viewers) to handle gstos (for GPU) or textures, then we have to delete them first.
|
||||
// It is assumed that we pass here BEFORE the attached/managed viewers are deleted.
|
||||
fpTransient2DObjects.clear();
|
||||
fpPersistent2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
fpPersistent3DObjects.clear();
|
||||
delete fFreetypeNode;
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EstablishBaseNodes()
|
||||
{
|
||||
fpTransientObjects = new tools::sg::separator;
|
||||
fpToolsSGScene->add(fpTransientObjects);
|
||||
|
||||
fpPersistentObjects = new tools::sg::separator;
|
||||
fpToolsSGScene->add(fpPersistentObjects);
|
||||
|
||||
// Physical volume objects for each world hang from POs
|
||||
G4TransportationManager* transportationManager = G4TransportationManager::GetTransportationManager ();
|
||||
size_t nWorlds = transportationManager->GetNoWorlds();
|
||||
@@ -90,7 +112,7 @@ void G4ToolsSGSceneHandler::EstablishBaseNodes()
|
||||
for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
|
||||
G4VPhysicalVolume* _world = (*iterWorld);
|
||||
auto entity = new G4ToolsSGNode;
|
||||
fpPersistentObjects->add(entity);
|
||||
fpPersistent3DObjects.add(entity);
|
||||
entity->SetPVNodeID(G4PhysicalVolumeModel::G4PhysicalVolumeNodeID(_world));
|
||||
fpPhysicalVolumeObjects[i] = entity;
|
||||
}
|
||||
@@ -106,15 +128,15 @@ tools::sg::separator* G4ToolsSGSceneHandler::GetOrCreateNode()
|
||||
|
||||
if (fReadyForTransients) { // All transients hang from this node
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpTransientObjects->add(sep);
|
||||
fpTransient3DObjects.add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
G4PhysicalVolumeModel* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
auto* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
|
||||
if (!pPVModel) { // Persistent objects (e.g., axes)
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpPersistentObjects->add(sep);
|
||||
fpPersistent3DObjects.add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
@@ -172,88 +194,65 @@ tools::sg::separator* G4ToolsSGSceneHandler::GetOrCreateNode()
|
||||
return node;
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PreAddSolid
|
||||
(const G4Transform3D& objectTransformation,
|
||||
const G4VisAttributes& visAttribs)
|
||||
{
|
||||
parent::PreAddSolid(objectTransformation, visAttribs);
|
||||
void G4ToolsSGSceneHandler::ClearStore ()
|
||||
{
|
||||
fpTransient2DObjects.clear();
|
||||
fpPersistent2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
fpPersistent3DObjects.clear();
|
||||
EstablishBaseNodes();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PostAddSolid()
|
||||
void G4ToolsSGSceneHandler::ClearTransientStore ()
|
||||
{
|
||||
parent::PostAddSolid();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::BeginPrimitives2D(const G4Transform3D& objectTransformation)
|
||||
{
|
||||
// The x,y coordinates of the primitives passed to AddPrimitive are
|
||||
// intrepreted as screen coordinates, -1 < x,y < 1. The
|
||||
// z-coordinate is ignored.
|
||||
static G4bool first = true;
|
||||
if (first) {
|
||||
first = false;
|
||||
G4Exception("G4ToolsSGSceneHandler::BeginPrimitives2D", "ToolsSG-0001",
|
||||
JustWarning,
|
||||
"2D drawing not yet implemented");
|
||||
}
|
||||
parent::BeginPrimitives2D (objectTransformation);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EndPrimitives2D ()
|
||||
{
|
||||
parent::EndPrimitives2D ();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::BeginPrimitives(const G4Transform3D& objectTransformation)
|
||||
{
|
||||
parent::BeginPrimitives(objectTransformation);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EndPrimitives ()
|
||||
{
|
||||
parent::EndPrimitives ();
|
||||
fpTransient2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline& a_polyline)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline&) : \n" << a_polyline << G4endl;
|
||||
#endif
|
||||
//G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline&) : \n" << a_polyline << G4endl;
|
||||
if (a_polyline.size() == 0) return;
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
tools::sg::separator* parentNode = 0;
|
||||
if(fProcessing2D) {
|
||||
parentNode = new tools::sg::separator;
|
||||
if (fReadyForTransients) {
|
||||
fpTransient2DObjects.add(parentNode);
|
||||
} else {
|
||||
fpPersistent2DObjects.add(parentNode);
|
||||
}
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyline.GetVisAttributes());
|
||||
} else {
|
||||
parentNode = GetOrCreateNode();
|
||||
if(!parentNode) return;
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
parentNode->add(mtx);
|
||||
}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
{const auto& colour = GetColour(a_polyline);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
float(colour.GetGreen()),
|
||||
float(colour.GetBlue()),
|
||||
float(colour.GetAlpha()));
|
||||
currentNode->add(mat);}
|
||||
parentNode->add(mat);}
|
||||
|
||||
{tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_lines;
|
||||
ds->line_width = 1;
|
||||
currentNode->add(ds);}
|
||||
parentNode->add(ds);}
|
||||
|
||||
// Geometry :
|
||||
tools::sg::vertices* vtxs = new tools::sg::vertices;
|
||||
vtxs->mode = tools::gl::line_strip(); //polyline
|
||||
currentNode->add(vtxs);
|
||||
parentNode->add(vtxs);
|
||||
|
||||
{for (size_t i = 0; i < a_polyline.size(); ++i) {
|
||||
vtxs->add(float(a_polyline[i].x()),float(a_polyline[i].y()),float(a_polyline[i].z()));
|
||||
@@ -261,20 +260,14 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline& a_polyline)
|
||||
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive (const G4Scale& a_scale) {parent::AddPrimitive(a_scale);}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug G4ToolsSGSceneHandler::AddPrimitive(const G4Polymarker&) : %lu, type %d\n",
|
||||
a_polymarker.size(),a_polymarker.GetMarkerType());
|
||||
#endif
|
||||
//::printf("debug G4ToolsSGSceneHandler::AddPrimitive(const G4Polymarker&) : %lu, type %d\n",
|
||||
// a_polymarker.size(),a_polymarker.GetMarkerType());
|
||||
if (a_polymarker.size() == 0) return;
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polymarker.GetVisAttributes());
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
@@ -284,8 +277,7 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
{const auto& colour = GetColour(a_polymarker);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
@@ -319,24 +311,6 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
markers->add(float(a_polymarker[i].x()),float(a_polymarker[i].y()),float(a_polymarker[i].z()));
|
||||
}
|
||||
currentNode->add(markers);}
|
||||
/*
|
||||
G4Circle circle (a_polymarker);
|
||||
G4double radius;
|
||||
if (circle.GetSizeType() == G4VMarker::world ) {
|
||||
radius = circle.GetWorldRadius();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
for (size_t iPoint = 0; iPoint < a_polymarker.size (); iPoint++) {
|
||||
auto position = fObjectTransformation*G4Translate3D(a_polymarker[iPoint]);
|
||||
auto node = new G4ToolsSGNode(currentNode);
|
||||
//node->addComponent(material);
|
||||
//node->addComponent(position);
|
||||
//node->addComponent(sphere); // Sphere of given radius
|
||||
}
|
||||
*/
|
||||
}break;
|
||||
case G4Polymarker::squares:{
|
||||
//::printf("debug : GB : Add Markers : +++++++++++++++++++++++++++++++++++++++++++ : square\n");
|
||||
@@ -347,78 +321,66 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
markers->add(float(a_polymarker[i].x()),float(a_polymarker[i].y()),float(a_polymarker[i].z()));
|
||||
}
|
||||
currentNode->add(markers);}
|
||||
/*
|
||||
G4Square square (a_polymarker);
|
||||
G4double side;
|
||||
if (square.GetSizeType() == G4VMarker::world ) {
|
||||
side = square.GetWorldDiameter();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
side = square.GetScreenDiameter()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
for (size_t iPoint = 0; iPoint < a_polymarker.size (); iPoint++) {
|
||||
auto position = fObjectTransformation*G4Translate3D(a_polymarker[iPoint]);
|
||||
auto node = new G4ToolsSGNode(currentNode);
|
||||
//node->addComponent(material);
|
||||
//node->addComponent(position);
|
||||
//node->addComponent(box); // Cube of given side
|
||||
}
|
||||
*/
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Text& a_text)
|
||||
{
|
||||
//static G4bool first = true;
|
||||
//if (first) {
|
||||
// first = false;
|
||||
// G4Exception("G4ToolsSGSceneHandler::AddPrimitive(const G4Text& text)",
|
||||
// "ToolsSG-0002", JustWarning,
|
||||
// "Text drawing not yet implemented");
|
||||
//}
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : \"%s\"\n",a_text.GetText().c_str());
|
||||
#endif
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_text.GetVisAttributes());
|
||||
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : 000 : \"%s\"\n",a_text.GetText().c_str());
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : 2D ? %d\n",fProcessing2D);
|
||||
auto pos = a_text.GetPosition();
|
||||
//::printf("debug : Add Text : pos %g %g %g\n",pos.x(),pos.y(),pos.z());
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
auto elem = fObjectTransformation*G4Translate3D(a_text.GetPosition());
|
||||
//G4Transform3D& elem = fObjectTransformation*G4Translate3D(a_text.GetPosition());
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
tools::sg::separator* parentNode = 0;
|
||||
if(fProcessing2D) {
|
||||
parentNode = new tools::sg::separator;
|
||||
if (fReadyForTransients) {
|
||||
fpTransient2DObjects.add(parentNode);
|
||||
} else {
|
||||
fpPersistent2DObjects.add(parentNode);
|
||||
}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
mtx->set_translate(pos.x(),pos.y(),pos.z());
|
||||
parentNode->add(mtx);
|
||||
|
||||
} else {
|
||||
parentNode = GetOrCreateNode();
|
||||
if (!parentNode) return;
|
||||
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
auto elem = fObjectTransformation*G4Translate3D(pos);
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
parentNode->add(mtx);
|
||||
}
|
||||
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize(a_text, sizeType);
|
||||
|
||||
{const auto& colour = GetTextColour(a_text);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
float(colour.GetGreen()),
|
||||
float(colour.GetBlue()),
|
||||
float(colour.GetAlpha()));
|
||||
currentNode->add(mat);}
|
||||
|
||||
parentNode->add(mat);}
|
||||
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
tools::sg::text_freetype_marker* text = new tools::sg::text_freetype_marker;
|
||||
text->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
|
||||
text->font = tools::sg::font_lato_regular_ttf();
|
||||
text->front_face = tools::sg::winding_cw;
|
||||
text->modeling = tools::sg::font_pixmap;
|
||||
//text->modeling = tools::sg::font_pixmap; //problem with Qt/GL. It slows rendering!
|
||||
#else
|
||||
tools::sg::text_hershey_marker* text = new tools::sg::text_hershey_marker;
|
||||
//text->encoding.value(a_encoding);
|
||||
#endif
|
||||
text->height = float(size); //pixels
|
||||
text->strings.add(a_text.GetText());
|
||||
{switch (a_text.GetLayout()) {
|
||||
default:
|
||||
@@ -433,24 +395,8 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Text& a_text)
|
||||
break;
|
||||
}}
|
||||
//text->vjust.value(a_vjust);
|
||||
currentNode->add(text);
|
||||
|
||||
/*
|
||||
//text.GetText(), text.GetXOffset(), etc.
|
||||
parentNode->add(text);
|
||||
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize (text, sizeType);
|
||||
switch (sizeType) {
|
||||
default:
|
||||
case screen:
|
||||
// Draw in screen coordinates. OK.
|
||||
break;
|
||||
case world:
|
||||
// Draw in world coordinates. Not implemented. Use size = 20.
|
||||
size = 20.;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Circle& a_circle)
|
||||
@@ -460,33 +406,6 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Circle& a_circle)
|
||||
oneCircle.SetMarkerType(G4Polymarker::circles);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4ToolsSGSceneHandler::AddPrimitive(oneCircle);
|
||||
|
||||
/*
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(circle.GetVisAttributes());
|
||||
|
||||
auto circleNode = new G4ToolsSGNode(currentNode);
|
||||
|
||||
// Transformation
|
||||
auto position = fObjectTransformation*G4Translate3D(circle.GetPosition());
|
||||
//circleNode->addComponent(position);
|
||||
|
||||
// Material (colour, etc.)
|
||||
const auto& colour = fpVisAttribs->GetColour();
|
||||
//circleNode->addComponent(colour);
|
||||
|
||||
G4double radius;
|
||||
if (circle.GetSizeType() == G4VMarker::world ) {
|
||||
radius =circle.GetWorldRadius();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
//circleNode->addComponent(sphere); // Of given radius
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Square& a_square)
|
||||
@@ -496,42 +415,13 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Square& a_square)
|
||||
oneSquare.SetMarkerType(G4Polymarker::squares);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4ToolsSGSceneHandler::AddPrimitive(oneSquare);
|
||||
|
||||
/*
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(square.GetVisAttributes());
|
||||
|
||||
auto squareNode = new G4ToolsSGNode(currentNode);
|
||||
|
||||
// Transformation
|
||||
auto position = fObjectTransformation*G4Translate3D(square.GetPosition());
|
||||
//squareNode->addComponent(position);
|
||||
|
||||
// Material (colour, etc.)
|
||||
const auto& colour = fpVisAttribs->GetColour();
|
||||
//squareNode->addComponent(colour);
|
||||
|
||||
G4double side;
|
||||
if (square.GetSizeType() == G4VMarker::world ) {
|
||||
side = square.GetWorldDiameter();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
side = square.GetScreenDiameter()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
//squareNode->addComponent(cube); // Of given side
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
{
|
||||
if (a_polyhedron.GetNoFacets() == 0) return;
|
||||
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron&) : %d\n",a_polyhedron.GetNoFacets());
|
||||
#endif
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron&) : %d\n",a_polyhedron.GetNoFacets());
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyhedron.GetVisAttributes());
|
||||
|
||||
@@ -630,8 +520,7 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
0, 0, 0, 1);
|
||||
sep->add(mtx);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = fpVisAttribs->GetColour();
|
||||
{const auto& colour = GetColour(a_polyhedron);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
@@ -681,15 +570,262 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearStore ()
|
||||
{
|
||||
fpToolsSGScene->clear();
|
||||
EstablishBaseNodes();
|
||||
//plotting:
|
||||
inline void SetRegionStyles(tools::xml::styles& a_styles,
|
||||
tools::sg::plots& a_plots,
|
||||
tools::sg::plotter& a_plotter,
|
||||
const G4String& a_style) {
|
||||
if(a_style=="reset") {
|
||||
a_plotter.reset_style(true);
|
||||
a_plots.touch(); //to apply indirectly plots::set_plotter_layout() on _plotter.
|
||||
} else if( (a_style=="inlib_default")|| (a_style=="default")) {
|
||||
tools::sg::set_inlib_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
|
||||
} else if(a_style=="ROOT_default") {
|
||||
tools::sg::set_ROOT_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
|
||||
} else if(a_style=="hippodraw") {
|
||||
tools::sg::set_hippodraw_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
|
||||
} else {
|
||||
tools::sg::style_from_res(a_styles,a_style,a_plotter,false);
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearTransientStore ()
|
||||
{
|
||||
fpTransientObjects->clear();
|
||||
inline tools::xml::styles::style_t* find_style(tools::xml::styles& a_styles,const std::string& a_name) {
|
||||
tools_vforit(tools::xml::styles::named_style_t,a_styles.named_styles(),it){
|
||||
if((*it).first==a_name) return &((*it).second);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
inline void SetPlotterStyles(tools::sg::plots& a_plots,
|
||||
const std::vector<G4String>& a_plotter_styles,
|
||||
const std::vector<G4Plotter::RegionStyle>& a_region_styles) {
|
||||
|
||||
G4PlotterManager::Styles& _styles = G4PlotterManager::GetInstance().GetStyles();
|
||||
|
||||
tools::xml::styles _tools_styles(G4cout);
|
||||
_tools_styles.add_colormap("default",tools::sg::style_default_colormap());
|
||||
_tools_styles.add_colormap("ROOT",tools::sg::style_ROOT_colormap());
|
||||
|
||||
{tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
|
||||
tools::xml::styles::style_t _tools_style;
|
||||
tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
|
||||
const G4String& param = (*its).first;
|
||||
if(param.find('.')==std::string::npos) {
|
||||
const G4String& value = (*its).second;
|
||||
_tools_style.push_back(tools::xml::styles::style_item_t(param,value));
|
||||
}
|
||||
}
|
||||
_tools_styles.add_style((*it).first,_tools_style);
|
||||
}}
|
||||
|
||||
// sub styles:
|
||||
{tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
|
||||
tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
|
||||
const G4String& param = (*its).first;
|
||||
std::string::size_type pos = param.rfind('.');
|
||||
if(pos!=std::string::npos) {
|
||||
std::string sub_style = (*it).first+"."+param.substr(0,pos);
|
||||
G4String parameter = param.substr(pos+1,param.size()-pos);
|
||||
const G4String& value = (*its).second;
|
||||
tools::xml::styles::style_t* _tools_style = find_style(_tools_styles,sub_style);
|
||||
if(_tools_style) {
|
||||
_tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
|
||||
} else {
|
||||
tools::xml::styles::style_t _tools_style_2;
|
||||
_tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
|
||||
_tools_styles.add_style(sub_style,_tools_style_2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
{unsigned int number = a_plots.number();
|
||||
for(unsigned int index=0;index<number;index++) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter(index);
|
||||
if(_plotter) {
|
||||
tools_vforcit(G4String,a_plotter_styles,it) {
|
||||
SetRegionStyles(_tools_styles,a_plots,*_plotter,*it);
|
||||
}
|
||||
}
|
||||
}}
|
||||
{tools_vforcit(G4Plotter::RegionStyle,a_region_styles,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
SetRegionStyles(_tools_styles,a_plots,*_plotter,(*it).second);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
inline void SetPlotterParameters(tools::sg::cmaps_t& a_cmaps,tools::sg::plots& a_plots,
|
||||
const std::vector<G4Plotter::RegionParameter>& a_region_parameters) {
|
||||
// parameter/field examples :
|
||||
// title_automated
|
||||
// title
|
||||
// bins_style.0.color
|
||||
// x_axis.divisions
|
||||
// x_axis.line_style.color
|
||||
// background_style.back_color
|
||||
tools_vforcit(G4Plotter::RegionParameter,a_region_parameters,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
const G4String& parameter = (*it).second.first;
|
||||
const G4String& value = (*it).second.second;
|
||||
tools::sg::field* fd = _plotter->find_field_by_name(parameter);
|
||||
if(!fd) fd = _plotter->find_field_by_name(_plotter->s_cls()+"."+parameter);
|
||||
if(fd) {if(fd->s2value(value)) continue;}
|
||||
// look for sf_enum for which value is given with a string, or
|
||||
// for sf<bool> for which value given with true/false, or
|
||||
// for a style, for example: bins_style.0.color:
|
||||
if(!_plotter->set_from_string(G4cout,a_cmaps,parameter,value)) {
|
||||
G4cout << "G4ToolsSGSceneHandler::SetPlotterParameters: plotter.set_from_string() failed for field "
|
||||
<< tools::sout(parameter) << ", and value " << tools::sout(value) << "."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
|
||||
void G4ToolsSGSceneHandler::SetPlotterHistograms(tools::sg::plots& a_plots) {
|
||||
a_plots.clear();
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if(UI==NULL) return;
|
||||
{tools_vforcit(Region_h1,fRegionH1s,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
int hid = (*it).second;
|
||||
std::ostringstream os;
|
||||
os << hid;
|
||||
std::string cmd("/analysis/h1/get ");
|
||||
cmd += std::string(os.str());
|
||||
G4int status = UI->ApplyCommand(cmd.c_str());
|
||||
if(status==G4UIcommandStatus::fCommandSucceeded) {
|
||||
G4String hexString = UI->GetCurrentValues("/analysis/h1/get");
|
||||
if(hexString.size()) {
|
||||
void* ptr;
|
||||
std::istringstream is(hexString);
|
||||
is >> ptr;
|
||||
tools::histo::h1d* _h = (tools::histo::h1d*)ptr;
|
||||
tools::sg::plottable* p = new tools::sg::h1d2plot_cp(*_h);
|
||||
_plotter->add_plottable(p); //give ownership of p to sg::plotter.
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
{tools_vforcit(Region_h2,fRegionH2s,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
int hid = (*it).second;
|
||||
std::ostringstream os;
|
||||
os << hid;
|
||||
std::string cmd("/analysis/h2/get ");
|
||||
cmd += std::string(os.str());
|
||||
G4int status = UI->ApplyCommand(cmd.c_str());
|
||||
if(status==G4UIcommandStatus::fCommandSucceeded) {
|
||||
G4String hexString = UI->GetCurrentValues("/analysis/h2/get");
|
||||
if(hexString.size()) {
|
||||
void* ptr;
|
||||
std::istringstream is(hexString);
|
||||
is >> ptr;
|
||||
tools::histo::h2d* _h = (tools::histo::h2d*)ptr;
|
||||
tools::sg::plottable* p = new tools::sg::h2d2plot_cp(*_h);
|
||||
_plotter->add_plottable(p); //give ownership of p to sg::plotter.
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
class plots_cbk : public tools::sg::ecbk {
|
||||
TOOLS_CBK(plots_cbk,plots_cbk,tools::sg::ecbk)
|
||||
public:
|
||||
virtual tools::sg::return_action action() {
|
||||
if(const tools::sg::size_event* sz_evt = tools::sg::event_cast<tools::sg::event,tools::sg::size_event>(*m_event)){
|
||||
m_plots.adjust_size(sz_evt->width(),sz_evt->height());
|
||||
m_event_action->set_done(true);
|
||||
return tools::sg::return_to_render;
|
||||
}
|
||||
return tools::sg::return_none;
|
||||
}
|
||||
public:
|
||||
plots_cbk(tools::sg::plots& a_plots)
|
||||
:parent()
|
||||
,m_plots(a_plots)
|
||||
{}
|
||||
virtual ~plots_cbk(){}
|
||||
public:
|
||||
plots_cbk(const plots_cbk& a_from)
|
||||
:parent(a_from)
|
||||
,m_plots(a_from.m_plots)
|
||||
{}
|
||||
plots_cbk& operator=(const plots_cbk& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
tools::sg::plots& m_plots;
|
||||
};
|
||||
|
||||
void G4ToolsSGSceneHandler::TouchPlotters(tools::sg::node& a_sg) {
|
||||
tools::sg::search_action sa(G4cout);
|
||||
const tools::sg::search_action::paths_t& paths = tools::sg::find_paths<tools::sg::plots>(sa,a_sg);
|
||||
tools_vforcit(tools::sg::path_t,paths,it) {
|
||||
tools::sg::plots* _plots = tools::sg::tail<tools::sg::plots>(*it);
|
||||
if(_plots) {
|
||||
SetPlotterHistograms(*_plots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Plotter& a_plotter)
|
||||
{
|
||||
//G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive : 004" << std::endl;
|
||||
if(!fpViewer) return;
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
currentNode->add(new tools::sg::light_off());
|
||||
|
||||
tools::sg::plots* _plots = new tools::sg::plots(*fFreetypeNode);
|
||||
currentNode->add(_plots);
|
||||
|
||||
_plots->view_border = false;
|
||||
_plots->set_regions(a_plotter.GetColumns(),a_plotter.GetRows());
|
||||
|
||||
{tools::sg::event_dispatcher* dpt = new tools::sg::event_dispatcher;
|
||||
dpt->add_callback(new plots_cbk(*_plots));
|
||||
currentNode->add(dpt);}
|
||||
|
||||
SetPlotterStyles(*_plots,a_plotter.GetStyles(),a_plotter.GetRegionStyles());
|
||||
|
||||
tools::sg::cmaps_t _cmaps;
|
||||
_cmaps["default"] = tools::sg::style_default_colormap();
|
||||
_cmaps["ROOT"] = tools::sg::style_ROOT_colormap();
|
||||
|
||||
SetPlotterParameters(_cmaps,*_plots,a_plotter.GetRegionParameters());
|
||||
|
||||
fRegionH1s = a_plotter.GetRegionH1s();
|
||||
fRegionH2s = a_plotter.GetRegionH2s();
|
||||
|
||||
SetPlotterHistograms(*_plots);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::Messenger::SetNewValue(G4UIcommand* a_cmd,G4String) {
|
||||
G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler();
|
||||
if (!pSceneHandler) {
|
||||
G4cout << "G4ToolsSGSceneHandler::Messenger::SetNewValue: no current sceneHandler. Please create one." << G4endl;
|
||||
return;
|
||||
}
|
||||
auto* tsg_scene_handler = dynamic_cast<G4ToolsSGSceneHandler*>(pSceneHandler);
|
||||
if(!tsg_scene_handler) {
|
||||
G4cout << "G4ToolsSGSceneHandler::Messenger::SetNewValue: current sceneHandler not a G4ToolsSGSceneHandler." << G4endl;
|
||||
return;
|
||||
}
|
||||
if(a_cmd==print_plotter_params) {
|
||||
tools::sg::dummy_freetype _ttf;
|
||||
tools::sg::plotter _plotter(_ttf);
|
||||
_plotter.print_available_customization(G4cout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 6th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGWindowsGLES.hh"
|
||||
|
||||
@@ -113,5 +112,3 @@ G4bool G4ToolsSGWindowsGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGX11GLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
@@ -115,5 +113,3 @@ G4bool G4ToolsSGX11GLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGXtGLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
@@ -137,5 +135,3 @@ G4bool G4ToolsSGXtGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user