Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveGeoTopNode.cxx
Go to the documentation of this file.
1
4#include <ROOT/RGeomData.hxx>
6
8
9
10#include "TMath.h"
11#include "TGeoManager.h"
12#include "TClass.h"
13#include "TGeoNode.h"
14#include "TGeoManager.h"
15#include "TBase64.h"
16
17#include <cassert>
18#include <iostream>
19
20#include <nlohmann/json.hpp>
21
22
23using namespace ROOT::Experimental;
24
25thread_local ElementId_t gSelId;
26
27#define REVEGEO_DEBUG
28#ifdef REVEGEO_DEBUG
29#define REVEGEO_DEBUG_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
30#else
31#define REVEGEO_DEBUG_PRINT(fmt, ...)
32#endif
33
34////////////////////////////////////////////////////////////////////////////////
35/// Constructor.
36
38{
39 fWebHierarchy = std::make_shared<RGeomHierarchy>(fDesc, true);
40}
41
43{
44 fGeoNode = n;
46 fDesc.AddSignalHandler(this, [this](const std::string &kind) { ProcessSignal(kind); });
47}
48////////////////////////////////////////////////////////////////////////////////
49
50void REveGeoTopNodeData::SetChannel(unsigned connid, int chid)
51{
52 fWebHierarchy->Show({gEve->GetWebWindow(), connid, chid});
53}
54
55////////////////////////////////////////////////////////////////////////////////
56namespace {
57std::size_t getHash(std::vector<int> &vec)
58{
59 std::size_t seed = vec.size();
60 for (auto &x : vec) {
61 uint32_t i = (uint32_t)x;
62 seed ^= i + 0x9e3779b9 + (seed << 6) + (seed >> 2);
63 }
64 return seed;
65}
66} // namespace
67
68void REveGeoTopNodeData::ProcessSignal(const std::string &kind)
69{
71 if ((kind == "SelectTop") || (kind == "NodeVisibility")) {
73 for (auto &n : fNieces) {
74 n->StampObjProps();
75 }
76 } else if (kind == "HighlightItem") {
77 // printf("REveGeoTopNodeData element highlighted --------------------------------");
78 auto sstack = fDesc.GetHighlightedItem();
79 std::set<int> ss;
80 ss.insert((int)getHash(sstack));
81 for (auto &n : fNieces) {
82 gEve->GetHighlight()->NewElementPicked(n->GetElementId(), false, true, ss);
83 }
85
86 } else if (kind == "ClickItem") {
87 // printf("REveGeoTopNodeData element selected --------------------------------");
88 auto sstack = fDesc.GetClickedItem();
89 std::set<int> ss;
90 ss.insert((int)getHash(sstack));
91
92 for (auto &n : fNieces) {
93 gEve->GetSelection()->NewElementPicked(n->GetElementId(), false, true, ss);
94 }
96 }
97}
98
99////////////////////////////////////////////////////////////////////////////////
100/// Fill core part of JSON representation.
101
102Int_t REveGeoTopNodeData::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
103{
104 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
105
106 if (!fGeoNode){ return ret;}
107 return ret;
108}
109
110////////////////////////////////////////////////////////////////////////////////
111////////////////////////////////////////////////////////////////////////////////
112////////////////////////////////////////////////////////////////////////////////
114
115std::string REveGeoTopNodeViz::GetHighlightTooltip(const std::set<int> &) const
116{
117 auto stack = fGeoData->fDesc.GetHighlightedItem();
118 auto sa = fGeoData->fDesc.MakePathByStack(stack);
119 if (sa.empty())
120 return "";
121 else {
122 std::string res;
123 size_t n = sa.size();
124 for (size_t i = 0; i < n; ++i) {
125 res += sa[i];
126 if (i < (n - 1))
127 res += "/";
128 }
129 return res;
130 }
131}
132
134{
135 fRenderData = std::make_unique<REveRenderData>("makeGeoTopNode");
136}
137
138int REveGeoTopNodeViz::WriteCoreJson(nlohmann::json &j, Int_t rnr_offset)
139{
140 Int_t ret = REveElement::WriteCoreJson(j, rnr_offset);
141 if (!fGeoData) {
142 j["dataId"] = -1;
143 } else {
144 std::string json = fGeoData->fDesc.ProduceJson();
145 j["geomDescription"] = TBase64::Encode(json.c_str());
146 printf("REveGeoTopNodeViz::WriteCoreJson stream geomDescription json size = %lu\n", json.size());
147 j["dataId"] = fGeoData->GetElementId();
148 }
149 return ret;
150}
151
152void REveGeoTopNodeViz::FillExtraSelectionData(nlohmann::json &j, const std::set<int> &) const
153{
154 j["stack"] = nlohmann::json::array();
155 std::vector<int> stack;
158 else if (gSelId == gEve->GetSelection()->GetElementId())
159 stack = fGeoData->fDesc.GetClickedItem();
160
161 if (stack.empty())
162 return;
163
164#ifdef REVEGEO_DEBUG
165 printf("cicked stack: ");
166 for (auto i : stack)
167 printf(" %d, ", i);
168 printf("\n");
169#endif
170
171 for (auto i : stack)
172 j["stack"].push_back(i);
173
174
175#ifdef REVEGEO_DEBUG
176 printf("extra stack: ");
177 int ss = j["stack"].size();
178 for (int i = 0; i < ss; ++i) {
179 int d = j["stack"][i];
180 printf(" %d,", d);
181 }
182 printf("----\n");
183 auto ids = fGeoData->fDesc.MakeIdsByStack(stack);
184 printf("node ids from stack: ");
185 for (auto i : ids)
186 printf(" %d, ", i);
187 printf("\n");
188
189 int id = fGeoData->fDesc.FindNodeId(stack);
190 printf("NODE ID %d\n", id);
191#endif
192}
nlohmann::json json
thread_local ElementId_t gSelId
#define d(i)
Definition RSha256.hxx:102
char Text_t
Definition RtypesCore.h:62
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
std::unique_ptr< REveRenderData > fRenderData
Externally assigned and controlled user data.
ElementId_t GetElementId() const
void SetChannel(unsigned connid, int chid)
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
RGeomDescription fDesc
! geometry description, send to the client as first message
std::shared_ptr< RGeomHierarchy > fWebHierarchy
! web handle for hierarchy part
REveGeoTopNodeData(const REveGeoTopNodeData &)=delete
void ProcessSignal(const std::string &)
std::string GetHighlightTooltip(const std::set< int > &secondary_idcs) const override
REveGeoTopNodeViz(const REveGeoTopNodeViz &)=delete
void BuildRenderData() override
Write transformation Matrix to render data.
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
void FillExtraSelectionData(nlohmann::json &j, const std::set< int > &secondary_idcs) const override
REveSelection * GetHighlight() const
REveSelection * GetSelection() const
std::shared_ptr< ROOT::RWebWindow > GetWebWindow() const
void NewElementPicked(ElementId_t id, bool multi, bool secondary, const std::set< int > &secondary_idcs={})
Called from GUI when user picks or un-picks an element.
std::vector< int > MakeIdsByStack(const std::vector< int > &stack)
Produce list of node ids for given stack If found nodes preselected - use their ids.
std::string ProduceJson(bool all_nodes=false)
Produce JSON string which can be directly used with build function from JSROOT to create three....
std::vector< std::string > MakePathByStack(const std::vector< int > &stack)
Returns path string for provided stack.
void AddSignalHandler(const void *handler, RGeomSignalFunc_t func)
Add signal handler.
std::vector< int > GetClickedItem() const
std::vector< int > GetHighlightedItem() const
int FindNodeId(const std::vector< int > &stack)
Returns nodeid for given stack array, returns -1 in case of failure.
void Build(TGeoManager *mgr, const std::string &volname="")
Collect information about geometry hierarchy into flat list like it done in JSROOT ClonedNodes....
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:107
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:39
TGeoVolume * GetVolume() const
Definition TGeoNode.h:99
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
R__EXTERN REveManager * gEve