Import Geant4 11.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2021-12-10 14:46:44 +01:00
committed by Ben Morgan
parent 6399a014b6
commit 80e2389dd8
3932 changed files with 202519 additions and 246221 deletions
-4
View File
@@ -25,8 +25,6 @@
//
// John Allison 17th June 2019
#if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
#include "G4Qt3D.hh"
#include "G4Qt3DSceneHandler.hh"
#include "G4Qt3DViewer.hh"
@@ -99,5 +97,3 @@ G4bool G4Qt3D::IsUISessionCompatible () const
}
return isCompatible;
}
#endif // #if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
@@ -25,8 +25,6 @@
//
// John Allison 17th June 2019
#if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
#include "G4Qt3DSceneHandler.hh"
#include "G4PhysicalVolumeModel.hh"
@@ -43,6 +41,10 @@
#include "G4Polyhedron.hh"
#include "G4Scene.hh"
#include "G4Threading.hh"
#include "G4Mesh.hh"
#include "G4PseudoScene.hh"
#include "G4VisManager.hh"
#include "Randomize.hh"
#include "G4Qt3DViewer.hh"
#include "G4Qt3DUtils.hh"
@@ -117,12 +119,8 @@ void G4Qt3DSceneHandler::EstablishG4Qt3DQEntities()
}
G4Qt3DQEntity* G4Qt3DSceneHandler::CreateNewNode()
{ // Create a G4Qt3DQEntity node suitable for next solid or primitive
// Avoid Qt errors in MT mode - see G4Qt3DViewer::SwitchToMasterThread
#ifdef G4MULTITHREADED
if (!G4Threading::IsMasterThread()) return nullptr;
#endif
{
// Create a G4Qt3DQEntity node suitable for next solid or primitive
G4Qt3DQEntity* newNode = nullptr;
@@ -265,11 +263,20 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline)
<< G4endl;
#endif
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (polyline.size() == 0) return;
auto currentNode = CreateNewNode();
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polyline&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
fpVisAttribs = fpViewer->GetApplicableVisAttributes(polyline.GetVisAttributes());
auto transform = G4Qt3DUtils::CreateQTransformFrom(fObjectTransformation);
@@ -323,7 +330,7 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline)
polylineEntity->addComponent(material);
auto renderer = new Qt3DRender::QGeometryRenderer;
renderer->setObjectName("polyhedronWireframeRenderer");
renderer->setObjectName("polylineWireframeRenderer");
renderer->setGeometry(polylineGeometry);
renderer->setVertexCount(2*nLines);
renderer->setPrimitiveType(Qt3DRender::QGeometryRenderer::Lines);
@@ -332,11 +339,20 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Polyline& polyline)
void G4Qt3DSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
{
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (polymarker.size() == 0) return;
auto currentNode = CreateNewNode();
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polymarker&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
fpVisAttribs = fpViewer->GetApplicableVisAttributes(polymarker.GetVisAttributes());
switch (polymarker.GetMarkerType()) {
@@ -416,15 +432,17 @@ void G4Qt3DSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
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
const G4double scale = 200.; // Roughly pixels per scene
radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale;
}
sphereMesh->setRadius(radius);
// sphereMesh->setInstanceCount(polymarker.size()); // Not undertood instancing yet
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
// auto currentEntity = new Qt3DCore::QEntity(currentNode); // Not undertood instancing yet
for (size_t iPoint = 0; iPoint < polymarker.size(); iPoint++) {
auto position = fObjectTransformation*G4Translate3D(polymarker[iPoint]);
auto transform = G4Qt3DUtils::CreateQTransformFrom(position);
auto currentEntity = new Qt3DCore::QEntity(currentNode);
auto currentEntity = new Qt3DCore::QEntity(currentNode); // Not undertood instancing yet
currentEntity->addComponent(material);
currentEntity->addComponent(transform);
currentEntity->addComponent(sphereMesh);
@@ -455,7 +473,7 @@ void G4Qt3DSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
boxMesh->setYExtent(side);
boxMesh->setZExtent(side);
for (size_t iPoint = 0; iPoint < polymarker.size (); iPoint++) {
for (size_t iPoint = 0; iPoint < polymarker.size(); iPoint++) {
auto position = fObjectTransformation*G4Translate3D(polymarker[iPoint]);
auto transform = G4Qt3DUtils::CreateQTransformFrom(position);
auto currentEntity = new Qt3DCore::QEntity(currentNode);
@@ -468,25 +486,36 @@ void G4Qt3DSceneHandler::AddPrimitive (const G4Polymarker& polymarker)
}
}
void G4Qt3DSceneHandler::AddPrimitive(const G4Text& /*text*/) {
#ifdef G4QT3DDEBUG
void G4Qt3DSceneHandler::AddPrimitive(const G4Text& text) {
G4cout <<
"G4Qt3DSceneHandler::AddPrimitive(const G4Text& text) called.\n"
<< text
<< G4endl;
#else
void G4Qt3DSceneHandler::AddPrimitive(const G4Text& /*text*/) {
#endif
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Text& text)",
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Text&)",
"qt3D-0002", JustWarning,
"Text drawing doesn't work yet");
} // OK. Not working, but let it execute, which it does without error.
/* But it crashes after /vis/viewer/rebuild!!!
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Text&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
fpVisAttribs = fpViewer->GetApplicableVisAttributes(text.GetVisAttributes());
@@ -555,7 +584,16 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Circle& circle)
#endif
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Circle&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
fpVisAttribs = fpViewer->GetApplicableVisAttributes(circle.GetVisAttributes());
@@ -613,7 +651,16 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Square& square)
#endif
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Square&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
fpVisAttribs = fpViewer->GetApplicableVisAttributes(square.GetVisAttributes());
@@ -649,7 +696,16 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Square& square)
void G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron)
{
auto currentNode = CreateNewNode();
if (!currentNode) return; // Node not available
if (!currentNode) {
static G4bool first = true;
if (first) {
first = false;
G4Exception("G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron&)",
"qt3d-0003", JustWarning,
"No available node!");
}
return;
}
if (polyhedron.GetNoFacets() == 0) return;
@@ -994,6 +1050,119 @@ void G4Qt3DSceneHandler::AddPrimitive(const G4Polyhedron& polyhedron)
}
}
void G4Qt3DSceneHandler::AddCompound(const G4Mesh& mesh)
{
// Special mesh rendering
// Limited to rectangular 3-deep meshes
if (mesh.GetMeshType() != G4Mesh::rectangle ||
mesh.GetMeshDepth() != 3) {
G4VSceneHandler::AddCompound(mesh);
}
auto container = mesh.GetContainerVolume();
static G4bool firstPrint = true;
G4VisManager::Verbosity verbosity = G4VisManager::GetVerbosity();
G4bool print = firstPrint && verbosity >= G4VisManager::confirmations;
if (print) {
G4cout
<< "Special case drawing of G4VNestedParameterisation in G4OpenGLSceneHandler"
<< '\n' << mesh
<< G4endl;
}
// Instantiate a temporary G4PhysicalVolumeModel
G4ModelingParameters tmpMP;
tmpMP.SetCulling(true); // This avoids drawing transparent...
tmpMP.SetCullingInvisible(true); // ... or invisble volumes.
const G4bool useFullExtent = true; // To avoid calculating the extent
G4PhysicalVolumeModel tmpPVModel
(container,
G4PhysicalVolumeModel::UNLIMITED,
G4Transform3D(),
&tmpMP,
useFullExtent);
// Instantiate a pseudo scene so that we can make a "private" descent
// into the nested parameterisation and fill a multimap...
std::multimap<const G4Colour,G4ThreeVector> positionByColour;
G4double halfX = 0., halfY = 0., halfZ = 0.;
struct PseudoScene: public G4PseudoScene {
PseudoScene
(G4PhysicalVolumeModel* pvModel // input...the following are outputs
, std::multimap<const G4Colour,G4ThreeVector>& positionByColour
, G4double& halfX, G4double& halfY, G4double& halfZ)
: fpPVModel(pvModel)
, fPositionByColour(positionByColour)
, fHalfX(halfX), fHalfY(halfY), fHalfZ(halfZ)
{}
using G4PseudoScene::AddSolid; // except for...
void AddSolid(const G4Box& box) {
const G4Colour& colour = fpPVModel->GetCurrentLV()->GetVisAttributes()->GetColour();
const G4ThreeVector& position = fpCurrentObjectTransformation->getTranslation();
fPositionByColour.insert(std::make_pair(colour,position));
fHalfX = box.GetXHalfLength();
fHalfY = box.GetYHalfLength();
fHalfZ = box.GetZHalfLength();
}
G4PhysicalVolumeModel* fpPVModel;
std::multimap<const G4Colour,G4ThreeVector>& fPositionByColour;
G4double &fHalfX, &fHalfY, &fHalfZ;
}
pseudoScene(&tmpPVModel,positionByColour,halfX,halfY,halfZ);
// Make private descent into the nested parameterisation
tmpPVModel.DescribeYourselfTo(pseudoScene);
// Make list of found colours
std::set<G4Colour> setOfColours;
for (const auto& entry: positionByColour) {
setOfColours.insert(entry.first);
}
if (print) {
for (const auto& colour: setOfColours) {
G4cout << "setOfColours: " << colour << G4endl;
}
}
// Draw as dots
BeginPrimitives (mesh.GetTransform());
G4int nDotsTotal = 0;
for (const auto& colour: setOfColours) {
G4int nDots = 0;
G4Polymarker dots;
dots.SetVisAttributes(G4Colour(colour));
dots.SetMarkerType(G4Polymarker::dots);
dots.SetSize(G4VMarker::screen,1.);
dots.SetInfo(container->GetName());
const auto range = positionByColour.equal_range(colour);
for (auto posByCol = range.first; posByCol != range.second; ++posByCol) {
const G4double x = posByCol->second.getX() + (2.*G4UniformRand()-1.)*halfX;
const G4double y = posByCol->second.getY() + (2.*G4UniformRand()-1.)*halfY;
const G4double z = posByCol->second.getZ() + (2.*G4UniformRand()-1.)*halfZ;
dots.push_back(G4ThreeVector(x,y,z));
++nDots;
}
AddPrimitive(dots);
if (print) {
G4cout
<< "Number of dots for colour " << colour
<< ": " << nDots << G4endl;
}
nDotsTotal += nDots;
}
if (print) {
G4cout << "Total number of dots: " << nDotsTotal << G4endl;
}
EndPrimitives ();
firstPrint = false;
return;
}
void G4Qt3DSceneHandler::ClearStore ()
{
G4Qt3DUtils::delete_components_and_children_of_entity_recursively(fpQt3DScene);
@@ -1004,5 +1173,3 @@ void G4Qt3DSceneHandler::ClearTransientStore ()
{
G4Qt3DUtils::delete_components_and_children_of_entity_recursively(fpTransientObjects);
}
#endif // #if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
+4 -6
View File
@@ -25,8 +25,6 @@
//
// John Allison, 18th July 2020
#if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
#include "G4Qt3DUtils.hh"
#include "G4Qt3DQEntity.hh"
@@ -150,12 +148,14 @@ void G4Qt3DUtils::PrintQObjectTree
if (where.length()) logFile << "\n===== QObjectTree at " << where << std::endl;
static G4int iDep = -1;
++iDep;
const auto* g4node = dynamic_cast<const G4Qt3DQEntity*>(node);
G4String nodeName = node->objectName().toStdString();
if (nodeName == "") nodeName = "X";
for (G4int i = 0; i < iDep; ++i) logFile << " ";
logFile << (void*)node << ": "
<< "Node at depth " << iDep << ": " << nodeName << ": ";
<< "Node at depth " << iDep << ": " << nodeName << ": "
<< "thread: " << node->thread() << ": "
<< "parent: " << node->parent() << ": ";
const auto* g4node = dynamic_cast<const G4Qt3DQEntity*>(node);
if (g4node) {
logFile << g4node->GetPVNodeID() << std::endl;
} else {
@@ -178,5 +178,3 @@ void G4Qt3DUtils::PrintQObjectTree
return;
}
#endif
#endif // #if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
+61 -46
View File
@@ -25,8 +25,6 @@
//
// John Allison 17th June 2019
#if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)
#include "G4Qt3DViewer.hh"
#include "G4Qt3DSceneHandler.hh"
@@ -54,10 +52,6 @@ void G4Qt3DViewer::Initialise()
fVP.SetAutoRefresh(true);
fDefaultVP.SetAutoRefresh(true);
// Background is white (not figured out how to change it) so...
fVP.SetDefaultColour(G4Colour::Black());
fDefaultVP.SetDefaultColour(G4Colour::Black());
auto UI = G4UImanager::GetUIpointer();
auto uiQt = dynamic_cast<G4UIQt*>(UI->GetG4UIWindow());
if (!uiQt) {
@@ -67,6 +61,9 @@ void G4Qt3DViewer::Initialise()
return;
}
fUIWidget = QWidget::createWindowContainer(this);
fUIWidget->setMinimumSize(QSize(200, 100));
fUIWidget->setMaximumSize(screen()->size());
// fUIWidget->setFocusPolicy(Qt::NoFocus); //??
uiQt->AddTabWidget(fUIWidget,QString(fName));
setRootEntity(fQt3DSceneHandler.fpQt3DScene);
@@ -77,6 +74,9 @@ G4Qt3DViewer::~G4Qt3DViewer()
void G4Qt3DViewer::SetView()
{
// Background colour
defaultFrameGraph()->setClearColor(G4Qt3DUtils::ConvertToQColor(fVP.GetBackgroundColour()));
// Get radius of scene, etc.
// Note that this procedure properly takes into account zoom, dolly and pan.
const G4Point3D targetPoint
@@ -154,60 +154,77 @@ void G4Qt3DViewer::DrawView()
void G4Qt3DViewer::ShowView()
{
show();
// show() may only be called from master thread
if (G4Threading::IsMasterThread()) {
show();
}
// The way Qt seems to work, we don't seem to need a show() anyway, but
// we'll leave it in - it seems not to have any effect, good or bad.
}
void G4Qt3DViewer::FinishView()
{
show();
if (G4Threading::IsMasterThread()) {
show();
}
}
namespace {
QThread* masterQThread = nullptr;
QThread* visSubThreadQThread = nullptr;
}
# include <chrono>
void G4Qt3DViewer::MovingToVisSubThread()
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::MovingToVisSubThread" << G4endl;
#endif
// Still on master thread but vis thread has been launched
// Make note of master QThread
masterQThread = QThread::currentThread();
// Wait until SwitchToVisSubThread has found vis sub-thread QThread
std::this_thread::sleep_for(std::chrono::milliseconds(100));
// Move relevant stuff to vis sub-thread QThread
auto p1 = fQt3DSceneHandler.fpQt3DScene->parent();
auto p2 = p1->parent();
p2->moveToThread(visSubThreadQThread);
}
void G4Qt3DViewer::SwitchToVisSubThread()
{
// fUIWidget->moveToThread(QThread::currentThread());
// moveToThread(QThread::currentThread());
// fQt3DSceneHandler.fpQt3DScene->moveToThread(QThread::currentThread());
// fQt3DSceneHandler.fpTransientObjects->moveToThread(QThread::currentThread());
#ifdef G4QT3DDEBUG
// G4cout
// << "G4Qt3DViewer::SwitchToVisSubThread: (void*)fQt3DSceneHandler.fpQt3DScene: "
// << (void*)fQt3DSceneHandler.fpQt3DScene
// << G4endl;
G4cout << "G4Qt3DViewer::SwitchToVisSubThread" << G4endl;
#endif
// On vis sub-thread before any drawing
// Make note of vis-subthread QThread for MovingToVisSubThread
visSubThreadQThread = QThread::currentThread();
// Wait until SwitchToVisSubThread has moved stuff
std::this_thread::sleep_for(std::chrono::milliseconds(1000));
}
void G4Qt3DViewer::MovingToMasterThread()
{
#ifdef G4QT3DDEBUG
G4cout << "G4Qt3DViewer::MovingToMasterThread" << G4endl;
#endif
// On vis sub-thread just before exit
// Move relevant stuff to master QThread.
auto p1 = fQt3DSceneHandler.fpQt3DScene->parent();
auto p2 = p1->parent();
p2->moveToThread(masterQThread);
// Zero - will be different next run
visSubThreadQThread = nullptr;
}
void G4Qt3DViewer::SwitchToMasterThread()
{
// fUIWidget->moveToThread(QThread::currentThread());
// moveToThread(QThread::currentThread());
// fQt3DSceneHandler.fpQt3DScene->moveToThread(QThread::currentThread());
// fQt3DSceneHandler.fpTransientObjects->moveToThread(QThread::currentThread());
#ifdef G4QT3DDEBUG
// G4cout
// << "G4Qt3DViewer::SwitchToMasterThread: (void*)fQt3DSceneHandler.fpQt3DScene: "
// << (void*)fQt3DSceneHandler.fpQt3DScene
// << G4endl;
#endif
#ifdef G4MULTITHREADED
if (G4Threading::IsMultithreadedApplication()) {
// I have not figured out how to draw during a run. In fact, even attempting
// to fill nodes gives the error "Cannot create children for a parent that
// is in a different thread." So instead draw events from kept events.
//
// 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
}
G4cout << "G4Qt3DViewer::SwitchToMasterThread" << G4endl;
#endif
// On master thread after vis sub-thread has terminated
// Nothing to do
}
void G4Qt3DViewer::KernelVisitDecision () {
@@ -366,5 +383,3 @@ void G4Qt3DViewer::wheelEvent(QWheelEvent* ev)
SetView();
DrawView();
}
#endif // #if defined (G4VIS_BUILD_QT3D_DRIVER) || defined (G4VIS_USE_QT3D)