Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
REveViewer.cxx
Go to the documentation of this file.
1// @(#)root/eve7:$Id$
2// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
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#include <ROOT/REveViewer.hxx>
13#include <ROOT/REveCamera.hxx>
14#include <ROOT/REveUtil.hxx>
15#include <ROOT/REveScene.hxx>
17#include <ROOT/REveManager.hxx>
19#include <ROOT/REveText.hxx>
20
21#include <nlohmann/json.hpp>
22#include "TROOT.h"
23
24using namespace ROOT::Experimental;
25namespace REX = ROOT::Experimental;
26
27/** \class REveViewer
28\ingroup REve
29Eve representation of a GL view. In a gist, it's a camera + a list of scenes.
30
31*/
32
33////////////////////////////////////////////////////////////////////////////////
34/// Constructor.
35
36REveViewer::REveViewer(const std::string& n, const std::string& t) :
37 REveElement(n, t),
38 fCamera(nullptr)
39{
41}
42
43////////////////////////////////////////////////////////////////////////////////
44/// Destructor.
45
48
49////////////////////////////////////////////////////////////////////////////////
50/// Redraw viewer immediately.
51
52void REveViewer::Redraw(Bool_t /*resetCameras*/)
53{
54 // if (resetCameras) fGLViewer->PostSceneBuildSetup(kTRUE);
55 // fGLViewer->RequestDraw(TGLRnrCtx::kLODHigh);
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Add 'scene' to the list of scenes.
60
62{
63 static const REveException eh("REveViewer::AddScene ");
64
65 for (auto &c: RefChildren()) {
66 auto sinfo = dynamic_cast<REveSceneInfo*>(c);
67
68 if (sinfo && sinfo->GetScene() == scene)
69 {
70 throw eh + "scene already in the viewer.";
71 }
72 }
73
74 auto si = new REveSceneInfo(this, scene);
76}
77
78////////////////////////////////////////////////////////////////////////////////
79/// Remove element 'el' from the list of children and also remove
80/// appropriate GLScene from GLViewer's list of scenes.
81/// Virtual from REveElement.
82
84{
85 // fGLViewer->RemoveScene(((REveSceneInfo*)el)->GetGLScene());
86
87 // XXXXX Notify clients !!! Or will this be automatic?
88}
89
90////////////////////////////////////////////////////////////////////////////////
91/// Remove all children, forwarded to GLViewer.
92/// Virtual from REveElement.
93
95{
96 // fGLViewer->RemoveAllScenes();
97
98 // XXXXX Notify clients !!! Or will this be automatic?
99}
100
101
102/** \class REveViewerList
103\ingroup REve
104List of Viewers providing common operations on REveViewer collections.
105*/
106
107////////////////////////////////////////////////////////////////////////////////
108//
110{
111 fAxesType = (EAxesType)at;
112 if (fAxesType != kAxesNone) {
113 std::string fn = "LiberationSerif-Regular";
114 std::string rf_dir = std::string(TROOT::GetDataDir().Data()) + "/fonts/";
115 REX::REveText::AssertSdfFont(fn, rf_dir + fn + ".ttf");
116 }
118}
119
120////////////////////////////////////////////////////////////////////////////////
121//
127
128////////////////////////////////////////////////////////////////////////////////
129/// Stream Camera Info.
130/// Virtual from REveElement.
132{
133 // fCamera.WriteCoreJson(j, rnr_offset);
134
135 j["Mandatory"] = fMandatory;
136 j["AxesType"] = fAxesType;
137 j["BlackBg"] = fBlackBackground;
138 j["fCameraId"] = fCamera ? fCamera->GetElementId() : 0;
139 j["fSyncCam"] = fSyncCamera;
140
141 j["UT_PostStream"] = "UT_EveViewerUpdate";
142
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Function called from MIR when user closes one of the viewer window.
148// Client id stored in thread local data
153////////////////////////////////////////////////////////////////////////////////
154/// Function called from MIR when user wants to stream unsubscribed view.
155// Client id stored in thread local data
160
161////////////////////////////////////////////////////////////////////////////////
162///
163// Set Flag if this viewer is presented on connect
165{
166 fMandatory = x;
167 for (auto &c : RefChildren()) {
168 REveSceneInfo *sinfo = dynamic_cast<REveSceneInfo *>(c);
169 sinfo->GetScene()->GetScene()->SetMandatory(fMandatory);
170 }
171}
172
173////////////////////////////////////////////////////////////////////////////////
174/// Set camera reference
175
181
182////////////////////////////////////////////////////////////////////////////////
183
184REveViewerList::REveViewerList(const std::string &n, const std::string &t) :
185 REveElement (n, t),
186 fShowTooltip (kTRUE),
187
188 fBrightness(0),
189 fUseLightColorSet(kFALSE)
190{
191 // Constructor.
192
193 SetChildClass(TClass::GetClass<REveViewer>());
194 Connect();
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Destructor.
199
204
205////////////////////////////////////////////////////////////////////////////////
206/// Call base-class implementation.
207/// If compound is open and compound of the new element is not set,
208/// the el's compound is set to this.
209
214
215////////////////////////////////////////////////////////////////////////////////
216/// Decompoundofy el, call base-class version.
217
219{
220 // This was needed as viewer was in EveWindowManager hierarchy, too.
221 // el->DecParentIgnoreCnt();
222
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Decompoundofy children, call base-class version.
228
230{
231 // This was needed as viewer was in EveWindowManager hierarchy, too.
232 // el->DecParentIgnoreCnt();
233 // for (auto &c: fChildren)
234 // {
235 // c->DecParentIgnoreCnt();
236 // }
237
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Connect to TGLViewer class-signals.
243
245{
246 // TQObject::Connect("TGLViewer", "MouseOver(TObject*,UInt_t)",
247 // "REveViewerList", this, "OnMouseOver(TObject*,UInt_t)");
248
249 // TQObject::Connect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
250 // "REveViewerList", this, "OnReMouseOver(TObject*,UInt_t)");
251
252 // TQObject::Connect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
253 // "REveViewerList", this, "OnUnMouseOver(TObject*,UInt_t)");
254
255 // TQObject::Connect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
256 // "REveViewerList", this, "OnClicked(TObject*,UInt_t,UInt_t)");
257
258 // TQObject::Connect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
259 // "REveViewerList", this, "OnReClicked(TObject*,UInt_t,UInt_t)");
260
261 // TQObject::Connect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
262 // "REveViewerList", this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
263}
264
265////////////////////////////////////////////////////////////////////////////////
266/// Disconnect from TGLViewer class-signals.
267
269{
270 // TQObject::Disconnect("TGLViewer", "MouseOver(TObject*,UInt_t)",
271 // this, "OnMouseOver(TObject*,UInt_t)");
272
273 // TQObject::Disconnect("TGLViewer", "ReMouseOver(TObject*,UInt_t)",
274 // this, "OnReMouseOver(TObject*,UInt_t)");
275
276 // TQObject::Disconnect("TGLViewer", "UnMouseOver(TObject*,UInt_t)",
277 // this, "OnUnMouseOver(TObject*,UInt_t)");
278
279 // TQObject::Disconnect("TGLViewer", "Clicked(TObject*,UInt_t,UInt_t)",
280 // this, "OnClicked(TObject*,UInt_t,UInt_t)");
281
282 // TQObject::Disconnect("TGLViewer", "ReClicked(TObject*,UInt_t,UInt_t)",
283 // this, "OnReClicked(TObject*,UInt_t,UInt_t)");
284
285 // TQObject::Disconnect("TGLViewer", "UnClicked(TObject*,UInt_t,UInt_t)",
286 // this, "OnUnClicked(TObject*,UInt_t,UInt_t)");
287}
288
289////////////////////////////////////////////////////////////////////////////////
290/// Repaint viewers that are tagged as changed.
291
292void REveViewerList::RepaintChangedViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
293{
294 //for (auto &c: fChildren) {
295 // TGLViewer* glv = ((REveViewer*)c)->GetGLViewer();
296 // if (glv->IsChanged())
297 // {
298 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
299 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
300
301 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
302
303 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
304 // }
305 //}
306}
307
308////////////////////////////////////////////////////////////////////////////////
309/// Repaint all viewers.
310
311void REveViewerList::RepaintAllViewers(Bool_t /*resetCameras*/, Bool_t /*dropLogicals*/)
312{
313 // for (auto &c: fChildren) {
314 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
315
316 // if (resetCameras) glv->PostSceneBuildSetup(kTRUE);
317 // if (dropLogicals) glv->SetSmartRefresh(kFALSE);
318
319 // glv->RequestDraw(TGLRnrCtx::kLODHigh);
320
321 // if (dropLogicals) glv->SetSmartRefresh(kTRUE);
322 // }
323}
324
325////////////////////////////////////////////////////////////////////////////////
326/// Delete annotations from all viewers.
327
329{
330 // for (auto &c: fChildren) {
331 // TGLViewer* glv = ((REveViewer *)c)->GetGLViewer();
332 // glv->DeleteOverlayAnnotations();
333 // }
334}
335
336////////////////////////////////////////////////////////////////////////////////
337/// Callback done from a REveScene destructor allowing proper
338/// removal of the scene from affected viewers.
339
341{
342 for (auto &viewer: fChildren) {
343 for (auto &j: viewer->RefChildren()) {
345 if (sinfo->GetScene() == scene)
346 viewer->RemoveElement(sinfo);
347 }
348 }
349}
350
351////////////////////////////////////////////////////////////////////////////////
352/// Set color brightness.
353
358
359////////////////////////////////////////////////////////////////////////////////
360/// Switch background color.
361
363{
365 // To implement something along the lines of:
366 // BeginChanges on EveWorld; // Here or in the calling function
367 // for (auto &c: fChildren) {
368 // REveViewer* v = (REveViewer *)c;
369 // if ( fUseLightColorSet)
370 // c->UseLightColorSet();
371 // else
372 // c->UseDarkColorSet();
373 // }
374 // EndChanges on EveWorld;
375}
376
378{
380 auto cam = dynamic_cast<REveCamera *>(element);
381
382 if (cam) {
383 fCamera = cam;
385 }
386}
387
388////////////////////////////////////////////////////////////////////////////////
389/// Set camera by type (backward compatibility with old API)
390
392{
393 for (auto &cam : fCameraList) {
394 if (cam->GetType() == type) {
395 fCamera = cam;
396 }
397 }
398
400 fCameraList.push_back(fCamera);
402}
403
404////////////////////////////////////////////////////////////////////////////////
405// Create Camera Based on Type Enum (Lines 161-190)
407{
408 REveCamera *cam = nullptr;
409
410 struct CameraDef {
412 const char *name;
415 };
416
417 static const CameraDef predefinedCameras[] = {
418 // Perspective cameras
419 {REveCamera::kCameraPerspXOZ, "PerspXOZ", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0)},
420 {REveCamera::kCameraPerspYOZ, "PerspYOZ", REveVector(0.0, -1.0, 0.0), REveVector(1.0, 0.0, 0.0)},
421 {REveCamera::kCameraPerspXOY, "PerspXOY", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 0.0, 1.0)},
422 // Orthographic cameras
423 {REveCamera::kCameraOrthoXOY, "OrthoXOY", REveVector(0.0, 0.0, 1.0), REveVector(0.0, 1.0, 0.0)},
424 {REveCamera::kCameraOrthoXOZ, "OrthoXOZ", REveVector(0.0, -1.0, 0.0), REveVector(0.0, 0.0, 1.0)},
425 {REveCamera::kCameraOrthoZOY, "OrthoZOY", REveVector(-1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0)},
426 {REveCamera::kCameraOrthoZOX, "OrthoZOX", REveVector(0.0, -1.0, 0.0), REveVector(1.0, 0.0, 0.0)},
427 // Orthographic negative camera
428 {REveCamera::kCameraOrthoXnOY, "OrthoXnOY", REveVector(0.0, 0.0, -1.0), REveVector(0.0, 1.0, 0.0)},
429 {REveCamera::kCameraOrthoXnOZ, "OrthoXnOZ", REveVector(0.0, 1.0, 0.0), REveVector(0.0, 0.0, 1.0)},
430 {REveCamera::kCameraOrthoZnOY, "OrthoZnOY", REveVector(1.0, 0.0, 0.0), REveVector(0.0, 1.0, 0.0)},
431 {REveCamera::kCameraOrthoZnOX, "OrthoZnOX", REveVector(0.0, 1.0, 0.0), REveVector(1.0, 0.0, 0.0)}};
432
433 // Create and add all predefined cameras
434 for (const auto &camDef : predefinedCameras) {
435 if (type == camDef.type) {
436 cam = new REveCamera(camDef.name);
438 cam->Setup(camDef.type, camDef.name, camDef.v1, camDef.v2);
439 }
440 }
441
442 return cam;
443}
#define b(i)
Definition RSha256.hxx:100
#define c(i)
Definition RSha256.hxx:101
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
char name[80]
Definition TGX11.cxx:148
virtual void RemoveElementsLocal()
Perform additional local removal of all elements.
virtual Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset)
Write core json.
virtual void AddElement(REveElement *el)
Add el to the list of children.
virtual void RemoveElementLocal(REveElement *el)
Perform additional local removal of el.
ElementId_t GetElementId() const
REveException Exception-type thrown by Eve classes.
Definition REveTypes.hxx:42
void DisconnectEveViewer(REveViewer *)
REveElement * FindElementById(ElementId_t id) const
Lookup ElementId in element map and return corresponding REveElement*.
void ConnectEveViewer(REveViewer *)
REveElement * GetCameras() const
REveSceneInfo Scene in a viewer.
static void SetColorBrightness(Float_t value, Bool_t full_redraw=kFALSE)
Tweak all ROOT colors to become brighter (if value > 0) or darker (value < 0).
Definition REveUtil.cxx:226
void RemoveElementsLocal() override
Decompoundofy children, call base-class version.
void AddElement(REveElement *el) override
Call base-class implementation.
~REveViewerList() override
Destructor.
void SceneDestructing(REveScene *scene)
Callback done from a REveScene destructor allowing proper removal of the scene from affected viewers.
void SetColorBrightness(Float_t b)
Set color brightness.
void RepaintAllViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint all viewers.
virtual void Disconnect()
Disconnect from TGLViewer class-signals.
void RepaintChangedViewers(Bool_t resetCameras, Bool_t dropLogicals)
Repaint viewers that are tagged as changed.
void SwitchColorSet()
Switch background color.
REveViewerList(const REveViewerList &)=delete
virtual void Connect()
Connect to TGLViewer class-signals.
void DeleteAnnotations()
Delete annotations from all viewers.
void RemoveElementLocal(REveElement *el) override
Decompoundofy el, call base-class version.
void RemoveElementLocal(REveElement *el) override
Remove element 'el' from the list of children and also remove appropriate GLScene from GLViewer's lis...
void DisconnectClient()
Function called from MIR when user closes one of the viewer window.
void ConnectClient()
Function called from MIR when user wants to stream unsubscribed view.
~REveViewer() override
Destructor.
void SetCamera(ROOT::Experimental::REveCamera *cam)
Set camera reference.
std::vector< REveCamera * > fCameraList
void RemoveElementsLocal() override
Remove all children, forwarded to GLViewer.
void SetCameraType(REveCamera::ECameraType type)
Set camera by type (backward compatibility with old API)
Int_t WriteCoreJson(nlohmann::json &cj, Int_t rnr_offset) override
Stream Camera Info.
void SetCameraByElementId(ElementId_t cameraId)
void Redraw(Bool_t resetCameras=kFALSE)
Redraw viewer immediately.
virtual void AddScene(REveScene *scene)
Add 'scene' to the list of scenes.
ROOT::Experimental::REveCamera * CreateCamera(ECameraType type)
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Definition TROOT.cxx:3391
Double_t x[n]
Definition legend1.C:17
const Int_t n
Definition legend1.C:16
Namespace for ROOT features in testing.
Definition TROOT.h:100
R__EXTERN REveManager * gEve
REveVectorT< Float_t > REveVector