Logo ROOT  
Reference Guide
REveGeomData.hxx
Go to the documentation of this file.
1// @(#)root/eve7:$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_REveGeomData
13#define ROOT7_REveGeomData
14
16
17#include <vector>
18#include <string>
19#include <functional>
20#include <memory>
21
22class TGeoNode;
23class TGeoManager;
24class TGeoShape;
25class TGeoMatrix;
26class TGeoVolume;
27
28// do not use namespace to avoid too long JSON
29
30namespace ROOT {
31namespace Experimental {
32
33class REveRenderData;
34class RGeomBrowserIter;
35
36/** Base description of geometry node, required only to build hierarchy */
37
39public:
40 int id{0}; ///< node id, index in array
41 std::string name; ///< node name
42 std::vector<int> chlds; ///< list of childs id
43 int vis{0}; ///< visibility flag, 0 - off, 1 - only when level==0, 99 - always
44 bool nochlds{false}; ///< how far in hierarchy depth should be scanned
45
46 std::string color; ///< rgb code without rgb() prefix
47 int sortid{0}; ///<! place in sorted array, to check cuts, or id of original node when used search structures
48
49 REveGeomNodeBase(int _id = 0) : id(_id) {}
50
51 bool IsVisible() const { return vis > 0; }
52};
53
54/** Full node description including matrices and other attributes */
55
57public:
58 std::vector<float> matr; ///< matrix for the node, can have reduced number of elements
59 double vol{0}; ///<! volume estimation
60 int nfaces{0}; ///<! number of shape faces
61 int idshift{-1}; ///<! used to jump over then scan all geom hierarchy
62 bool useflag{false}; ///<! extra flag, used for selection
63 float opacity{1.}; ///<! opacity of the color
64
65 REveGeomNode(int _id = 0) : REveGeomNodeBase(_id) {}
66
67 /** True when there is shape and it can be displayed */
68 bool CanDisplay() const { return (vol > 0.) && (nfaces > 0); }
69};
70
71/** Base class for render info block */
73public:
74 /// virtual destructor required for the I/O
75 virtual ~RGeomRenderInfo() = default;
76};
77
78/** Render info with raw data */
80public:
81 // render data, equivalent of REveElement::WriteCoreJson
82 int sz[3]={0,0, 0}; ///< fRenderData: [SizeV(), SizeN(), SizeI()];
83 std::vector<unsigned char> raw; ///< raw shape data with render information, JSON_base64
84 virtual ~RGeomRawRenderInfo() = default;
85};
86
87/** Render info with shape itself - client can produce shape better */
89public:
90 TGeoShape *shape{nullptr}; ///< original shape - can be much less than binary data
91 virtual ~RGeomShapeRenderInfo() = default;
92};
93
94
95/** REveGeomVisible contains description of visible node
96 * It is path to the node plus reference to shape rendering data */
97
99public:
100 int nodeid{0}; ///< selected node id,
101 int seqid{0}; ///< sequence id, used for merging later
102 std::vector<int> stack; ///< path to the node, index in list of childs
103 std::string color; ///< color in rgb format
104 double opacity{1}; ///< opacity
105 RGeomRenderInfo *ri{nullptr}; ///< render information for the shape, can be same for different nodes
106
107 REveGeomVisible() = default;
108 REveGeomVisible(int _nodeid, int _seqid, const std::vector<int> &_stack) : nodeid(_nodeid), seqid(_seqid), stack(_stack) {}
109};
110
111
112/** Configuration parameters which can be configured on the client
113 * Send as is to-from client */
114
116public:
117 int vislevel{0}; ///< visible level
118 int maxnumnodes{0}; ///< maximal number of nodes
119 int maxnumfaces{0}; ///< maximal number of faces
120 bool showtop{false}; ///< show geometry top volume, off by default
121 int build_shapes{1}; ///< when shapes build on server 0 - never, 1 - TGeoComposite, 2 - plus non-cylindrical, 3 - all
122 int nsegm{0}; ///< number of segments for cylindrical shapes
123 std::string drawopt; ///< draw options for TGeoPainter
124};
125
126
127/** Object with full description for drawing geometry
128 * It includes list of visible items and list of nodes required to build them */
129
131public:
132 REveGeomConfig *cfg{nullptr}; ///< current configurations
133 int numnodes{0}; ///< total number of nodes in description
134 std::vector<REveGeomNode*> nodes; ///< all used nodes to display visible items and not known for client
135 std::vector<REveGeomVisible> visibles; ///< all visible items
136};
137
138
139/** Request object send from client for different operations */
141public:
142 std::string oper; ///< operation like HIGHL or HOVER
143 std::string path; ///< path parameter, used with HOVER
144 std::vector<int> stack; ///< stack parameter, used with HIGHL
145};
146
148public:
149 std::string fullpath; ///< full path to node
150 std::string node_type; ///< node class name
151 std::string node_name; ///< node name
152 std::string shape_type; ///< shape type (if any)
153 std::string shape_name; ///< shape class name (if any)
154
155 RGeomRenderInfo *ri{nullptr}; ///< rendering information (if applicable)
156};
157
158using REveGeomScanFunc_t = std::function<bool(REveGeomNode &, std::vector<int> &, bool, int)>;
159
160
162
163 friend class RGeomBrowserIter;
164
166 public:
167 int id{0}; ///<! sequential id
168 TGeoShape *fShape{nullptr}; ///<! original shape
169 int nfaces{0}; ///<! number of faces in render data
170 RGeomRawRenderInfo fRawInfo; ///<! raw render info
171 RGeomShapeRenderInfo fShapeInfo; ///<! shape itself as info
173
174 bool has_shape() const { return nfaces == 1; }
175 bool has_raw() const { return nfaces > 1; }
176
177 /// Provide render info for visible item
179 {
180 if (has_shape()) return &fShapeInfo;
181 if (has_raw()) return &fRawInfo;
182 return nullptr;
183 }
184
185 void reset()
186 {
187 nfaces = 0;
188 fShapeInfo.shape = nullptr;
189 fRawInfo.raw.clear();
190 }
191 };
192
193 std::vector<TGeoNode *> fNodes; ///<! flat list of all nodes
194 std::vector<REveGeomNode> fDesc; ///< converted description, send to client
195
196 std::vector<int> fSortMap; ///<! nodes in order large -> smaller volume
197 std::vector<ShapeDescr> fShapes; ///<! shapes with created descriptions
198
199 std::string fDrawJson; ///<! JSON with main nodes drawn by client
200 int fDrawIdCut{0}; ///<! sortid used for selection of most-significant nodes
201 int fActualLevel{0}; ///<! level can be reduced when selecting nodes
202 bool fPreferredOffline{false}; ///<! indicates that full description should be provided to client
203 int fJsonComp{0}; ///<! default JSON compression
204
205 REveGeomConfig fCfg; ///<! configuration parameter editable from GUI
206
207 void PackMatrix(std::vector<float> &arr, TGeoMatrix *matr);
208
209 int MarkVisible(bool on_screen = false);
210
211 void ProduceIdShifts();
212
213 int ScanNodes(bool only_visible, int maxlvl, REveGeomScanFunc_t func);
214
215 void ResetRndrInfos();
216
218
220
222
223 void CollectNodes(REveGeomDrawing &drawing);
224
225 std::string MakeDrawingJson(REveGeomDrawing &drawing, bool has_shapes = false);
226
227public:
229
230 void Build(TGeoManager *mgr, const std::string &volname = "");
231
232 /** Number of unique nodes in the geometry */
233 int GetNumNodes() const { return fDesc.size(); }
234
235 bool IsBuild() const { return GetNumNodes() > 0; }
236
237 /** Set maximal number of nodes which should be selected for drawing */
239
240 /** Returns maximal visible number of nodes, ignored when non-positive */
241 int GetMaxVisNodes() const { return fCfg.maxnumnodes; }
242
243 /** Set maximal number of faces which should be selected for drawing */
245
246 /** Returns maximal visible number of faces, ignored when non-positive */
247 int GetMaxVisFaces() const { return fCfg.maxnumfaces; }
248
249 /** Set maximal visible level */
250 void SetVisLevel(int lvl = 3) { fCfg.vislevel = lvl; }
251
252 /** Returns maximal visible level */
253 int GetVisLevel() const { return fCfg.vislevel; }
254
255 /** Set preference of offline operations.
256 * Server provides more info to client from the begin on to avoid communication */
258
259 /** Is offline operations preferred.
260 * After get full description, client can do most operations without extra requests */
261 bool IsPreferredOffline() const { return fPreferredOffline; }
262
263 bool CollectVisibles();
264
265 bool IsPrincipalEndNode(int nodeid);
266
267 std::string ProcessBrowserRequest(const std::string &req = "");
268
269 bool HasDrawData() const { return (fDrawJson.length() > 0) && (fDrawIdCut > 0); }
270 const std::string &GetDrawJson() const { return fDrawJson; }
271 void ClearDrawData();
272
273 int SearchVisibles(const std::string &find, std::string &hjson, std::string &json);
274
275 int FindNodeId(const std::vector<int> &stack);
276
277 std::string ProduceModifyReply(int nodeid);
278
279 std::vector<int> MakeStackByIds(const std::vector<int> &ids);
280
281 std::vector<int> MakeIdsByStack(const std::vector<int> &stack);
282
283 std::vector<int> MakeStackByPath(const std::string &path);
284
285 std::string MakePathByStack(const std::vector<int> &stack);
286
287 bool ProduceDrawingFor(int nodeid, std::string &json, bool check_volume = false);
288
289 bool ChangeNodeVisibility(int nodeid, bool selected);
290
291 /** Set number of segments for cylindrical shapes, if 0 - default value will be used */
292 void SetNSegments(int n = 0) { fCfg.nsegm = n; }
293 /** Return of segments for cylindrical shapes, if 0 - default value will be used */
294 int GetNSegments() const { return fCfg.nsegm; }
295
296 /** Set JSON compression level for data transfer */
297 void SetJsonComp(int comp = 0) { fJsonComp = comp; }
298 /** Returns JSON compression level for data transfer */
299 int GetJsonComp() const { return fJsonComp; }
300
301 /** Set draw options as string for JSROOT TGeoPainter */
302 void SetDrawOptions(const std::string &opt = "") { fCfg.drawopt = opt; }
303 /** Returns draw options, used for JSROOT TGeoPainter */
304 std::string GetDrawOptions() const { return fCfg.drawopt; }
305
306 /** Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client, which can build model itself */
307 void SetBuildShapes(int lvl = 1) { fCfg.build_shapes = lvl; }
308 /** Returns true if binary 3D model build already by C++ server (default) */
309 int IsBuildShapes() const { return fCfg.build_shapes; }
310
311 bool ChangeConfiguration(const std::string &json);
312
313 std::unique_ptr<REveGeomNodeInfo> MakeNodeInfo(const std::string &path);
314};
315
316
317} // namespace Experimental
318} // namespace ROOT
319
320#endif
Configuration parameters which can be configured on the client Send as is to-from client.
bool showtop
show geometry top volume, off by default
std::string drawopt
draw options for TGeoPainter
int build_shapes
when shapes build on server 0 - never, 1 - TGeoComposite, 2 - plus non-cylindrical,...
int maxnumnodes
maximal number of nodes
int nsegm
number of segments for cylindrical shapes
int maxnumfaces
maximal number of faces
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
void SetVisLevel(int lvl=3)
Set maximal visible level.
void CollectNodes(REveGeomDrawing &drawing)
Collect nodes which are used in visibles.
REveGeomConfig fCfg
! configuration parameter editable from GUI
std::vector< int > MakeStackByIds(const std::vector< int > &ids)
Creates stack for given array of ids, first element always should be 0.
ShapeDescr & MakeShapeDescr(TGeoShape *shape)
Find description object and create render information.
int GetNumNodes() const
Number of unique nodes in the geometry.
bool IsPreferredOffline() const
Is offline operations preferred.
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...
int GetVisLevel() const
Returns maximal visible level.
int GetMaxVisFaces() const
Returns maximal visible number of faces, ignored when non-positive.
int GetMaxVisNodes() const
Returns maximal visible number of nodes, ignored when non-positive.
void SetMaxVisFaces(int cnt)
Set maximal number of faces which should be selected for drawing.
std::string ProduceModifyReply(int nodeid)
Return string with only part of nodes description which were modified Checks also volume.
int fDrawIdCut
! sortid used for selection of most-significant nodes
std::vector< REveGeomNode > fDesc
converted description, send to client
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 ...
bool CollectVisibles()
Collect all information required to draw geometry on the client This includes list of each visible no...
int GetJsonComp() const
Returns JSON compression level for data transfer.
int fJsonComp
! default JSON compression
void Build(TGeoManager *mgr, const std::string &volname="")
Collect information about geometry hierarchy into flat list like it done JSROOT.GEO....
void SetNSegments(int n=0)
Set number of segments for cylindrical shapes, if 0 - default value will be used.
bool ChangeConfiguration(const std::string &json)
Change configuration by client Returns true if any parameter was really changed.
int ScanNodes(bool only_visible, int maxlvl, REveGeomScanFunc_t func)
Iterate over all nodes and call function for visible.
std::string GetDrawOptions() const
Returns draw options, used for JSROOT TGeoPainter.
int fActualLevel
! level can be reduced when selecting nodes
void ClearDrawData()
Clear raw data. Will be rebuild when next connection will be established.
void SetJsonComp(int comp=0)
Set JSON compression level for data transfer.
std::vector< int > fSortMap
! nodes in order large -> smaller volume
bool ChangeNodeVisibility(int nodeid, bool selected)
Change visibility for specified element Returns true if changes was performed.
int GetNSegments() const
Return of segments for cylindrical shapes, if 0 - default value will be used.
void ProduceIdShifts()
Count total number of visible childs under each node.
bool fPreferredOffline
! indicates that full description should be provided to client
std::string MakeDrawingJson(REveGeomDrawing &drawing, bool has_shapes=false)
Produce JSON for the drawing If TGeoShape appears in the drawing, one has to keep typeinfo But in thi...
void SetMaxVisNodes(int cnt)
Set maximal number of nodes which should be selected for drawing.
void ResetRndrInfos()
Reset shape info, which used to pack binary data.
ShapeDescr & FindShapeDescr(TGeoShape *shape)
Find description object for requested shape If not exists - will be created.
void SetBuildShapes(int lvl=1)
Instruct to build binary 3D model already on the server (true) or send TGeoShape as is to client,...
bool IsPrincipalEndNode(int nodeid)
return true when node used in main geometry drawing and does not have childs for such nodes one could...
int FindNodeId(const std::vector< int > &stack)
Returns nodeid for given stack array, returns -1 in case of failure.
std::string ProcessBrowserRequest(const std::string &req="")
Find description object for requested shape If not exists - will be created.
std::unique_ptr< REveGeomNodeInfo > MakeNodeInfo(const std::string &path)
Change visibility for specified element Returns true if changes was performed.
std::string MakePathByStack(const std::vector< int > &stack)
Returns path string for provided stack.
void SetPreferredOffline(bool on)
Set preference of offline operations.
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...
std::vector< TGeoNode * > fNodes
! flat list of all nodes
const std::string & GetDrawJson() const
int IsBuildShapes() const
Returns true if binary 3D model build already by C++ server (default)
std::vector< int > MakeStackByPath(const std::string &path)
Produce stack based on string path Used to highlight geo volumes by browser hover event.
std::vector< int > MakeIdsByStack(const std::vector< int > &stack)
Produce list of node ids for given stack If found nodes preselected - use their ids.
void SetDrawOptions(const std::string &opt="")
Set draw options as string for JSROOT TGeoPainter.
std::vector< ShapeDescr > fShapes
! shapes with created descriptions
void CopyMaterialProperties(TGeoVolume *vol, REveGeomNode &node)
Copy material properties.
int MarkVisible(bool on_screen=false)
Set visibility flag for each nodes.
std::string fDrawJson
! JSON with main nodes drawn by client
Object with full description for drawing geometry It includes list of visible items and list of nodes...
std::vector< REveGeomNode * > nodes
all used nodes to display visible items and not known for client
std::vector< REveGeomVisible > visibles
all visible items
int numnodes
total number of nodes in description
REveGeomConfig * cfg
current configurations
Base description of geometry node, required only to build hierarchy.
int vis
visibility flag, 0 - off, 1 - only when level==0, 99 - always
int sortid
! place in sorted array, to check cuts, or id of original node when used search structures
bool nochlds
how far in hierarchy depth should be scanned
std::vector< int > chlds
list of childs id
std::string color
rgb code without rgb() prefix
int id
node id, index in array
RGeomRenderInfo * ri
rendering information (if applicable)
std::string shape_type
shape type (if any)
std::string fullpath
full path to node
std::string node_type
node class name
std::string shape_name
shape class name (if any)
Full node description including matrices and other attributes.
std::vector< float > matr
matrix for the node, can have reduced number of elements
bool useflag
! extra flag, used for selection
double vol
! volume estimation
float opacity
! opacity of the color
bool CanDisplay() const
True when there is shape and it can be displayed.
int idshift
! used to jump over then scan all geom hierarchy
int nfaces
! number of shape faces
Request object send from client for different operations.
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
REveGeomVisible contains description of visible node It is path to the node plus reference to shape r...
std::vector< int > stack
path to the node, index in list of childs
int seqid
sequence id, used for merging later
RGeomRenderInfo * ri
render information for the shape, can be same for different nodes
std::string color
color in rgb format
REveGeomVisible(int _nodeid, int _seqid, const std::vector< int > &_stack)
Render info with raw data.
int sz[3]
fRenderData: [SizeV(), SizeN(), SizeI()];
std::vector< unsigned char > raw
raw shape data with render information, JSON_base64
Base class for render info block.
virtual ~RGeomRenderInfo()=default
virtual destructor required for the I/O
Render info with shape itself - client can produce shape better.
TGeoShape * shape
original shape - can be much less than binary data
The manager class for any TGeo geometry.
Definition: TGeoManager.h:43
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:47
const Int_t n
Definition: legend1.C:16
std::function< bool(REveGeomNode &, std::vector< int > &, bool, int)> REveGeomScanFunc_t
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
Definition: StringConv.hxx:21
static constexpr double s
basic_json<> json
default JSON class
Definition: REveElement.hxx:88
const char * cnt
Definition: TXMLSetup.cxx:74