Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RGeomData.hxx
Go to the documentation of this file.
1// @(#)root/geom/webviewer:$Id$
2// Author: Sergey Linev, 14.12.2018
3
4/*************************************************************************
5 * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT7_RGeomData
13#define ROOT7_RGeomData
14
15#include <vector>
16#include <string>
17#include <functional>
18#include <memory>
19
20class TGeoNode;
21class TGeoManager;
22class TGeoShape;
23class TGeoMatrix;
24class TGeoVolume;
25
26// do not use namespace to avoid too long JSON
27
28namespace ROOT {
29namespace Experimental {
30
31class RGeomBrowserIter;
32class RLogChannel;
33
34/** Base description of geometry node, required only to build hierarchy */
35
37public:
38 int id{0}; ///< node id, index in array
39 std::string name; ///< node name
40 std::vector<int> chlds; ///< list of childs id
41 int vis{0}; ///< visibility flag, 0 - off, 1 - only when level==0, 99 - always
42 bool nochlds{false}; ///< how far in hierarchy depth should be scanned
43
44 std::string color; ///< rgb code without rgb() prefix
45 int sortid{0}; ///<! place in sorted array, to check cuts, or id of original node when used search structures
46
47 RGeomNodeBase(int _id = 0) : id(_id) {}
48
49 bool IsVisible() const { return vis > 0; }
50};
51
52/** Full node description including matrices and other attributes */
53
54class RGeomNode : public RGeomNodeBase {
55public:
56 std::vector<float> matr; ///< matrix for the node, can have reduced number of elements
57 double vol{0}; ///<! volume estimation
58 int nfaces{0}; ///<! number of shape faces
59 int idshift{-1}; ///<! used to jump over then scan all geom hierarchy
60 bool useflag{false}; ///<! extra flag, used for selection
61 float opacity{1.}; ///<! opacity of the color
62
63 RGeomNode(int _id = 0) : RGeomNodeBase(_id) {}
64
65 /** True when there is shape and it can be displayed */
66 bool CanDisplay() const { return (vol > 0.) && (nfaces > 0); }
67};
68
69/** Base class for render info block */
71public:
72 /// virtual destructor required for the I/O
73 virtual ~RGeomRenderInfo() = default;
74};
75
76/** Render info with raw data */
78public:
79 std::vector<unsigned char> raw; ///< float vertices as raw data, JSON_base64
80 std::vector<int> idx; ///< vertex indexes, always triangles
81 virtual ~RGeomRawRenderInfo() = default;
82};
83
84/** Render info with shape itself - client can produce shape better */
86public:
87 TGeoShape *shape{nullptr}; ///< original shape - can be much less than binary data
88 virtual ~RGeomShapeRenderInfo() = default;
89};
90
91
92/** RGeomVisible contains description of visible node
93 * It is path to the node plus reference to shape rendering data */
94
96public:
97 int nodeid{0}; ///< selected node id,
98 int seqid{0}; ///< sequence id, used for merging later
99 std::vector<int> stack; ///< path to the node, index in list of childs
100 std::string color; ///< color in rgb format
101 double opacity{1}; ///< opacity
102 RGeomRenderInfo *ri{nullptr}; ///< render information for the shape, can be same for different nodes
103
104 RGeomVisible() = default;
105 RGeomVisible(int _nodeid, int _seqid, const std::vector<int> &_stack) : nodeid(_nodeid), seqid(_seqid), stack(_stack) {}
106};
107
108
109/** Configuration parameters which can be configured on the client
110 * Send as is to-from client */
111
113public:
114 int vislevel{0}; ///< visible level
115 int maxnumnodes{0}; ///< maximal number of nodes
116 int maxnumfaces{0}; ///< maximal number of faces
117 bool showtop{false}; ///< show geometry top volume, off by default
118 int build_shapes{1}; ///< when shapes build on server 0 - never, 1 - TGeoComposite, 2 - plus non-cylindrical, 3 - all
119 int nsegm{0}; ///< number of segments for cylindrical shapes
120 std::string drawopt; ///< draw options for TGeoPainter
121};
122
123
124/** Object with full description for drawing geometry
125 * It includes list of visible items and list of nodes required to build them */
126
128public:
129 RGeomConfig *cfg{nullptr}; ///< current configurations
130 int numnodes{0}; ///< total number of nodes in description
131 std::vector<RGeomNode*> nodes; ///< all used nodes to display visible items and not known for client
132 std::vector<RGeomVisible> visibles; ///< all visible items
133};
134
135
136/** Request object send from client for different operations */
138public:
139 std::string oper; ///< operation like HIGHL or HOVER
140 std::vector<std::string> path; ///< path parameter, used with HOVER
141 std::vector<int> stack; ///< stack parameter, used with HIGHL
142};
143
145public:
146 std::vector<std::string> path; ///< full path to node
147 std::string node_type; ///< node class name
148 std::string node_name; ///< node name
149 std::string shape_type; ///< shape type (if any)
150 std::string shape_name; ///< shape class name (if any)
151
152 RGeomRenderInfo *ri{nullptr}; ///< rendering information (if applicable)
153};
154
155using RGeomScanFunc_t = std::function<bool(RGeomNode &, std::vector<int> &, bool, int)>;
156
157
159
160 friend class RGeomBrowserIter;
161
163 public:
164 int id{0}; ///<! sequential id
165 TGeoShape *fShape{nullptr}; ///<! original shape
166 int nfaces{0}; ///<! number of faces in render data
167 RGeomRawRenderInfo fRawInfo; ///<! raw render info
168 RGeomShapeRenderInfo fShapeInfo; ///<! shape itself as info
170
171 bool has_shape() const { return nfaces == 1; }
172 bool has_raw() const { return nfaces > 1; }
173
174 /// Provide render info for visible item
176 {
177 if (has_shape()) return &fShapeInfo;
178 if (has_raw()) return &fRawInfo;
179 return nullptr;
180 }
181
182 void reset()
183 {
184 nfaces = 0;
185 fShapeInfo.shape = nullptr;
186 fRawInfo.raw.clear();
187 }
188 };
189
190 std::vector<TGeoNode *> fNodes; ///<! flat list of all nodes
191 std::vector<RGeomNode> fDesc; ///< converted description, send to client
192 TGeoVolume *fDrawVolume{nullptr}; ///<! select volume independent from TGeoMaanger
193
194 std::vector<int> fSortMap; ///<! nodes in order large -> smaller volume
195 std::vector<ShapeDescr> fShapes; ///<! shapes with created descriptions
196
197 std::string fDrawJson; ///<! JSON with main nodes drawn by client
198 int fDrawIdCut{0}; ///<! sortid used for selection of most-significant nodes
199 int fActualLevel{0}; ///<! level can be reduced when selecting nodes
200 bool fPreferredOffline{false}; ///<! indicates that full description should be provided to client
201 int fJsonComp{0}; ///<! default JSON compression
202
203 RGeomConfig fCfg; ///<! configuration parameter editable from GUI
204
205 void PackMatrix(std::vector<float> &arr, TGeoMatrix *matr);
206
207 int MarkVisible(bool on_screen = false);
208
209 void ProduceIdShifts();
210
211 int ScanNodes(bool only_visible, int maxlvl, RGeomScanFunc_t func);
212
213 void ResetRndrInfos();
214
216
218
220
221 void CollectNodes(RGeomDrawing &drawing);
222
223 std::string MakeDrawingJson(RGeomDrawing &drawing, bool has_shapes = false);
224
225 void ClearDescription();
226
227 void BuildDescription(TGeoNode *topnode, TGeoVolume *topvolume);
228
229 TGeoVolume *GetVolume(int nodeid);
230
231public:
232 RGeomDescription() = default;
233
234 void Build(TGeoManager *mgr, const std::string &volname = "");
235
236 void Build(TGeoVolume *vol);
237
238 /** Number of unique nodes in the geometry */
239 int GetNumNodes() const { return fDesc.size(); }
240
241 bool IsBuild() const { return GetNumNodes() > 0; }
242
243 /** Set maximal number of nodes which should be selected for drawing */
244 void SetMaxVisNodes(int cnt) { fCfg.maxnumnodes = cnt; }
245
246 /** Returns maximal visible number of nodes, ignored when non-positive */
247 int GetMaxVisNodes() const { return fCfg.maxnumnodes; }
248
249 /** Set maximal number of faces which should be selected for drawing */
250 void SetMaxVisFaces(int cnt) { fCfg.maxnumfaces = cnt; }
251
252 /** Returns maximal visible number of faces, ignored when non-positive */
253 int GetMaxVisFaces() const { return fCfg.maxnumfaces; }
254
255 /** Set maximal visible level */
256 void SetVisLevel(int lvl = 3) { fCfg.vislevel = lvl; }
257
258 /** Returns maximal visible level */
259 int GetVisLevel() const { return fCfg.vislevel; }
260
261 /** Set preference of offline operations.
262 * Server provides more info to client from the begin on to avoid communication */
264
265 /** Is offline operations preferred.
266 * After get full description, client can do most operations without extra requests */
267 bool IsPreferredOffline() const { return fPreferredOffline; }
268
269 std::string ProduceJson();
270
271 bool IsPrincipalEndNode(int nodeid);
272
273 std::string ProcessBrowserRequest(const std::string &req = "");
274
275 bool HasDrawData() const { return (fDrawJson.length() > 0) && (fDrawIdCut > 0); }
276 void ProduceDrawData();
277 const std::string &GetDrawJson() const { return fDrawJson; }
278 void ClearDrawData();
279
280 int SearchVisibles(const std::string &find, std::string &hjson, std::string &json);
281
282 int FindNodeId(const std::vector<int> &stack);
283
284 std::string ProduceModifyReply(int nodeid);
285
286 std::vector<int> MakeStackByIds(const std::vector<int> &ids);
287
288 std::vector<int> MakeIdsByStack(const std::vector<int> &stack);
289
290 std::vector<int> MakeStackByPath(const std::vector<std::string> &path);
291
292 std::vector<std::string> MakePathByStack(const std::vector<int> &stack);
293
294 bool ProduceDrawingFor(int nodeid, std::string &json, bool check_volume = false);
295
296 bool ChangeNodeVisibility(int nodeid, bool selected);
297
298 /** Set number of segments for cylindrical shapes, if 0 - default value will be used */
299 void SetNSegments(int n = 0) { fCfg.nsegm = n; }
300 /** Return of segments for cylindrical shapes, if 0 - default value will be used */
301 int GetNSegments() const { return fCfg.nsegm; }
302
303 /** Set JSON compression level for data transfer */
304 void SetJsonComp(int comp = 0) { fJsonComp = comp; }
305 /** Returns JSON compression level for data transfer */
306 int GetJsonComp() const { return fJsonComp; }
307
308 /** Set draw options as string for JSROOT TGeoPainter */
309 void SetDrawOptions(const std::string &opt = "") { fCfg.drawopt = opt; }
310 /** Returns draw options, used for JSROOT TGeoPainter */
311 std::string GetDrawOptions() const { return fCfg.drawopt; }
312
313 /** Set draw options as string for JSROOT TGeoPainter */
314 void SetTopVisible(bool on = true) { fCfg.showtop = on; }
315 /** Returns draw options, used for JSROOT TGeoPainter */
316 bool GetTopVisible() const { return fCfg.showtop; }
317
318 /** Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client, which can build model itself */
319 void SetBuildShapes(int lvl = 1) { fCfg.build_shapes = lvl; }
320 /** Returns true if binary 3D model build already by C++ server (default) */
321 int IsBuildShapes() const { return fCfg.build_shapes; }
322
323 bool ChangeConfiguration(const std::string &json);
324
325 std::unique_ptr<RGeomNodeInfo> MakeNodeInfo(const std::vector<std::string> &path);
326};
327
328
329/// Log channel for Eve diagnostics.
330RLogChannel &RGeomLog();
331
332
333} // namespace Experimental
334} // namespace ROOT
335
336#endif
nlohmann::json json
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Iterator of hierarchical geometry structures.
Definition RGeomData.cxx:49
Configuration parameters which can be configured on the client Send as is to-from client.
int maxnumfaces
maximal number of faces
int build_shapes
when shapes build on server 0 - never, 1 - TGeoComposite, 2 - plus non-cylindrical,...
std::string drawopt
draw options for TGeoPainter
int nsegm
number of segments for cylindrical shapes
bool showtop
show geometry top volume, off by default
int maxnumnodes
maximal number of nodes
RGeomRawRenderInfo fRawInfo
! raw render info
int nfaces
! number of faces in render data
RGeomRenderInfo * rndr_info()
Provide render info for visible item.
RGeomShapeRenderInfo fShapeInfo
! shape itself as info
std::vector< int > fSortMap
! nodes in order large -> smaller volume
std::string ProcessBrowserRequest(const std::string &req="")
Find description object for requested shape If not exists - will be created.
void PackMatrix(std::vector< float > &arr, TGeoMatrix *matr)
Pack matrix into vector, which can be send to client Following sizes can be used for vector: 0 - Iden...
bool ProduceDrawingFor(int nodeid, std::string &json, bool check_volume=false)
Produce shape rendering data for given stack All nodes, which are referencing same shape will be tran...
std::vector< int > MakeIdsByStack(const std::vector< int > &stack)
Produce list of node ids for given stack If found nodes preselected - use their ids.
int fActualLevel
! level can be reduced when selecting nodes
RGeomConfig fCfg
! configuration parameter editable from GUI
int MarkVisible(bool on_screen=false)
Set visibility flag for each nodes.
int GetJsonComp() const
Returns JSON compression level for data transfer.
bool IsPrincipalEndNode(int nodeid)
return true when node used in main geometry drawing and does not have childs for such nodes one could...
int GetMaxVisFaces() const
Returns maximal visible number of faces, ignored when non-positive.
TGeoVolume * fDrawVolume
! select volume independent from TGeoMaanger
int GetNumNodes() const
Number of unique nodes in the geometry.
int GetNSegments() const
Return of segments for cylindrical shapes, if 0 - default value will be used.
void SetMaxVisNodes(int cnt)
Set maximal number of nodes which should be selected for drawing.
void SetVisLevel(int lvl=3)
Set maximal visible level.
int GetMaxVisNodes() const
Returns maximal visible number of nodes, ignored when non-positive.
void ClearDescription()
Clear geometry description.
std::vector< int > MakeStackByIds(const std::vector< int > &ids)
Creates stack for given array of ids, first element always should be 0.
int GetVisLevel() const
Returns maximal visible level.
const std::string & GetDrawJson() const
std::vector< RGeomNode > fDesc
converted description, send to client
void SetMaxVisFaces(int cnt)
Set maximal number of faces which should be selected for drawing.
std::vector< ShapeDescr > fShapes
! shapes with created descriptions
std::string MakeDrawingJson(RGeomDrawing &drawing, bool has_shapes=false)
Produce JSON for the drawing If TGeoShape appears in the drawing, one has to keep typeinfo But in thi...
TGeoVolume * GetVolume(int nodeid)
Get volume for specified nodeid If specific volume was configured, it will be returned for nodeid==0.
std::unique_ptr< RGeomNodeInfo > MakeNodeInfo(const std::vector< std::string > &path)
Change visibility for specified element Returns true if changes was performed.
void ProduceDrawData()
Collect all information required to draw geometry on the client This includes list of each visible no...
bool fPreferredOffline
! indicates that full description should be provided to client
std::string GetDrawOptions() const
Returns draw options, used for JSROOT TGeoPainter.
void SetNSegments(int n=0)
Set number of segments for cylindrical shapes, if 0 - default value will be used.
void BuildDescription(TGeoNode *topnode, TGeoVolume *topvolume)
Build geometry description.
int SearchVisibles(const std::string &find, std::string &hjson, std::string &json)
Search visible nodes for provided name If number of found elements less than 100, create description ...
void ClearDrawData()
Clear raw data. Will be rebuild when next connection will be established.
std::vector< std::string > MakePathByStack(const std::vector< int > &stack)
Returns path string for provided stack.
bool ChangeConfiguration(const std::string &json)
Change configuration by client Returns true if any parameter was really changed.
void CopyMaterialProperties(TGeoVolume *vol, RGeomNode &node)
Copy material properties.
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.
int ScanNodes(bool only_visible, int maxlvl, RGeomScanFunc_t func)
Iterate over all nodes and call function for visible.
void SetBuildShapes(int lvl=1)
Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client,...
bool IsPreferredOffline() const
Is offline operations preferred.
std::vector< TGeoNode * > fNodes
! flat list of all nodes
ShapeDescr & MakeShapeDescr(TGeoShape *shape)
Find description object and create render information.
void SetPreferredOffline(bool on)
Set preference of offline operations.
bool GetTopVisible() const
Returns draw options, used for JSROOT TGeoPainter.
int IsBuildShapes() const
Returns true if binary 3D model build already by C++ server (default)
ShapeDescr & FindShapeDescr(TGeoShape *shape)
Find description object for requested shape If not exists - will be created.
std::string fDrawJson
! JSON with main nodes drawn by client
std::string ProduceJson()
Produce JSON string which can be directly used with build function from JSROOT to create three....
int FindNodeId(const std::vector< int > &stack)
Returns nodeid for given stack array, returns -1 in case of failure.
bool ChangeNodeVisibility(int nodeid, bool selected)
Change visibility for specified element Returns true if changes was performed.
void CollectNodes(RGeomDrawing &drawing)
Collect nodes which are used in visibles.
void ProduceIdShifts()
Count total number of visible childs under each node.
std::string ProduceModifyReply(int nodeid)
Return string with only part of nodes description which were modified Checks also volume.
void SetTopVisible(bool on=true)
Set draw options as string for JSROOT TGeoPainter.
void SetDrawOptions(const std::string &opt="")
Set draw options as string for JSROOT TGeoPainter.
void ResetRndrInfos()
Reset shape info, which used to pack binary data.
int fJsonComp
! default JSON compression
void SetJsonComp(int comp=0)
Set JSON compression level for data transfer.
int fDrawIdCut
! sortid used for selection of most-significant nodes
void Build(TGeoManager *mgr, const std::string &volname="")
Collect information about geometry hierarchy into flat list like it done in JSROOT ClonedNodes....
Object with full description for drawing geometry It includes list of visible items and list of nodes...
RGeomConfig * cfg
current configurations
std::vector< RGeomVisible > visibles
all visible items
std::vector< RGeomNode * > nodes
all used nodes to display visible items and not known for client
int numnodes
total number of nodes in description
Base description of geometry node, required only to build hierarchy.
Definition RGeomData.hxx:36
int sortid
! place in sorted array, to check cuts, or id of original node when used search structures
Definition RGeomData.hxx:45
int vis
visibility flag, 0 - off, 1 - only when level==0, 99 - always
Definition RGeomData.hxx:41
int id
node id, index in array
Definition RGeomData.hxx:38
bool nochlds
how far in hierarchy depth should be scanned
Definition RGeomData.hxx:42
std::string color
rgb code without rgb() prefix
Definition RGeomData.hxx:44
std::vector< int > chlds
list of childs id
Definition RGeomData.hxx:40
std::string shape_name
shape class name (if any)
std::string shape_type
shape type (if any)
RGeomRenderInfo * ri
rendering information (if applicable)
std::vector< std::string > path
full path to node
std::string node_name
node name
std::string node_type
node class name
Full node description including matrices and other attributes.
Definition RGeomData.hxx:54
double vol
! volume estimation
Definition RGeomData.hxx:57
std::vector< float > matr
matrix for the node, can have reduced number of elements
Definition RGeomData.hxx:56
int idshift
! used to jump over then scan all geom hierarchy
Definition RGeomData.hxx:59
bool CanDisplay() const
True when there is shape and it can be displayed.
Definition RGeomData.hxx:66
bool useflag
! extra flag, used for selection
Definition RGeomData.hxx:60
float opacity
! opacity of the color
Definition RGeomData.hxx:61
int nfaces
! number of shape faces
Definition RGeomData.hxx:58
Render info with raw data.
Definition RGeomData.hxx:77
std::vector< int > idx
vertex indexes, always triangles
Definition RGeomData.hxx:80
std::vector< unsigned char > raw
float vertices as raw data, JSON_base64
Definition RGeomData.hxx:79
Base class for render info block.
Definition RGeomData.hxx:70
virtual ~RGeomRenderInfo()=default
virtual destructor required for the I/O
Request object send from client for different operations.
std::vector< std::string > path
path parameter, used with HOVER
std::vector< int > stack
stack parameter, used with HIGHL
std::string oper
operation like HIGHL or HOVER
Render info with shape itself - client can produce shape better.
Definition RGeomData.hxx:85
TGeoShape * shape
original shape - can be much less than binary data
Definition RGeomData.hxx:87
RGeomVisible contains description of visible node It is path to the node plus reference to shape rend...
Definition RGeomData.hxx:95
std::string color
color in rgb format
std::vector< int > stack
path to the node, index in list of childs
Definition RGeomData.hxx:99
int seqid
sequence id, used for merging later
Definition RGeomData.hxx:98
int nodeid
selected node id,
Definition RGeomData.hxx:97
RGeomVisible(int _nodeid, int _seqid, const std::vector< int > &_stack)
RGeomRenderInfo * ri
render information for the shape, can be same for different nodes
The manager class for any TGeo geometry.
Definition TGeoManager.h:45
Geometrical transformation package.
Definition TGeoMatrix.h:41
A node represent a volume positioned inside another.They store links to both volumes and to the TGeoM...
Definition TGeoNode.h:41
Base abstract class for all shapes.
Definition TGeoShape.h:26
TGeoVolume, TGeoVolumeMulti, TGeoVolumeAssembly are the volume classes.
Definition TGeoVolume.h:49
const Int_t n
Definition legend1.C:16
std::function< bool(RGeomNode &, std::vector< int > &, bool, int)> RGeomScanFunc_t
RLogChannel & RGeomLog()
Log channel for Eve diagnostics.
Definition RGeomData.cxx:40
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.