33#include <nlohmann/json.hpp>
42#define REVEGEO_DEBUG_PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
44#define REVEGEO_DEBUG_PRINT(fmt, ...)
68 for (
auto iter = visVec.begin(); iter != visVec.end(); iter++) {
69 if (iter->stack == stack) {
76 visVec.emplace_back(stack,
on);
83 stack.insert(stack.end(), iStack.begin(), iStack.end());
85 auto isVisible = [&stack](std::vector<RGeomNodeVisibility> &visVec) ->
bool {
86 for (
auto &visVecEl : visVec) {
92 if (stack == visVecEl.stack)
93 return visVecEl.visible ? 1 : 0;
118 if (nodeStack == visVecEl.stack) {
126 nodeStack.size() >= visVecEl.stack.size() && std::equal(visVecEl.stack.begin(), visVecEl.stack.end(), nodeStack.begin());
139 using namespace std::string_literals;
143 if (arg.compare(0, 6,
"CDTOP:") == 0)
145 std::vector<std::string> ep;
150 else if (arg.compare(0, 5,
"CDUP:") == 0)
158 else if (arg.compare(0, 8,
"SETAPEX:") == 0) {
159 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(8));
164 if (path->size() > 1) {
165 result.insert(
result.end(), path->begin() + 1, path->end());
171 else if ((arg.compare(0, 7,
"SETVI0:") == 0) || (arg.compare(0, 7,
"SETVI1:") == 0)) {
174 bool on = (arg[5] ==
'1');
175 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(7));
179 stack.insert(stack.begin(), base.begin(), base.end());
182 std::cout <<
"Set visibilty rnr CHIDLREN \n";
187 else if ((arg.compare(0, 5,
"SHOW:") == 0) || (arg.compare(0, 5,
"HIDE:") == 0)) {
189 auto path = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(5));
190 bool on = (arg.compare(0, 5,
"SHOW:") == 0);
195 stack.insert(stack.begin(), base.begin(), base.end());
198 std::cout <<
"Set visibility rnr PHY \n";
204 else if (arg.compare(0, 9,
"PrintInfo") == 0)
206 auto a = TBufferJSON::FromJSON<std::vector<std::string>>(arg.substr(10));
209 std::ostringstream oss;
210 if (!prefix.empty()) {
211 a->erase(
a->begin());
212 a->insert(
a->begin(), prefix.begin(), prefix.end());
216 if (topName.rfind(
"_1") != std::string::npos) {
217 topName = topName.substr(0, topName.size() - 2);
219 oss << topName <<
"/";
221 for (
size_t i = 0; i <
a->size(); ++i) {
227 std::string targetPath = oss.str();
230 printf(
"Node path:\n%s \n", targetPath.c_str());
237 printf(
"ERROR locating the node with given path\n");
268 for (
size_t t = 0; t < path.size(); t++) {
269 std::string s = path[t];
270 std::cout << s << std::endl;
273 throw std::runtime_error(
"Apex::LocateNodeWithPath(), can't locate node with path " + s);
284 std::ostringstream oss;
288 for (
size_t i = 1; i < fPath.size(); ++i)
289 oss <<
"/" << fPath[i];
296 std::vector<int> indexStack;
302 std::vector<std::string> nameStack = fPath;
303 if (!nameStack.empty() && nameStack[0] == current->
GetName())
306 for (
size_t i = start; i < nameStack.size(); ++i)
308 const std::string& targetName = nameStack[i];
316 for (
int j = 0; j < nd; ++j)
320 if (targetName == daughter->
GetName())
328 if (foundIndex == -1)
330 std::cerr <<
"Node not found: " << targetName << std::endl;
334 indexStack.push_back(foundIndex);
345 throw std::runtime_error(
"Critical Error: Failed to import geometry file");
356 fDesc.AddSignalHandler(
this, [
this](
const std::string &kind) { ProcessSignal(kind); });
360 fWebHierarchy = std::make_shared<REveGeomHierarchy>(
fDesc,
true);
361 fWebHierarchy->SetReceiver(
this);
366 std::regex re(R
"([/\\]+)");
367 std::sregex_token_iterator it(path.begin(), path.end(), re, -1);
368 std::sregex_token_iterator end;
369 std::vector<std::string>
result;
371 for (; it != end; ++it) {
372 if (!it->str().empty()) {
379 for (
auto &el : fNieces) {
388 for (
auto &el : fNieces) {
405 if ((kind ==
"SelectTop") || (kind ==
"CdTop") || (kind ==
"CdUp"))
407 for (
auto &el : fNieces) {
412 else if (kind ==
"HighlightItem") {
417 }
else if (kind ==
"ClickItem") {
418 printf(
"REveGeoTopNodeData element CLICKED selected --------------------------------\n");
419 auto sstack =
fDesc.GetClickedItem();
422 for (
auto &
n : fNieces) {
426 bool secondary =
true;
490 auto it = set.begin();
493 std::cout <<
"highlight node with ID " << pos <<
"\n";
495 std::string res =
"GeoNode name";
502 while ((node = git.
Next()))
517 if (topName.rfind(
"_1") != std::string::npos) {
518 topName = topName.substr(0, topName.size() - 2);
519 std::cout << topName <<
"/";
523 for (
size_t f = 0;
f < prefix.size(); ++
f) {
524 std::cout << prefix[
f];
527 std::cout << res <<
"\n";
541 std::set<TGeoShape *> shapes;
545 std::cout <<
"Shape size " << shapes.size() <<
"\n";
549 printf(
"Collect Shapes Real time: %.3f s\n", timer.
RealTime());
559 printf(
"Collect Nodes Real time: %.3f s\n", timer.
RealTime());
567 printf(
"collect nodes \n");
578 for (
int idx : apexStack) {
584 while ((node = it.
Next()))
645 for (
int i = 0; i < 16; ++i)
651 for (
size_t i = 0; i < browsables.size(); i++) {
652 if (shape == browsables[i].shape) {
657 assert(
b.shapeId >= 0);
661 std::vector<int> visStack = apexStack;
662 for (
int i = 1; i <= it.
GetLevel(); ++i)
671 if (nodeId > 300000) {
673 printf(
"num nodes locked !!! \n");
681 printf(
"collect shapes \n");
684 while ((node = geoit.
Next()))
693 auto it = shapes.find(shape);
694 if (it == shapes.end()) {
695 shapes.insert(shape);
710 browserShape.
shape = shape;
711 browsables.push_back(browserShape);
714 browsables.back().vertices.reserve(polyShape.
GetVertices().size());
715 for (
size_t i = 0; i < polyShape.
GetVertices().size(); i++)
716 browsables.back().vertices.push_back(polyShape.
GetVertices()[i]);
719 for (
size_t i = 0; i < polyShape.
GetPolyDesc().size(); i += 4) {
720 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 1]);
721 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 2]);
722 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 3]);
733 fRenderData = std::make_unique<REveRenderData>(
"makeGeoTopNode");
734 for (
size_t i = 0; i <
fNodes.size(); ++i) {
739 uint32_t
v = (
c[0] << 16) + (
c[1] << 8) +
c[2];
741 std::memcpy(&pc, &
v,
sizeof(pc));
791 using namespace nlohmann;
793 json shapeVertexArr = json::array();
796 json shapeIndexArr = json::array();
797 json shapePolySizeArr = json::array();
798 json shapePolyOffArr = json::array();
800 json nodeVisibility = json::array();
805 for (
size_t i = 0; i <
fShapes.size(); ++i) {
808 std::copy(
fShapes[i].vertices.begin(),
fShapes[i].vertices.end(), std::back_inserter(shapeVertexArr));
810 int numVertices =
int(
fShapes[i].vertices.size());
813 for (
size_t p = 0;
p <
fShapes[i].indices.size(); ++
p)
814 shapeIndexArr.push_back(
fShapes[i].indices[
p] + vertexOff);
817 shapePolySizeArr.push_back(numIndices);
818 shapePolyOffArr.push_back(polyOff);
822 polyOff += numIndices;
823 vertexOff += numVertices / 3;
827 json nodeShapeIds = json::array();
828 json nodeTrans = json::array();
829 json nodeColors = json::array();
831 for (
size_t i = 0; i <
fNodes.size(); ++i) {
832 nodeShapeIds.push_back(
fNodes[i].shapeId);
833 nodeVisibility.push_back(
fNodes[i].visible);
834 for (
int t = 0; t < 16; t++)
835 nodeTrans.push_back(
fNodes[i].trans[t]);
839 j[
"shapeVertices"] = shapeVertexArr;
842 j[
"shapeIndices"] = shapeIndexArr;
845 j[
"shapeIndicesOff"] = shapePolyOffArr;
846 j[
"shapeIndicesSize"] = shapePolySizeArr;
848 j[
"nodeShapeIds"] = nodeShapeIds;
849 j[
"nodeTrans"] = nodeTrans;
850 j[
"nodeVisibility"] = nodeVisibility;
869 std::vector<int> nodeStack;
873 while ((node = it.
Next())) {
878 nodeStack.resize(level);
880 nodeStack[level - 1] = it.
GetIndex(level);
882 bool inside = nodeStack.size() >= stack.size() && std::equal(stack.begin(), stack.end(), nodeStack.begin());
889 printf(
"GetIndicesFromBrowserStack stack size %zu res size %zu\n", stack.size(), res.size());
896 std::vector<int> stack(iStack.begin() + apexDepth, iStack.end());
902 std::vector<int> nodeStack;
905 while ((node = it.
Next())) {
911 nodeStack.resize(level);
913 nodeStack[level - 1] = it.
GetIndex(level);
921 if (nodeStack == stack) {
927 bool inside = nodeStack.size() >= stack.size() && std::equal(stack.begin(), stack.end(), nodeStack.begin());
thread_local ElementId_t gSelId
#define R__LOG_ERROR(...)
char Text_t
General string (char)
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char)
winID h TVirtualViewer3D TVirtualGLPainter p
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TGeoManager * gGeoManager
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
std::unique_ptr< REveRenderData > fRenderData
! Vertex / normal / triangle index information for rendering.
void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0)
Set the bounding box to a cube of half-side epsilon at (x, y, z); with the defaults,...
void BBoxInit()
Start filling the bounding box with BBoxCheckPoint(): min at +infinity, max at -infinity,...
ElementId_t GetElementId() const
void BBoxCheckBox(const REveVector &c, const REveVector &h)
Grow the box to hold the axis-aligned box with centre c and half sizes h.
REveRenderData * GetRenderData() const
REveGeoManagerHolder Exception-safe global variable holders.
const std::vector< UInt_t > & GetPolyDesc() const
void BuildFromShape(TGeoShape *shape, Int_t n_seg=60)
Produce all polygons from normal shape.
void BuildFromComposite(TGeoCompositeShape *cshp, Int_t n_seg=60)
Produce all polygons from composite shape.
const std::vector< Double_t > & GetVertices() const
void SetChannel(unsigned connid, int chid)
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Fill core part of JSON representation.
void InitPath(const std::string &path)
void VisibilityChanged(bool on, REveGeomDescription::ERnrFlags flag, const std::vector< int > &path)
REveGeomDescription fDesc
REveGeomDescription & RefDescription()
REveGeoTopNodeData(const REveGeoTopNodeData &)=delete
void ProcessSignal(const std::string &)
void GetIndicesFromBrowserStack(const std::vector< int > &stack, std::set< int > &outStack)
std::string GetHighlightTooltip(const std::set< int > &secondary_idcs) const override
REveGeoTopNodeViz(const REveGeoTopNodeViz &)=delete
void CollectNodes(TGeoVolume *volume, std::vector< BNode > &bnl, std::vector< BShape > &browsables)
void BuildRenderData() override
Build fRenderData, what the client draws.
REveGeoTopNodeData * fGeoData
void ComputeBBox() override
Fill the bounding box (virtual from REveElement) from the box of the apex node's shape.
void VisibilityChanged(bool on, REveGeomDescription::ERnrFlags flag, const std::vector< int > &path)
Int_t WriteCoreJson(nlohmann::json &j, Int_t rnr_offset) override
Write core json.
void SetGeoData(REveGeoTopNodeData *d, bool rebuild=true)
std::vector< BNode > fNodes
void SetVizMode(EMode mode)
bool AcceptNode(TGeoIterator &it, bool skip=true) const
void CollectShapes(TGeoNode *node, std::set< TGeoShape * > &shapes, std::vector< BShape > &browsables)
std::vector< BShape > fShapes
std::vector< int > GetIndexStack() const
std::string GetFlatPath() const
void SetFromPath(std::vector< std::string > absPath)
TGeoNode * LocateNodeWithPath(const std::vector< std::string > &path) const
std::vector< std::string > fPath
void InitPath(const std::vector< std::string > &path)
bool ChangeEveVisibility(const std::vector< int > &stack, ERnrFlags rnrFlag, bool on)
std::vector< int > GetIndexStack()
std::vector< RGeomNodeVisibility > fVisibilitySelf
virtual void RefineGeoItem(ROOT::RGeoItem &item, const std::vector< int > &stack) override
Method which allows to add/modify information in RGeoItem which will be provided to client - like tit...
bool GetVisiblityForStack(const std::vector< int > &stack)
void ImportFile(const char *filePath)
const std::vector< std::string > & GetApexPath() const
static TGeoManager * s_geoManager
static TGeoManager * GetGeoManager()
std::vector< RGeomNodeVisibility > fVisibilityRec
REveGeoTopNodeData * fReceiver
virtual void WebWindowCallback(unsigned connid, const std::string &kind) override
Table signal handling.
REveSelection * GetSelection() const
std::shared_ptr< ROOT::RWebWindow > GetWebWindow() const
void SetAlwaysSecSelect(Bool_t f)
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.
static void ColorFromIdx(Color_t ci, UChar_t col[4], Bool_t alpha=kTRUE)
Fill col with RGBA values corresponding to index ci.
Representation of single item in the geometry browser.
void SetPhysicalVisibility(int physicalVis)
void SetLogicalVisibility(int logicalVis)
std::vector< RGeomNode > fDesc
! converted description, send to client
void SetVisLevel(int lvl=3)
Set maximal visible level.
void IssueSignal(const void *handler, const std::string &kind)
Issue signal, which distributed on all handlers - excluding source handler.
int GetVisLevel() const
Returns maximal visible level.
std::vector< int > MakeStackByPath(const std::vector< std::string > &path)
Produce stack based on string path Used to highlight geo volumes by browser hover event.
void Build(TGeoManager *mgr, const std::string &volname="")
Collect information about geometry hierarchy into flat list like it done in JSROOT ClonedNodes....
std::shared_ptr< RWebWindow > fWebWindow
! web window to show geometry
virtual void WebWindowCallback(unsigned connid, const std::string &arg)
Process data from client.
RGeomDescription & fDesc
! geometry description, shared with external
virtual Color_t GetLineColor() const
Return the line color.
Composite shapes are Boolean combinations of two or more shape components.
Matrix class used for computing global transformations Should NOT be used for node definition.
void Multiply(const TGeoMatrix *right)
multiply to the right with an other transformation if right is identity matrix, just return
const TGeoMatrix * GetCurrentMatrix() const
Returns global matrix for current node.
void GetPath(TString &path) const
Returns the path for the current node.
TGeoNode * GetNode(Int_t level) const
Returns current node at a given level.
Int_t GetIndex(Int_t i) const
TGeoNode * Next()
Returns next node.
void Skip()
Stop iterating the current branch.
The manager class for any TGeo geometry.
virtual Bool_t cd(const char *path="")
Browse the tree of nodes starting from fTopNode according to pathname.
TGeoNode * GetCurrentNode() const
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
TGeoNode * GetTopNode() const
const char * GetPath() const
Get path to the current node in the form /node0/node1/...
Geometrical transformation package.
virtual const Double_t * GetTranslation() const =0
virtual const Double_t * GetScale() const =0
virtual const Double_t * GetRotationMatrix() const =0
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
TGeoVolume * GetVolume() const
Int_t GetNdaughters() const
TGeoNode * GetDaughter(Int_t ind) const
virtual TGeoMatrix * GetMatrix() const =0
Base abstract class for all shapes.
virtual void ComputeBBox()=0
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Int_t GetNdaughters() const
TGeoNode * GetNode(const char *name) const
get the pointer to a daughter node
TGeoShape * GetShape() const
void InspectShape() const
TGeoNode * FindNode(const char *name) const
search a daughter inside the list of nodes
const char * GetName() const override
Returns name of object.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Stop()
Stop the stopwatch.
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Namespace for ROOT features in testing.
ROOT::RLogChannel & REveLog()
Log channel for Eve diagnostics.
R__EXTERN REveManager * gEve
REveVectorT< Float_t > REveVector