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
40
41////////////////////////////////////////////////////////////////////////////////
42/// Constructor.
43
45 fViewer(v), fCamera(nullptr),
46 fTimer(new TTimer), fWatch(new TStopwatch),
47 fRotateScene(kFALSE),
48 fDeltaPhi(0.005),
49 fDt (0.01),
50 fWPhi (0.40),
51 fWTheta(0.15), fATheta(0.5),
52 fWDolly(0.30), fADolly(0.4),
53 fTimerRunning(kFALSE),
54 fImageCount(0), fImageAutoSave(kFALSE),
55 fImageGUIBaseName("animation"), fImageGUIOutMode(1)
56{
57 fTimer->Connect("Timeout()", "TGLAutoRotator", this, "Timeout()");
58}
59
60////////////////////////////////////////////////////////////////////////////////
61/// Destructor.
62
64{
65 delete fWatch;
66 delete fTimer;
67}
68
69////////////////////////////////////////////////////////////////////////////////
70/// Set time between two redraws in seconds.
71/// Range: 0.001 -> 1.
72
74{
75 fDt = TMath::Range(0.01, 1.0, dt);
76 if (fTimerRunning)
77 {
79 fTimer->Reset();
80 }
81}
82
83////////////////////////////////////////////////////////////////////////////////
84/// Set relative amplitude of theta oscillation.
85/// Value range: 0.01 -> 1.
86
88{
89 a = TMath::Range(0.01, 1.0, a);
90 if (fTimerRunning)
91 {
93 }
94 fATheta = a;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Set relative amplitude of forward/backward oscillation.
99/// Value range: 0.01 -> 1.
100
102{
103 a = TMath::Range(0.01, 1.0, a);
104 if (fTimerRunning)
105 {
107 }
108 fADolly = a;
109}
110
111////////////////////////////////////////////////////////////////////////////////
112/// Start the auto-rotator.
113
115{
116 if (fTimerRunning)
117 {
118 Stop();
119 }
120
122
124 fDollyA0 = fADolly * fCamera->GetCamTrans().GetBaseVec(4).Mag();
125
128 fTimer->Reset();
129 fTimer->TurnOn();
130 fWatch->Start();
131}
132
133////////////////////////////////////////////////////////////////////////////////
134/// Stop the auto-rotator.
135
137{
138 if (fTimerRunning)
139 {
140 fWatch->Stop();
141 fTimer->TurnOff();
143 }
144}
145
146////////////////////////////////////////////////////////////////////////////////
147/// Called on every timer timeout. Moves / rotates the camera and optionally
148/// produces a screenshot.
149
151{
152 if (!fTimerRunning || gTQSender != fTimer)
153 {
154 Error("Timeout", "Not running or not called via timer.");
155 return;
156 }
157
158 using namespace TMath;
159
160 fWatch->Stop();
161 Double_t time = fWatch->RealTime();
162 fWatch->Continue();
163
164 if (fRotateScene) {
165 RotateScene();
166 } else {
170 Double_t th = fCamera->GetTheta();
171
172 if (th + delta_t > 3.0 || th + delta_t < 0.1416)
173 delta_t = 0;
174
177 }
178
180
181 if (fImageAutoSave)
182 {
184 if (fImageName.Contains("%"))
185 {
187 }
188 else
189 {
191 }
193 ++fImageCount;
194 }
195}
196
197////////////////////////////////////////////////////////////////////////////////
198/// Start saving into animated gif. The provided name will be used as it is,
199/// so make sure to end it with '.gif+'.
200/// Use convert tool from ImageMagic if you want to set a different delay or
201/// enable looping.
202
204{
205 if ( ! filename.Contains(".gif+"))
206 {
207 Error("StartImageAutoSaveAnimatedGif", "Name should end with '.gif+'. Not starting.");
208 return;
209 }
210
212 fImageCount = 0;
214}
215
216////////////////////////////////////////////////////////////////////////////////
217/// Start saving into a set of images. The provided name will be used as a
218/// format to insert additional image sequence number so it should include
219/// an '%' character. A good name would be something like:
220/// "image-%04d.png"
221/// On GNU/Linux use mencoder and/or ffmpeg to bundle images into a movie.
222
224{
225 if ( ! filename.Contains("%"))
226 {
227 Error("StartImageAutoSave", "Name should include a '%%' character, like 'image-%%05d.png'. Not starting.");
228 return;
229 }
230
232 fImageCount = 0;
234}
235
236////////////////////////////////////////////////////////////////////////////////
237/// Stops automatic saving of images.
238
243
244////////////////////////////////////////////////////////////////////////////////
245/// Set output mode for GUI operation:
246/// 1 - animated gif;
247/// 2 - a series of pngs
248
250{
251 if (m < 1 || m > 2)
252 {
253 Warning("SetImageGUIOutMode", "Invalid value, ignoring");
254 return;
255 }
257}
258
259////////////////////////////////////////////////////////////////////////////////
260/// Start auto-saving images as set-up via GUI.
261
263{
264 if (fImageGUIOutMode == 1)
265 {
266 TString name = fImageGUIBaseName + ".gif+";
268 }
269 else if (fImageGUIOutMode == 2)
270 {
271 TString name = fImageGUIBaseName + "-%05d.png";
273 }
274 else
275 {
276 Warning("StartImageAutoSaveWithGUISettings", "Unsupported mode '%d'.", fImageGUIOutMode);
277 }
278}
279
280////////////////////////////////////////////////////////////////////////////////
281///"Scene rotation": either find a special object,
282///which will be an axis of rotation (it's Z actually)
283///or use a "global" Z axis.
284
286{
289
290 for (; sceneIter != scenes.end(); ++sceneIter) {
291 TGLScene::TSceneInfo *sceneInfo = dynamic_cast<TGLScene::TSceneInfo *>(*sceneIter);
292 if (sceneInfo) {
293 TGLPhysicalShape *axisShape = nullptr;
294 TGLScene::ShapeVec_i shapeIter = sceneInfo->fShapesOfInterest.begin();
295 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
296 TGLPhysicalShape * const testShape = const_cast<TGLPhysicalShape *>(*shapeIter);
297 if (testShape && testShape->GetLogical()->ID()->TestBit(13)) {
299 break;
300 }
301 }
302
303 TGLVector3 axis;
304 TGLVertex3 center;
305
306 if (!axisShape) {
307 const TGLBoundingBox &bbox = sceneInfo->GetTransformedBBox();
308 axis = bbox.Axis(2);
309 center = bbox.Center();
310 } else {
311 axis = axisShape->BoundingBox().Axis(2);
312 center = axisShape->BoundingBox().Center();
313 }
314
315 shapeIter = sceneInfo->fShapesOfInterest.begin();
316 for (; shapeIter != sceneInfo->fShapesOfInterest.end(); ++shapeIter) {
317 if (TGLPhysicalShape * const shape = const_cast<TGLPhysicalShape *>(*shapeIter))
318 shape->Rotate(center, axis, fDeltaPhi);
319 }
320 }
321 }
322}
#define a(i)
Definition RSha256.hxx:99
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
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 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
const_iterator begin() const
const_iterator end() const
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
void MoveLF(Int_t ai, Double_t amount)
Translate in local frame.
Definition TGLUtil.cxx:807
Concrete physical shape - a GL drawable.
ShapeVec_t::iterator ShapeVec_i
Definition TGLScene.h:73
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
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...
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Definition TObject.cxx:1071
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:865
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:138
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Definition TString.h:640
Handles synchronous and a-synchronous timer events.
Definition TTimer.h:51
virtual void TurnOff()
Remove timer from system timer list.
Definition TTimer.cxx:234
virtual void TurnOn()
Add the timer to the system timer list.
Definition TTimer.cxx:246
void Reset()
Reset the timer.
Definition TTimer.cxx:162
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:704
constexpr Double_t PiOver2()
Definition TMath.h:54
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:303
TMarker m
Definition textangle.C:8