Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLAutoRotator.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, 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 "TGLAutoRotator.h"
13
14#include "TGLPhysicalShape.h"
15#include "TGLLogicalShape.h"
16#include "TGLViewer.h"
17#include "TGLCamera.h"
18#include "TGLScene.h"
19
20#include "TMath.h"
21#include "TTimer.h"
22#include "TStopwatch.h"
23
24/** \class TGLAutoRotator
25\ingroup opengl
26Automatically rotates GL camera.
27
28W's are angular velocities.
29 - ATheta -- Theta amplitude in units of Pi/2.
30 - ADolly -- In/out amplitude in units of initial distance.
31
32Can also save images automatically.
33
34fGUIOutMode is used internally between TGLAutoRotator and TGLViewerEditor,
35allowed values are:
36 1. animated gif
37 2. a series of png images
38*/
39
41
42////////////////////////////////////////////////////////////////////////////////
43/// Constructor.
44
46 fViewer(v), fCamera(nullptr),
47 fTimer(new TTimer), fWatch(new TStopwatch),
48 fRotateScene(kFALSE),
49 fDeltaPhi(0.005),
50 fDt (0.01),
51 fWPhi (0.40),
52 fWTheta(0.15), fATheta(0.5),
53 fWDolly(0.30), fADolly(0.4),
54 fTimerRunning(kFALSE),
55 fImageCount(0), fImageAutoSave(kFALSE),
56 fImageGUIBaseName("animation"), fImageGUIOutMode(1)
57{
58 fTimer->Connect("Timeout()", "TGLAutoRotator", this, "Timeout()");
59}
60
61////////////////////////////////////////////////////////////////////////////////
62/// Destructor.
63
65{
66 delete fWatch;
67 delete fTimer;
68}
69
70////////////////////////////////////////////////////////////////////////////////
71/// Set time between two redraws in seconds.
72/// Range: 0.001 -> 1.
73
75{
76 fDt = TMath::Range(0.01, 1.0, dt);
77 if (fTimerRunning)
78 {
80 fTimer->Reset();
81 }
82}
83
84////////////////////////////////////////////////////////////////////////////////
85/// Set relative amplitude of theta oscillation.
86/// Value range: 0.01 -> 1.
87
89{
90 a = TMath::Range(0.01, 1.0, a);
91 if (fTimerRunning)
92 {
94 }
95 fATheta = a;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Set relative amplitude of forward/backward oscillation.
100/// Value range: 0.01 -> 1.
101
103{
104 a = TMath::Range(0.01, 1.0, a);
105 if (fTimerRunning)
106 {
108 }
109 fADolly = a;
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Start the auto-rotator.
114
116{
117 if (fTimerRunning)
118 {
119 Stop();
120 }
121
123
126
129 fTimer->Reset();
130 fTimer->TurnOn();
131 fWatch->Start();
132}
133
134////////////////////////////////////////////////////////////////////////////////
135/// Stop the auto-rotator.
136
138{
139 if (fTimerRunning)
140 {
141 fWatch->Stop();
142 fTimer->TurnOff();
144 }
145}
146
147////////////////////////////////////////////////////////////////////////////////
148/// Called on every timer timeout. Moves / rotates the camera and optionally
149/// produces a screenshot.
150
152{
153 if (!fTimerRunning || gTQSender != fTimer)
154 {
155 Error("Timeout", "Not running or not called via timer.");
156 return;
157 }
158
159 using namespace TMath;
160
161 fWatch->Stop();
162 Double_t time = fWatch->RealTime();
163 fWatch->Continue();
164
165 if (fRotateScene) {
166 RotateScene();
167 } else {
168 Double_t delta_p = fWPhi*fDt;
169 Double_t delta_t = fThetaA0*fWTheta*Cos(fWTheta*time)*fDt;
170 Double_t delta_d = fDollyA0*fWDolly*Cos(fWDolly*time)*fDt;
171 Double_t th = fCamera->GetTheta();
172
173 if (th + delta_t > 3.0 || th + delta_t < 0.1416)
174 delta_t = 0;
175
176 fCamera->RotateRad(delta_t, delta_p);
177 fCamera->RefCamTrans().MoveLF(1, -delta_d);
178 }
179
181
182 if (fImageAutoSave)
183 {
185 if (fImageName.Contains("%"))
186 {
188 }
189 else
190 {
192 }
194 ++fImageCount;
195 }
196}
197
198////////////////////////////////////////////////////////////////////////////////
199/// Start saving into animated gif. The provided name will be used as it is,
200/// so make sure to end it with '.gif+'.
201/// Use convert tool from ImageMagic if you want to set a different delay or
202/// enable looping.
203
205{
206 if ( ! filename.Contains(".gif+"))
207 {
208 Error("StartImageAutoSaveAnimatedGif", "Name should end with '.gif+'. Not starting.");
209 return;
210 }
211
213 fImageCount = 0;
215}
216
217////////////////////////////////////////////////////////////////////////////////
218/// Start saving into a set of images. The provided name will be used as a
219/// format to insert additional image sequence number so it should include
220/// an '%' character. A good name would be something like:
221/// "image-%04d.png"
222/// On GNU/Linux use mencoder and/or ffmpeg to bundle images into a movie.
223
225{
226 if ( ! filename.Contains("%"))
227 {
228 Error("StartImageAutoSave", "Name should include a '%%' character, like 'image-%%05d.png'. Not starting.");
229 return;
230 }
231
233 fImageCount = 0;
235}
236
237////////////////////////////////////////////////////////////////////////////////
238/// Stops automatic saving of images.
239
241{
243}
244
245////////////////////////////////////////////////////////////////////////////////
246/// Set output mode for GUI operation:
247/// 1 - animated gif;
248/// 2 - a series of pngs
249
251{
252 if (m < 1 || m > 2)
253 {
254 Warning("SetImageGUIOutMode", "Invalid value, ignoring");
255 return;
256 }
258}
259
260////////////////////////////////////////////////////////////////////////////////
261/// Start auto-saving images as set-up via GUI.
262
264{
265 if (fImageGUIOutMode == 1)
266 {
267 TString name = fImageGUIBaseName + ".gif+";
269 }
270 else if (fImageGUIOutMode == 2)
271 {
272 TString name = fImageGUIBaseName + "-%05d.png";
274 }
275 else
276 {
277 Warning("StartImageAutoSaveWithGUISettings", "Unsupported mode '%d'.", fImageGUIOutMode);
278 }
279}
280
281////////////////////////////////////////////////////////////////////////////////
282///"Scene rotation": either find a special object,
283///which will be an axis of rotation (it's Z actually)
284///or use a "global" Z axis.
285
287{
289 TGLViewer::SceneInfoList_i sceneIter = scenes.begin();
290
291 for (; sceneIter != scenes.end(); ++sceneIter) {
292 TGLScene::TSceneInfo *sceneInfo = dynamic_cast<TGLScene::TSceneInfo *>(*sceneIter);
293 if (sceneInfo) {
294 TGLPhysicalShape *axisShape = nullptr;
295 TGLScene::ShapeVec_i shapeIter = sceneInfo->fShapesOfInterest.begin();
296 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
297 TGLPhysicalShape * const testShape = const_cast<TGLPhysicalShape *>(*shapeIter);
298 if (testShape && testShape->GetLogical()->ID()->TestBit(13)) {
299 axisShape = testShape;
300 break;
301 }
302 }
303
304 TGLVector3 axis;
305 TGLVertex3 center;
306
307 if (!axisShape) {
308 const TGLBoundingBox &bbox = sceneInfo->GetTransformedBBox();
309 axis = bbox.Axis(2);
310 center = bbox.Center();
311 } else {
312 axis = axisShape->BoundingBox().Axis(2);
313 center = axisShape->BoundingBox().Center();
314 }
315
316 shapeIter = sceneInfo->fShapesOfInterest.begin();
317 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
318 if (TGLPhysicalShape * const shape = const_cast<TGLPhysicalShape *>(*shapeIter))
319 shape->Rotate(center, axis, fDeltaPhi);
320 }
321 }
322 }
323}
#define a(i)
Definition RSha256.hxx:99
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:377
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 filename
char name[80]
Definition TGX11.cxx:110
R__EXTERN void * gTQSender
Definition TQObject.h:46
Automatically rotates GL camera.
void Start()
Start the auto-rotator.
void RotateScene()
"Scene rotation": either find a special object, which will be an axis of rotation (it's Z actually) o...
void SetATheta(Double_t a)
Set relative amplitude of theta oscillation.
TGLAutoRotator(const TGLAutoRotator &)=delete
void Stop()
Stop the auto-rotator.
TGLViewer * fViewer
void SetImageGUIOutMode(Int_t m)
Set output mode for GUI operation: 1 - animated gif; 2 - a series of pngs.
TString fImageGUIBaseName
TStopwatch * fWatch
void StartImageAutoSaveWithGUISettings()
Start auto-saving images as set-up via GUI.
void StopImageAutoSave()
Stops automatic saving of images.
void StartImageAutoSaveAnimatedGif(const TString &filename)
Start saving into animated gif.
TGLCamera * fCamera
void SetDt(Double_t dt)
Set time between two redraws in seconds.
void StartImageAutoSave(const TString &filename)
Start saving into a set of images.
~TGLAutoRotator() override
Destructor.
void SetADolly(Double_t a)
Set relative amplitude of forward/backward oscillation.
void Timeout()
Called on every timer timeout.
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
TGLVertex3 Center() const
const TGLVector3 & Axis(UInt_t i, Bool_t normalised=kTRUE) const
virtual Bool_t RotateRad(Double_t hRotate, Double_t vRotate)
Rotate camera around center.
const TGLMatrix & GetCamTrans() const
Definition TGLCamera.h:167
Double_t GetTheta() const
Get angle between camera up axis.
TGLMatrix & RefCamTrans()
Definition TGLCamera.h:170
TObject * ID() const
void MoveLF(Int_t ai, Double_t amount)
Translate in local frame.
Definition TGLUtil.cxx:813
TGLVector3 GetBaseVec(Int_t b) const
Definition TGLUtil.h:754
Concrete physical shape - a GL drawable.
const TGLBoundingBox & BoundingBox() const
const TGLLogicalShape * GetLogical() const
const TGLBoundingBox & GetTransformedBBox()
ShapeVec_t fShapesOfInterest
Definition TGLScene.h:88
ShapeVec_t::iterator ShapeVec_i
Definition TGLScene.h:73
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
Double_t Mag() const
Definition TGLUtil.h:298
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
SceneInfoList_t fScenes
std::list< TGLSceneInfo * > SceneInfoList_t
SceneInfoList_t::iterator SceneInfoList_i
Base GL viewer object - used by both standalone and embedded (in pad) GL.
Definition TGLViewer.h:55
void RequestDraw(Short_t LOD=TGLRnrCtx::kLODMed)
Post request for redraw of viewer at level of detail 'LOD' Request is directed via cross thread gVirt...
TGLCamera & CurrentCamera() const
Definition TGLViewer.h:268
Bool_t SavePicture()
Save current image using the default file name which can be set via SetPictureFileName() and defaults...
R__ALWAYS_INLINE Bool_t TestBit(UInt_t f) const
Definition TObject.h:199
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:973
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:987
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
Non-static method is used to connect from the signal of this object to the receiver slot.
Definition TQObject.cxx:869
Stopwatch class.
Definition TStopwatch.h:28
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Continue()
Resume a stopped stopwatch.
void Stop()
Stop the stopwatch.
Basic string class.
Definition TString.h:139
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:632
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOff()
Remove timer from system timer list.
Definition TTimer.cxx:231
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:243
void Reset()
Reset the timer.
Definition TTimer.cxx:159
void SetTime(Long_t milliSec)
Definition TTimer.h:91
TMath.
Definition TMathBase.h:35
Int_t Nint(T x)
Round to nearest integer. Rounds half integers to the nearest even integer.
Definition TMath.h:693
constexpr Double_t PiOver2()
Definition TMath.h:51
Short_t Range(Short_t lb, Short_t ub, Short_t x)
Returns x if lb < x < up, lb if x < lb and ub if x > ub.
Definition TMathBase.h:302
TMarker m
Definition textangle.C:8