Import Geant4 11.2.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2023-06-30 09:09:57 +02:00
parent aef78ca386
commit dd1f179cda
3780 changed files with 212808 additions and 142780 deletions
@@ -0,0 +1,56 @@
//
// ********************************************************************
// * 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
#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
@@ -0,0 +1,404 @@
//
// ********************************************************************
// * 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 09th June 2022
#ifndef G4TOOLSSGOFFSCREENVIEWER_HH
#define G4TOOLSSGOFFSCREENVIEWER_HH
#include "G4ToolsSGViewer.hh"
#include "G4UIcmdWithABool.hh"
#include <tools/fpng>
#include <tools/toojpeg>
#include <tools/offscreen/sg_viewer>
#include <tools/tos>
#include <tools/sto>
class G4ToolsSGOffscreenViewer : public G4ToolsSGViewer<tools::offscreen::session,tools::offscreen::sg_viewer> {
typedef G4ToolsSGViewer<tools::offscreen::session,tools::offscreen::sg_viewer> parent;
public:
G4ToolsSGOffscreenViewer(tools::offscreen::session& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
:parent(a_session,a_scene_handler,a_name)
,fFileName("auto")
,fFilePrefix("auto")
,fFileIndex(0)
,fResetFileIndex(false)
{
Messenger::Create();
}
virtual ~G4ToolsSGOffscreenViewer() = default;
protected:
G4ToolsSGOffscreenViewer(const G4ToolsSGOffscreenViewer& a_from):parent(a_from){}
G4ToolsSGOffscreenViewer& operator=(const G4ToolsSGOffscreenViewer&) {return *this;}
public:
virtual void Initialise() {
if(fSGViewer) return; //done.
//::printf("debug : G4ToolsSGOffscreenViewer::Initialize\n");
// auto refresh true produces too much files.
fVP.SetAutoRefresh(false);
fDefaultVP.SetAutoRefresh(false);
fSGViewer = new tools::offscreen::sg_viewer(fSGSession
,fVP.GetWindowAbsoluteLocationHintX(1440)
,fVP.GetWindowAbsoluteLocationHintY(900)
,fVP.GetWindowSizeHintX()
,fVP.GetWindowSizeHintY()
,fName);
fSGViewer->set_file_format("zb_png");
fSGViewer->set_file_name("out.png");
fSGViewer->set_png_writer(tools::fpng::write);
fSGViewer->set_jpeg_writer(tools::toojpeg::write);
fSGViewer->set_do_transparency(true);
fSGViewer->set_top_to_bottom(false); //if using tools::fpng, tools::toojpeg.
}
virtual void SetView() {
//::printf("debug : G4ToolsSGOffscreenViewer::SetView\n");
fVP.SetGlobalMarkerScale(1); //WARNING: for __APPLE__, the G4ToolsSGQtViewer set it to 2.
parent::SetView();
}
virtual void DrawView() {
if (!fNeedKernelVisit) KernelVisitDecision();
fLastVP = fVP;
ProcessView(); // Clears store and processes scene only if necessary.
//::printf("debug : G4ToolsSGOffscreenViewer::DrawView %s\n",fName.c_str());
if(fSGViewer) {
fSGSceneHandler.TouchPlotters(fSGViewer->sg());
if(fFileName=="auto") {
std::string prefix;
if(fFilePrefix=="auto") {
prefix = "g4tsg_offscreen_"+fSGViewer->file_format()+"_";
} else {
prefix = fFilePrefix;
}
std::string suffix;
if(G4ToolsSGOffscreenViewer::GetFormatExtension(fSGViewer->file_format(),suffix)) {
std::string file_name = prefix+tools::tos(GetFileIndex())+"."+suffix;
fSGViewer->set_file_name(file_name);
}
} else {
fSGViewer->set_file_name(fFileName);
}
if(fSGViewer->write_paper()) {
if (G4VisManager::GetVerbosity() >= G4VisManager::confirmations) {
G4cout << "File " << fSGViewer->file_name() << " produced." << G4endl;
}
}
}
}
virtual void ClearView() {
//::printf("debug : G4ToolsSGOffscreenViewer::ClearView %s\n",fName.c_str());
}
virtual void ShowView() {
//::printf("debug : G4ToolsSGOffscreenViewer::ShowView %s\n",fName.c_str());
}
virtual void FinishView() {
//::printf("debug : G4ToolsSGOffscreenViewer::FinishView %s\n",fName.c_str());
if(fSGViewer) {
fSGSceneHandler.TouchPlotters(fSGViewer->sg());
}
}
protected:
void SetSize(unsigned int a_w,unsigned int a_h) {
if(!fSGViewer) return;
if(!a_w || !a_h) {
fSGViewer->set_size(fVP.GetWindowSizeHintX(),fVP.GetWindowSizeHintY());
} else {
fSGViewer->set_size(a_w,a_h);
}
}
void SetFileFormat(const G4String& a_format) {
if(!fSGViewer) return;
fSGViewer->set_file_format(a_format);
}
void SetDoTransparency(bool a_value) {
if(!fSGViewer) return;
fSGViewer->set_do_transparency(a_value);
}
void SetFileName(const G4String& a_file,const G4String& a_prefix,bool a_reset_index) {
fFileName = a_file;
fFilePrefix = a_prefix;
fResetFileIndex = a_reset_index;
}
void SetGL2PSSort(const G4String& a_sort) {
if(!fSGViewer) return;
fSGViewer->set_opts_1(a_sort);
}
void SetGL2PSOptions(const G4String& a_opts) {
if(!fSGViewer) return;
fSGViewer->set_opts_2(a_opts);
}
class Messenger: public G4VVisCommand {
public:
static void Create() {static Messenger s_messenger;}
private:
Messenger() {
G4UIparameter* parameter;
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_format = new G4UIcommand("/vis/tsg/offscreen/set/format", this);
cmd_format->SetGuidance("Set file format.");
cmd_format->SetGuidance("Available formats are:");
cmd_format->SetGuidance("- zb_png: tools::sg offscreen zbuffer put in a png file.");
cmd_format->SetGuidance("- zb_jpeg: tools::sg offscreen zbuffer put in a jpeg file.");
cmd_format->SetGuidance("- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
cmd_format->SetGuidance("- gl2ps_eps: gl2ps producing eps");
cmd_format->SetGuidance("- gl2ps_ps: gl2ps producing ps");
cmd_format->SetGuidance("- gl2ps_pdf: gl2ps producing pdf");
cmd_format->SetGuidance("- gl2ps_svg: gl2ps producing svg");
cmd_format->SetGuidance("- gl2ps_tex: gl2ps producing tex");
cmd_format->SetGuidance("- gl2ps_pgf: gl2ps producing pgf");
parameter = new G4UIparameter("format",'s',true);
parameter->SetDefaultValue("gl2ps_eps");
cmd_format->SetParameter (parameter);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_file = new G4UIcommand("/vis/tsg/offscreen/set/file", this);
cmd_file->SetGuidance("Set file name.");
cmd_file->SetGuidance("Default file name is \"auto\" and default format is zb_png.");
cmd_file->SetGuidance("If file name is \"auto\", the output file name is built from");
cmd_file->SetGuidance("a viewer index counter with the form:");
cmd_file->SetGuidance(" g4tsg_offscreen_<format>_<index>.<format extension>");
cmd_file->SetGuidance("For example:");
cmd_file->SetGuidance(" g4tsg_offscreen_zb_png_1.png");
cmd_file->SetGuidance(" g4tsg_offscreen_zb_png_2.png");
cmd_file->SetGuidance(" ...");
cmd_file->SetGuidance("or if format is changed to \"gl2ps_pdf\":");
cmd_file->SetGuidance(" g4tsg_offscreen_gl2ps_pdf_3.pdf");
cmd_file->SetGuidance("If a prefix parameter is given, the output file name is built from");
cmd_file->SetGuidance("a global index counter with the form:");
cmd_file->SetGuidance(" <prefix><index>.<format extension>");
cmd_file->SetGuidance("For example:");
cmd_file->SetGuidance(" /vis/tsg/offscreen/set/file auto my_prefix_");
cmd_file->SetGuidance("will produce:");
cmd_file->SetGuidance(" my_prefix_1.png");
cmd_file->SetGuidance(" my_prefix_2.png");
cmd_file->SetGuidance(" ...");
cmd_file->SetGuidance("You can reset the index by specifying true as last argument:");
cmd_file->SetGuidance(" /vis/tsg/offscreen/set/file auto other_prefix_ true");
cmd_file->SetGuidance("will produce:");
cmd_file->SetGuidance(" other_prefix_1.png");
cmd_file->SetGuidance(" other_prefix_2.png");
cmd_file->SetGuidance(" ...");
parameter = new G4UIparameter("file",'s',true);
parameter->SetDefaultValue("auto");
cmd_file->SetParameter (parameter);
parameter = new G4UIparameter("prefix",'s',true);
parameter->SetDefaultValue("auto");
cmd_file->SetParameter (parameter);
parameter = new G4UIparameter("reset_index",'b',true);
parameter->SetDefaultValue("false");
cmd_file->SetParameter (parameter);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_size = new G4UIcommand("/vis/tsg/offscreen/set/size", this);
cmd_size->SetGuidance("Set viewer size in pixels.");
cmd_size->SetGuidance
("If width and/or height is set to zero, the viewer size specified with /vis/viewer/create (/vis/open) is taken.");
cmd_size->SetGuidance(" About the picture size, note that the gl2ps files will grow with the number of primitives");
cmd_size->SetGuidance("(gl2ps does not have a zbuffer logic). The \"zb\" files will not grow with the number of");
cmd_size->SetGuidance("primitives, but with the size of the viewer. It should be preferred for scenes with");
cmd_size->SetGuidance("a lot of objects to render. With zb, to have a better rendering, do not hesitate to");
cmd_size->SetGuidance("have a large viewer size.");
parameter = new G4UIparameter("width",'i',false);
parameter->SetDefaultValue("0");
cmd_size->SetParameter (parameter);
parameter = new G4UIparameter("height",'i',false);
parameter->SetDefaultValue("0");
cmd_size->SetParameter (parameter);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_do_transparency = new G4UIcmdWithABool("/vis/tsg/offscreen/set/transparency", this);
cmd_do_transparency->SetGuidance("True/false to enable/disable rendering of transparent objects.");
cmd_do_transparency->SetGuidance("This may be usefull if using file formats, as the gl2ps ones, unable to handle transparency.");
cmd_do_transparency->SetParameterName("transparency-enabled",true);
cmd_do_transparency->SetDefaultValue(true);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_gl2ps_sort = new G4UIcommand("/vis/tsg/offscreen/gl2ps/set/sort", this);
cmd_gl2ps_sort->SetGuidance("Set gl2ps sort algorithm when creating the file.");
cmd_gl2ps_sort->SetGuidance("The sort argument could be:");
cmd_gl2ps_sort->SetGuidance(" NO_SORT");
cmd_gl2ps_sort->SetGuidance(" SIMPLE_SORT");
cmd_gl2ps_sort->SetGuidance(" BSP_SORT");
cmd_gl2ps_sort->SetGuidance("The default being BSP_SORT");
parameter = new G4UIparameter("sort",'s',true);
parameter->SetDefaultValue("BSP_SORT");
cmd_gl2ps_sort->SetParameter (parameter);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
cmd_gl2ps_opts = new G4UIcommand("/vis/tsg/offscreen/gl2ps/set/options", this);
cmd_gl2ps_opts->SetGuidance("Set gl2ps options passed when creating the file.");
cmd_gl2ps_opts->SetGuidance("Options is a list of items separated by |. An item can be:");
cmd_gl2ps_opts->SetGuidance(" NONE");
cmd_gl2ps_opts->SetGuidance(" DRAW_BACKGROUND");
cmd_gl2ps_opts->SetGuidance(" SIMPLE_LINE_OFFSET");
cmd_gl2ps_opts->SetGuidance(" SILENT");
cmd_gl2ps_opts->SetGuidance(" BEST_ROOT");
cmd_gl2ps_opts->SetGuidance(" OCCLUSION_CULL");
cmd_gl2ps_opts->SetGuidance(" NO_TEXT");
cmd_gl2ps_opts->SetGuidance(" LANDSCAPE");
cmd_gl2ps_opts->SetGuidance(" NO_PS3_SHADING");
cmd_gl2ps_opts->SetGuidance(" NO_PIXMAP");
cmd_gl2ps_opts->SetGuidance(" USE_CURRENT_VIEWPORT");
cmd_gl2ps_opts->SetGuidance(" COMPRESS");
cmd_gl2ps_opts->SetGuidance(" NO_BLENDING");
cmd_gl2ps_opts->SetGuidance(" TIGHT_BOUNDING_BOX");
cmd_gl2ps_opts->SetGuidance(" NO_OPENGL_CONTEXT");
cmd_gl2ps_opts->SetGuidance(" NO_TEX_FONTSIZE");
cmd_gl2ps_opts->SetGuidance(" PORTABLE_SORT");
cmd_gl2ps_opts->SetGuidance("The default (typical) list of options is:");
cmd_gl2ps_opts->SetGuidance(" SILENT|OCCLUSION_CULL|BEST_ROOT|DRAW_BACKGROUND");
parameter = new G4UIparameter("options",'s',true);
parameter->SetDefaultValue("SILENT|OCCLUSION_CULL|BEST_ROOT|DRAW_BACKGROUND");
cmd_gl2ps_opts->SetParameter (parameter);
}
virtual ~Messenger() {
delete cmd_format;
delete cmd_file;
delete cmd_size;
delete cmd_do_transparency;
delete cmd_gl2ps_sort;
delete cmd_gl2ps_opts;
}
public:
virtual void SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
G4VisManager::Verbosity verbosity = GetVisManager()->GetVerbosity();
G4VViewer* viewer = GetVisManager()->GetCurrentViewer();
if (!viewer) {
if (verbosity >= G4VisManager::errors) G4cerr << "ERROR: No current viewer." << G4endl;
return;
}
G4ToolsSGOffscreenViewer* tsg_viewer = dynamic_cast<G4ToolsSGOffscreenViewer*>(viewer);
if(!tsg_viewer) {
G4cout << "G4ToolsSGOffscreenViewer::Messenger::SetNewValue:"
<< " current viewer is not a G4ToolsSGOffscreenViewer." << G4endl;
return;
}
std::vector<std::string> args;
tools::double_quotes_tokenize(a_value,args);
if(args.size()!=a_cmd->GetParameterEntries()) return;
if(a_cmd==cmd_format) {
if(!IsKnownFormat(args[0])) {
G4cout << "G4ToolsSGOffscreenViewer::Messenger::SetNewValue:"
<< " unknown file format " << args[0] << "." << G4endl;
return;
}
tsg_viewer->SetFileFormat(args[0]);
} else if(a_cmd==cmd_file) {
G4bool reset_index = G4UIcommand::ConvertToBool(args[2].c_str());
tsg_viewer->SetFileName(args[0],args[1],reset_index);
} else if(a_cmd==cmd_size) {
unsigned int w,h;
if(!tools::to(args[0],w)) w = 0;
if(!tools::to(args[1],h)) h = 0;
tsg_viewer->SetSize(w,h);
} else if(a_cmd==cmd_do_transparency) {
G4bool _do = a_cmd->ConvertToBool(args[0].c_str());
tsg_viewer->SetDoTransparency(_do);
} else if(a_cmd==cmd_gl2ps_sort) {
tsg_viewer->SetGL2PSSort(args[0]);
} else if(a_cmd==cmd_gl2ps_opts) {
tsg_viewer->SetGL2PSOptions(args[0]);
}
}
private:
G4UIcommand* cmd_format;
G4UIcommand* cmd_file;
G4UIcommand* cmd_size;
G4UIcmdWithABool* cmd_do_transparency;
G4UIcommand* cmd_gl2ps_sort;
G4UIcommand* cmd_gl2ps_opts;
};
protected:
unsigned int GetFileIndex() {
if(fResetFileIndex) {fFileIndex = 0;fResetFileIndex = false;}
fFileIndex++;
return fFileIndex;
}
static bool IsKnownFormat(const std::string& a_format) {
if(a_format=="gl2ps_eps") return true;
if(a_format=="gl2ps_ps") return true;
if(a_format=="gl2ps_pdf") return true;
if(a_format=="gl2ps_svg") return true;
if(a_format=="gl2ps_tex") return true;
if(a_format=="gl2ps_pgf") return true;
if(a_format=="zb_ps") return true;
if(a_format=="zb_png") return true;
if(a_format=="zb_jpeg") return true;
return false;
}
static bool GetFormatExtension(const std::string& a_format,std::string& a_ext) {
if(a_format=="gl2ps_eps") {a_ext = "eps";return true;}
if(a_format=="gl2ps_ps") {a_ext = "ps";return true;}
if(a_format=="gl2ps_pdf") {a_ext = "pdf";return true;}
if(a_format=="gl2ps_svg") {a_ext = "svg";return true;}
if(a_format=="gl2ps_tex") {a_ext = "tex";return true;}
if(a_format=="gl2ps_pgf") {a_ext = "pgf";return true;}
if(a_format=="zb_ps") {a_ext = "ps";return true;}
if(a_format=="zb_png") {a_ext = "png";return true;}
if(a_format=="zb_jpeg") {a_ext = "jpeg";return true;}
a_ext.clear();
return false;
}
protected:
std::string fFileName;
std::string fFilePrefix;
unsigned int fFileIndex;
bool fResetFileIndex;
};
#endif
@@ -0,0 +1,136 @@
//
// ********************************************************************
// * 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
#ifndef G4TOOLSSGQTVIEWER_HH
#define G4TOOLSSGQTVIEWER_HH
#include "G4ToolsSGViewer.hh"
#include "G4Qt.hh"
#include "G4UIQt.hh"
#include "G4UImanager.hh"
#include <toolx/Qt/sg_viewer>
#include <qmainwindow.h>
class G4ToolsSGQtDestroyCallback : public QObject {
Q_OBJECT
public:
G4ToolsSGQtDestroyCallback(G4VViewer* a_viewer):fViewer(a_viewer) {}
virtual ~G4ToolsSGQtDestroyCallback() {}
private:
G4ToolsSGQtDestroyCallback(const G4ToolsSGQtDestroyCallback&);
G4ToolsSGQtDestroyCallback& operator=(const G4ToolsSGQtDestroyCallback&);
public slots:
void execute(){
//::printf("debug : G4ToolsSGQtDestroyCallback::execute\n");
delete fViewer;
}
private:
G4VViewer* fViewer;
};
class G4ToolsSGQtViewer : public G4ToolsSGViewer<toolx::Qt::session,toolx::Qt::sg_viewer> {
typedef G4ToolsSGViewer<toolx::Qt::session,toolx::Qt::sg_viewer> parent;
public:
G4ToolsSGQtViewer(toolx::Qt::session& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
:parent(a_session,a_scene_handler,a_name)
,fSGQWidget(nullptr)
,fDestroyCallback(0)
{
fDestroyCallback = new G4ToolsSGQtDestroyCallback(this);
}
virtual ~G4ToolsSGQtViewer() {
delete fDestroyCallback; //it will remove the below signal/slot connection.
}
protected:
G4ToolsSGQtViewer(const G4ToolsSGQtViewer& a_from):parent(a_from){}
G4ToolsSGQtViewer& operator=(const G4ToolsSGQtViewer&) {return *this;}
public:
virtual void Initialise() {
if(fSGQWidget) return; //done.
parent::Initialise();
if(!fSGViewer) {
G4cerr << "G4ToolsSGQtViewer::Initialise: ERROR: G4ToolsSGQtViewer has no toolx::Qt::sg_viewer." << G4endl;
return;
}
fSGQWidget = fSGViewer->shell();
if (!fSGQWidget) {
G4cerr << "G4ToolsSGQtViewer::Initialise: ERROR: toolx::Qt::sg_viewer has no QWidget shell." << G4endl;
return;
}
{G4UImanager* ui = G4UImanager::GetUIpointer();
G4UIsession* session = ui->GetG4UIWindow();
fUIQt = session? dynamic_cast<G4UIQt*>(session) :nullptr;
if(fUIQt) {
G4Qt* interactorManager = G4Qt::getInstance ();
if (!interactorManager->IsExternalApp()) {
fSGViewer->set_own_shell(false);
fUIQt->AddTabWidget(fSGQWidget,QString(GetName()));
QObject::connect(fSGQWidget,SIGNAL(destroyed()),fDestroyCallback,SLOT(execute()));
QMainWindow* main_window = fUIQt->GetMainWindow();
if(main_window) {
main_window->show();
interactorManager->FlushAndWaitExecution();
}
}
}}
fSGViewer->enable_keyboard_focus();
}
virtual void SetView() {
#ifdef __APPLE__
if(fSGQWidget && fSGViewer) {
if( (2*fSGQWidget->width() == int(fSGViewer->width())) &&
(2*fSGQWidget->height() == int(fSGViewer->height())) ){
// With Qt/Cocoa, the received size in
// tools::sg::glarea::resizeGL is twice the QWidget::[width(),height()]!
// In general it does not pose problem, except when rendering 2D texts.
// In order to have similar sizes than other platforms, we have to double
// their pixel heights.
fVP.SetGlobalMarkerScale(2);
}
}
#endif
parent::SetView();
}
virtual void UpdateGUISceneTree() {
if (fUIQt) fUIQt->UpdateSceneTree(fSceneTree);
}
protected:
G4UIQt* fUIQt = nullptr;
QWidget* fSGQWidget;
G4ToolsSGQtDestroyCallback* fDestroyCallback;
};
#endif
@@ -0,0 +1,135 @@
//
// ********************************************************************
// * 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 13th April 2023
#ifndef G4TOOLSSGQTZBVIEWER_HH
#define G4TOOLSSGQTZBVIEWER_HH
#include "G4ToolsSGViewer.hh"
#include "G4Qt.hh"
#include "G4UIQt.hh"
#include "G4UImanager.hh"
#include <toolx/Qt/zb_viewer>
#include <qmainwindow.h>
class G4ToolsSGQtZBDestroyCallback : public QObject {
Q_OBJECT
public:
G4ToolsSGQtZBDestroyCallback(G4VViewer* a_viewer):fViewer(a_viewer) {}
virtual ~G4ToolsSGQtZBDestroyCallback() {}
private:
G4ToolsSGQtZBDestroyCallback(const G4ToolsSGQtZBDestroyCallback&);
G4ToolsSGQtZBDestroyCallback& operator=(const G4ToolsSGQtZBDestroyCallback&);
public slots:
void execute(){
delete fViewer;
}
private:
G4VViewer* fViewer;
};
class G4ToolsSGQtZBViewer : public G4ToolsSGViewer<toolx::Qt::session,toolx::Qt::zb_viewer> {
using parent = G4ToolsSGViewer<toolx::Qt::session,toolx::Qt::zb_viewer>;
public:
G4ToolsSGQtZBViewer(toolx::Qt::session& a_session,G4ToolsSGSceneHandler& a_scene_handler, const G4String& a_name)
:parent(a_session,a_scene_handler,a_name)
,fSGQWidget(nullptr)
,fDestroyCallback(0)
{
fDestroyCallback = new G4ToolsSGQtZBDestroyCallback(this);
}
virtual ~G4ToolsSGQtZBViewer() {
delete fDestroyCallback; //it will remove the below signal/slot connection.
}
protected:
G4ToolsSGQtZBViewer(const G4ToolsSGQtZBViewer& a_from):parent(a_from){}
G4ToolsSGQtZBViewer& operator=(const G4ToolsSGQtZBViewer&) {return *this;}
public:
virtual void Initialise() {
if(fSGQWidget) return; //done.
parent::Initialise();
if(!fSGViewer) {
G4cerr << "G4ToolsSGQtZBViewer::Initialise: ERROR: G4ToolsSGQtZBViewer has no toolx::Qt::zb_viewer." << G4endl;
return;
}
fSGQWidget = fSGViewer->shell();
if (!fSGQWidget) {
G4cerr << "G4ToolsSGQtZBViewer::Initialise: ERROR: toolx::Qt::zb_viewer has no QWidget shell." << G4endl;
return;
}
{G4UImanager* ui = G4UImanager::GetUIpointer();
G4UIsession* session = ui->GetG4UIWindow();
fUIQt = session? dynamic_cast<G4UIQt*>(session) :nullptr;
if(fUIQt) {
G4Qt* interactorManager = G4Qt::getInstance ();
if (!interactorManager->IsExternalApp()) {
fSGViewer->set_own_shell(false);
fUIQt->AddTabWidget(fSGQWidget,QString(GetName()));
QObject::connect(fSGQWidget,SIGNAL(destroyed()),fDestroyCallback,SLOT(execute()));
QMainWindow* main_window = fUIQt->GetMainWindow();
if(main_window) {
main_window->show();
interactorManager->FlushAndWaitExecution();
}
}
}}
fSGViewer->enable_keyboard_focus();
}
virtual void SetView() {
#ifdef __APPLE__
if(fSGQWidget && fSGViewer) {
if( (2*fSGQWidget->width() == int(fSGViewer->width())) &&
(2*fSGQWidget->height() == int(fSGViewer->height())) ){
// With Qt/Cocoa, the received size in
// tools::sg::glarea::resizeGL is twice the QWidget::[width(),height()]!
// In general it does not pose problem, except when rendering 2D texts.
// In order to have similar sizes than other platforms, we have to double
// their pixel heights.
fVP.SetGlobalMarkerScale(2);
}
}
#endif
parent::SetView();
}
virtual void UpdateGUISceneTree() {
if (fUIQt) fUIQt->UpdateSceneTree(fSceneTree);
}
protected:
G4UIQt* fUIQt = nullptr;
QWidget* fSGQWidget;
G4ToolsSGQtZBDestroyCallback* fDestroyCallback;
};
#endif
@@ -0,0 +1,118 @@
//
// ********************************************************************
// * 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
#ifndef G4TOOLSSGSCENEHANDLER_HH
#define G4TOOLSSGSCENEHANDLER_HH
#include "G4VSceneHandler.hh"
#include "G4VVisCommand.hh"
#include <vector>
#include <tools/sg/separator>
namespace tools {namespace sg {class base_freetype;}}
namespace tools {namespace sg {class plots;}}
class G4ToolsSGNode;
class G4ToolsSGSceneHandler: public G4VSceneHandler {
typedef G4VSceneHandler parent;
public:
virtual void AddPrimitive(const G4Polyline&);
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&);
virtual void AddPrimitive(const G4Plotter&);
using G4VSceneHandler::AddCompound;
virtual void AddCompound(const G4Mesh&);
virtual void ClearStore ();
virtual void ClearTransientStore ();
G4ToolsSGSceneHandler(G4VGraphicsSystem& system,const G4String& name);
virtual ~G4ToolsSGSceneHandler();
tools::sg::separator& GetTransient2DObjects() {return fpTransient2DObjects;}
tools::sg::separator& GetPersistent2DObjects() {return fpPersistent2DObjects;}
tools::sg::separator& GetTransient3DObjects() {return fpTransient3DObjects;}
tools::sg::separator& GetPersistent3DObjects() {return fpPersistent3DObjects;}
void TouchPlotters(tools::sg::node&);
protected:
G4ToolsSGSceneHandler(const G4ToolsSGSceneHandler&);
G4ToolsSGSceneHandler& operator=(const G4ToolsSGSceneHandler&){return *this;}
protected:
void CreateSG();
void EstablishBaseNodes();
tools::sg::separator* GetOrCreateNode(); // For next solid or primitive
void SetPlotterHistograms(tools::sg::plots&);
static G4int fSceneIdCount;
tools::sg::separator fpTransient2DObjects;
tools::sg::separator fpPersistent2DObjects;
tools::sg::separator fpTransient3DObjects;
tools::sg::separator fpPersistent3DObjects;
std::vector<G4ToolsSGNode*> fpPhysicalVolumeObjects; // Multiple worlds
tools::sg::base_freetype* fFreetypeNode;
using Region_h1 = std::pair<unsigned int,int>;
using Region_h2 = std::pair<unsigned int,int>;
std::vector<Region_h1> fRegionH1s;
std::vector<Region_h2> fRegionH2s;
class Messenger: public G4VVisCommand {
public:
static void Create() {static Messenger s_messenger;}
virtual void SetNewValue(G4UIcommand*,G4String);
private:
Messenger() {
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
print_plotter_params = new G4UIcommand("/vis/tsg/plotter/printParameters", this);
print_plotter_params->SetGuidance("Print available tools::sg::plotter parameters.");
}
virtual ~Messenger() {
delete print_plotter_params;
}
G4UIcommand* print_plotter_params;
};
};
#endif
@@ -0,0 +1,548 @@
//
// ********************************************************************
// * 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
#ifndef G4TOOLSSGVIEWER_HH
#define G4TOOLSSGVIEWER_HH
#include "G4VViewer.hh"
#include "G4ToolsSGSceneHandler.hh"
#include "G4Scene.hh"
#include "G4VVisCommand.hh"
#include <tools/fpng>
#include <tools/toojpeg>
#include <tools/sg/device_interactor>
#include <tools/sg/separator>
#include <tools/sg/ortho>
#include <tools/sg/perspective>
#include <tools/sg/torche>
#include <tools/sg/blend>
#include <tools/sg/noderef>
#include <tools/sg/keys>
#include <tools/tokenize>
#include <tools/sg/write_paper>
template <class SG_SESSION,class SG_VIEWER>
class G4ToolsSGViewer : public G4VViewer, tools::sg::device_interactor {
typedef G4VViewer parent;
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 delta = fSceneHandler.GetExtent().GetExtentRadius()/200.; // Empirical
fVP.SetDolly(fVP.GetDolly()+angleY*delta);
}
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: %lu, %s\n",this,a_name.c_str());
Messenger::Create();
}
virtual ~G4ToolsSGViewer() {
//::printf("debug : G4ToolsSGViewer::~G4ToolsSGViewer: %lu\n",this);
//WARNING : nodes may refer f_gl2ps_mgr, f_zb_mgr (to handle gstos (for GPU) or textures), then
// we have to delete them first.
fSGViewer->sg().clear();
delete fSGViewer;
}
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_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;
}
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
/*
G4cout << "debug : 0002 : radius " << radius << std::endl;
G4cout << "debug : cameraDistance : " << cameraDistance << std::endl;
G4cout << "debug : fieldHalfAngle : " << fVP.GetFieldHalfAngle() << std::endl;
G4cout << "debug : zoomFactor : " << fVP.GetZoomFactor() << std::endl;
G4cout << "debug : up : " << up.x() << " " << up.y() << " " << up.z() << std::endl;
G4cout << "debug : targetPoint : " << targetPoint.x() << " " << targetPoint.y() << " " << targetPoint.z() << std::endl;
G4cout << "debug : cameraPosition : " << cameraPosition.x() << " " << cameraPosition.y() << " " << cameraPosition.z() << std::endl;
G4cout << "debug : camera : znear " << pnear << ", zfar " << pfar << std::endl;
*/
//////////////////////////////////////////////////////////
/// create scene graph ///////////////////////////////////
//////////////////////////////////////////////////////////
// Set projection, then create the tools::sg camera node :
tools::sg::base_camera* _camera = nullptr;
if (fVP.GetFieldHalfAngle() <= 0.) {
//G4cout << "debug : camera : ortho : top " << top << " bottom " << bottom << " top-bottom " << top-bottom << std::endl;
if((top-bottom)<=0) {
fSGViewer->set_clear_color(0.3,0.3,0.3,1);
G4cerr << "G4ToolsSGViewer::SetView : for ortho camera, (top-bottom)<=0." << G4endl;
return;
}
tools::sg::ortho* ortho_camera = new tools::sg::ortho;
ortho_camera->height.value(float(top-bottom));
_camera = ortho_camera;
} else {
//G4cout << "debug : camera : perspec : heightAngle " << float(2*fVP.GetFieldHalfAngle()) << std::endl;
tools::sg::perspective* perspective_camera = new tools::sg::perspective;
perspective_camera->height_angle.value(float(2*fVP.GetFieldHalfAngle()));
_camera = perspective_camera;
}
_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.
/*
const G4Vector3D& lightDirection = fVP.GetLightpointDirection();
G4cout << "debug : lightDirection : " << lightDirection.x() << " " << lightDirection.y() << " " << lightDirection.z() << std::endl;
const G4Vector3D& actualLightDirection = fVP.GetActualLightpointDirection();
G4cout << "debug : actualLightDirection : " << actualLightDirection.x() << " " << actualLightDirection.y() << " " << actualLightDirection.z() << std::endl;
*/
CreateSG(_camera,fVP.GetActualLightpointDirection());
{G4Color background = fVP.GetBackgroundColour ();
fSGViewer->set_clear_color(float(background.GetRed()),float(background.GetGreen()),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() {FinishView();}
virtual void FinishView() {
if(fSGViewer) {
fSGSceneHandler.TouchPlotters(fSGViewer->sg());
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).
//
// Only do this if there are end-of-event models (e.g., trajectories) that
// may require it.
if (fSceneHandler.GetScene()->GetEndOfEventModelList().size()) {
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& vp) {
// Typical comparison. Taken from OpenInventor.
if (
(vp.GetDrawingStyle () != fVP.GetDrawingStyle ()) ||
(vp.GetNumberOfCloudPoints() != fVP.GetNumberOfCloudPoints()) ||
(vp.IsAuxEdgeVisible () != fVP.IsAuxEdgeVisible ()) ||
(vp.IsCulling () != fVP.IsCulling ()) ||
(vp.IsCullingInvisible () != fVP.IsCullingInvisible ()) ||
(vp.IsDensityCulling () != fVP.IsDensityCulling ()) ||
(vp.IsCullingCovered () != fVP.IsCullingCovered ()) ||
(vp.GetCBDAlgorithmNumber() !=
fVP.GetCBDAlgorithmNumber()) ||
(vp.IsSection () != fVP.IsSection ()) ||
(vp.IsCutaway () != fVP.IsCutaway ()) ||
// This assumes use of generic clipping (sectioning, slicing,
// DCUT, cutaway). If a decision is made to implement locally,
// this will need changing. See G4OpenGLViewer::SetView,
// G4OpenGLStoredViewer.cc::CompareForKernelVisit and
// G4OpenGLStoredSceneHander::CreateSection/CutawayPolyhedron.
(vp.IsExplode () != fVP.IsExplode ()) ||
(vp.GetNoOfSides () != fVP.GetNoOfSides ()) ||
(vp.GetGlobalMarkerScale() != fVP.GetGlobalMarkerScale()) ||
(vp.GetGlobalLineWidthScale() != fVP.GetGlobalLineWidthScale()) ||
(vp.IsMarkerNotHidden () != fVP.IsMarkerNotHidden ()) ||
(vp.GetDefaultVisAttributes()->GetColour() !=
fVP.GetDefaultVisAttributes()->GetColour()) ||
(vp.GetDefaultTextVisAttributes()->GetColour() !=
fVP.GetDefaultTextVisAttributes()->GetColour()) ||
(vp.GetBackgroundColour ()!= fVP.GetBackgroundColour ())||
(vp.IsPicking () != fVP.IsPicking ()) ||
// Scaling for Open Inventor is done by the scene handler so it
// needs a kernel visit. (In this respect, it differs from the
// OpenGL drivers, where it's done in SetView.)
(vp.GetScaleFactor () != fVP.GetScaleFactor ()) ||
(vp.GetVisAttributesModifiers() !=
fVP.GetVisAttributesModifiers()) ||
(vp.IsSpecialMeshRendering() !=
fVP.IsSpecialMeshRendering()) ||
(vp.GetSpecialMeshRenderingOption() !=
fVP.GetSpecialMeshRenderingOption())
)
return true;
if (vp.IsDensityCulling () &&
(vp.GetVisibleDensity () != fVP.GetVisibleDensity ()))
return true;
if (vp.GetCBDAlgorithmNumber() > 0) {
if (vp.GetCBDParameters().size() != fVP.GetCBDParameters().size()) return true;
else if (vp.GetCBDParameters() != fVP.GetCBDParameters()) return true;
}
if (vp.IsSection () &&
(vp.GetSectionPlane () != fVP.GetSectionPlane ()))
return true;
if (vp.IsCutaway ()) {
if (vp.GetCutawayMode() != fVP.GetCutawayMode()) return true;
if (vp.GetCutawayPlanes ().size () !=
fVP.GetCutawayPlanes ().size ()) return true;
for (size_t i = 0; i < vp.GetCutawayPlanes().size(); ++i)
if (vp.GetCutawayPlanes()[i] != fVP.GetCutawayPlanes()[i])
return true;
}
if (vp.IsExplode () &&
(vp.GetExplodeFactor () != fVP.GetExplodeFactor ()))
return true;
if (vp.IsSpecialMeshRendering() &&
(vp.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:
void CreateSG(tools::sg::base_camera* a_camera,const G4Vector3D& a_light_dir) {
tools::sg::group& _parent = fSGViewer->sg();
_parent.clear();
///////////////////////////////////////////////////
/// 2D scene graph: ///////////////////////////////
///////////////////////////////////////////////////
tools::sg::separator* scene_2D = new tools::sg::separator;
_parent.add(scene_2D);
scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient2DObjects()));
scene_2D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent2DObjects()));
///////////////////////////////////////////////////
/// 3D scene graph: ///////////////////////////////
///////////////////////////////////////////////////
tools::sg::separator* scene_3D = new tools::sg::separator;
_parent.add(scene_3D);
scene_3D->add(a_camera);
{tools::sg::torche* light = new tools::sg::torche;
light->on = true;
light->direction = tools::vec3f(-a_light_dir.x(),-a_light_dir.y(),-a_light_dir.z());
light->ambient = tools::colorf(0.2f,0.2f,0.2f,1.0f); //same as in G4OpenGLViewer.cc glLight(GL_LIGHT0,GL_AMBIENT and GL_DIFFUSE).
light->color = tools::colorf(0.8f,0.8f,0.8f,1.0f); //idem.
scene_3D->add(light);}
{tools::sg::blend* blend = new tools::sg::blend;
blend->on = true; //to handle transparency.
scene_3D->add(blend);}
scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetTransient3DObjects()));
scene_3D->add(new tools::sg::noderef(fSGSceneHandler.GetPersistent3DObjects()));
}
void Export(const G4String& a_format,const G4String& a_file,G4bool a_do_transparency) {
if(!fSGViewer) return;
const G4Colour& back_color = fVP.GetBackgroundColour();
bool top_to_bottom = false; //if using tools::fpng, tools::toojpeg.
if(!tools::sg::write_paper(G4cout,f_gl2ps_mgr,f_zb_mgr,
tools::fpng::write,tools::toojpeg::write,
float(back_color.GetRed()),float(back_color.GetGreen()),float(back_color.GetBlue()),float(back_color.GetAlpha()),
fSGViewer->sg(),fSGViewer->width(),fSGViewer->height(),
a_file,a_format,a_do_transparency,top_to_bottom,std::string(),std::string())) {
G4cout << "G4ToolsSGViewer::Export: write_paper() failed." << G4endl;
return;
}
}
protected:
class Messenger: public G4VVisCommand {
public:
static void Create() {static Messenger s_messenger;}
private:
Messenger() {
G4UIparameter* parameter;
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
write_scene = new G4UIcommand("/vis/tsg/export", this);
write_scene->SetGuidance("Write the content of the current viewer in a file at various formats.");
write_scene->SetGuidance("Default file is out.eps and default format is gl2ps_eps.");
write_scene->SetGuidance("Available formats are:");
write_scene->SetGuidance("- gl2ps_eps: gl2ps producing eps");
write_scene->SetGuidance("- gl2ps_ps: gl2ps producing ps");
write_scene->SetGuidance("- gl2ps_pdf: gl2ps producing pdf");
write_scene->SetGuidance("- gl2ps_svg: gl2ps producing svg");
write_scene->SetGuidance("- gl2ps_tex: gl2ps producing tex");
write_scene->SetGuidance("- gl2ps_pgf: gl2ps producing pgf");
write_scene->SetGuidance("- zb_ps: tools::sg offscreen zbuffer put in a PostScript file.");
write_scene->SetGuidance("- zb_png: tools::sg offscreen zbuffer put in a png file.");
write_scene->SetGuidance("- zb_jpeg: tools::sg offscreen zbuffer put in a jpeg file.");
parameter = new G4UIparameter("format",'s',true);
parameter->SetDefaultValue("gl2ps_eps");
write_scene->SetParameter (parameter);
parameter = new G4UIparameter("file",'s',true);
parameter->SetDefaultValue("out.eps");
write_scene->SetParameter (parameter);
parameter = new G4UIparameter ("do_transparency", 'b', true);
parameter->SetDefaultValue ("true");
write_scene->SetParameter (parameter);
}
virtual ~Messenger() {
delete write_scene;
}
public:
virtual void SetNewValue(G4UIcommand* a_cmd,G4String a_value) {
G4VisManager::Verbosity verbosity = GetVisManager()->GetVerbosity();
G4VViewer* viewer = GetVisManager()->GetCurrentViewer();
if (!viewer) {
if (verbosity >= G4VisManager::errors) G4cerr << "ERROR: No current viewer." << G4endl;
return;
}
G4ToolsSGViewer* tsg_viewer = dynamic_cast<G4ToolsSGViewer*>(viewer);
if(!tsg_viewer) {
G4cout << "G4ToolsSGViewer::SetNewValue:"
<< " current viewer is not a G4ToolsSGViewer." << G4endl;
return;
}
std::vector<std::string> args;
tools::double_quotes_tokenize(a_value,args);
if(args.size()!=a_cmd->GetParameterEntries()) return;
if(a_cmd==write_scene) {
G4bool do_transparency = G4UIcommand::ConvertToBool(args[2].c_str());
tsg_viewer->Export(args[0],args[1],do_transparency);
}
}
private:
G4UIcommand* write_scene;
};
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;
tools::sg::zb_manager f_zb_mgr;
tools::sg::gl2ps_manager f_gl2ps_mgr;
};
#endif