Logo ROOT  
Reference Guide
 
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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
22
23
24void ProcessData(unsigned connid, const std::string &arg)
25{
26 if (arg == "get") {
27 // send arbitrary text message
28 window->Send(connid, base64.Data());
29 } else if (arg == "halt") {
30 // terminate ROOT
31 window->TerminateROOT();
32 }
33}
34
35void geom_threejs()
36{
37
39
40 TGeoManager::Import("https://root.cern/files/cms.root");
41
58
60
61 data.Build(gGeoManager, "CMSE");
62
63 std::string json = data.ProduceJson();
64
65 base64 = TBase64::Encode(json.c_str());
66
67 // create window
68 window = ROOT::RWebWindow::Create();
69
70 // configure default html page
71 // either HTML code can be specified or just name of file after 'file:' prefix
72 std::string fdir = __FILE__;
73 auto pos = fdir.find("geom_threejs.cxx");
74 if (pos > 0)
75 fdir.resize(pos);
76 else
77 fdir = gROOT->GetTutorialsDir() + std::string("/webgui/geom/");
78 window->SetDefaultPage("file:" + fdir + "geom_threejs.html");
79
80 // this is call-back, invoked when message received from client
81 window->SetDataCallBack(ProcessData);
82
83 window->SetGeometry(800, 600); // configure predefined geometry
84
85 window->Show();
86}
nlohmann::json json
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 data
R__EXTERN TGeoManager * gGeoManager
#define gROOT
Definition TROOT.h:406
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:107
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:4637
void SetVisLevel(Int_t level=3)
set default level down to which visualization is performed
static TGeoManager * Import(const char *filename, const char *name="", Option_t *option="")
static function Import a geometry from a gdml or ROOT file
TGeoVolume * GetVolume(const char *name) const
Search for a named volume. All trailing blanks stripped.
void DefaultColors()
Set default volume colors according to A of material.
void SetTransparency(Char_t transparency=0)
Definition TGeoVolume.h:376
void InvisibleAll(Bool_t flag=kTRUE)
Make volume and each of it daughters (in)visible.
void SetLineColor(Color_t lcolor) override
Set the line color.
Basic string class.
Definition TString.h:139