Import Geant4 11.0.0 source tree
This commit is contained in:
committed by
Ben Morgan
parent
6399a014b6
commit
80e2389dd8
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_QT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGQtGLES.hh"
|
||||
|
||||
//
|
||||
@@ -127,5 +125,3 @@ G4bool G4ToolsSGQtGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
#include "G4ToolsSGQtViewer.hh"
|
||||
#include "moc_G4ToolsSGQtViewer.cpp"
|
||||
|
||||
@@ -25,10 +25,10 @@
|
||||
//
|
||||
// John Allison 6th October 2020
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_DRIVER
|
||||
|
||||
#include "G4ToolsSGSceneHandler.hh"
|
||||
|
||||
#include "G4ToolsSGNode.hh"
|
||||
|
||||
#include "G4TransportationManager.hh"
|
||||
#include "G4Polyline.hh"
|
||||
#include "G4Polymarker.hh"
|
||||
@@ -36,8 +36,7 @@
|
||||
#include "G4Square.hh"
|
||||
#include "G4Polyhedron.hh"
|
||||
#include "G4Text.hh"
|
||||
|
||||
//#define G4TOOLSSG_DEBUG
|
||||
#include "G4PlotterManager.hh"
|
||||
|
||||
#include <tools/sg/separator>
|
||||
#include <tools/sg/matrix>
|
||||
@@ -46,13 +45,28 @@
|
||||
#include <tools/sg/atb_vertices>
|
||||
#include <tools/sg/markers>
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
#include <tools/sg/text_freetype_marker>
|
||||
#include <tools/sg/text_freetype>
|
||||
#include <tools/sg/strings>
|
||||
#include <tools/font/lato_regular_ttf>
|
||||
#include <tools/font/roboto_bold_ttf>
|
||||
#include <tools/sg/text_freetype_marker>
|
||||
#else
|
||||
#include <tools/sg/dummy_freetype>
|
||||
#include <tools/sg/text_hershey_marker>
|
||||
#endif
|
||||
|
||||
#include "G4ToolsSGNode.hh"
|
||||
//for plotting:
|
||||
#include <tools/sg/dummy_freetype>
|
||||
#include <tools/sg/light_off>
|
||||
#include <tools/sg/plots>
|
||||
#include <tools/sg/h2plot_cp>
|
||||
#include <tools/sg/plotter_style>
|
||||
#include <tools/sg/event_dispatcher>
|
||||
#include <tools/sg/path>
|
||||
#include <tools/sg/search>
|
||||
#include <tools/histo/h1d>
|
||||
#include <tools/histo/h2d>
|
||||
#include <tools/sg/plotter_some_styles>
|
||||
|
||||
#include <utility>
|
||||
|
||||
@@ -61,27 +75,35 @@ G4int G4ToolsSGSceneHandler::fSceneIdCount = 0;
|
||||
G4ToolsSGSceneHandler::G4ToolsSGSceneHandler
|
||||
(G4VGraphicsSystem& system, const G4String& name)
|
||||
:parent(system, fSceneIdCount++, name)
|
||||
,fFreetypeNode(0)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "G4ToolsSGSceneHandler::G4ToolsSGSceneHandler called" << G4endl;
|
||||
#endif
|
||||
fpToolsSGScene = new tools::sg::separator;
|
||||
//::printf("debug : G4ToolsSGSceneHandler : %lu, %s\n",this,name.c_str());
|
||||
EstablishBaseNodes();
|
||||
#if defined(TOOLS_USE_FREETYPE)
|
||||
fFreetypeNode = new tools::sg::text_freetype();
|
||||
fFreetypeNode->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
|
||||
fFreetypeNode->add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
|
||||
#else
|
||||
fFreetypeNode = new tools::sg::dummy_freetype();
|
||||
#endif
|
||||
Messenger::Create();
|
||||
}
|
||||
|
||||
G4ToolsSGSceneHandler::~G4ToolsSGSceneHandler()
|
||||
{
|
||||
delete fpToolsSGScene;
|
||||
//::printf("debug : ~G4ToolsSGSceneHandler : %lu\n",this);
|
||||
//WARNING : nodes may refer graphics managers (as tools/sg/[GL_manager,gl2ps_manager,zb_manager]
|
||||
// used by viewers) to handle gstos (for GPU) or textures, then we have to delete them first.
|
||||
// It is assumed that we pass here BEFORE the attached/managed viewers are deleted.
|
||||
fpTransient2DObjects.clear();
|
||||
fpPersistent2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
fpPersistent3DObjects.clear();
|
||||
delete fFreetypeNode;
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EstablishBaseNodes()
|
||||
{
|
||||
fpTransientObjects = new tools::sg::separator;
|
||||
fpToolsSGScene->add(fpTransientObjects);
|
||||
|
||||
fpPersistentObjects = new tools::sg::separator;
|
||||
fpToolsSGScene->add(fpPersistentObjects);
|
||||
|
||||
// Physical volume objects for each world hang from POs
|
||||
G4TransportationManager* transportationManager = G4TransportationManager::GetTransportationManager ();
|
||||
size_t nWorlds = transportationManager->GetNoWorlds();
|
||||
@@ -90,7 +112,7 @@ void G4ToolsSGSceneHandler::EstablishBaseNodes()
|
||||
for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
|
||||
G4VPhysicalVolume* _world = (*iterWorld);
|
||||
auto entity = new G4ToolsSGNode;
|
||||
fpPersistentObjects->add(entity);
|
||||
fpPersistent3DObjects.add(entity);
|
||||
entity->SetPVNodeID(G4PhysicalVolumeModel::G4PhysicalVolumeNodeID(_world));
|
||||
fpPhysicalVolumeObjects[i] = entity;
|
||||
}
|
||||
@@ -106,15 +128,15 @@ tools::sg::separator* G4ToolsSGSceneHandler::GetOrCreateNode()
|
||||
|
||||
if (fReadyForTransients) { // All transients hang from this node
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpTransientObjects->add(sep);
|
||||
fpTransient3DObjects.add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
G4PhysicalVolumeModel* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
auto* pPVModel = dynamic_cast<G4PhysicalVolumeModel*>(fpModel);
|
||||
|
||||
if (!pPVModel) { // Persistent objects (e.g., axes)
|
||||
tools::sg::separator* sep = new tools::sg::separator;
|
||||
fpPersistentObjects->add(sep);
|
||||
fpPersistent3DObjects.add(sep);
|
||||
return sep;
|
||||
}
|
||||
|
||||
@@ -172,88 +194,65 @@ tools::sg::separator* G4ToolsSGSceneHandler::GetOrCreateNode()
|
||||
return node;
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PreAddSolid
|
||||
(const G4Transform3D& objectTransformation,
|
||||
const G4VisAttributes& visAttribs)
|
||||
{
|
||||
parent::PreAddSolid(objectTransformation, visAttribs);
|
||||
void G4ToolsSGSceneHandler::ClearStore ()
|
||||
{
|
||||
fpTransient2DObjects.clear();
|
||||
fpPersistent2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
fpPersistent3DObjects.clear();
|
||||
EstablishBaseNodes();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::PostAddSolid()
|
||||
void G4ToolsSGSceneHandler::ClearTransientStore ()
|
||||
{
|
||||
parent::PostAddSolid();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::BeginPrimitives2D(const G4Transform3D& objectTransformation)
|
||||
{
|
||||
// The x,y coordinates of the primitives passed to AddPrimitive are
|
||||
// intrepreted as screen coordinates, -1 < x,y < 1. The
|
||||
// z-coordinate is ignored.
|
||||
static G4bool first = true;
|
||||
if (first) {
|
||||
first = false;
|
||||
G4Exception("G4ToolsSGSceneHandler::BeginPrimitives2D", "ToolsSG-0001",
|
||||
JustWarning,
|
||||
"2D drawing not yet implemented");
|
||||
}
|
||||
parent::BeginPrimitives2D (objectTransformation);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EndPrimitives2D ()
|
||||
{
|
||||
parent::EndPrimitives2D ();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::BeginPrimitives(const G4Transform3D& objectTransformation)
|
||||
{
|
||||
parent::BeginPrimitives(objectTransformation);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::EndPrimitives ()
|
||||
{
|
||||
parent::EndPrimitives ();
|
||||
fpTransient2DObjects.clear();
|
||||
fpTransient3DObjects.clear();
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline& a_polyline)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline&) : \n" << a_polyline << G4endl;
|
||||
#endif
|
||||
//G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline&) : \n" << a_polyline << G4endl;
|
||||
if (a_polyline.size() == 0) return;
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
tools::sg::separator* parentNode = 0;
|
||||
if(fProcessing2D) {
|
||||
parentNode = new tools::sg::separator;
|
||||
if (fReadyForTransients) {
|
||||
fpTransient2DObjects.add(parentNode);
|
||||
} else {
|
||||
fpPersistent2DObjects.add(parentNode);
|
||||
}
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyline.GetVisAttributes());
|
||||
} else {
|
||||
parentNode = GetOrCreateNode();
|
||||
if(!parentNode) return;
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
parentNode->add(mtx);
|
||||
}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
{const auto& colour = GetColour(a_polyline);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
float(colour.GetGreen()),
|
||||
float(colour.GetBlue()),
|
||||
float(colour.GetAlpha()));
|
||||
currentNode->add(mat);}
|
||||
parentNode->add(mat);}
|
||||
|
||||
{tools::sg::draw_style* ds = new tools::sg::draw_style;
|
||||
ds->style = tools::sg::draw_lines;
|
||||
ds->line_width = 1;
|
||||
currentNode->add(ds);}
|
||||
parentNode->add(ds);}
|
||||
|
||||
// Geometry :
|
||||
tools::sg::vertices* vtxs = new tools::sg::vertices;
|
||||
vtxs->mode = tools::gl::line_strip(); //polyline
|
||||
currentNode->add(vtxs);
|
||||
parentNode->add(vtxs);
|
||||
|
||||
{for (size_t i = 0; i < a_polyline.size(); ++i) {
|
||||
vtxs->add(float(a_polyline[i].x()),float(a_polyline[i].y()),float(a_polyline[i].z()));
|
||||
@@ -261,20 +260,14 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyline& a_polyline)
|
||||
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive (const G4Scale& a_scale) {parent::AddPrimitive(a_scale);}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
{
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug G4ToolsSGSceneHandler::AddPrimitive(const G4Polymarker&) : %lu, type %d\n",
|
||||
a_polymarker.size(),a_polymarker.GetMarkerType());
|
||||
#endif
|
||||
//::printf("debug G4ToolsSGSceneHandler::AddPrimitive(const G4Polymarker&) : %lu, type %d\n",
|
||||
// a_polymarker.size(),a_polymarker.GetMarkerType());
|
||||
if (a_polymarker.size() == 0) return;
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polymarker.GetVisAttributes());
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
G4Transform3D& elem = fObjectTransformation;
|
||||
@@ -284,8 +277,7 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
{const auto& colour = GetColour(a_polymarker);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
@@ -319,24 +311,6 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
markers->add(float(a_polymarker[i].x()),float(a_polymarker[i].y()),float(a_polymarker[i].z()));
|
||||
}
|
||||
currentNode->add(markers);}
|
||||
/*
|
||||
G4Circle circle (a_polymarker);
|
||||
G4double radius;
|
||||
if (circle.GetSizeType() == G4VMarker::world ) {
|
||||
radius = circle.GetWorldRadius();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
for (size_t iPoint = 0; iPoint < a_polymarker.size (); iPoint++) {
|
||||
auto position = fObjectTransformation*G4Translate3D(a_polymarker[iPoint]);
|
||||
auto node = new G4ToolsSGNode(currentNode);
|
||||
//node->addComponent(material);
|
||||
//node->addComponent(position);
|
||||
//node->addComponent(sphere); // Sphere of given radius
|
||||
}
|
||||
*/
|
||||
}break;
|
||||
case G4Polymarker::squares:{
|
||||
//::printf("debug : GB : Add Markers : +++++++++++++++++++++++++++++++++++++++++++ : square\n");
|
||||
@@ -347,78 +321,66 @@ void G4ToolsSGSceneHandler::AddPrimitive (const G4Polymarker& a_polymarker)
|
||||
markers->add(float(a_polymarker[i].x()),float(a_polymarker[i].y()),float(a_polymarker[i].z()));
|
||||
}
|
||||
currentNode->add(markers);}
|
||||
/*
|
||||
G4Square square (a_polymarker);
|
||||
G4double side;
|
||||
if (square.GetSizeType() == G4VMarker::world ) {
|
||||
side = square.GetWorldDiameter();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
side = square.GetScreenDiameter()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
for (size_t iPoint = 0; iPoint < a_polymarker.size (); iPoint++) {
|
||||
auto position = fObjectTransformation*G4Translate3D(a_polymarker[iPoint]);
|
||||
auto node = new G4ToolsSGNode(currentNode);
|
||||
//node->addComponent(material);
|
||||
//node->addComponent(position);
|
||||
//node->addComponent(box); // Cube of given side
|
||||
}
|
||||
*/
|
||||
}break;
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Text& a_text)
|
||||
{
|
||||
//static G4bool first = true;
|
||||
//if (first) {
|
||||
// first = false;
|
||||
// G4Exception("G4ToolsSGSceneHandler::AddPrimitive(const G4Text& text)",
|
||||
// "ToolsSG-0002", JustWarning,
|
||||
// "Text drawing not yet implemented");
|
||||
//}
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : \"%s\"\n",a_text.GetText().c_str());
|
||||
#endif
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_text.GetVisAttributes());
|
||||
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : 000 : \"%s\"\n",a_text.GetText().c_str());
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Text&) : 2D ? %d\n",fProcessing2D);
|
||||
auto pos = a_text.GetPosition();
|
||||
//::printf("debug : Add Text : pos %g %g %g\n",pos.x(),pos.y(),pos.z());
|
||||
|
||||
// Transformation
|
||||
{tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
auto elem = fObjectTransformation*G4Translate3D(a_text.GetPosition());
|
||||
//G4Transform3D& elem = fObjectTransformation*G4Translate3D(a_text.GetPosition());
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
currentNode->add(mtx);}
|
||||
tools::sg::separator* parentNode = 0;
|
||||
if(fProcessing2D) {
|
||||
parentNode = new tools::sg::separator;
|
||||
if (fReadyForTransients) {
|
||||
fpTransient2DObjects.add(parentNode);
|
||||
} else {
|
||||
fpPersistent2DObjects.add(parentNode);
|
||||
}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = GetColour();
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
mtx->set_translate(pos.x(),pos.y(),pos.z());
|
||||
parentNode->add(mtx);
|
||||
|
||||
} else {
|
||||
parentNode = GetOrCreateNode();
|
||||
if (!parentNode) return;
|
||||
|
||||
tools::sg::matrix* mtx = new tools::sg::matrix;
|
||||
auto elem = fObjectTransformation*G4Translate3D(pos);
|
||||
mtx->mtx.value().set_matrix(elem(0,0),elem(0,1),elem(0,2),elem(0,3),
|
||||
elem(1,0),elem(1,1),elem(1,2),elem(1,3),
|
||||
elem(2,0),elem(2,1),elem(2,2),elem(2,3),
|
||||
0, 0, 0, 1);
|
||||
parentNode->add(mtx);
|
||||
}
|
||||
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize(a_text, sizeType);
|
||||
|
||||
{const auto& colour = GetTextColour(a_text);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
float(colour.GetGreen()),
|
||||
float(colour.GetBlue()),
|
||||
float(colour.GetAlpha()));
|
||||
currentNode->add(mat);}
|
||||
|
||||
parentNode->add(mat);}
|
||||
|
||||
#ifdef TOOLS_USE_FREETYPE
|
||||
tools::sg::text_freetype_marker* text = new tools::sg::text_freetype_marker;
|
||||
text->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
|
||||
text->font = tools::sg::font_lato_regular_ttf();
|
||||
text->front_face = tools::sg::winding_cw;
|
||||
text->modeling = tools::sg::font_pixmap;
|
||||
//text->modeling = tools::sg::font_pixmap; //problem with Qt/GL. It slows rendering!
|
||||
#else
|
||||
tools::sg::text_hershey_marker* text = new tools::sg::text_hershey_marker;
|
||||
//text->encoding.value(a_encoding);
|
||||
#endif
|
||||
text->height = float(size); //pixels
|
||||
text->strings.add(a_text.GetText());
|
||||
{switch (a_text.GetLayout()) {
|
||||
default:
|
||||
@@ -433,24 +395,8 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Text& a_text)
|
||||
break;
|
||||
}}
|
||||
//text->vjust.value(a_vjust);
|
||||
currentNode->add(text);
|
||||
|
||||
/*
|
||||
//text.GetText(), text.GetXOffset(), etc.
|
||||
parentNode->add(text);
|
||||
|
||||
MarkerSizeType sizeType;
|
||||
G4double size = GetMarkerSize (text, sizeType);
|
||||
switch (sizeType) {
|
||||
default:
|
||||
case screen:
|
||||
// Draw in screen coordinates. OK.
|
||||
break;
|
||||
case world:
|
||||
// Draw in world coordinates. Not implemented. Use size = 20.
|
||||
size = 20.;
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Circle& a_circle)
|
||||
@@ -460,33 +406,6 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Circle& a_circle)
|
||||
oneCircle.SetMarkerType(G4Polymarker::circles);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4ToolsSGSceneHandler::AddPrimitive(oneCircle);
|
||||
|
||||
/*
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(circle.GetVisAttributes());
|
||||
|
||||
auto circleNode = new G4ToolsSGNode(currentNode);
|
||||
|
||||
// Transformation
|
||||
auto position = fObjectTransformation*G4Translate3D(circle.GetPosition());
|
||||
//circleNode->addComponent(position);
|
||||
|
||||
// Material (colour, etc.)
|
||||
const auto& colour = fpVisAttribs->GetColour();
|
||||
//circleNode->addComponent(colour);
|
||||
|
||||
G4double radius;
|
||||
if (circle.GetSizeType() == G4VMarker::world ) {
|
||||
radius =circle.GetWorldRadius();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
radius = circle.GetScreenRadius()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
//circleNode->addComponent(sphere); // Of given radius
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Square& a_square)
|
||||
@@ -496,42 +415,13 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Square& a_square)
|
||||
oneSquare.SetMarkerType(G4Polymarker::squares);
|
||||
// Call this AddPrimitive to avoid re-doing sub-class code.
|
||||
G4ToolsSGSceneHandler::AddPrimitive(oneSquare);
|
||||
|
||||
/*
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(square.GetVisAttributes());
|
||||
|
||||
auto squareNode = new G4ToolsSGNode(currentNode);
|
||||
|
||||
// Transformation
|
||||
auto position = fObjectTransformation*G4Translate3D(square.GetPosition());
|
||||
//squareNode->addComponent(position);
|
||||
|
||||
// Material (colour, etc.)
|
||||
const auto& colour = fpVisAttribs->GetColour();
|
||||
//squareNode->addComponent(colour);
|
||||
|
||||
G4double side;
|
||||
if (square.GetSizeType() == G4VMarker::world ) {
|
||||
side = square.GetWorldDiameter();
|
||||
} else { // Screen-size or none
|
||||
// Not figured out how to do screen-size, so use scene extent
|
||||
const G4double scale = 200.; // Roughly pixles per scene
|
||||
side = square.GetScreenDiameter()*fpScene->GetExtent().GetExtentRadius()/scale;
|
||||
}
|
||||
//squareNode->addComponent(cube); // Of given side
|
||||
*/
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
{
|
||||
if (a_polyhedron.GetNoFacets() == 0) return;
|
||||
|
||||
#ifdef G4TOOLSSG_DEBUG
|
||||
::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron&) : %d\n",a_polyhedron.GetNoFacets());
|
||||
#endif
|
||||
//::printf("debug : G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron&) : %d\n",a_polyhedron.GetNoFacets());
|
||||
|
||||
fpVisAttribs = fpViewer->GetApplicableVisAttributes(a_polyhedron.GetVisAttributes());
|
||||
|
||||
@@ -630,8 +520,7 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
0, 0, 0, 1);
|
||||
sep->add(mtx);}
|
||||
|
||||
// Material (colour, etc.)
|
||||
{const auto& colour = fpVisAttribs->GetColour();
|
||||
{const auto& colour = GetColour(a_polyhedron);
|
||||
tools::sg::rgba* mat = new tools::sg::rgba();
|
||||
mat->color =
|
||||
tools::colorf(float(colour.GetRed()),
|
||||
@@ -681,15 +570,262 @@ void G4ToolsSGSceneHandler::AddPrimitive(const G4Polyhedron& a_polyhedron)
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearStore ()
|
||||
{
|
||||
fpToolsSGScene->clear();
|
||||
EstablishBaseNodes();
|
||||
//plotting:
|
||||
inline void SetRegionStyles(tools::xml::styles& a_styles,
|
||||
tools::sg::plots& a_plots,
|
||||
tools::sg::plotter& a_plotter,
|
||||
const G4String& a_style) {
|
||||
if(a_style=="reset") {
|
||||
a_plotter.reset_style(true);
|
||||
a_plots.touch(); //to apply indirectly plots::set_plotter_layout() on _plotter.
|
||||
} else if( (a_style=="inlib_default")|| (a_style=="default")) {
|
||||
tools::sg::set_inlib_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
|
||||
} else if(a_style=="ROOT_default") {
|
||||
tools::sg::set_ROOT_default_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
|
||||
} else if(a_style=="hippodraw") {
|
||||
tools::sg::set_hippodraw_style(G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
|
||||
} else {
|
||||
tools::sg::style_from_res(a_styles,a_style,a_plotter,false);
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::ClearTransientStore ()
|
||||
{
|
||||
fpTransientObjects->clear();
|
||||
inline tools::xml::styles::style_t* find_style(tools::xml::styles& a_styles,const std::string& a_name) {
|
||||
tools_vforit(tools::xml::styles::named_style_t,a_styles.named_styles(),it){
|
||||
if((*it).first==a_name) return &((*it).second);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
inline void SetPlotterStyles(tools::sg::plots& a_plots,
|
||||
const std::vector<G4String>& a_plotter_styles,
|
||||
const std::vector<G4Plotter::RegionStyle>& a_region_styles) {
|
||||
|
||||
G4PlotterManager::Styles& _styles = G4PlotterManager::GetInstance().GetStyles();
|
||||
|
||||
tools::xml::styles _tools_styles(G4cout);
|
||||
_tools_styles.add_colormap("default",tools::sg::style_default_colormap());
|
||||
_tools_styles.add_colormap("ROOT",tools::sg::style_ROOT_colormap());
|
||||
|
||||
{tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
|
||||
tools::xml::styles::style_t _tools_style;
|
||||
tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
|
||||
const G4String& param = (*its).first;
|
||||
if(param.find('.')==std::string::npos) {
|
||||
const G4String& value = (*its).second;
|
||||
_tools_style.push_back(tools::xml::styles::style_item_t(param,value));
|
||||
}
|
||||
}
|
||||
_tools_styles.add_style((*it).first,_tools_style);
|
||||
}}
|
||||
|
||||
// sub styles:
|
||||
{tools_vforcit(G4PlotterManager::NamedStyle,_styles,it) {
|
||||
tools_vforcit(G4PlotterManager::StyleItem,(*it).second,its) {
|
||||
const G4String& param = (*its).first;
|
||||
std::string::size_type pos = param.rfind('.');
|
||||
if(pos!=std::string::npos) {
|
||||
std::string sub_style = (*it).first+"."+param.substr(0,pos);
|
||||
G4String parameter = param.substr(pos+1,param.size()-pos);
|
||||
const G4String& value = (*its).second;
|
||||
tools::xml::styles::style_t* _tools_style = find_style(_tools_styles,sub_style);
|
||||
if(_tools_style) {
|
||||
_tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
|
||||
} else {
|
||||
tools::xml::styles::style_t _tools_style_2;
|
||||
_tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
|
||||
_tools_styles.add_style(sub_style,_tools_style_2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
{unsigned int number = a_plots.number();
|
||||
for(unsigned int index=0;index<number;index++) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter(index);
|
||||
if(_plotter) {
|
||||
tools_vforcit(G4String,a_plotter_styles,it) {
|
||||
SetRegionStyles(_tools_styles,a_plots,*_plotter,*it);
|
||||
}
|
||||
}
|
||||
}}
|
||||
{tools_vforcit(G4Plotter::RegionStyle,a_region_styles,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
SetRegionStyles(_tools_styles,a_plots,*_plotter,(*it).second);
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
inline void SetPlotterParameters(tools::sg::cmaps_t& a_cmaps,tools::sg::plots& a_plots,
|
||||
const std::vector<G4Plotter::RegionParameter>& a_region_parameters) {
|
||||
// parameter/field examples :
|
||||
// title_automated
|
||||
// title
|
||||
// bins_style.0.color
|
||||
// x_axis.divisions
|
||||
// x_axis.line_style.color
|
||||
// background_style.back_color
|
||||
tools_vforcit(G4Plotter::RegionParameter,a_region_parameters,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
const G4String& parameter = (*it).second.first;
|
||||
const G4String& value = (*it).second.second;
|
||||
tools::sg::field* fd = _plotter->find_field_by_name(parameter);
|
||||
if(!fd) fd = _plotter->find_field_by_name(_plotter->s_cls()+"."+parameter);
|
||||
if(fd) {if(fd->s2value(value)) continue;}
|
||||
// look for sf_enum for which value is given with a string, or
|
||||
// for sf<bool> for which value given with true/false, or
|
||||
// for a style, for example: bins_style.0.color:
|
||||
if(!_plotter->set_from_string(G4cout,a_cmaps,parameter,value)) {
|
||||
G4cout << "G4ToolsSGSceneHandler::SetPlotterParameters: plotter.set_from_string() failed for field "
|
||||
<< tools::sout(parameter) << ", and value " << tools::sout(value) << "."
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#include "G4UImanager.hh"
|
||||
|
||||
void G4ToolsSGSceneHandler::SetPlotterHistograms(tools::sg::plots& a_plots) {
|
||||
a_plots.clear();
|
||||
G4UImanager* UI = G4UImanager::GetUIpointer();
|
||||
if(UI==NULL) return;
|
||||
{tools_vforcit(Region_h1,fRegionH1s,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
int hid = (*it).second;
|
||||
std::ostringstream os;
|
||||
os << hid;
|
||||
std::string cmd("/analysis/h1/get ");
|
||||
cmd += std::string(os.str());
|
||||
G4int status = UI->ApplyCommand(cmd.c_str());
|
||||
if(status==G4UIcommandStatus::fCommandSucceeded) {
|
||||
G4String hexString = UI->GetCurrentValues("/analysis/h1/get");
|
||||
if(hexString.size()) {
|
||||
void* ptr;
|
||||
std::istringstream is(hexString);
|
||||
is >> ptr;
|
||||
tools::histo::h1d* _h = (tools::histo::h1d*)ptr;
|
||||
tools::sg::plottable* p = new tools::sg::h1d2plot_cp(*_h);
|
||||
_plotter->add_plottable(p); //give ownership of p to sg::plotter.
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
{tools_vforcit(Region_h2,fRegionH2s,it) {
|
||||
tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
|
||||
if(_plotter) {
|
||||
int hid = (*it).second;
|
||||
std::ostringstream os;
|
||||
os << hid;
|
||||
std::string cmd("/analysis/h2/get ");
|
||||
cmd += std::string(os.str());
|
||||
G4int status = UI->ApplyCommand(cmd.c_str());
|
||||
if(status==G4UIcommandStatus::fCommandSucceeded) {
|
||||
G4String hexString = UI->GetCurrentValues("/analysis/h2/get");
|
||||
if(hexString.size()) {
|
||||
void* ptr;
|
||||
std::istringstream is(hexString);
|
||||
is >> ptr;
|
||||
tools::histo::h2d* _h = (tools::histo::h2d*)ptr;
|
||||
tools::sg::plottable* p = new tools::sg::h2d2plot_cp(*_h);
|
||||
_plotter->add_plottable(p); //give ownership of p to sg::plotter.
|
||||
}
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
class plots_cbk : public tools::sg::ecbk {
|
||||
TOOLS_CBK(plots_cbk,plots_cbk,tools::sg::ecbk)
|
||||
public:
|
||||
virtual tools::sg::return_action action() {
|
||||
if(const tools::sg::size_event* sz_evt = tools::sg::event_cast<tools::sg::event,tools::sg::size_event>(*m_event)){
|
||||
m_plots.adjust_size(sz_evt->width(),sz_evt->height());
|
||||
m_event_action->set_done(true);
|
||||
return tools::sg::return_to_render;
|
||||
}
|
||||
return tools::sg::return_none;
|
||||
}
|
||||
public:
|
||||
plots_cbk(tools::sg::plots& a_plots)
|
||||
:parent()
|
||||
,m_plots(a_plots)
|
||||
{}
|
||||
virtual ~plots_cbk(){}
|
||||
public:
|
||||
plots_cbk(const plots_cbk& a_from)
|
||||
:parent(a_from)
|
||||
,m_plots(a_from.m_plots)
|
||||
{}
|
||||
plots_cbk& operator=(const plots_cbk& a_from){
|
||||
parent::operator=(a_from);
|
||||
return *this;
|
||||
}
|
||||
protected:
|
||||
tools::sg::plots& m_plots;
|
||||
};
|
||||
|
||||
void G4ToolsSGSceneHandler::TouchPlotters(tools::sg::node& a_sg) {
|
||||
tools::sg::search_action sa(G4cout);
|
||||
const tools::sg::search_action::paths_t& paths = tools::sg::find_paths<tools::sg::plots>(sa,a_sg);
|
||||
tools_vforcit(tools::sg::path_t,paths,it) {
|
||||
tools::sg::plots* _plots = tools::sg::tail<tools::sg::plots>(*it);
|
||||
if(_plots) {
|
||||
SetPlotterHistograms(*_plots);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::AddPrimitive(const G4Plotter& a_plotter)
|
||||
{
|
||||
//G4cout << "debug : G4ToolsSGSceneHandler::AddPrimitive : 004" << std::endl;
|
||||
if(!fpViewer) return;
|
||||
|
||||
auto currentNode = GetOrCreateNode();
|
||||
if (!currentNode) return; // Node not available
|
||||
|
||||
currentNode->add(new tools::sg::light_off());
|
||||
|
||||
tools::sg::plots* _plots = new tools::sg::plots(*fFreetypeNode);
|
||||
currentNode->add(_plots);
|
||||
|
||||
_plots->view_border = false;
|
||||
_plots->set_regions(a_plotter.GetColumns(),a_plotter.GetRows());
|
||||
|
||||
{tools::sg::event_dispatcher* dpt = new tools::sg::event_dispatcher;
|
||||
dpt->add_callback(new plots_cbk(*_plots));
|
||||
currentNode->add(dpt);}
|
||||
|
||||
SetPlotterStyles(*_plots,a_plotter.GetStyles(),a_plotter.GetRegionStyles());
|
||||
|
||||
tools::sg::cmaps_t _cmaps;
|
||||
_cmaps["default"] = tools::sg::style_default_colormap();
|
||||
_cmaps["ROOT"] = tools::sg::style_ROOT_colormap();
|
||||
|
||||
SetPlotterParameters(_cmaps,*_plots,a_plotter.GetRegionParameters());
|
||||
|
||||
fRegionH1s = a_plotter.GetRegionH1s();
|
||||
fRegionH2s = a_plotter.GetRegionH2s();
|
||||
|
||||
SetPlotterHistograms(*_plots);
|
||||
}
|
||||
|
||||
void G4ToolsSGSceneHandler::Messenger::SetNewValue(G4UIcommand* a_cmd,G4String) {
|
||||
G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler();
|
||||
if (!pSceneHandler) {
|
||||
G4cout << "G4ToolsSGSceneHandler::Messenger::SetNewValue: no current sceneHandler. Please create one." << G4endl;
|
||||
return;
|
||||
}
|
||||
auto* tsg_scene_handler = dynamic_cast<G4ToolsSGSceneHandler*>(pSceneHandler);
|
||||
if(!tsg_scene_handler) {
|
||||
G4cout << "G4ToolsSGSceneHandler::Messenger::SetNewValue: current sceneHandler not a G4ToolsSGSceneHandler." << G4endl;
|
||||
return;
|
||||
}
|
||||
if(a_cmd==print_plotter_params) {
|
||||
tools::sg::dummy_freetype _ttf;
|
||||
tools::sg::plotter _plotter(_ttf);
|
||||
_plotter.print_available_customization(G4cout);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 6th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_WINDOWS_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGWindowsGLES.hh"
|
||||
|
||||
@@ -113,5 +112,3 @@ G4bool G4ToolsSGWindowsGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_X11_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGX11GLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
@@ -115,5 +113,3 @@ G4bool G4ToolsSGX11GLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -25,8 +25,6 @@
|
||||
//
|
||||
// Guy Barrand 12th March 2021
|
||||
|
||||
#ifdef G4VIS_BUILD_TOOLSSG_XT_GLES_DRIVER
|
||||
|
||||
#include "G4ToolsSGXtGLES.hh"
|
||||
|
||||
#include "G4ToolsSGViewer.hh"
|
||||
@@ -137,5 +135,3 @@ G4bool G4ToolsSGXtGLES::IsUISessionCompatible () const
|
||||
// }
|
||||
return isCompatible;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user