Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
server.cxx
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_webgui
3/// This tutorial demonstrates how three.js model for geometry can be created.
4/// In server.cxx one uses RGeomDescription class from geometry viewer, which produces
5/// JSON data with all necessary information. Then RWebWindow is started and this information provided.
6/// In client.html one uses **build** function to create Object3D with geometry
7/// Then such object placed in three.js scene and rendered. Also simple animation is implemented
8///
9/// \macro_code
10///
11/// \author Sergey Linev
12
13#include <ROOT/RGeomData.hxx>
14
15#include <ROOT/RWebWindow.hxx>
16
17
18std::shared_ptr<ROOT::RWebWindow> window;
19
20std::string json;
21
22TString base64;
23
24
25void ProcessData(unsigned connid, const std::string &arg)
26{
27 if (arg == "get") {
28 // send arbitrary text message
29 window->Send(connid, base64.Data());
30 } else if (arg == "halt") {
31 // terminate ROOT
32 window->TerminateROOT();
33 }
34}
35
36void server()
37{
38
40
41 TGeoManager::Import("https://root.cern/files/cms.root");
42
59
61
62 data.Build(gGeoManager, "CMSE");
63
64 json = data.ProduceJson();
65
66 base64 = TBase64::Encode(json.c_str());
67
68 // create window
69 window = ROOT::RWebWindow::Create();
70
71 // configure default html page
72 // either HTML code can be specified or just name of file after 'file:' prefix
73 window->SetDefaultPage("file:client.html");
74
75 // this is call-back, invoked when message received from client
76 window->SetDataCallBack(ProcessData);
77
78 window->SetGeometry(800, 600); // configure predefined geometry
79
80 window->Show();
81}
nlohmann::json json
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
R__EXTERN TGeoManager * gGeoManager
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(ROOT::Internal::TStringView cacheDir, Bool_t operateDisconnected=kTRUE, Bool_t forceCacheread=kFALSE)
Definition TFile.h:332
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
const char * Data() const
Definition TString.h:380