42#include <tools/sg/separator>
43#include <tools/sg/matrix>
44#include <tools/sg/rgba>
45#include <tools/sg/draw_style>
46#include <tools/sg/atb_vertices>
47#include <tools/sg/markers>
48#ifdef TOOLS_USE_FREETYPE
49#include <toolx/sg/text_freetype>
50#include <tools/sg/strings>
51#include <tools/font/lato_regular_ttf>
52#include <tools/font/roboto_bold_ttf>
53#include <toolx/sg/text_freetype_marker>
55#include <tools/sg/dummy_freetype>
56#include <tools/sg/text_hershey_marker>
60#include <tools/sg/dummy_freetype>
61#include <tools/sg/light_off>
62#include <tools/sg/plots>
63#include <tools/sg/h2plot_cp>
64#include <tools/sg/plotter_style>
65#include <tools/sg/event_dispatcher>
66#include <tools/sg/path>
67#include <tools/sg/search>
68#include <tools/histo/h1d>
69#include <tools/histo/h2d>
70#include <tools/sg/plotter_some_styles>
78:
parent(system, fSceneIdCount++, name)
83#if defined(TOOLS_USE_FREETYPE)
85 fFreetypeNode->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
86 fFreetypeNode->add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
110 size_t nWorlds = transportationManager->
GetNoWorlds();
111 std::vector<G4VPhysicalVolume*>::iterator iterWorld = transportationManager->
GetWorldsIterator();
113 for (
size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
126#ifdef G4MULTITHREADED
131 tools::sg::separator* sep =
new tools::sg::separator;
139 tools::sg::separator* sep =
new tools::sg::separator;
146 typedef std::vector<PVNodeID> PVPath;
148 const PVPath& fullPVPath = pPVModel->GetFullPVPath();
158 for (; iWorld < nWorlds; ++iWorld) {
159 if (fullPVPath[0].GetPhysicalVolume() ==
162 if (iWorld == nWorlds) {
164 "World mis-match - not possible(!?)");
173 const size_t depth = fullPVPath.size();
175 while (iDepth < depth) {
176 const auto& children = node->children();
177 const G4int nChildren = (
G4int)children.size();
180 for (; iChild < nChildren; ++iChild) {
182 if (child->
GetPVNodeID() == fullPVPath[iDepth])
break;
184 if (iChild != nChildren) {
216 if (a_polyline.size() == 0)
return;
218 tools::sg::separator* parentNode = 0;
220 parentNode =
new tools::sg::separator;
229 if(!parentNode)
return;
231 tools::sg::matrix* mtx =
new tools::sg::matrix;
237 parentNode->add(mtx);
240 {
const auto& colour =
GetColour(a_polyline);
241 tools::sg::rgba* mat =
new tools::sg::rgba();
243 tools::colorf(
float(colour.GetRed()),
244 float(colour.GetGreen()),
245 float(colour.GetBlue()),
246 float(colour.GetAlpha()));
247 parentNode->add(mat);}
249 {tools::sg::draw_style* ds =
new tools::sg::draw_style;
250 ds->style = tools::sg::draw_lines;
252 parentNode->add(ds);}
254 tools::sg::vertices* vtxs =
new tools::sg::vertices;
255 vtxs->mode = tools::gl::line_strip();
256 parentNode->add(vtxs);
258 {
for (
size_t i = 0; i < a_polyline.size(); ++i) {
259 vtxs->add(
float(a_polyline[i].x()),
float(a_polyline[i].y()),
float(a_polyline[i].z()));
268 if (a_polymarker.size() == 0)
return;
270 if (!currentNode)
return;
273 {tools::sg::matrix* mtx =
new tools::sg::matrix;
279 currentNode->add(mtx);}
281 {
const auto& colour =
GetColour(a_polymarker);
282 tools::sg::rgba* mat =
new tools::sg::rgba();
284 tools::colorf(
float(colour.GetRed()),
285 float(colour.GetGreen()),
286 float(colour.GetBlue()),
287 float(colour.GetAlpha()));
288 currentNode->add(mat);}
297 tools::sg::draw_style* ds =
new tools::sg::draw_style;
298 ds->style = tools::sg::draw_points;
300 currentNode->add(ds);
301 tools::sg::vertices* vtxs =
new tools::sg::vertices;
302 vtxs->mode = tools::gl::points();
303 {
for (
size_t i = 0; i < a_polymarker.size(); ++i) {
304 vtxs->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
306 currentNode->add(vtxs);
310 {tools::sg::markers* markers =
new tools::sg::markers;
316 markers->size = diameter;
317 markers->style = tools::sg::marker_circle_line;
318 for (
size_t i = 0; i < a_polymarker.size(); ++i) {
319 markers->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
321 currentNode->add(markers);}
325 {tools::sg::markers* markers =
new tools::sg::markers;
331 markers->size = side;
332 markers->style = tools::sg::marker_square_line;
333 for (
size_t i = 0; i < a_polymarker.size(); ++i) {
334 markers->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
336 currentNode->add(markers);}
348 tools::sg::separator* parentNode = 0;
350 parentNode =
new tools::sg::separator;
357 tools::sg::matrix* mtx =
new tools::sg::matrix;
358 mtx->set_translate(pos.x(),pos.y(),pos.z());
359 parentNode->add(mtx);
363 if (!parentNode)
return;
365 tools::sg::matrix* mtx =
new tools::sg::matrix;
371 parentNode->add(mtx);
378 tools::sg::rgba* mat =
new tools::sg::rgba();
380 tools::colorf(
float(colour.GetRed()),
381 float(colour.GetGreen()),
382 float(colour.GetBlue()),
383 float(colour.GetAlpha()));
384 parentNode->add(mat);}
386#ifdef TOOLS_USE_FREETYPE
387 toolx::sg::text_freetype_marker* text =
new toolx::sg::text_freetype_marker;
388 text->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
389 text->font = tools::sg::font_lato_regular_ttf();
390 text->front_face = tools::sg::winding_cw;
393 tools::sg::text_hershey_marker* text =
new tools::sg::text_hershey_marker;
396 text->height = float(size);
397 text->strings.add(a_text.
GetText());
401 text->hjust = tools::sg::left;
404 text->hjust = tools::sg::center;
407 text->hjust = tools::sg::right;
411 parentNode->add(text);
448 std::vector<G4Point3D> vertices;
449 std::vector<G4Normal3D> normals;
453 typedef std::pair<G4Point3D,G4Point3D> Line;
454 std::vector<Line> lines;
455 auto insertIfNew = [&lines](
const Line& newLine) {
461 lines.push_back(newLine);
471 notLastFace = a_polyhedron.
GetNextFacet(nEdges, vertex, edgeFlag, normal);
472 vertices.push_back(vertex[0]);
473 vertices.push_back(vertex[1]);
474 vertices.push_back(vertex[2]);
475 normals.push_back(normal[0]);
476 normals.push_back(normal[1]);
477 normals.push_back(normal[2]);
478 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
479 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
483 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
484 }
else if (nEdges == 4) {
487 vertices.push_back(vertex[2]);
488 vertices.push_back(vertex[3]);
489 vertices.push_back(vertex[0]);
490 normals.push_back(normal[2]);
491 normals.push_back(normal[3]);
492 normals.push_back(normal[0]);
493 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
494 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
497 <<
"ERROR: polyhedron face with unexpected number of edges (" << nEdges <<
')'
502 }
while (notLastFace);
505 switch (drawing_style) {
522 if (!currentNode)
return;
524 tools::sg::separator* sep =
new tools::sg::separator;
525 currentNode->add(sep);
528 {tools::sg::matrix* mtx =
new tools::sg::matrix;
536 {
const auto& colour =
GetColour(a_polyhedron);
537 tools::sg::rgba* mat =
new tools::sg::rgba();
539 tools::colorf(
float(colour.GetRed()),
540 float(colour.GetGreen()),
541 float(colour.GetBlue()),
542 float(colour.GetAlpha()));
549 {tools::sg::draw_style* ds =
new tools::sg::draw_style;
550 ds->style = tools::sg::draw_filled;
554 tools::sg::atb_vertices* vtxs =
new tools::sg::atb_vertices;
555 vtxs->mode = tools::gl::triangles();
558 const auto nVerts = vertices.size();
559 for (
size_t i = 0; i < nVerts; i++) {
560 vtxs->add(
float(vertices[i].x()),
float(vertices[i].y()),
float(vertices[i].z()));
561 vtxs->add_normal(
float(normals[i].x()),
float(normals[i].y()),
float(normals[i].z()));
569 {tools::sg::draw_style* ds =
new tools::sg::draw_style;
570 ds->style = tools::sg::draw_lines;
574 tools::sg::vertices* vtxs =
new tools::sg::vertices;
575 vtxs->mode = tools::gl::lines();
578 for (
const auto& line: lines) {
579 vtxs->add(
float(line.first.x()),
float(line.first.y()),
float(line.first.z()));
580 vtxs->add(
float(line.second.x()),
float(line.second.y()),
float(line.second.z()));
593 tools::sg::plots& a_plots,
594 tools::sg::plotter& a_plotter,
596 if(a_style==
"reset") {
597 a_plotter.reset_style(
true);
599 }
else if( (a_style==
"inlib_default")|| (a_style==
"default")) {
600 tools::sg::set_inlib_default_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
601 }
else if(a_style==
"ROOT_default") {
602 tools::sg::set_ROOT_default_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
603 }
else if(a_style==
"hippodraw") {
604 tools::sg::set_hippodraw_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
606 tools::sg::style_from_res(a_styles,a_style,a_plotter,
false);
610inline tools::xml::styles::style_t*
find_style(tools::xml::styles& a_styles,
const std::string& a_name) {
611 tools_vforit(tools::xml::styles::named_style_t,a_styles.named_styles(),it){
612 if((*it).first==a_name)
return &((*it).second);
618 const std::vector<G4String>& a_plotter_styles,
619 const std::vector<G4Plotter::RegionStyle>& a_region_styles) {
623 tools::xml::styles _tools_styles(
G4cout);
624 _tools_styles.add_colormap(
"default",tools::sg::style_default_colormap());
625 _tools_styles.add_colormap(
"ROOT",tools::sg::style_ROOT_colormap());
628 tools::xml::styles::style_t _tools_style;
630 const G4String& param = (*its).first;
631 if(param.find(
'.')==std::string::npos) {
632 const G4String& value = (*its).second;
633 _tools_style.push_back(tools::xml::styles::style_item_t(param,value));
636 _tools_styles.add_style((*it).first,_tools_style);
642 const G4String& param = (*its).first;
643 std::string::size_type pos = param.rfind(
'.');
644 if(pos!=std::string::npos) {
645 std::string sub_style = (*it).first+
"."+param.substr(0,pos);
646 G4String parameter = param.substr(pos+1,param.size()-pos);
647 const G4String& value = (*its).second;
648 tools::xml::styles::style_t* _tools_style =
find_style(_tools_styles,sub_style);
650 _tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
652 tools::xml::styles::style_t _tools_style_2;
653 _tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
654 _tools_styles.add_style(sub_style,_tools_style_2);
660 {
unsigned int number = a_plots.number();
661 for(
unsigned int index=0;index<number;index++) {
662 tools::sg::plotter* _plotter = a_plots.find_plotter(index);
664 tools_vforcit(
G4String,a_plotter_styles,it) {
670 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
678 const std::vector<G4Plotter::RegionParameter>& a_region_parameters) {
687 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
689 const G4String& parameter = (*it).second.first;
690 const G4String& value = (*it).second.second;
691 tools::sg::field* fd = _plotter->find_field_by_name(parameter);
692 if(!fd) fd = _plotter->find_field_by_name(_plotter->s_cls()+
"."+parameter);
693 if(fd) {
if(fd->s2value(value))
continue;}
697 if(!_plotter->set_from_string(
G4cout,a_cmaps,parameter,value)) {
698 G4cout <<
"G4ToolsSGSceneHandler::SetPlotterParameters: plotter.set_from_string() failed for field "
699 << tools::sout(parameter) <<
", and value " << tools::sout(value) <<
"."
713 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
715 int hid = (*it).second;
716 std::ostringstream os;
718 std::string cmd(
"/analysis/h1/get ");
719 cmd += std::string(os.str());
726 if(hexString.size()) {
728 std::istringstream is(hexString);
730 tools::histo::h1d* _h = (tools::histo::h1d*)ptr;
731 tools::sg::plottable* p =
new tools::sg::h1d2plot_cp(*_h);
732 _plotter->add_plottable(p);
736 "G4ToolsSGSceneHandler::SetPlotterHistograms: cannot get histogram - maybe doesn't exist?"
737 "\n Maybe this app does not do analysis at all?"
743 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
745 int hid = (*it).second;
746 std::ostringstream os;
748 std::string cmd(
"/analysis/h2/get ");
749 cmd += std::string(os.str());
756 if(hexString.size()) {
758 std::istringstream is(hexString);
760 tools::histo::h2d* _h = (tools::histo::h2d*)ptr;
761 tools::sg::plottable* p =
new tools::sg::h2d2plot_cp(*_h);
762 _plotter->add_plottable(p);
766 "G4ToolsSGSceneHandler::SetPlotterHistograms: cannot get histogram - maybe doesn't exist?"
767 "\n Maybe this app does not do analysis at all?"
777 virtual tools::sg::return_action
action() {
778 if(
const tools::sg::size_event* sz_evt = tools::sg::event_cast<tools::sg::event,tools::sg::size_event>(*m_event)){
779 m_plots.adjust_size(sz_evt->width(),sz_evt->height());
780 m_event_action->set_done(
true);
781 return tools::sg::return_to_render;
783 return tools::sg::return_none;
797 parent::operator=(a_from);
805 tools::sg::search_action sa(
G4cout);
806 const tools::sg::search_action::paths_t& paths = tools::sg::find_paths<tools::sg::plots>(sa,a_sg);
807 tools_vforcit(tools::sg::path_t,paths,it) {
808 tools::sg::plots* _plots = tools::sg::tail<tools::sg::plots>(*it);
821 if (!currentNode)
return;
823 currentNode->add(
new tools::sg::light_off());
825 tools::sg::plots* _plots =
new tools::sg::plots(*
fFreetypeNode);
826 currentNode->add(_plots);
828 _plots->view_border =
false;
831 {tools::sg::event_dispatcher* dpt =
new tools::sg::event_dispatcher;
832 dpt->add_callback(
new plots_cbk(*_plots));
833 currentNode->add(dpt);}
837 tools::sg::cmaps_t _cmaps;
838 _cmaps[
"default"] = tools::sg::style_default_colormap();
839 _cmaps[
"ROOT"] = tools::sg::style_ROOT_colormap();
851 if (!pSceneHandler) {
852 G4cout <<
"G4ToolsSGSceneHandler::Messenger::SetNewValue: no current sceneHandler. Please create one." <<
G4endl;
856 if(!tsg_scene_handler) {
857 G4cout <<
"G4ToolsSGSceneHandler::Messenger::SetNewValue: current sceneHandler not a G4ToolsSGSceneHandler." <<
G4endl;
860 if(a_cmd==print_plotter_params) {
861 tools::sg::dummy_freetype _ttf;
862 tools::sg::plotter _plotter(_ttf);
863 _plotter.print_available_customization(
G4cout);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
std::vector< NamedStyle > Styles
std::pair< G4String, Style > NamedStyle
std::pair< G4String, G4String > StyleItem
static G4PlotterManager & GetInstance()
const Styles & GetStyles() const
std::pair< unsigned int, G4String > RegionStyle
unsigned int GetRows() const
const std::vector< RegionParameter > & GetRegionParameters() const
const std::vector< G4String > & GetStyles() const
const std::vector< Region_h2 > & GetRegionH2s() const
const std::vector< RegionStyle > & GetRegionStyles() const
std::pair< unsigned int, Parameter > RegionParameter
const std::vector< Region_h1 > & GetRegionH1s() const
unsigned int GetColumns() const
void SetMarkerType(MarkerType)
MarkerType GetMarkerType() const
const G4VisExtent & GetExtent() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const
G4int ApplyCommand(const char *aCommand)
G4int GetVerboseLevel() const
G4String GetCurrentValues(const char *aCommand)
static G4UImanager * GetUIpointer()
void SetVerboseLevel(G4int val)
G4Point3D GetPosition() const
virtual G4String GetCurrentTag() const
const G4Colour & GetTextColour(const G4Text &)
const G4Colour & GetColour()
G4Transform3D fObjectTransformation
G4double GetMarkerSize(const G4VMarker &, MarkerSizeType &)
const G4VisAttributes * fpVisAttribs
G4bool fReadyForTransients
G4ViewParameters::DrawingStyle GetDrawingStyle(const G4VisAttributes *)
void StandardSpecialMeshRendering(const G4Mesh &)
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4ViewParameters & GetViewParameters() const
static G4VisManager * GetVisManager()
G4bool IsAuxEdgeVisible() const
G4double GetExtentRadius() const
G4VSceneHandler * GetCurrentSceneHandler() const
const G4VisAttributes * GetVisAttributes() const
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=nullptr, G4Normal3D *normals=nullptr) const
plots_cbk(const plots_cbk &a_from)
plots_cbk(tools::sg::plots &a_plots)
virtual tools::sg::return_action action()
plots_cbk & operator=(const plots_cbk &a_from)
tools::sg::plots & m_plots