Import Geant4 11.0.0.beta source tree
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
#------------------------------------------------------------------------------
|
||||
# Module : G4ToolsSG
|
||||
# Package: Geant4.src.G4visualization.G4ToolsSG
|
||||
#------------------------------------------------------------------------------
|
||||
|
||||
geant4_global_library_target(COMPONENTS sources.cmake)
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
|
||||
name := G4ToolsSG
|
||||
|
||||
ifndef G4INSTALL
|
||||
G4INSTALL = ../../..
|
||||
endif
|
||||
|
||||
GLOBLIBS = libG4vis_management.lib libG4modeling.lib
|
||||
GLOBLIBS += libG4run.lib libG4event.lib
|
||||
GLOBLIBS += libG4tracking.lib libG4processes.lib libG4digits_hits.lib
|
||||
GLOBLIBS += libG4track.lib libG4particles.lib libG4geometry.lib
|
||||
GLOBLIBS += libG4materials.lib libG4graphics_reps.lib
|
||||
GLOBLIBS += libG4intercoms.lib libG4global.lib
|
||||
|
||||
include $(G4INSTALL)/config/architecture.gmk
|
||||
# include $(G4INSTALL)/config/G4VIS_BUILD.gmk
|
||||
include $(G4INSTALL)/config/interactivity.gmk
|
||||
|
||||
CPPFLAGS += -I$(G4BASE)/visualization/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/visualization/modeling/include
|
||||
CPPFLAGS += -I$(G4BASE)/global/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/global/HEPGeometry/include
|
||||
CPPFLAGS += -I$(G4BASE)/graphics_reps/include
|
||||
CPPFLAGS += -I$(G4BASE)/intercoms/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/management/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/solids/CSG/include
|
||||
CPPFLAGS += -I$(G4BASE)/geometry/solids/specific/include
|
||||
CPPFLAGS += -I$(G4BASE)/tracking/include
|
||||
CPPFLAGS += -I$(G4BASE)/digits_hits/hits/include
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
endif
|
||||
|
||||
ifdef G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
CPPFLAGS += -DG4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
endif
|
||||
|
||||
include $(G4INSTALL)/config/common.gmk
|
||||
@@ -0,0 +1,57 @@
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=========================================================
|
||||
Geant4 - an Object-Oriented Toolkit for Simulation in HEP
|
||||
=========================================================
|
||||
|
||||
Category History file
|
||||
---------------------
|
||||
This file should be used by G4 developers and category coordinators
|
||||
to briefly summarize all major modifications introduced in the code
|
||||
and keep track of all category-tags.
|
||||
It DOES NOT substitute the CVS log-message one should put at every
|
||||
committal in the CVS repository !
|
||||
|
||||
----------------------------------------------------------
|
||||
* Reverse chronological order (last date on top), please *
|
||||
----------------------------------------------------------
|
||||
|
||||
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)
|
||||
- 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).
|
||||
- G4ToolsSGViewer.hh:
|
||||
o Force kernel visit if special mesh rendering parameters change.
|
||||
|
||||
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)
|
||||
- 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)
|
||||
- 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)
|
||||
- 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)
|
||||
- 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:
|
||||
. TOOLSSG_X11_GLES
|
||||
. TOOLSSG_WINDOWS_GLES
|
||||
. TOOLSSG_XT_GLES
|
||||
. TOOLSSG_QT_GLES
|
||||
@@ -0,0 +1,60 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// John Allison, 6th October 2020
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_DRIVER) || defined (G4VIS_USE_TOOLSSG)
|
||||
|
||||
#ifndef G4TOOLSSGNODE_HH
|
||||
#define G4TOOLSSGNODE_HH
|
||||
|
||||
#include <tools/sg/separator>
|
||||
|
||||
#include "G4PhysicalVolumeModel.hh"
|
||||
|
||||
class G4ToolsSGNode: public tools::sg::separator {
|
||||
typedef tools::sg::separator parent;
|
||||
public:
|
||||
G4ToolsSGNode():parent(),fPVNodeID(0) {}
|
||||
virtual ~G4ToolsSGNode() = default;
|
||||
public:
|
||||
G4ToolsSGNode(const G4ToolsSGNode& a_from):parent(a_from),fPVNodeID(a_from.fPVNodeID) {}
|
||||
G4ToolsSGNode& operator=(const G4ToolsSGNode& a_from) {
|
||||
parent::operator=(a_from);
|
||||
fPVNodeID = a_from.fPVNodeID;
|
||||
return *this;
|
||||
}
|
||||
public:
|
||||
const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& GetPVNodeID () const
|
||||
{return fPVNodeID;}
|
||||
void SetPVNodeID(const G4PhysicalVolumeModel::G4PhysicalVolumeNodeID& id)
|
||||
{fPVNodeID = id;}
|
||||
private:
|
||||
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID fPVNodeID;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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
|
||||
|
||||
#include "G4VGraphicsSystem.hh"
|
||||
|
||||
namespace tools {namespace Qt {class session;}}
|
||||
|
||||
class G4ToolsSGQtGLES: public G4VGraphicsSystem {
|
||||
typedef G4VGraphicsSystem parent;
|
||||
public:
|
||||
G4ToolsSGQtGLES();
|
||||
virtual ~G4ToolsSGQtGLES();
|
||||
protected:
|
||||
G4ToolsSGQtGLES(const G4ToolsSGQtGLES& a_from):parent(a_from){}
|
||||
G4ToolsSGQtGLES& operator=(const G4ToolsSGQtGLES&) {return *this;}
|
||||
public:
|
||||
G4VSceneHandler* CreateSceneHandler(const G4String& name = "");
|
||||
G4VViewer* CreateViewer (G4VSceneHandler&, const G4String& name = "");
|
||||
G4bool IsUISessionCompatible () const;
|
||||
protected:
|
||||
void Initialise();
|
||||
protected:
|
||||
tools::Qt::session* fSGSession;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,108 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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"
|
||||
|
||||
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;
|
||||
protected:
|
||||
G4ToolsSGQtViewer(const G4ToolsSGQtViewer& a_from):parent(a_from),fInTab(false){}
|
||||
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;
|
||||
}
|
||||
fSGQWidget = fSGViewer->shell();
|
||||
if (!fSGQWidget) {
|
||||
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);
|
||||
}
|
||||
}}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
protected:
|
||||
bool fInTab;
|
||||
QWidget* fSGQWidget;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,90 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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 <vector>
|
||||
|
||||
namespace tools {namespace sg {class separator;}}
|
||||
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 ();
|
||||
|
||||
public:
|
||||
tools::sg::separator* ToolsSGScene() {return fpToolsSGScene;}
|
||||
protected:
|
||||
|
||||
void EstablishBaseNodes();
|
||||
|
||||
tools::sg::separator* GetOrCreateNode(); // For next solid or primitive
|
||||
|
||||
static G4int fSceneIdCount; // Counter for Qt3D scene handlers.
|
||||
|
||||
tools::sg::separator* fpToolsSGScene;
|
||||
tools::sg::separator* fpTransientObjects;
|
||||
tools::sg::separator* fpPersistentObjects;
|
||||
std::vector<G4ToolsSGNode*> fpPhysicalVolumeObjects; // Multiple worlds
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,397 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// John Allison 6th October 2019
|
||||
|
||||
#if defined (G4VIS_BUILD_TOOLSSG_DRIVER) || defined (G4VIS_USE_TOOLSSG)
|
||||
|
||||
#ifndef G4TOOLSSGVIEWER_HH
|
||||
#define G4TOOLSSGVIEWER_HH
|
||||
|
||||
#include "G4VViewer.hh"
|
||||
|
||||
#include "G4ToolsSGSceneHandler.hh"
|
||||
#include "G4Scene.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/blend>
|
||||
#include <tools/sg/noderef>
|
||||
#include <tools/sg/keys>
|
||||
|
||||
template <class SG_SESSION,class SG_VIEWER>
|
||||
class G4ToolsSGViewer : public G4VViewer, tools::sg::device_interactor {
|
||||
typedef G4VViewer parent;
|
||||
typedef tools::sg::device_interactor parent_interactor;
|
||||
public: //tools::sg::device_interactor interface.
|
||||
virtual void key_press(const tools::sg::key_down_event& a_event) {
|
||||
fKeyPressed = true;
|
||||
fKeyShift = a_event.key() == tools::sg::key_shift()?true:false;
|
||||
}
|
||||
virtual void key_release(const tools::sg::key_up_event&) {fKeyPressed = false;}
|
||||
virtual void mouse_press(const tools::sg::mouse_down_event& a_event) {
|
||||
fMousePressed = true;
|
||||
fMousePressedX = a_event.x();
|
||||
fMousePressedY = a_event.y();
|
||||
}
|
||||
virtual void mouse_release(const tools::sg::mouse_up_event&) {fMousePressed = false;}
|
||||
virtual void mouse_move(const tools::sg::mouse_move_event& a_event) {
|
||||
G4double x = a_event.x();
|
||||
G4double y = a_event.y();
|
||||
G4double dx = x-fMousePressedX;
|
||||
G4double dy = y-fMousePressedY;
|
||||
fMousePressedX = x;
|
||||
fMousePressedY = y;
|
||||
|
||||
if (fMousePressed) {
|
||||
|
||||
if (fKeyPressed && fKeyShift) { // Translation (pan)
|
||||
|
||||
const G4double sceneRadius = fSGSceneHandler.GetScene()->GetExtent().GetExtentRadius();
|
||||
const G4double scale = 300; // Roughly pixels per window, empirically chosen
|
||||
const G4double dxScene = dx*sceneRadius/scale;
|
||||
const G4double dyScene = dy*sceneRadius/scale;
|
||||
fVP.IncrementPan(-dxScene,dyScene);
|
||||
|
||||
} else { // Rotation
|
||||
|
||||
// Simple ad-hoc algorithms
|
||||
const G4Vector3D& x_prime = fVP.GetViewpointDirection().cross(fVP.GetUpVector());
|
||||
const G4Vector3D& y_prime = x_prime.cross(fVP.GetViewpointDirection());
|
||||
const G4double scale = 200; // Roughly pixels per window, empirically chosen
|
||||
G4Vector3D newViewpointDirection = fVP.GetViewpointDirection();
|
||||
newViewpointDirection += dx*x_prime/scale;
|
||||
newViewpointDirection += dy*y_prime/scale;
|
||||
fVP.SetViewpointDirection(newViewpointDirection.unit());
|
||||
|
||||
if (fVP.GetRotationStyle() == G4ViewParameters::freeRotation) {
|
||||
G4Vector3D newUpVector = fVP.GetUpVector();
|
||||
newUpVector += dx*x_prime/scale;
|
||||
newUpVector += dy*y_prime/scale;
|
||||
fVP.SetUpVector(newUpVector.unit());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SetView();
|
||||
DrawView();
|
||||
}
|
||||
virtual void wheel_rotate(const tools::sg::wheel_rotate_event& a_event) {
|
||||
const G4double angleY = a_event.angle();
|
||||
if (fVP.GetFieldHalfAngle() == 0.) { // Orthographic projection
|
||||
const G4double scale = 500; // Empirically chosen
|
||||
fVP.MultiplyZoomFactor(1.+angleY/scale);
|
||||
} else { // Perspective projection
|
||||
const G4double scale = fVP.GetFieldHalfAngle()/(10.*CLHEP::deg); // Empirical
|
||||
fVP.SetDolly(fVP.GetDolly()+angleY/scale);
|
||||
}
|
||||
SetView();
|
||||
DrawView();
|
||||
}
|
||||
public:
|
||||
G4ToolsSGViewer(SG_SESSION& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
|
||||
:parent(a_scene_handler,a_scene_handler.IncrementViewCount(),a_name)
|
||||
,fSGSession(a_session)
|
||||
,fSGSceneHandler(a_scene_handler)
|
||||
,fSGViewer(nullptr)
|
||||
,fKeyPressed(false)
|
||||
,fKeyShift(false)
|
||||
,fMousePressed(false)
|
||||
,fMousePressedX(0)
|
||||
,fMousePressedY(0)
|
||||
{
|
||||
//::printf("debug : G4ToolsSGViewer::G4ToolsSGViewer.\n");
|
||||
}
|
||||
|
||||
virtual ~G4ToolsSGViewer() {
|
||||
delete fSGViewer;
|
||||
//::printf("debug : G4ToolsSGViewer::~G4ToolsSGViewer.\n");
|
||||
}
|
||||
protected:
|
||||
G4ToolsSGViewer(const G4ToolsSGViewer& a_from)
|
||||
:parent(a_from)
|
||||
,parent_interactor(a_from)
|
||||
,fSGSession(a_from.fSGSession)
|
||||
,fSGSceneHandler(a_from.fSGSceneHandler)
|
||||
,fSGViewer(nullptr)
|
||||
,fKeyPressed(false)
|
||||
,fKeyShift(false)
|
||||
,fMousePressed(false)
|
||||
,fMousePressedX(0)
|
||||
,fMousePressedY(0)
|
||||
{}
|
||||
G4ToolsSGViewer& operator=(const G4ToolsSGViewer&) {return *this;}
|
||||
public:
|
||||
virtual void Initialise() {
|
||||
if(fSGViewer) return; //done.
|
||||
fVP.SetAutoRefresh(true);
|
||||
fDefaultVP.SetAutoRefresh(true);
|
||||
//::printf("debug : G4ToolsSGViewer::Initialise\n");
|
||||
//////////////////////////////////////////////////////////
|
||||
/// create the viewer, set the scene graph ///////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
fSGViewer = new SG_VIEWER(fSGSession
|
||||
,fVP.GetWindowAbsoluteLocationHintX(1440)
|
||||
,fVP.GetWindowAbsoluteLocationHintY(900)
|
||||
,fVP.GetWindowSizeHintX()
|
||||
,fVP.GetWindowSizeHintY()
|
||||
,fName);
|
||||
if(!fSGViewer->has_window()) {
|
||||
fViewId = -1; // This flags an error.
|
||||
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);
|
||||
}
|
||||
|
||||
virtual void SetView() {
|
||||
//::printf("debug : G4ToolsSGViewer::SetView\n");
|
||||
if(!fSceneHandler.GetScene()) {
|
||||
fSGViewer->set_clear_color(0.3,0.3,0.3,1); //some grey color to signal the user that something is wrong.
|
||||
G4cerr << "G4ToolsSGViewer::SetView : no G4Scene.." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
// Get radius of scene, etc.
|
||||
// Note that this procedure properly takes into account zoom, dolly and pan.
|
||||
const G4Point3D targetPoint
|
||||
= fSceneHandler.GetScene()->GetStandardTargetPoint() + fVP.GetCurrentTargetPoint ();
|
||||
G4double radius = fSceneHandler.GetScene()->GetExtent().GetExtentRadius();
|
||||
if(radius<=0.) radius = 1.;
|
||||
const G4double cameraDistance = fVP.GetCameraDistance (radius);
|
||||
const G4Point3D cameraPosition = targetPoint + cameraDistance * fVP.GetViewpointDirection().unit();
|
||||
const G4Normal3D& up = fVP.GetUpVector ();
|
||||
const G4double pnear = fVP.GetNearDistance (cameraDistance, radius);
|
||||
const G4double pfar = fVP.GetFarDistance (cameraDistance, pnear, radius);
|
||||
//const G4double right = fVP.GetFrontHalfHeight (pnear, radius);
|
||||
//const G4double left = -right;
|
||||
const G4double top = fVP.GetFrontHalfHeight (pnear, radius);
|
||||
const G4double bottom = -top;
|
||||
// sanity check :
|
||||
tools::vec3f dir(float(targetPoint.x()-cameraPosition.x()),
|
||||
float(targetPoint.y()-cameraPosition.y()),
|
||||
float(targetPoint.z()-cameraPosition.z()));
|
||||
if(!dir.length()) {
|
||||
fSGViewer->set_clear_color(0.3,0.3,0.3,1);
|
||||
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);
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
/// create scene graph ///////////////////////////////////
|
||||
//////////////////////////////////////////////////////////
|
||||
// Set projection, then create the tools::sg camera node :
|
||||
tools::sg::base_camera* _camera = nullptr;
|
||||
if (fVP.GetFieldHalfAngle() <= 0.) {
|
||||
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;
|
||||
return;
|
||||
}
|
||||
tools::sg::ortho* ortho_camera = new tools::sg::ortho;
|
||||
ortho_camera->height.value(float(top-bottom));
|
||||
_camera = ortho_camera;
|
||||
} else {
|
||||
tools::sg::perspective* perspective_camera = new tools::sg::perspective;
|
||||
perspective_camera->height_angle.value(float(2*fVP.GetFieldHalfAngle()));
|
||||
_camera = perspective_camera;
|
||||
}
|
||||
|
||||
_camera->position.value
|
||||
(tools::vec3f(float(cameraPosition.x()),
|
||||
float(cameraPosition.y()),
|
||||
float(cameraPosition.z())));
|
||||
_camera->znear.value(float(pnear));
|
||||
_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);}
|
||||
|
||||
{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.
|
||||
|
||||
{G4Color background = fVP.GetBackgroundColour ();
|
||||
fSGViewer->set_clear_color(float(background.GetRed()),float(background.GetBlue()),float(background.GetBlue()),1);}
|
||||
}
|
||||
|
||||
virtual void ClearView() {}
|
||||
|
||||
virtual void DrawView() {
|
||||
if (!fNeedKernelVisit) KernelVisitDecision();
|
||||
G4bool kernelVisitWasNeeded = fNeedKernelVisit; // Keep (ProcessView resets).
|
||||
fLastVP = fVP;
|
||||
ProcessView(); // Clears store and processes scene only if necessary.
|
||||
if (kernelVisitWasNeeded) {
|
||||
// We might need to do something if the kernel was visited.
|
||||
} else {
|
||||
}
|
||||
FinishView (); // Flush streams and/or swap buffers.
|
||||
}
|
||||
|
||||
virtual void ShowView() {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->show();
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
}
|
||||
|
||||
virtual void FinishView() {
|
||||
if(!fSGViewer) return;
|
||||
fSGViewer->show();
|
||||
fSGViewer->win_render();
|
||||
fSGSession.sync();
|
||||
}
|
||||
|
||||
|
||||
#ifdef G4MULTITHREADED
|
||||
virtual void SwitchToVisSubThread() {}
|
||||
|
||||
virtual void SwitchToMasterThread() {
|
||||
if (G4Threading::IsMultithreadedApplication()) {
|
||||
// I have not figured out how to draw during a run.
|
||||
//
|
||||
// Setting fNeedKernelVisit=true causes scene deletion and a complete rebuild,
|
||||
// including trajectories, hits, etc. from kept events.
|
||||
//
|
||||
// Clearly this is a limitation because even if you run 1000 events you only
|
||||
// get those kept (default 100), and even worse, if end-if-event-action is
|
||||
// "refresh", you only get one event (the last I think).
|
||||
//
|
||||
// Also, strictly, there is no need to rebuid run-duration models (detector),
|
||||
// but a complete rebuild is the easiest way (already imeplemented).
|
||||
fNeedKernelVisit = true;
|
||||
DrawView(); // Draw trajectories, etc., from kept events
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//SG_VIEWER* sg_viewer() {return fSGViewer;}
|
||||
protected:
|
||||
void KernelVisitDecision () {
|
||||
if (CompareForKernelVisit(fLastVP)) {
|
||||
NeedKernelVisit (); // Sets fNeedKernelVisit.
|
||||
}
|
||||
}
|
||||
|
||||
G4bool CompareForKernelVisit(G4ViewParameters& lastVP) {
|
||||
// Typical comparison. Taken from OpenGL.
|
||||
if (
|
||||
(lastVP.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
|
||||
(lastVP.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
|
||||
(lastVP.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
|
||||
(lastVP.IsCulling () != fVP.IsCulling ()) ||
|
||||
(lastVP.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
|
||||
(lastVP.IsDensityCulling () != fVP.IsDensityCulling ()) ||
|
||||
(lastVP.IsCullingCovered () != fVP.IsCullingCovered ()) ||
|
||||
(lastVP.GetCBDAlgorithmNumber() !=
|
||||
fVP.GetCBDAlgorithmNumber()) ||
|
||||
(lastVP.IsSection () != fVP.IsSection ()) ||
|
||||
(lastVP.IsCutaway () != fVP.IsCutaway ()) ||
|
||||
(lastVP.IsExplode () != fVP.IsExplode ()) ||
|
||||
(lastVP.GetNoOfSides () != fVP.GetNoOfSides ()) ||
|
||||
(lastVP.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
|
||||
(lastVP.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
|
||||
(lastVP.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
|
||||
(lastVP.GetDefaultVisAttributes()->GetColour() !=
|
||||
fVP.GetDefaultVisAttributes()->GetColour()) ||
|
||||
(lastVP.GetDefaultTextVisAttributes()->GetColour() !=
|
||||
fVP.GetDefaultTextVisAttributes()->GetColour()) ||
|
||||
(lastVP.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
|
||||
(lastVP.IsPicking () != fVP.IsPicking ()) ||
|
||||
(lastVP.GetVisAttributesModifiers() !=
|
||||
fVP.GetVisAttributesModifiers()) ||
|
||||
(lastVP.IsSpecialMeshRendering() !=
|
||||
fVP.IsSpecialMeshRendering())
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lastVP.IsDensityCulling () &&
|
||||
(lastVP.GetVisibleDensity () != fVP.GetVisibleDensity ())) return true;
|
||||
|
||||
if (lastVP.GetCBDAlgorithmNumber() > 0) {
|
||||
if (lastVP.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
|
||||
else if (lastVP.GetCBDParameters() != fVP.GetCBDParameters()) return true;
|
||||
}
|
||||
|
||||
if (lastVP.IsExplode () &&
|
||||
(lastVP.GetExplodeFactor () != fVP.GetExplodeFactor ()))
|
||||
return true;
|
||||
|
||||
if (lastVP.IsSpecialMeshRendering() &&
|
||||
(lastVP.GetSpecialMeshVolumes() != fVP.GetSpecialMeshVolumes()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// void keyPressEvent (KeyEvent*);
|
||||
// void keyReleaseEvent (KeyEvent*);
|
||||
// void mouseDoubleClickEvent(MouseEvent*);
|
||||
// void mouseMoveEvent (MouseEvent*);
|
||||
// void mousePressEvent (MouseEvent*);
|
||||
// void mouseReleaseEvent (MouseEvent*);
|
||||
// void wheelEvent (WheelEvent*);
|
||||
|
||||
protected:
|
||||
SG_SESSION& fSGSession;
|
||||
G4ToolsSGSceneHandler& fSGSceneHandler;
|
||||
SG_VIEWER* fSGViewer;
|
||||
G4ViewParameters fLastVP; // Memory for making kernel visit decisions.
|
||||
|
||||
G4bool fKeyPressed;
|
||||
G4bool fKeyShift;
|
||||
G4bool fMousePressed;
|
||||
G4double fMousePressedX, fMousePressedY;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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
|
||||
|
||||
#include "G4VGraphicsSystem.hh"
|
||||
|
||||
namespace tools {namespace Windows {class session;}}
|
||||
|
||||
class G4ToolsSGWindowsGLES: public G4VGraphicsSystem {
|
||||
typedef G4VGraphicsSystem parent;
|
||||
public:
|
||||
G4ToolsSGWindowsGLES();
|
||||
virtual ~G4ToolsSGWindowsGLES();
|
||||
protected:
|
||||
G4ToolsSGWindowsGLES(const G4ToolsSGWindowsGLES& a_from):parent(a_from){}
|
||||
G4ToolsSGWindowsGLES& operator=(const G4ToolsSGWindowsGLES&) {return *this;}
|
||||
public:
|
||||
G4VSceneHandler* CreateSceneHandler(const G4String& name = "");
|
||||
G4VViewer* CreateViewer (G4VSceneHandler&, const G4String& name = "");
|
||||
G4bool IsUISessionCompatible () const;
|
||||
protected:
|
||||
void Initialise();
|
||||
protected:
|
||||
tools::Windows::session* fSGSession;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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
|
||||
|
||||
#include "G4VGraphicsSystem.hh"
|
||||
|
||||
namespace tools {namespace X11 {class session;}}
|
||||
|
||||
class G4ToolsSGX11GLES: public G4VGraphicsSystem {
|
||||
typedef G4VGraphicsSystem parent;
|
||||
public:
|
||||
G4ToolsSGX11GLES();
|
||||
virtual ~G4ToolsSGX11GLES();
|
||||
protected:
|
||||
G4ToolsSGX11GLES(const G4ToolsSGX11GLES& a_from):parent(a_from){}
|
||||
G4ToolsSGX11GLES& operator=(const G4ToolsSGX11GLES&) {return *this;}
|
||||
public:
|
||||
G4VSceneHandler* CreateSceneHandler(const G4String& name = "");
|
||||
G4VViewer* CreateViewer (G4VSceneHandler&, const G4String& name = "");
|
||||
G4bool IsUISessionCompatible () const;
|
||||
protected:
|
||||
void Initialise();
|
||||
protected:
|
||||
tools::X11::session* fSGSession;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// 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
|
||||
|
||||
#include "G4VGraphicsSystem.hh"
|
||||
|
||||
namespace tools {namespace Xt {class session;}}
|
||||
|
||||
class G4ToolsSGXtGLES: public G4VGraphicsSystem {
|
||||
typedef G4VGraphicsSystem parent;
|
||||
public:
|
||||
G4ToolsSGXtGLES();
|
||||
virtual ~G4ToolsSGXtGLES();
|
||||
protected:
|
||||
G4ToolsSGXtGLES(const G4ToolsSGXtGLES& a_from):parent(a_from){}
|
||||
G4ToolsSGXtGLES& operator=(const G4ToolsSGXtGLES&) {return *this;}
|
||||
public:
|
||||
G4VSceneHandler* CreateSceneHandler(const G4String& name = "");
|
||||
G4VViewer* CreateViewer (G4VSceneHandler&, const G4String& name = "");
|
||||
G4bool IsUISessionCompatible () const;
|
||||
protected:
|
||||
void Initialise();
|
||||
protected:
|
||||
tools::Xt::session* fSGSession;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
# - G4ToolsSG module build definition
|
||||
|
||||
# Module has optional sources
|
||||
# List those always built
|
||||
set(G4VIS_MODULE_TOOLSSG_HEADERS
|
||||
G4ToolsSGNode.hh
|
||||
G4ToolsSGSceneHandler.hh
|
||||
G4ToolsSGViewer.hh
|
||||
)
|
||||
|
||||
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
|
||||
G4ToolsSGX11GLES.hh
|
||||
)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
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)
|
||||
else()
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Xt sources/links if selected
|
||||
if(GEANT4_USE_TOOLSSG_XT_GLES)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_HEADERS
|
||||
G4ToolsSGXtGLES.hh
|
||||
)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
G4ToolsSGXtGLES.cc
|
||||
)
|
||||
|
||||
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})
|
||||
if(APPLE)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES XQuartzGL::GL)
|
||||
else()
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Qt sources/links if selected
|
||||
if(GEANT4_USE_TOOLSSG_QT_GLES)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_HEADERS
|
||||
G4ToolsSGQtViewer.hh
|
||||
G4ToolsSGQtGLES.hh
|
||||
)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
G4ToolsSGQtGLES.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()
|
||||
|
||||
|
||||
# Windows sources if selected
|
||||
if(GEANT4_USE_TOOLSSG_WINDOWS_GLES)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_HEADERS
|
||||
G4ToolsSGWindowsGLES.hh
|
||||
)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_SOURCES
|
||||
G4ToolsSGWindowsGLES.cc
|
||||
)
|
||||
|
||||
add_definitions(-DG4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER)
|
||||
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES OpenGL::GL)
|
||||
endif()
|
||||
|
||||
|
||||
# Freetype support if selected
|
||||
if(GEANT4_USE_FREETYPE)
|
||||
add_definitions(-DTOOLS_USE_FREETYPE)
|
||||
list(APPEND G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES Freetype::Freetype)
|
||||
endif()
|
||||
|
||||
list(REMOVE_DUPLICATES G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES)
|
||||
|
||||
# Define the Geant4 Module.
|
||||
geant4_add_module(G4ToolsSG
|
||||
PUBLIC_HEADERS ${G4VIS_MODULE_TOOLSSG_HEADERS}
|
||||
SOURCES ${G4VIS_MODULE_TOOLSSG_SOURCES})
|
||||
|
||||
geant4_module_link_libraries(G4ToolsSG
|
||||
PUBLIC
|
||||
G4intercoms
|
||||
G4interfaces
|
||||
G4modeling
|
||||
G4vis_management
|
||||
G4tools
|
||||
${G4VIS_MODULE_TOOLSSG_LINK_LIBRARIES}
|
||||
PRIVATE
|
||||
G4navigation)
|
||||
@@ -0,0 +1,131 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGQtGLES.hh"
|
||||
|
||||
//
|
||||
#define G4TOOLSSG_QT_VIEWER_IN_TAB
|
||||
|
||||
#ifdef G4TOOLSSG_QT_VIEWER_IN_TAB
|
||||
#include "G4ToolsSGQtViewer.hh"
|
||||
#else
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
#include <tools/Qt/sg_viewer>
|
||||
#endif
|
||||
|
||||
#include <tools/argcv>
|
||||
|
||||
G4ToolsSGQtGLES::G4ToolsSGQtGLES():
|
||||
parent
|
||||
("TOOLSSG_QT_GLES",
|
||||
"TSG_QT_GLES",
|
||||
"TOOLSSG_QT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
|
||||
the rendering is done with GLES and the windowing is done with Qt.",
|
||||
parent::threeDInteractive)
|
||||
,fSGSession(nullptr)
|
||||
{}
|
||||
|
||||
G4ToolsSGQtGLES::~G4ToolsSGQtGLES() {
|
||||
delete fSGSession;
|
||||
}
|
||||
|
||||
void G4ToolsSGQtGLES::Initialise() {
|
||||
if(fSGSession) return; //done.
|
||||
int* argc = new int;
|
||||
char** argv = nullptr;
|
||||
std::vector<std::string> args;args.push_back("");
|
||||
tools::new_argcv(args,*argc,argv);
|
||||
fSGSession = new tools::Qt::session(G4cout,*argc,argv);
|
||||
if(!fSGSession->is_valid()) {
|
||||
G4cerr << "G4ToolsSGQtGLES::Initialise : session::is_valid() failed." << G4endl;
|
||||
delete fSGSession;
|
||||
fSGSession = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
G4VSceneHandler* G4ToolsSGQtGLES::CreateSceneHandler(const G4String& a_name) {
|
||||
G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name);
|
||||
return pScene;
|
||||
}
|
||||
|
||||
G4VViewer* G4ToolsSGQtGLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) {
|
||||
if(!fSGSession) Initialise();
|
||||
if(!fSGSession) return nullptr;
|
||||
G4VViewer* pView =
|
||||
#ifdef G4TOOLSSG_QT_VIEWER_IN_TAB
|
||||
new G4ToolsSGQtViewer(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name);
|
||||
#else
|
||||
new G4ToolsSGViewer<tools::Qt::session,tools::Qt::sg_viewer>(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name);
|
||||
#endif
|
||||
if (pView) {
|
||||
if (pView->GetViewId() < 0) {
|
||||
G4cerr << "G4ToolsSGQtGLES::CreateViewer:"
|
||||
<< " ERROR flagged by negative view id in G4ToolsSGViewer creation."
|
||||
<< "\n Destroying view and returning null pointer." << G4endl;
|
||||
delete pView;
|
||||
pView = nullptr;
|
||||
}
|
||||
}
|
||||
if (!pView) {
|
||||
G4cerr << "G4ToolsSGQtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer." << G4endl;
|
||||
return nullptr;
|
||||
}
|
||||
return pView;
|
||||
}
|
||||
|
||||
G4bool G4ToolsSGQtGLES::IsUISessionCompatible () const
|
||||
{
|
||||
G4bool isCompatible = false;
|
||||
// G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
// G4UIsession* session = ui->GetSession();
|
||||
//
|
||||
// // If session is a batch session, it may be:
|
||||
// // a) this is a batch job (the user has not instantiated any UI session);
|
||||
// // b) we are currently processing a UI command, in which case the UI
|
||||
// // manager creates a temporary batch session and to find out if there is
|
||||
// // a genuine UI session that the user has instantiated we must drill
|
||||
// // down through previous sessions to a possible non-batch session.
|
||||
// while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) {
|
||||
// session = batch->GetPreviousSession();
|
||||
// }
|
||||
//
|
||||
// // Qt windows are only appropriate in a Qt session.
|
||||
// if (session) {
|
||||
// // If non-zero, this is the originating non-batch session
|
||||
// // The user has instantiated a UI session...
|
||||
// if (dynamic_cast<G4UIQt*>(session)) {
|
||||
// // ...and it's a G4UIQt session, which is OK.
|
||||
isCompatible = true;
|
||||
// }
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,695 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// John Allison 6th October 2020
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_DRIVER
|
||||
|
||||
#include "G4ToolsSGSceneHandler.hh"
|
||||
|
||||
#include "G4TransportationManager.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Polymarker.hh"
|
||||
#include "G4Circle.hh"
|
||||
#include "G4Square.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Text.hh"
|
||||
|
||||
//#define G4TOOLSSG_DEBUG
|
||||
|
||||
#include <tools/sg/separator>
|
||||
#include <tools/sg/matrix>
|
||||
#include <tools/sg/rgba>
|
||||
#include <tools/sg/draw_style>
|
||||
#include <tools/sg/atb_vertices>
|
||||
#include <tools/sg/markers>
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
#include <tools/sg/text_freetype_marker>
|
||||
#include <tools/sg/strings>
|
||||
#else
|
||||
#include <tools/sg/text_hershey_marker>
|
||||
#endif
|
||||
|
||||
#include "G4ToolsSGNode.hh"
|
||||
|
||||
#include <utility>
|
||||
|
||||
G4int G4ToolsSGSceneHandler::fSceneIdCount = 0;
|
||||
|
||||
G4ToolsSGSceneHandler::G4ToolsSGSceneHandler
|
||||
(G4VGraphicsSystem& system, const G4String& name)
|
||||
:parent(system, fSceneIdCount++, name)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "G4ToolsSGSceneHandler::G4ToolsSGSceneHandler called" << G4endl;
|
||||
#endif
|
||||
fpToolsSGScene = new tools::sg::separator;
|
||||
EstablishBaseNodes();
|
||||
}
|
||||
|
||||
G4ToolsSGSceneHandler::~G4ToolsSGSceneHandler()
|
||||
{
|
||||
delete fpToolsSGScene;
|
||||
}
|
||||
|
||||
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();
|
||||
std::vector<G4VPhysicalVolume*>::iterator iterWorld = transportationManager->GetWorldsIterator();
|
||||
fpPhysicalVolumeObjects.resize(nWorlds);
|
||||
for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
|
||||
G4VPhysicalVolume* _world = (*iterWorld);
|
||||
auto entity = new G4ToolsSGNode;
|
||||
fpPersistentObjects->add(entity);
|
||||
entity->SetPVNodeID(G4PhysicalVolumeModel::G4PhysicalVolumeNodeID(_world));
|
||||
fpPhysicalVolumeObjects[i] = entity;
|
||||
}
|
||||
}
|
||||
|
||||
tools::sg::separator* G4ToolsSGSceneHandler::GetOrCreateNode()
|
||||
{ // Retrieve or create a G4ToolsSGNode node suitable for next solid or primitive
|
||||
|
||||
// For time being, avoid errors in MT mode - see G4ToolsSGViewer::SwitchToMasterThread
|
||||
#ifdef G4MULTITHREADED
|
||||
if (!G4Threading::IsMasterThread()) return nullptr;
|
||||
#endif
|
||||
|
||||
if (fReadyForTransients) { // All transients hang from this node
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpTransientObjects->add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
G4PhysicalVolumeModel* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
|
||||
if (!pPVModel) { // Persistent objects (e.g., axes)
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpPersistentObjects->add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
// So this is a G4PhysicalVolumeModel
|
||||
typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
|
||||
typedef std::vector<PVNodeID> PVPath;
|
||||
//const PVPath& drawnPVPath = pPVModel->GetDrawnPVPath();
|
||||
const PVPath& fullPVPath = pPVModel->GetFullPVPath();
|
||||
//G4int currentDepth = pPVModel->GetCurrentDepth();
|
||||
//G4VPhysicalVolume* pCurrentPV = pPVModel->GetCurrentPV();
|
||||
//G4LogicalVolume* pCurrentLV = pPVModel->GetCurrentLV();
|
||||
//G4Material* pCurrentMaterial = pPVModel->GetCurrentMaterial();
|
||||
// Note: pCurrentMaterial may be zero (parallel world).
|
||||
|
||||
// Find appropriate root
|
||||
const size_t nWorlds = fpPhysicalVolumeObjects.size();
|
||||
size_t iWorld = 0;
|
||||
for (; iWorld < nWorlds; ++iWorld) {
|
||||
if (fullPVPath[0].GetPhysicalVolume() ==
|
||||
fpPhysicalVolumeObjects[iWorld]->GetPVNodeID().GetPhysicalVolume()) break;
|
||||
}
|
||||
if (iWorld == nWorlds) {
|
||||
G4Exception("G4ToolsSGSceneHandler::GetOrCreateNode", "ToolsSG-0000", FatalException,
|
||||
"World mis-match - not possible(!?)");
|
||||
}
|
||||
|
||||
// (Re-)establish pv path of root entity
|
||||
G4ToolsSGNode* _world = fpPhysicalVolumeObjects[iWorld];
|
||||
_world->SetPVNodeID(fullPVPath[0]);
|
||||
|
||||
// Provide nodes as required - may be a new node or a pre-existing node
|
||||
G4ToolsSGNode* node = _world; // Working variable - default to world
|
||||
const size_t depth = fullPVPath.size();
|
||||
size_t iDepth = 1;
|
||||
while (iDepth < depth) {
|
||||
const auto& children = node->children();
|
||||
const G4int nChildren = children.size();
|
||||
G4int iChild = 0;
|
||||
G4ToolsSGNode* child = nullptr;
|
||||
for (; iChild < nChildren; ++iChild) {
|
||||
child = static_cast<G4ToolsSGNode*>(children[iChild]);
|
||||
if (child->GetPVNodeID() == fullPVPath[iDepth]) break;
|
||||
}
|
||||
if (iChild != nChildren) { // Existing node found
|
||||
node = child; // Must be the ancestor of new node (subsequent iteration)
|
||||
} else {
|
||||
// Add a new node as child of node
|
||||
G4ToolsSGNode* newNode = new G4ToolsSGNode;
|
||||
node->add(newNode);
|
||||
newNode->SetPVNodeID(fullPVPath[iDepth]);
|
||||
node = newNode;
|
||||
}
|
||||
++iDepth;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PreAddSolid
|
||||
(const G4Transform3D& objectTransformation,
|
||||
const G4VisAttributes& visAttribs)
|
||||
{
|
||||
parent::PreAddSolid(objectTransformation, visAttribs);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PostAddSolid()
|
||||
{
|
||||
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 ();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline& a_polyline)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline&) : \n" << a_polyline << G4endl;
|
||||
#endif
|
||||
if (a_polyline.size() == 0) return;
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyline.GetVisAttributes());
|
||||
|
||||
// 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);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
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);}
|
||||
|
||||
{tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_lines;
|
||||
ds->line_width = 1;
|
||||
currentNode->add(ds);}
|
||||
|
||||
// Geometry :
|
||||
tools::sg::vertices* vtxs = new tools::sg::vertices;
|
||||
vtxs->mode = tools::gl::line_strip(); //polyline
|
||||
currentNode->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()));
|
||||
}}
|
||||
|
||||
}
|
||||
|
||||
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
|
||||
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;
|
||||
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);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
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);}
|
||||
|
||||
switch (a_polymarker.GetMarkerType()) {
|
||||
default:
|
||||
case G4Polymarker::dots:{
|
||||
//::printf("debug : GB : Add Markers : +++++++++++++++++++++++++++++++++++++++++++ : dots\n");
|
||||
tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_points;
|
||||
ds->point_size = 10;
|
||||
currentNode->add(ds);
|
||||
|
||||
tools::sg::vertices* vtxs = new tools::sg::vertices;
|
||||
vtxs->mode = tools::gl::points();
|
||||
{for (size_t i = 0; i < a_polymarker.size(); ++i) {
|
||||
vtxs->add(float(a_polymarker[i].x()),float(a_polymarker[i].y()),float(a_polymarker[i].z()));
|
||||
}}
|
||||
currentNode->add(vtxs);
|
||||
}break;
|
||||
case G4Polymarker::circles:{
|
||||
//::printf("debug : GB : Add Markers : +++++++++++++++++++++++++++++++++++++++++++ : circles\n");
|
||||
{tools::sg::markers* markers = new tools::sg::markers;
|
||||
markers->size = 10;
|
||||
markers->style = tools::sg::marker_circle_line;
|
||||
for (size_t i = 0; i < a_polymarker.size(); ++i) {
|
||||
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");
|
||||
{tools::sg::markers* markers = new tools::sg::markers;
|
||||
markers->size = 10;
|
||||
markers->style = tools::sg::marker_square_line;
|
||||
for (size_t i = 0; i < a_polymarker.size(); ++i) {
|
||||
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());
|
||||
|
||||
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);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
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);}
|
||||
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
tools::sg::text_freetype_marker* text = new tools::sg::text_freetype_marker;
|
||||
text->font = tools::sg::font_lato_regular_ttf();
|
||||
text->front_face = tools::sg::winding_cw;
|
||||
text->modeling = tools::sg::font_pixmap;
|
||||
#else
|
||||
tools::sg::text_hershey_marker* text = new tools::sg::text_hershey_marker;
|
||||
//text->encoding.value(a_encoding);
|
||||
#endif
|
||||
text->strings.add(a_text.GetText());
|
||||
{switch (a_text.GetLayout()) {
|
||||
default:
|
||||
case G4Text::left:
|
||||
text->hjust = tools::sg::left;
|
||||
break;
|
||||
case G4Text::centre:
|
||||
text->hjust = tools::sg::center;
|
||||
break;
|
||||
case G4Text::right:
|
||||
text->hjust = tools::sg::right;
|
||||
break;
|
||||
}}
|
||||
//text->vjust.value(a_vjust);
|
||||
currentNode->add(text);
|
||||
|
||||
/*
|
||||
//text.GetText(), text.GetXOffset(), etc.
|
||||
|
||||
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)
|
||||
{
|
||||
G4Polymarker oneCircle(a_circle);
|
||||
oneCircle.push_back(a_circle.GetPosition());
|
||||
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)
|
||||
{
|
||||
G4Polymarker oneSquare(a_square);
|
||||
oneSquare.push_back(a_square.GetPosition());
|
||||
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
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyhedron.GetVisAttributes());
|
||||
|
||||
// Roll out vertices and normals for the faces. Note that this means vertices
|
||||
// are duplicated. For example a box has 8 vertices, but to define 6 faces
|
||||
// you need 12 triangles and 36 vertices. If it was just a matter of vertices
|
||||
// we could restrict the number to 8 and use the indices to define the
|
||||
// triangles, but we also have to consider the normals. A vertex can be have
|
||||
// more than one normal, depending on which face it is being used to define.
|
||||
// So we roll out all the vertices and normals for each triangle.
|
||||
std::vector<G4Point3D> vertices;
|
||||
std::vector<G4Normal3D> normals;
|
||||
|
||||
// Also roll out edges (as lines) for wireframe. Avoid duplicate lines,
|
||||
// including those that differ only in the order of vertices.
|
||||
typedef std::pair<G4Point3D,G4Point3D> Line;
|
||||
std::vector<Line> lines;
|
||||
auto insertIfNew = [&lines](const Line& newLine) {
|
||||
for (const auto& line: lines) {
|
||||
if ((newLine.first==line.first && newLine.second==line.second) ||
|
||||
(newLine.first==line.second && newLine.second==line.first))
|
||||
return;
|
||||
}
|
||||
lines.push_back(newLine);
|
||||
};
|
||||
|
||||
G4bool isAuxilaryEdgeVisible = fpViewer->GetViewParameters().IsAuxEdgeVisible();
|
||||
G4bool notLastFace;
|
||||
do {
|
||||
G4int nEdges;
|
||||
G4Point3D vertex [4];
|
||||
G4int edgeFlag[4];
|
||||
G4Normal3D normal [4];
|
||||
notLastFace = a_polyhedron.GetNextFacet(nEdges, vertex, edgeFlag, normal);
|
||||
vertices.push_back(vertex[0]);
|
||||
vertices.push_back(vertex[1]);
|
||||
vertices.push_back(vertex[2]);
|
||||
normals.push_back(normal[0]);
|
||||
normals.push_back(normal[1]);
|
||||
normals.push_back(normal[2]);
|
||||
if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
|
||||
if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
|
||||
if (nEdges == 3) {
|
||||
// Face is a triangle
|
||||
// One more line for wireframe, triangles for surfaces are complete
|
||||
if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
|
||||
} else if (nEdges == 4) {
|
||||
// Face is a quadrilateral
|
||||
// Create another triangle for surfaces, add two more lines for wireframe
|
||||
vertices.push_back(vertex[2]);
|
||||
vertices.push_back(vertex[3]);
|
||||
vertices.push_back(vertex[0]);
|
||||
normals.push_back(normal[2]);
|
||||
normals.push_back(normal[3]);
|
||||
normals.push_back(normal[0]);
|
||||
if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
|
||||
if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
|
||||
} else {
|
||||
G4cerr
|
||||
<< "ERROR: polyhedron face with unexpected number of edges (" << nEdges << ')'
|
||||
<< "\n Tag: " << fpModel->GetCurrentTag()
|
||||
<< G4endl;
|
||||
return;
|
||||
}
|
||||
} while (notLastFace);
|
||||
|
||||
G4ViewParameters::DrawingStyle drawing_style = GetDrawingStyle (fpVisAttribs);
|
||||
switch (drawing_style) {
|
||||
case G4ViewParameters::wireframe:
|
||||
//vertices.clear();
|
||||
break;
|
||||
case G4ViewParameters::hlr:
|
||||
break;
|
||||
case G4ViewParameters::hsr:
|
||||
//lines.clear();
|
||||
break;
|
||||
case G4ViewParameters::hlhsr:
|
||||
break;
|
||||
case G4ViewParameters::cloud:
|
||||
// Shouldn't happen in this function (it's a polyhedron!) - ignore
|
||||
return;
|
||||
}
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
currentNode->add(sep);
|
||||
|
||||
// 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);
|
||||
sep->add(mtx);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = fpVisAttribs->GetColour();
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
float(colour.GetGreen()),
|
||||
float(colour.GetBlue()),
|
||||
float(colour.GetAlpha()));
|
||||
sep->add(mat);}
|
||||
|
||||
if (drawing_style == G4ViewParameters::hlr ||
|
||||
drawing_style == G4ViewParameters::hsr ||
|
||||
drawing_style == G4ViewParameters::hlhsr) {
|
||||
|
||||
{tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_filled;
|
||||
//ds->cull_face = true;
|
||||
sep->add(ds);}
|
||||
|
||||
tools::sg::atb_vertices* vtxs = new tools::sg::atb_vertices;
|
||||
vtxs->mode = tools::gl::triangles();
|
||||
sep->add(vtxs);
|
||||
|
||||
const auto nVerts = vertices.size();
|
||||
for (size_t i = 0; i < nVerts; i++) {
|
||||
vtxs->add(float(vertices[i].x()),float(vertices[i].y()),float(vertices[i].z()));
|
||||
vtxs->add_normal(float(normals[i].x()),float(normals[i].y()),float(normals[i].z()));
|
||||
}
|
||||
}
|
||||
|
||||
if (drawing_style == G4ViewParameters::wireframe ||
|
||||
drawing_style == G4ViewParameters::hlr ||
|
||||
drawing_style == G4ViewParameters::hlhsr) {
|
||||
|
||||
{tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_lines;
|
||||
ds->line_width = 1;
|
||||
sep->add(ds);}
|
||||
|
||||
tools::sg::vertices* vtxs = new tools::sg::vertices;
|
||||
vtxs->mode = tools::gl::lines(); //segments
|
||||
sep->add(vtxs);
|
||||
|
||||
for (const auto& line: lines) {
|
||||
vtxs->add(float(line.first.x()),float(line.first.y()),float(line.first.z()));
|
||||
vtxs->add(float(line.second.x()),float(line.second.y()),float(line.second.z()));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearStore ()
|
||||
{
|
||||
fpToolsSGScene->clear();
|
||||
EstablishBaseNodes();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearTransientStore ()
|
||||
{
|
||||
fpTransientObjects->clear();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,117 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Guy Barrand 6th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGWindowsGLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
#include <tools/Windows/sg_viewer>
|
||||
|
||||
G4ToolsSGWindowsGLES::G4ToolsSGWindowsGLES():
|
||||
parent
|
||||
("TOOLSSG_WINDOWS_GLES",
|
||||
"TSG_WINDOWS_GLES",
|
||||
"TOOLSSG_WINDOWS_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
|
||||
the rendering is done with Microsoft GLES and the windowing is done with Microsoft Windows.",
|
||||
parent::threeDInteractive)
|
||||
,fSGSession(nullptr)
|
||||
{}
|
||||
|
||||
G4ToolsSGWindowsGLES::~G4ToolsSGWindowsGLES() {
|
||||
delete fSGSession;
|
||||
}
|
||||
|
||||
void G4ToolsSGWindowsGLES::Initialise() {
|
||||
if(fSGSession) return; //done.
|
||||
fSGSession = new tools::Windows::session(G4cout);
|
||||
if(!fSGSession->is_valid()) {
|
||||
G4cerr << "G4ToolsSGWindowsGLES::Initialise : session::is_valid() failed." << G4endl;
|
||||
delete fSGSession;
|
||||
fSGSession = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
G4VSceneHandler* G4ToolsSGWindowsGLES::CreateSceneHandler(const G4String& a_name) {
|
||||
G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name);
|
||||
return pScene;
|
||||
}
|
||||
|
||||
G4VViewer* G4ToolsSGWindowsGLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) {
|
||||
if(!fSGSession) Initialise();
|
||||
if(!fSGSession) return nullptr;
|
||||
G4VViewer* pView =
|
||||
new G4ToolsSGViewer<tools::Windows::session,tools::Windows::sg_viewer>(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name);
|
||||
if (pView) {
|
||||
if (pView->GetViewId() < 0) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGWindowsGLES::CreateViewer: ERROR flagged by negative"
|
||||
" view id in G4ToolsSGViewer creation."
|
||||
"\n Destroying view and returning null pointer."
|
||||
<< G4endl;
|
||||
delete pView;
|
||||
pView = nullptr;
|
||||
}
|
||||
}
|
||||
if (!pView) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGWindowsGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer."
|
||||
<< G4endl;
|
||||
}
|
||||
return pView;
|
||||
}
|
||||
|
||||
G4bool G4ToolsSGWindowsGLES::IsUISessionCompatible () const
|
||||
{
|
||||
G4bool isCompatible = false;
|
||||
// G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
// G4UIsession* session = ui->GetSession();
|
||||
//
|
||||
// // If session is a batch session, it may be:
|
||||
// // a) this is a batch job (the user has not instantiated any UI session);
|
||||
// // b) we are currently processing a UI command, in which case the UI
|
||||
// // manager creates a temporary batch session and to find out if there is
|
||||
// // a genuine UI session that the user has instantiated we must drill
|
||||
// // down through previous sessions to a possible non-batch session.
|
||||
// while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) {
|
||||
// session = batch->GetPreviousSession();
|
||||
// }
|
||||
//
|
||||
// // Qt windows are only appropriate in a Qt session.
|
||||
// if (session) {
|
||||
// // If non-zero, this is the originating non-batch session
|
||||
// // The user has instantiated a UI session...
|
||||
// if (dynamic_cast<G4UIQt*>(session)) {
|
||||
// // ...and it's a G4UIQt session, which is OK.
|
||||
isCompatible = true;
|
||||
// }
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGX11GLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
|
||||
#include <tools/X11/sg_viewer>
|
||||
|
||||
G4ToolsSGX11GLES::G4ToolsSGX11GLES():
|
||||
parent
|
||||
("TOOLSSG_X11_GLES",
|
||||
"TSG_X11_GLES",
|
||||
"TOOLSSG_X11_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
|
||||
the rendering is done with GLES and the windowing is done with X11.",
|
||||
parent::threeDInteractive)
|
||||
,fSGSession(nullptr)
|
||||
{}
|
||||
|
||||
G4ToolsSGX11GLES::~G4ToolsSGX11GLES() {
|
||||
delete fSGSession;
|
||||
}
|
||||
|
||||
void G4ToolsSGX11GLES::Initialise() {
|
||||
if(fSGSession) return; //done.
|
||||
fSGSession = new tools::X11::session(G4cout);
|
||||
if(!fSGSession->is_valid()) {
|
||||
G4cerr << "G4ToolsSGX11GLES::Initialise : session::is_valid() failed." << G4endl;
|
||||
delete fSGSession;
|
||||
fSGSession = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
G4VSceneHandler* G4ToolsSGX11GLES::CreateSceneHandler(const G4String& a_name) {
|
||||
G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this,a_name);
|
||||
return pScene;
|
||||
}
|
||||
|
||||
G4VViewer* G4ToolsSGX11GLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) {
|
||||
if(!fSGSession) Initialise();
|
||||
if(!fSGSession) return nullptr;
|
||||
G4VViewer* pView =
|
||||
new G4ToolsSGViewer<tools::X11::session,tools::X11::sg_viewer>
|
||||
(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name);
|
||||
if (pView) {
|
||||
if (pView->GetViewId() < 0) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGX11GLES::CreateViewer: ERROR flagged by negative"
|
||||
" view id in G4ToolsSGViewer creation."
|
||||
"\n Destroying view and returning null pointer."
|
||||
<< G4endl;
|
||||
delete pView;
|
||||
pView = nullptr;
|
||||
}
|
||||
}
|
||||
if (!pView) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGX11GLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer."
|
||||
<< G4endl;
|
||||
}
|
||||
return pView;
|
||||
}
|
||||
|
||||
G4bool G4ToolsSGX11GLES::IsUISessionCompatible () const
|
||||
{
|
||||
G4bool isCompatible = false;
|
||||
// G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
// G4UIsession* session = ui->GetSession();
|
||||
//
|
||||
// // If session is a batch session, it may be:
|
||||
// // a) this is a batch job (the user has not instantiated any UI session);
|
||||
// // b) we are currently processing a UI command, in which case the UI
|
||||
// // manager creates a temporary batch session and to find out if there is
|
||||
// // a genuine UI session that the user has instantiated we must drill
|
||||
// // down through previous sessions to a possible non-batch session.
|
||||
// while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) {
|
||||
// session = batch->GetPreviousSession();
|
||||
// }
|
||||
//
|
||||
// // Qt windows are only appropriate in a Qt session.
|
||||
// if (session) {
|
||||
// // If non-zero, this is the originating non-batch session
|
||||
// // The user has instantiated a UI session...
|
||||
// if (dynamic_cast<G4UIQt*>(session)) {
|
||||
// // ...and it's a G4UIQt session, which is OK.
|
||||
isCompatible = true;
|
||||
// }
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,141 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGXtGLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
#include <tools/Xt/sg_viewer>
|
||||
|
||||
#include "G4Xt.hh"
|
||||
|
||||
class session : public tools::Xt::session {
|
||||
typedef tools::Xt::session parent;
|
||||
public:
|
||||
session(std::ostream& a_out,int a_argc,char** a_argv)
|
||||
:parent(a_out,a_argc,a_argv)
|
||||
{
|
||||
if(m_app_widget) {::XtDestroyWidget(m_app_widget);m_app_widget = nullptr;}
|
||||
if(m_app_context) {::XtDestroyApplicationContext(m_app_context);m_app_context = nullptr;}
|
||||
m_app_widget = (Widget)G4Xt::getInstance()->GetMainInteractor();
|
||||
m_app_context = ::XtWidgetToApplicationContext(m_app_widget);
|
||||
}
|
||||
virtual ~session() {}
|
||||
protected:
|
||||
session(const session& a_from):parent(a_from){}
|
||||
session& operator=(const session& a_from){parent::operator=(a_from);return *this;}
|
||||
};
|
||||
|
||||
#include <tools/argcv>
|
||||
|
||||
G4ToolsSGXtGLES::G4ToolsSGXtGLES():
|
||||
parent
|
||||
("TOOLSSG_XT_GLES",
|
||||
"TSG_XT_GLES",
|
||||
"TOOLSSG_XT_GLES is a graphics driver based on the g4tools tools/sg scene graph logic where\n\
|
||||
the rendering is done with GLES and the windowing is done with the Xt toolkit.",
|
||||
parent::threeDInteractive)
|
||||
,fSGSession(nullptr)
|
||||
{}
|
||||
|
||||
G4ToolsSGXtGLES::~G4ToolsSGXtGLES() {
|
||||
delete fSGSession;
|
||||
}
|
||||
|
||||
void G4ToolsSGXtGLES::Initialise() {
|
||||
if(fSGSession) return; //done.
|
||||
int* argc = new int;
|
||||
char** argv = nullptr;
|
||||
tools::new_argcv(std::vector<std::string>(),*argc,argv);
|
||||
fSGSession = new session(G4cout,*argc,argv);
|
||||
if(!fSGSession->is_valid()) {
|
||||
G4cerr << "G4ToolsSGXtGLES::Initialise : session::is_valid() failed." << G4endl;
|
||||
delete fSGSession;
|
||||
fSGSession = nullptr;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
G4VSceneHandler* G4ToolsSGXtGLES::CreateSceneHandler(const G4String& a_name) {
|
||||
G4VSceneHandler* pScene = new G4ToolsSGSceneHandler(*this, a_name);
|
||||
return pScene;
|
||||
}
|
||||
|
||||
G4VViewer* G4ToolsSGXtGLES::CreateViewer(G4VSceneHandler& a_scene,const G4String& a_name) {
|
||||
if(!fSGSession) Initialise();
|
||||
if(!fSGSession) return nullptr;
|
||||
G4VViewer* pView =
|
||||
new G4ToolsSGViewer<tools::Xt::session,tools::Xt::sg_viewer>(*fSGSession,(G4ToolsSGSceneHandler&)a_scene,a_name);
|
||||
if (pView) {
|
||||
if (pView->GetViewId() < 0) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGXtGLES::CreateViewer: ERROR flagged by negative"
|
||||
" view id in G4ToolsSGViewer creation."
|
||||
"\n Destroying view and returning null pointer."
|
||||
<< G4endl;
|
||||
delete pView;
|
||||
pView = nullptr;
|
||||
}
|
||||
}
|
||||
if (!pView) {
|
||||
G4cerr <<
|
||||
"G4ToolsSGXtGLES::CreateViewer: ERROR: null pointer on new G4ToolsSGViewer."
|
||||
<< G4endl;
|
||||
}
|
||||
return pView;
|
||||
}
|
||||
|
||||
G4bool G4ToolsSGXtGLES::IsUISessionCompatible () const
|
||||
{
|
||||
G4bool isCompatible = false;
|
||||
// G4UImanager* ui = G4UImanager::GetUIpointer();
|
||||
// G4UIsession* session = ui->GetSession();
|
||||
//
|
||||
// // If session is a batch session, it may be:
|
||||
// // a) this is a batch job (the user has not instantiated any UI session);
|
||||
// // b) we are currently processing a UI command, in which case the UI
|
||||
// // manager creates a temporary batch session and to find out if there is
|
||||
// // a genuine UI session that the user has instantiated we must drill
|
||||
// // down through previous sessions to a possible non-batch session.
|
||||
// while (G4UIbatch* batch = dynamic_cast<G4UIbatch*>(session)) {
|
||||
// session = batch->GetPreviousSession();
|
||||
// }
|
||||
//
|
||||
// // Qt windows are only appropriate in a Qt session.
|
||||
// if (session) {
|
||||
// // If non-zero, this is the originating non-batch session
|
||||
// // The user has instantiated a UI session...
|
||||
// if (dynamic_cast<G4UIQt*>(session)) {
|
||||
// // ...and it's a G4UIQt session, which is OK.
|
||||
isCompatible = true;
|
||||
// }
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user