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);
82 std::vector<int> stack =
fApex.GetIndexStack();
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;
110 fApex.SetFromPath(path);
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;
147 fDesc.IssueSignal(
this,
"CdTop");
150 else if (arg.compare(0, 5,
"CDUP:") == 0)
152 std::vector<std::string> result = eveDesc.
GetApexPath();
155 fDesc.IssueSignal(
this,
"CdUp");
158 else if (arg.compare(0, 8,
"SETAPEX:") == 0) {
163 std::vector<std::string> result = eveDesc.
GetApexPath();
164 if (path->size() > 1) {
165 result.insert(result.end(), path->begin() + 1, path->end());
167 fDesc.IssueSignal(
this,
"SelectTop");
171 else if ((arg.compare(0, 7,
"SETVI0:") == 0) || (arg.compare(0, 7,
"SETVI1:") == 0)) {
174 bool on = (arg[5] ==
'1');
178 std::vector<int> stack =
fDesc.MakeStackByPath(*path);
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)) {
190 bool on = (arg.compare(0, 5,
"SHOW:") == 0);
194 std::vector<int> stack =
fDesc.MakeStackByPath(*path);
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)
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); });
357 fDesc.ImportFile(filename);
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()) {
373 result.push_back(*it);
377 fDesc.InitPath(result);
405 if ((kind ==
"SelectTop") || (kind ==
"CdTop") || (kind ==
"CdUp"))
412 else if (kind ==
"HighlightItem") {
417 }
else if (kind ==
"ClickItem") {
418 printf(
"REveGeoTopNodeData element CLICKED selected --------------------------------\n");
419 auto sstack =
fDesc.GetClickedItem();
426 bool secondary =
true;
427 gEve->GetSelection()->NewElementPicked(
n->GetElementId(), multi, secondary, ss);
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()))
525 std::set<TGeoShape *> shapes;
529 std::cout <<
"Shape size " << shapes.size() <<
"\n";
533 printf(
"Collect Shapes Real time: %.3f s\n", timer.
RealTime());
543 printf(
"Collect Nodes Real time: %.3f s\n", timer.
RealTime());
551 printf(
"collect nodes \n");
556 std::vector<int> apexStack =
fGeoData->RefDescription().GetIndexStack();
562 for (
int idx : apexStack) {
568 while ((node = it.
Next()))
629 for (
int i = 0; i < 16; ++i)
635 for (
size_t i = 0; i < browsables.size(); i++) {
636 if (shape == browsables[i].shape) {
641 assert(
b.shapeId >= 0);
645 std::vector<int> visStack = apexStack;
646 for (
int i = 1; i <= it.
GetLevel(); ++i)
649 b.visible =
fGeoData->RefDescription().GetVisiblityForStack(visStack);
655 if (nodeId > 300000) {
657 printf(
"num nodes locked !!! \n");
665 printf(
"collect shapes \n");
668 while ((node = geoit.
Next()))
677 auto it = shapes.find(shape);
678 if (it == shapes.end()) {
679 shapes.insert(shape);
694 browserShape.
shape = shape;
695 browsables.push_back(browserShape);
698 browsables.back().vertices.reserve(polyShape.
GetVertices().size());
700 browsables.back().vertices.push_back(polyShape.
GetVertices()[i]);
704 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 1]);
705 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 2]);
706 browsables.back().indices.push_back(polyShape.
GetPolyDesc()[i + 3]);
717 fRenderData = std::make_unique<REveRenderData>(
"makeGeoTopNode");
718 for (
size_t i = 0; i <
fNodes.size(); ++i) {
723 uint32_t
v = (
c[0] << 16) + (
c[1] << 8) +
c[2];
725 std::memcpy(&pc, &
v,
sizeof(pc));
750 j[
"dataId"] =
fGeoData->GetElementId();
755 using namespace nlohmann;
757 json shapeVertexArr = json::array();
760 json shapeIndexArr = json::array();
761 json shapePolySizeArr = json::array();
762 json shapePolyOffArr = json::array();
764 json nodeVisibility = json::array();
769 for (
size_t i = 0; i <
fShapes.size(); ++i) {
772 std::copy(
fShapes[i].vertices.begin(),
fShapes[i].vertices.end(), std::back_inserter(shapeVertexArr));
774 int numVertices =
int(
fShapes[i].vertices.size());
777 for (
size_t p = 0; p <
fShapes[i].indices.size(); ++p)
778 shapeIndexArr.push_back(
fShapes[i].indices[p] + vertexOff);
781 shapePolySizeArr.push_back(numIndices);
782 shapePolyOffArr.push_back(polyOff);
786 polyOff += numIndices;
787 vertexOff += numVertices / 3;
791 json nodeShapeIds = json::array();
792 json nodeTrans = json::array();
793 json nodeColors = json::array();
795 for (
size_t i = 0; i <
fNodes.size(); ++i) {
796 nodeShapeIds.push_back(
fNodes[i].shapeId);
797 nodeVisibility.push_back(
fNodes[i].visible);
798 for (
int t = 0; t < 16; t++)
799 nodeTrans.push_back(
fNodes[i].trans[t]);
803 j[
"shapeVertices"] = shapeVertexArr;
806 j[
"shapeIndices"] = shapeIndexArr;
809 j[
"shapeIndicesOff"] = shapePolyOffArr;
810 j[
"shapeIndicesSize"] = shapePolySizeArr;
812 j[
"nodeShapeIds"] = nodeShapeIds;
813 j[
"nodeTrans"] = nodeTrans;
814 j[
"nodeVisibility"] = nodeVisibility;
832 auto jbb = json::array();
833 jbb.push_back(origin[0] -
box->GetDX());
834 jbb.push_back(origin[0] +
box->GetDX());
835 jbb.push_back(origin[1] -
box->GetDY());
836 jbb.push_back(origin[1] +
box->GetDY());
837 jbb.push_back(origin[2] -
box->GetDZ());
838 jbb.push_back(origin[2] +
box->GetDZ());
857 std::vector<int> nodeStack;
861 while ((node = it.
Next())) {
866 nodeStack.resize(level);
868 nodeStack[level - 1] = it.
GetIndex(level);
870 bool inside = nodeStack.size() >= stack.size() && std::equal(stack.begin(), stack.end(), nodeStack.begin());
877 printf(
"GetIndicesFromBrowserStack stack size %zu res size %zu\n", stack.size(), res.size());
883 size_t apexDepth =
fGeoData->RefDescription().GetApexPath().size();
884 std::vector<int> stack(iStack.begin() + apexDepth, iStack.end());
890 std::vector<int> nodeStack;
893 while ((node = it.
Next())) {
899 nodeStack.resize(level);
901 nodeStack[level - 1] = it.
GetIndex(level);
909 if (nodeStack == stack) {
915 bool inside = nodeStack.size() >= stack.size() && std::equal(stack.begin(), stack.end(), nodeStack.begin());
#define R__LOG_ERROR(...)
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
int Int_t
Signed integer 4 bytes (int).
char Text_t
General string (char).
unsigned char UChar_t
Unsigned Character 1 byte (unsigned char).
double Double_t
Double 8 bytes.
externTGeoManager * gGeoManager
REveElement::List_t fNieces
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.
REveElement(const std::string &name="", const std::string &title="")
Default constructor.
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)
std::shared_ptr< REveGeomHierarchy > fWebHierarchy
! web handle for hierarchy part
void VisibilityChanged(bool on, REveGeomDescription::ERnrFlags flag, const std::vector< int > &path)
REveGeomDescription fDesc
REveGeoTopNodeData(const REveGeoTopNodeData &)=delete
void ProcessSignal(const std::string &)
friend class REveGeoTopNodeViz
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
Write transformation Matrix to render data.
REveGeoTopNodeData * fGeoData
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.
void SetAlwaysSecSelect(Bool_t f)
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)
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.
static Bool_t FromJSON(T *&obj, const char *json)
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.
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
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.