Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
geom_threejs.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webgui
3/// \ingroup webwidgets
4/// The tutorial demonstrates how three.js model for geometry can be created and displayed.
5///
6/// In geom_threejs.cxx one uses RGeomDescription class from geometry viewer, which produces
7/// JSON data with all necessary information. Then RWebWindow is started and this information provided.
8/// In client.html one uses **build** function to create Object3D with geometry
9/// Then such object placed in three.js scene and rendered. Also simple animation is implemented
10///
11/// \macro_code
12///
13/// \author Sergey Linev
14
15#include <ROOT/RGeomData.hxx>
16
17#include <ROOT/RWebWindow.hxx>
18
19std::shared_ptr<ROOT::RWebWindow> window;
20
21TString base64;
22
23void ProcessData(unsigned connid, const std::string &arg)
24{
25 if (arg == "get") {
26 // send arbitrary text message
27 window->Send(connid, base64.Data());
28 } else if (arg == "halt") {
29 // terminate ROOT
30 window->TerminateROOT();
31 }
32}
33
34void geom_threejs()
35{
36
38
39 TGeoManager::Import("https://root.cern/files/cms.root");
40
41 gGeoManager->DefaultColors();
42 gGeoManager->SetVisLevel(4);
43 gGeoManager->GetVolume("TRAK")->InvisibleAll();
44 gGeoManager->GetVolume("HVP2")->SetTransparency(20);
45 gGeoManager->GetVolume("HVEQ")->SetTransparency(20);
46 gGeoManager->GetVolume("YE4")->SetTransparency(10);
47 gGeoManager->GetVolume("YE3")->SetTransparency(20);
48 gGeoManager->GetVolume("RB2")->SetTransparency(99);
49 gGeoManager->GetVolume("RB3")->SetTransparency(99);
50 gGeoManager->GetVolume("COCF")->SetTransparency(99);
51 gGeoManager->GetVolume("HEC1")->SetLineColor(7);
52 gGeoManager->GetVolume("EAP1")->SetLineColor(7);
53 gGeoManager->GetVolume("EAP2")->SetLineColor(7);
54 gGeoManager->GetVolume("EAP3")->SetLineColor(7);
55 gGeoManager->GetVolume("EAP4")->SetLineColor(7);
56 gGeoManager->GetVolume("HTC1")->SetLineColor(2);
57
59
60 data.Build(gGeoManager, "CMSE");
61
62 std::string json = data.ProduceJson();
63
64 base64 = TBase64::Encode(json.c_str());
65
66 // create window
67 window = ROOT::RWebWindow::Create();
68
69 // configure default html page
70 // either HTML code can be specified or just name of file after 'file:' prefix
71 std::string fdir = __FILE__;
72 auto pos = fdir.find("geom_threejs.cxx");
73 if (pos > 0)
74 fdir.resize(pos);
75 else
76 fdir = gROOT->GetTutorialsDir() + std::string("/visualisation/webgui/geom/");
77 window->SetDefaultPage("file:" + fdir + "geom_threejs.html");
78
79 // this is call-back, invoked when message received from client
80 window->SetDataCallBack(ProcessData);
81
82 window->SetGeometry(800, 600); // configure predefined geometry
83
84 window->Show();
85}
nlohmann::json json
externTGeoManager * gGeoManager
#define gROOT
Definition TROOT.h:417
static std::shared_ptr< RWebWindow > Create()
Create new RWebWindow Using default RWebWindowsManager.
static TString Encode(const char *data)
Transform data into a null terminated base64 string.
Definition TBase64.cxx:106
static Bool_t SetCacheFileDir(std::string_view cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Sets the directory where to locally stage/cache remote files.
Definition TFile.cxx:4328
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
Basic string class.
Definition TString.h:138
const char * Data() const
Definition TString.h:384