41#include <tools/sg/separator>
42#include <tools/sg/matrix>
43#include <tools/sg/rgba>
44#include <tools/sg/draw_style>
45#include <tools/sg/atb_vertices>
46#include <tools/sg/markers>
47#ifdef TOOLS_USE_FREETYPE
48#include <tools/sg/text_freetype>
49#include <tools/sg/strings>
50#include <tools/font/lato_regular_ttf>
51#include <tools/font/roboto_bold_ttf>
52#include <tools/sg/text_freetype_marker>
54#include <tools/sg/dummy_freetype>
55#include <tools/sg/text_hershey_marker>
59#include <tools/sg/dummy_freetype>
60#include <tools/sg/light_off>
61#include <tools/sg/plots>
62#include <tools/sg/h2plot_cp>
63#include <tools/sg/plotter_style>
64#include <tools/sg/event_dispatcher>
65#include <tools/sg/path>
66#include <tools/sg/search>
67#include <tools/histo/h1d>
68#include <tools/histo/h2d>
69#include <tools/sg/plotter_some_styles>
82#if defined(TOOLS_USE_FREETYPE)
84 fFreetypeNode->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
85 fFreetypeNode->add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
109 size_t nWorlds = transportationManager->
GetNoWorlds();
110 std::vector<G4VPhysicalVolume*>::iterator iterWorld = transportationManager->
GetWorldsIterator();
112 for (
size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
125#ifdef G4MULTITHREADED
130 tools::sg::separator* sep =
new tools::sg::separator;
138 tools::sg::separator* sep =
new tools::sg::separator;
145 typedef std::vector<PVNodeID> PVPath;
147 const PVPath& fullPVPath = pPVModel->GetFullPVPath();
157 for (; iWorld < nWorlds; ++iWorld) {
158 if (fullPVPath[0].GetPhysicalVolume() ==
161 if (iWorld == nWorlds) {
163 "World mis-match - not possible(!?)");
172 const size_t depth = fullPVPath.size();
174 while (iDepth < depth) {
175 const auto& children = node->children();
176 const G4int nChildren = children.size();
179 for (; iChild < nChildren; ++iChild) {
181 if (child->
GetPVNodeID() == fullPVPath[iDepth])
break;
183 if (iChild != nChildren) {
215 if (a_polyline.size() == 0)
return;
217 tools::sg::separator* parentNode = 0;
219 parentNode =
new tools::sg::separator;
228 if(!parentNode)
return;
230 tools::sg::matrix* mtx =
new tools::sg::matrix;
236 parentNode->add(mtx);
239 {
const auto& colour =
GetColour(a_polyline);
240 tools::sg::rgba* mat =
new tools::sg::rgba();
242 tools::colorf(
float(colour.GetRed()),
243 float(colour.GetGreen()),
244 float(colour.GetBlue()),
245 float(colour.GetAlpha()));
246 parentNode->add(mat);}
248 {tools::sg::draw_style*
ds =
new tools::sg::draw_style;
249 ds->style = tools::sg::draw_lines;
251 parentNode->add(
ds);}
253 tools::sg::vertices* vtxs =
new tools::sg::vertices;
254 vtxs->mode = tools::gl::line_strip();
255 parentNode->add(vtxs);
257 {
for (
size_t i = 0; i < a_polyline.size(); ++i) {
258 vtxs->add(
float(a_polyline[i].x()),
float(a_polyline[i].y()),
float(a_polyline[i].z()));
267 if (a_polymarker.size() == 0)
return;
269 if (!currentNode)
return;
272 {tools::sg::matrix* mtx =
new tools::sg::matrix;
278 currentNode->add(mtx);}
280 {
const auto& colour =
GetColour(a_polymarker);
281 tools::sg::rgba* mat =
new tools::sg::rgba();
283 tools::colorf(
float(colour.GetRed()),
284 float(colour.GetGreen()),
285 float(colour.GetBlue()),
286 float(colour.GetAlpha()));
287 currentNode->add(mat);}
293 tools::sg::draw_style*
ds =
new tools::sg::draw_style;
294 ds->style = tools::sg::draw_points;
296 currentNode->add(
ds);
298 tools::sg::vertices* vtxs =
new tools::sg::vertices;
299 vtxs->mode = tools::gl::points();
300 {
for (
size_t i = 0; i < a_polymarker.size(); ++i) {
301 vtxs->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
303 currentNode->add(vtxs);
307 {tools::sg::markers* markers =
new tools::sg::markers;
309 markers->style = tools::sg::marker_circle_line;
310 for (
size_t i = 0; i < a_polymarker.size(); ++i) {
311 markers->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
313 currentNode->add(markers);}
317 {tools::sg::markers* markers =
new tools::sg::markers;
319 markers->style = tools::sg::marker_square_line;
320 for (
size_t i = 0; i < a_polymarker.size(); ++i) {
321 markers->add(
float(a_polymarker[i].x()),
float(a_polymarker[i].y()),
float(a_polymarker[i].z()));
323 currentNode->add(markers);}
335 tools::sg::separator* parentNode = 0;
337 parentNode =
new tools::sg::separator;
344 tools::sg::matrix* mtx =
new tools::sg::matrix;
345 mtx->set_translate(
pos.x(),
pos.y(),
pos.z());
346 parentNode->add(mtx);
350 if (!parentNode)
return;
352 tools::sg::matrix* mtx =
new tools::sg::matrix;
358 parentNode->add(mtx);
365 tools::sg::rgba* mat =
new tools::sg::rgba();
367 tools::colorf(
float(colour.GetRed()),
368 float(colour.GetGreen()),
369 float(colour.GetBlue()),
370 float(colour.GetAlpha()));
371 parentNode->add(mat);}
373#ifdef TOOLS_USE_FREETYPE
374 tools::sg::text_freetype_marker* text =
new tools::sg::text_freetype_marker;
375 text->add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
376 text->font = tools::sg::font_lato_regular_ttf();
377 text->front_face = tools::sg::winding_cw;
380 tools::sg::text_hershey_marker* text =
new tools::sg::text_hershey_marker;
383 text->height = float(size);
384 text->strings.add(a_text.
GetText());
388 text->hjust = tools::sg::left;
391 text->hjust = tools::sg::center;
394 text->hjust = tools::sg::right;
398 parentNode->add(text);
435 std::vector<G4Point3D> vertices;
436 std::vector<G4Normal3D> normals;
440 typedef std::pair<G4Point3D,G4Point3D> Line;
441 std::vector<Line> lines;
442 auto insertIfNew = [&lines](
const Line& newLine) {
443 for (
const auto& line: lines) {
444 if ((newLine.first==line.first && newLine.second==line.second) ||
445 (newLine.first==line.second && newLine.second==line.first))
448 lines.push_back(newLine);
459 vertices.push_back(vertex[0]);
460 vertices.push_back(vertex[1]);
461 vertices.push_back(vertex[2]);
462 normals.push_back(
normal[0]);
463 normals.push_back(
normal[1]);
464 normals.push_back(
normal[2]);
465 if(isAuxilaryEdgeVisible||edgeFlag[0]>0)insertIfNew(Line(vertex[0],vertex[1]));
466 if(isAuxilaryEdgeVisible||edgeFlag[1]>0)insertIfNew(Line(vertex[1],vertex[2]));
470 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[0]));
471 }
else if (nEdges == 4) {
474 vertices.push_back(vertex[2]);
475 vertices.push_back(vertex[3]);
476 vertices.push_back(vertex[0]);
477 normals.push_back(
normal[2]);
478 normals.push_back(
normal[3]);
479 normals.push_back(
normal[0]);
480 if(isAuxilaryEdgeVisible||edgeFlag[2]>0)insertIfNew(Line(vertex[2],vertex[3]));
481 if(isAuxilaryEdgeVisible||edgeFlag[3]>0)insertIfNew(Line(vertex[3],vertex[0]));
484 <<
"ERROR: polyhedron face with unexpected number of edges (" << nEdges <<
')'
489 }
while (notLastFace);
492 switch (drawing_style) {
509 if (!currentNode)
return;
511 tools::sg::separator* sep =
new tools::sg::separator;
512 currentNode->add(sep);
515 {tools::sg::matrix* mtx =
new tools::sg::matrix;
523 {
const auto& colour =
GetColour(a_polyhedron);
524 tools::sg::rgba* mat =
new tools::sg::rgba();
526 tools::colorf(
float(colour.GetRed()),
527 float(colour.GetGreen()),
528 float(colour.GetBlue()),
529 float(colour.GetAlpha()));
536 {tools::sg::draw_style*
ds =
new tools::sg::draw_style;
537 ds->style = tools::sg::draw_filled;
541 tools::sg::atb_vertices* vtxs =
new tools::sg::atb_vertices;
542 vtxs->mode = tools::gl::triangles();
545 const auto nVerts = vertices.size();
546 for (
size_t i = 0; i < nVerts; i++) {
547 vtxs->add(
float(vertices[i].x()),
float(vertices[i].y()),
float(vertices[i].z()));
548 vtxs->add_normal(
float(normals[i].x()),
float(normals[i].y()),
float(normals[i].z()));
556 {tools::sg::draw_style*
ds =
new tools::sg::draw_style;
557 ds->style = tools::sg::draw_lines;
561 tools::sg::vertices* vtxs =
new tools::sg::vertices;
562 vtxs->mode = tools::gl::lines();
565 for (
const auto& line: lines) {
566 vtxs->add(
float(line.first.x()),
float(line.first.y()),
float(line.first.z()));
567 vtxs->add(
float(line.second.x()),
float(line.second.y()),
float(line.second.z()));
575 tools::sg::plots& a_plots,
576 tools::sg::plotter& a_plotter,
578 if(a_style==
"reset") {
579 a_plotter.reset_style(
true);
581 }
else if( (a_style==
"inlib_default")|| (a_style==
"default")) {
582 tools::sg::set_inlib_default_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_hershey());
583 }
else if(a_style==
"ROOT_default") {
584 tools::sg::set_ROOT_default_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_roboto_bold_ttf());
585 }
else if(a_style==
"hippodraw") {
586 tools::sg::set_hippodraw_style(
G4cout,a_styles.cmaps(),a_plotter,tools::sg::font_lato_regular_ttf());
588 tools::sg::style_from_res(a_styles,a_style,a_plotter,
false);
592inline tools::xml::styles::style_t*
find_style(tools::xml::styles& a_styles,
const std::string& a_name) {
593 tools_vforit(tools::xml::styles::named_style_t,a_styles.named_styles(),it){
594 if((*it).first==a_name)
return &((*it).second);
600 const std::vector<G4String>& a_plotter_styles,
601 const std::vector<G4Plotter::RegionStyle>& a_region_styles) {
605 tools::xml::styles _tools_styles(
G4cout);
606 _tools_styles.add_colormap(
"default",tools::sg::style_default_colormap());
607 _tools_styles.add_colormap(
"ROOT",tools::sg::style_ROOT_colormap());
610 tools::xml::styles::style_t _tools_style;
612 const G4String& param = (*its).first;
613 if(param.find(
'.')==std::string::npos) {
614 const G4String& value = (*its).second;
615 _tools_style.push_back(tools::xml::styles::style_item_t(param,value));
618 _tools_styles.add_style((*it).first,_tools_style);
624 const G4String& param = (*its).first;
625 std::string::size_type
pos = param.rfind(
'.');
626 if(
pos!=std::string::npos) {
627 std::string sub_style = (*it).first+
"."+param.substr(0,
pos);
629 const G4String& value = (*its).second;
630 tools::xml::styles::style_t* _tools_style =
find_style(_tools_styles,sub_style);
632 _tools_style->push_back(tools::xml::styles::style_item_t(parameter,value));
634 tools::xml::styles::style_t _tools_style_2;
635 _tools_style_2.push_back(tools::xml::styles::style_item_t(parameter,value));
636 _tools_styles.add_style(sub_style,_tools_style_2);
642 {
unsigned int number = a_plots.number();
643 for(
unsigned int index=0;index<number;index++) {
644 tools::sg::plotter* _plotter = a_plots.find_plotter(index);
646 tools_vforcit(
G4String,a_plotter_styles,it) {
652 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
660 const std::vector<G4Plotter::RegionParameter>& a_region_parameters) {
669 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
671 const G4String& parameter = (*it).second.first;
672 const G4String& value = (*it).second.second;
673 tools::sg::field* fd = _plotter->find_field_by_name(parameter);
674 if(!fd) fd = _plotter->find_field_by_name(_plotter->s_cls()+
"."+parameter);
675 if(fd) {
if(fd->s2value(value))
continue;}
679 if(!_plotter->set_from_string(
G4cout,a_cmaps,parameter,value)) {
680 G4cout <<
"G4ToolsSGSceneHandler::SetPlotterParameters: plotter.set_from_string() failed for field "
681 << tools::sout(parameter) <<
", and value " << tools::sout(value) <<
"."
695 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
697 int hid = (*it).second;
698 std::ostringstream os;
700 std::string cmd(
"/analysis/h1/get ");
701 cmd += std::string(os.str());
705 if(hexString.size()) {
707 std::istringstream is(hexString);
709 tools::histo::h1d* _h = (tools::histo::h1d*)ptr;
710 tools::sg::plottable* p =
new tools::sg::h1d2plot_cp(*_h);
711 _plotter->add_plottable(p);
717 tools::sg::plotter* _plotter = a_plots.find_plotter((*it).first);
719 int hid = (*it).second;
720 std::ostringstream os;
722 std::string cmd(
"/analysis/h2/get ");
723 cmd += std::string(os.str());
727 if(hexString.size()) {
729 std::istringstream is(hexString);
731 tools::histo::h2d* _h = (tools::histo::h2d*)ptr;
732 tools::sg::plottable* p =
new tools::sg::h2d2plot_cp(*_h);
733 _plotter->add_plottable(p);
743 virtual tools::sg::return_action
action() {
744 if(
const tools::sg::size_event* sz_evt = tools::sg::event_cast<tools::sg::event,tools::sg::size_event>(*m_event)){
745 m_plots.adjust_size(sz_evt->width(),sz_evt->height());
746 m_event_action->set_done(
true);
747 return tools::sg::return_to_render;
749 return tools::sg::return_none;
763 parent::operator=(a_from);
771 tools::sg::search_action sa(
G4cout);
772 const tools::sg::search_action::paths_t& paths = tools::sg::find_paths<tools::sg::plots>(sa,a_sg);
773 tools_vforcit(tools::sg::path_t,paths,it) {
774 tools::sg::plots* _plots = tools::sg::tail<tools::sg::plots>(*it);
787 if (!currentNode)
return;
789 currentNode->add(
new tools::sg::light_off());
791 tools::sg::plots* _plots =
new tools::sg::plots(*
fFreetypeNode);
792 currentNode->add(_plots);
794 _plots->view_border =
false;
797 {tools::sg::event_dispatcher* dpt =
new tools::sg::event_dispatcher;
798 dpt->add_callback(
new plots_cbk(*_plots));
799 currentNode->add(dpt);}
803 tools::sg::cmaps_t _cmaps;
804 _cmaps[
"default"] = tools::sg::style_default_colormap();
805 _cmaps[
"ROOT"] = tools::sg::style_ROOT_colormap();
817 if (!pSceneHandler) {
818 G4cout <<
"G4ToolsSGSceneHandler::Messenger::SetNewValue: no current sceneHandler. Please create one." <<
G4endl;
822 if(!tsg_scene_handler) {
823 G4cout <<
"G4ToolsSGSceneHandler::Messenger::SetNewValue: current sceneHandler not a G4ToolsSGSceneHandler." <<
G4endl;
827 tools::sg::dummy_freetype _ttf;
828 tools::sg::plotter _plotter(_ttf);
829 _plotter.print_available_customization(
G4cout);
static const G4double pos
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
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
size_t GetNoWorlds() const
G4int ApplyCommand(const char *aCommand)
G4String GetCurrentValues(const char *aCommand)
static G4UImanager * GetUIpointer()
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 *)
const G4VisAttributes * GetApplicableVisAttributes(const G4VisAttributes *) const
const G4ViewParameters & GetViewParameters() const
static G4VisManager * fpVisManager
G4bool IsAuxEdgeVisible() const
G4VSceneHandler * GetCurrentSceneHandler() const
const G4VisAttributes * GetVisAttributes() const
G4int GetNoFacets() const
G4bool GetNextFacet(G4int &n, G4Point3D *nodes, G4int *edgeFlags=0, G4Normal3D *normals=0) 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
static double normal(HepRandomEngine *eptr)
const char * name(G4int ptype)