Import Geant4 11.4.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2025-06-26 09:17:29 +02:00
parent 20a218bbe1
commit a499fb82e9
1941 changed files with 203285 additions and 95593 deletions
+27 -1
View File
@@ -6,10 +6,36 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2025-04-12 John Allison (raytracer-V11-02-00)
## 2025-04-12 John Allison (raytracer-V11-03-01)
- G4RayTracerXViewer.cc:
- Use G4TheMTRayTracer.
## 2025-04-04 John Allison (raytracer-V11-03-00)
- Coworks: visman-V11-03-07, cmake-V11-03-02.
- Introduce RayTracerQt.
- 6 new files and modification of sources.cmake.
- Uses multithreading tracer, G4TheMTRayTracer.
- Other changes (improve Ray Tracer experience):
- G4RayTracerViewer:
- Use G4Timer to estimate fKernelVisitElapsedTimeSeconds.
- Normally it's ProcessView() that takes the time, but for RayTracer it's Trace().
- Long elapsed times (currently >0.1 s) inhibit fancy options such as zoom in on
and twinkle that require multiple rebuilds.
- G4VRTScanner (and inherited classes):
- Remove misleading and un-used methods: GetGSName() and GetGSNickName().
- Introduce nicknames (long names still work):
- RT (for RayTracer)
- RTX (for RayTracerX)
- RTQt (for RayTracerQt)
- With multithreading, image construction is quite fast. Maybe 1000x1000 could be
the default.
- Use /vis/open RTqt 1000x1000
- (Currently the default is 600x600).
- Most vis commands work fine:
- /vis/viewer/set/viewpoint..., /vis/viewer/zoom, vis/viewer/centreAndZoomInOn,...
- Even some of the scene tree actions work. E.g:
- Select you chosen volume, right click, and click on centreAndZoomInOn.
## 2023-03-22 Ben Morgan (raytracer-V11-01-01)
- Export public compile definitions to indicate availablity of specific drivers. Moves to
"use on link" model.
@@ -0,0 +1,51 @@
//
// ********************************************************************
// * 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 4th March 2025
#ifndef G4RAYTRACERQT_HH
#define G4RAYTRACERQT_HH
// class description:
//
// G4RayTracerQt
// Qt window version of RayTracer - opens Qt window for viewing as well
// as producing jpeg file just like G4RayTracer.
#include "G4VGraphicsSystem.hh"
class G4RayTracerQt : public G4VGraphicsSystem
{
public: // with description
G4RayTracerQt();
~G4RayTracerQt();
G4VSceneHandler* CreateSceneHandler (const G4String& );
G4VViewer* CreateViewer (G4VSceneHandler&, const G4String& );
};
#endif
@@ -0,0 +1,78 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
#ifndef G4RTQtScanner_H
#define G4RTQtScanner_H 1
// class description:
//
// G4RTQtScanner
// Provides a sequence of window coordinates suitable for a visible
// window of ever increasing resolution.
#include "G4VRTScanner.hh"
#include <QScrollArea>
class G4ViewParameters;
class QLabel;
class QImage;
class G4RTQtScanner: public G4VRTScanner, QScrollArea {
public: // with description
G4RTQtScanner();
virtual ~G4RTQtScanner();
// Compiler defaults for copy constructor and assignmemt.
virtual void Initialize(G4int nRow, G4int nColumn);
// Intialises scanner for window with nRow rows and nColumn columns.
virtual G4bool Coords(G4int& iRow, G4int& iColumn);
// Supplies coordinate (iRow,iColumn) and returns false when the
// sequence has finished, i.e., on the call *after* suplying the
// last valid coordinate.
virtual void Draw
(unsigned char red, unsigned char green, unsigned char blue);
// Draw coloured square at current position.
G4bool GetQtWindow(const G4String& name, G4ViewParameters&);
protected:
G4int theNRow, theNColumn, theIRow, theIColumn;
G4int theWindowSizeX, theWindowSizeY;
QLabel* fpImageLabel;
QImage* fpImage;
};
#endif
@@ -46,14 +46,6 @@ public: // with description
// Compiler defaults for copy constructor and assignmemt.
virtual const G4String& GetGSName() const;
// Get name that acts as graphics system name.
virtual const G4String& GetGSNickname() const;
// Get name that acts as graphics system nickname. It is this that
// the user specifies on the /vis/open and /vis/sceneHandler/create
// commands.
virtual void Initialize(G4int nRow, G4int nColumn);
// Intialises scanner for window with nRow rows and nColumn columns.
@@ -63,7 +55,6 @@ public: // with description
// last valid coordinate.
protected:
G4String theGSName, theGSNickname;
G4int theNRow, theNColumn, theIRow, theIColumn;
};
@@ -52,14 +52,6 @@ public: // with description
// Compiler defaults for copy constructor and assignmemt.
virtual const G4String& GetGSName() const;
// Get name that acts as graphics system name.
virtual const G4String& GetGSNickname() const;
// Get name that acts as graphics system nickname. It is this that
// the user specifies on the /vis/open and /vis/sceneHandler/create
// commands.
virtual void Initialize(G4int nRow, G4int nColumn);
// Intialises scanner for window with nRow rows and nColumn columns.
@@ -75,7 +67,6 @@ public: // with description
G4bool GetXWindow(const G4String& name, G4ViewParameters&);
protected:
G4String theGSName, theGSNickname;
G4int theNRow, theNColumn, theStep, theIRow, theIColumn;
// X Window variables...
Display* display;
@@ -0,0 +1,42 @@
//
// ********************************************************************
// * 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 4th March 2025
#ifndef G4RAYTRACERQTVIEWER_HH
#define G4RAYTRACERQTVIEWER_HH
#include "G4RayTracerViewer.hh"
class G4RayTracerQtViewer: public G4RayTracerViewer {
public:
G4RayTracerQtViewer(G4VSceneHandler&,const G4String& name);
virtual ~G4RayTracerQtViewer();
void Initialise();
};
#endif
@@ -44,14 +44,6 @@ public: // with description
G4VRTScanner();
virtual ~G4VRTScanner();
virtual const G4String& GetGSName() const = 0;
// Get name that acts as graphics system name.
virtual const G4String& GetGSNickname() const = 0;
// Get name that acts as graphics system nickname. It is this that
// the user specifies on the /vis/open and /vis/sceneHandler/create
// commands.
virtual void Initialize(G4int nRow, G4int nColumn) = 0;
// Intialises scanner for window with nRow rows and nColumn columns.
@@ -75,6 +75,7 @@ geant4_module_link_libraries(G4RayTracer
# X11 RayTracer only if selected
if(GEANT4_USE_RAYTRACER_X11)
geant4_module_sources(G4RayTracer
PUBLIC_HEADERS
G4RayTracerX.hh
@@ -89,4 +90,27 @@ if(GEANT4_USE_RAYTRACER_X11)
geant4_module_compile_definitions(G4RayTracer PUBLIC G4VIS_USE_RAYTRACERX)
geant4_module_link_libraries(G4RayTracer PRIVATE X11::SM X11::ICE X11::X11 X11::Xext X11::Xmu)
endif()
# Qt RayTracer only if selected
if(GEANT4_USE_RAYTRACER_QT)
geant4_module_sources(G4RayTracer
PUBLIC_HEADERS
G4RayTracerQt.hh
PRIVATE_HEADERS
G4RayTracerQtViewer.hh
G4RTQtScanner.hh
SOURCES
G4RayTracerQt.cc
G4RayTracerQtViewer.cc
G4RTQtScanner.cc)
geant4_module_compile_definitions(G4RayTracer PUBLIC G4VIS_USE_RAYTRACER_QT)
geant4_module_link_libraries(G4RayTracer PRIVATE G4UIimplementation
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Widgets)
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. *
// ********************************************************************
//
//
//
//
#include "G4RTQtScanner.hh"
//#include "G4TheRayTracer.hh"
//#include "G4RayTracerQtViewer.hh"
#include "G4ViewParameters.hh"
#include "G4UImanager.hh"
#include "G4UIQt.hh"
#include <QLabel>
#include <QImage>
#include <QPainter>
#include <QColor>
#define G4warn G4cout
G4RTQtScanner::G4RTQtScanner()
: G4VRTScanner()
, theNRow(0), theNColumn(0)
, theIRow(0), theIColumn(0)
, fpImageLabel(nullptr)
, fpImage(nullptr)
{}
G4RTQtScanner::~G4RTQtScanner() {}
void G4RTQtScanner::Initialize(G4int nRow, G4int nColumn) {
theNRow = nRow;
theNColumn = nColumn;
theIRow = 0;
theIColumn = -1;
}
G4bool G4RTQtScanner::Coords(G4int& iRow, G4int& iColumn)
{
// Increment column and, if necessary, increment row...
++theIColumn;
if (theIColumn >= theNColumn) {
theIColumn = 0;
++theIRow;
}
// Return if finished...
if (theIRow >= theNRow) {
// ...and paint the image
fpImageLabel->setPixmap(QPixmap::fromImage(*fpImage));
QPainter windowPainter(fpImageLabel);
windowPainter.drawImage(0, 0, *fpImage);
return false;
}
// Return current row and column...
iRow = theIRow;
iColumn = theIColumn;
return true;
}
G4bool G4RTQtScanner::GetQtWindow(const G4String& name, G4ViewParameters& vp)
{
auto UI = G4UImanager::GetUIpointer();
auto uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
if (!uiQt) {
G4warn << "G4RTQtScanner::GetQtWindow: RayTracerQt requires G4UIQt"
<< G4endl;
return false;
}
uiQt->AddTabWidget(this,QString(name));
setBackgroundRole(QPalette::Dark);
theWindowSizeX = vp.GetWindowSizeHintX(); // As used by the ray tracer
theWindowSizeY = vp.GetWindowSizeHintY(); // and to make fpImage
fpImage = new QImage(theWindowSizeX, theWindowSizeY, QImage::Format_RGB32);
fpImageLabel = new QLabel;
fpImageLabel->setPixmap(QPixmap::fromImage(*fpImage));
setWidget(fpImageLabel);
setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
ensureVisible(theWindowSizeX/2, theWindowSizeY/2);
return true;
}
void G4RTQtScanner::Draw
(unsigned char red, unsigned char green, unsigned char blue)
// Add a coloured point to the image at current position.
{
QPainter painter(fpImage);
painter.setPen(QPen(QColor(int(red), int(green), int(blue))));
painter.drawPoint(theIColumn, theIRow);
}
@@ -31,19 +31,10 @@
G4RTSimpleScanner::G4RTSimpleScanner():
G4VRTScanner(), theNRow(0), theNColumn(0), theIRow(0), theIColumn(0)
{
theGSName = "RayTracer";
theGSNickname = "RayTracer";
}
{}
G4RTSimpleScanner::~G4RTSimpleScanner(){}
const G4String& G4RTSimpleScanner::GetGSName() const
{return theGSName;}
const G4String& G4RTSimpleScanner::GetGSNickname() const
{return theGSNickname;}
void G4RTSimpleScanner::Initialize(G4int nRow, G4int nColumn) {
theNRow = nRow;
theNColumn = nColumn;
@@ -48,19 +48,10 @@ G4RTXScanner::G4RTXScanner():
G4VRTScanner(), theNRow(0), theNColumn(0), theStep(0)
,theIRow(0), theIColumn(0)
,display(0), win(0), scmap(0)
{
theGSName = "RayTracerX";
theGSNickname = "RayTracerX";
}
{}
G4RTXScanner::~G4RTXScanner() {}
const G4String& G4RTXScanner::GetGSName() const
{return theGSName;}
const G4String& G4RTXScanner::GetGSNickname() const
{return theGSNickname;}
void G4RTXScanner::Initialize(G4int nRow, G4int nColumn) {
theNRow = nRow;
theNColumn = nColumn;
@@ -34,7 +34,7 @@
G4RayTracer::G4RayTracer():
G4VGraphicsSystem("RayTracer",
"RayTracer",
"RT",
RAYTRACER_FEATURES,
G4VGraphicsSystem::threeD)
, theRayTracer(nullptr)
@@ -0,0 +1,73 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
//
//
//
#include "G4RayTracerQt.hh"
#include "G4RayTracerFeatures.hh"
#include "G4RayTracerSceneHandler.hh"
#include "G4RayTracerQtViewer.hh"
#define G4warn G4cerr
G4RayTracerQt::G4RayTracerQt():
G4VGraphicsSystem("RayTracerQt",
"RTQt",
RAYTRACER_FEATURES,
G4VGraphicsSystem::threeD)
{}
G4RayTracerQt::~G4RayTracerQt()
{}
G4VSceneHandler* G4RayTracerQt::CreateSceneHandler (const G4String& name) {
G4VSceneHandler* pSceneHandler = new G4RayTracerSceneHandler (*this, name);
return pSceneHandler;
}
G4VViewer* G4RayTracerQt::CreateViewer (G4VSceneHandler& sceneHandler,
const G4String& name) {
G4VViewer* pViewer = new G4RayTracerQtViewer (sceneHandler, name);
if (pViewer) {
if (pViewer->GetViewId() < 0) {
G4warn <<
"G4RayTracerQt::CreateViewer: ERROR flagged by negative"
" view id in G4RayTracerQtViewer creation."
"\n Destroying view and returning null pointer."
<< G4endl;
delete pViewer;
pViewer = 0;
}
}
else {
G4warn <<
"G4RayTracerQt::CreateViewer: ERROR: null pointer on new G4RayTracerQtViewer."
<< G4endl;
}
return pViewer;
}
@@ -0,0 +1,62 @@
//
// ********************************************************************
// * 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. *
// ********************************************************************
//
//
#include "G4RayTracerQtViewer.hh"
#include "G4VSceneHandler.hh"
#include "G4Scene.hh"
#include "G4TheMTRayTracer.hh"
#include "G4RTJpegMaker.hh"
#include "G4RTQtScanner.hh"
#include "G4UImanager.hh"
#include <cstdlib>
G4RayTracerQtViewer::G4RayTracerQtViewer
(G4VSceneHandler& sceneHandler, const G4String& name):
G4RayTracerViewer
(sceneHandler, name,
G4TheMTRayTracer::Instance(new G4RTJpegMaker, new G4RTQtScanner))
{}
G4RayTracerQtViewer::~G4RayTracerQtViewer() {}
void G4RayTracerQtViewer::Initialise() {
G4RayTracerViewer::Initialise();
fVP.SetAutoRefresh(true);
fDefaultVP.SetAutoRefresh(true);
// Set up Qt Window...
G4RTQtScanner* theQtScanner = (G4RTQtScanner*)theTracer->GetScanner();
if (!theQtScanner->GetQtWindow(fName,fVP)) {
G4cerr << "G4RayTracerQtViewer::Initialise: No scanner" << G4endl;
fViewId = -1; // This flags an error.
return;
}
}
@@ -27,6 +27,8 @@
#include "G4RayTracerViewer.hh"
#include "G4Timer.hh"
#include "G4ios.hh"
#include <sstream>
#include <iomanip>
@@ -53,7 +55,6 @@ G4RayTracerViewer::G4RayTracerViewer
: G4VViewer(sceneHandler, sceneHandler.IncrementViewCount(), name)
, fFileCount(0)
#ifdef G4MULTITHREADED
#include "G4TheMTRayTracer.hh"
, theTracer(aTracer? aTracer: G4TheMTRayTracer::Instance(new G4RTJpegMaker, new G4RTSimpleScanner))
#else
, theTracer(aTracer? aTracer: new G4TheRayTracer(new G4RTJpegMaker, new G4RTSimpleScanner))
@@ -103,7 +104,6 @@ void G4RayTracerViewer::SetView()
theTracer->SetBackgroundColour(fVP.GetBackgroundColour());
}
void G4RayTracerViewer::ClearView() {}
void G4RayTracerViewer::DrawView()
@@ -130,10 +130,16 @@ void G4RayTracerViewer::DrawView()
else {
ProcessView();
}
// Normally it's ProcessView() that takes the time, but for RayTracer it's Trace()
G4Timer timer;
timer.Start();
std::ostringstream filename;
filename << "g4RayTracer." << fShortName << '_'
<< std::setw(4) << std::setfill('0') << fFileCount++ << ".jpeg";
theTracer->Trace(filename.str());
timer.Stop();
fKernelVisitElapsedTimeSeconds = timer.GetRealElapsed();
// Reset call flag
called = false;
@@ -37,7 +37,7 @@
G4RayTracerX::G4RayTracerX():
G4VGraphicsSystem("RayTracerX",
"RayTracerX",
"RTX",
RAYTRACER_FEATURES,
G4VGraphicsSystem::threeD)
{}