Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
trans_update.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_eve_7
3/// Move an element from the server by changing only its transformation.
4///
5/// One box stands still in the centre. Four boxes go round a square about it,
6/// a step every 200 ms, each moved by SetTransMatrix(), which streams only the
7/// new matrix. The client moves the objects it already has and rebuilds no
8/// geometry.
9///
10/// \macro_code
11///
12/// \author Matevz Tadel
13
14#include <ROOT/REveManager.hxx>
15#include <ROOT/REveScene.hxx>
16#include <ROOT/REveBox.hxx>
17#include <ROOT/REveTrans.hxx>
18
19#include <TTimer.h>
20#include <TMath.h>
21
22#include <vector>
23
24using namespace ROOT::Experimental;
25
26/// Position (`x`, `y`) at `s` along the perimeter of a square of half-side
27/// `a`, s in [0, 4) going counter-clockwise from the corner (a, -a).
28static void square_pos(Double_t s, Double_t a, Double_t &x, Double_t &y)
29{
30 const Double_t f = 2 * a * (s - TMath::Floor(s)) - a; // -a .. a along the side
31 switch (Int_t(TMath::Floor(s)) % 4) {
32 case 0:
33 x = a;
34 y = f;
35 break;
36 case 1:
37 x = -f;
38 y = a;
39 break;
40 case 2:
41 x = -a;
42 y = -f;
43 break;
44 default:
45 x = f;
46 y = -a;
47 break;
48 }
49}
50
51class REveTransMover : public TTimer {
52 // clang-format off
53 std::vector<REveElement*> fEls;
54 int fStep{0};
55 // clang-format on
56
57public:
58 REveTransMover(std::vector<REveElement *> els, Long_t ms) : TTimer(ms, kTRUE), fEls(std::move(els)) {}
59
60 Bool_t Notify() override
61 {
63
64 for (size_t i = 0; i < fEls.size(); ++i) {
65 Double_t x, y;
66 square_pos(0.02 * fStep + i, 40, x, y);
67 REveTrans t;
68 t.SetPos(0.0, y, x); // in the yz plane, which faces the default camera
69 fEls[i]->SetTransMatrix(t.Array()); // a transformation-only change
70 }
71
72 ++fStep;
73 Reset();
74 return kTRUE;
75 }
76};
77
78static REveBox *make_box(const char *name, Color_t col, Float_t a, Float_t z)
79{
80 auto b = new REveBox(name);
81 b->SetMainColor(col);
82 b->SetMainTransparency(0);
83
84 // clang-format off
85 b->SetVertex(0, -a, -a, z - a); b->SetVertex(1, -a, a, z - a);
86 b->SetVertex(2, a, a, z - a); b->SetVertex(3, a, -a, z - a);
87 b->SetVertex(4, -a, -a, z + a); b->SetVertex(5, -a, a, z + a);
88 b->SetVertex(6, a, a, z + a); b->SetVertex(7, a, -a, z + a);
89 // clang-format on
90
91 return b;
92}
93
94void trans_update()
95{
96 auto eveMng = REveManager::Create();
97 eveMng->AllowMultipleRemoteConnections(false, false);
98
99 auto still = make_box("Still", kCyan, 10, 0);
100 eveMng->GetEventScene()->AddElement(still);
101
102 const Color_t colors[] = {kMagenta, kOrange, kGreen + 1, kBlue};
103 std::vector<REveElement *> movers;
104 for (int i = 0; i < 4; ++i) {
105 auto mover = make_box(Form("Mover %d", i), colors[i], 6, 0);
106 // Give the box a transformation from the start, so the first stream
107 // already carries its matrix.
108 mover->InitMainTrans();
109 eveMng->GetEventScene()->AddElement(mover);
110 movers.push_back(mover);
111 }
112
113 eveMng->Show();
114
115 auto timer = new REveTransMover(movers, 200);
116 timer->Notify();
117 timer->TurnOn();
118}
#define b(i)
Definition RSha256.hxx:100
#define f(i)
Definition RSha256.hxx:104
#define a(i)
Definition RSha256.hxx:99
bool Bool_t
Boolean (0=false, 1=true) (bool)
Definition RtypesCore.h:78
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:60
short Color_t
Color number (short)
Definition RtypesCore.h:100
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:69
float Float_t
Float 4 bytes (float)
Definition RtypesCore.h:72
double Double_t
Double 8 bytes.
Definition RtypesCore.h:74
constexpr Bool_t kTRUE
Definition RtypesCore.h:108
@ kOrange
Definition Rtypes.h:67
@ kGreen
Definition Rtypes.h:66
@ kMagenta
Definition Rtypes.h:66
@ kCyan
Definition Rtypes.h:66
@ kBlue
Definition Rtypes.h:66
char name[80]
Definition TGX11.cxx:142
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2571
3D box with arbitrary vertices (cuboid).
RAII guard for locking Eve manager (ctor) and processing changes (dtor).
REveTrans is a 4x4 transformation matrix for homogeneous coordinates stored internally in a column-ma...
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
void Reset()
Reset the timer.
Definition TTimer.cxx:162
Bool_t Notify() override
Notify when timer times out.
Definition TTimer.cxx:148
Double_t y[n]
Definition legend1.C:17
Double_t x[n]
Definition legend1.C:17
Namespace for ROOT features in testing.
Definition TROOT.h:100
Double_t Floor(Double_t x)
Rounds x downward, returning the largest integral value that is not greater than x.
Definition TMath.h:693