ATLAS Offline Software
AnimationSequencer.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 #include "VP1Base/VP1Msg.h"
9 #include "VP1Base/VP1QtUtils.h"
11 
12 #include <QTimer>
13 
14 #include <Inventor/nodes/SoNode.h>
15 #include <Inventor/nodes/SoSphere.h>
16 #include <Inventor/nodes/SoPerspectiveCamera.h>
17 #include <Inventor/nodes/SoGroup.h>
18 
19 #include <iostream>
20 
22 
23 public:
24 
26  mutable unsigned int animationFrameNumber;
28  SoSphere *sphere;
29 
30  SoSphere * getRegionSphere(AnimationSequence::REGION, bool perspective);
31 
33  int movieFPS;
36  QString movieOutdir;
39 };
40 
42 {
43  m_c->movieEnabled = b;
44 }
45 
46 void AnimationSequencer::setMovieParameters(QString outdir, QString frameFileNamePrefix, int fps, int width, int height)
47 {
48  m_c->movieFPS = fps;
49  m_c->movieWidth = width;
50  m_c->movieHeight = height;
52  m_c->frameFileNamePrefix = frameFileNamePrefix;
53 }
54 
56  m_c(new Clockwork)
57 {
59  m_c->viewer=viewer;
60  m_c->sphere=NULL;
61  m_c->movieEnabled=false;
62  m_c->movieFPS=24;
63  m_c->movieWidth=100;
64  m_c->movieHeight=100;
65  m_c->movieOutdir="/tmp/vp1frames";
66  m_c->frameFileNamePrefix="vp1_frame";
67 }
68 
70 {
71  if (m_c->sphere) m_c->sphere->unref();
72  delete m_c;
73 }
74 
76  return m_c->animationSequence;
77 }
78 
80  return m_c->animationSequence;
81 }
82 
83 void AnimationSequencer::startAnimating(bool skipFirstFrame) {
84 
85  m_c->animationFrameNumber=(skipFirstFrame?1:0);
86  m_c->last_clipVolPercent = 100;
88 }
89 
91  //Make sure we halt:
92  VP1Msg::messageVerbose("AnimationSequencer::abortAnimation.");
94 }
95 
97 {
98  VP1Msg::messageVerbose("AnimationSequencer::nextAnimationFrame.");
99 
100  if (m_c->animationFrameNumber>=sequence().getNumFrames()) {
102  VP1Msg::messageVerbose("animation succeeded!");
103  return;
104  }
105 
106  SoNode * rootnode = m_c->viewer->getSceneGraph();
107  if (!rootnode) {
108  VP1Msg::messageDebug("AnimationSequencer::nextAnimationFrame WARNING: No scenegraph set. Ignoring.");
109  return;
110  }
111  if ( ! ( rootnode->getTypeId().isDerivedFrom(SoGroup::getClassTypeId())) ) {
112  VP1Msg::messageDebug("AnimationSequencer::nextAnimationFrame WARNING: Root node does not derive from SoGroup. Ignoring.");
113  return;
114  }
115 
116 // if (m_c->viewer->getCameraType() == SoPerspectiveCamera::getClassTypeId() ) {
117 // //Fix for bad camera:
118 // m_c->viewer->toggleCameraType();
119 // m_c->viewer->toggleCameraType();
120 // }
121 
122  SoCamera * camera = m_c->viewer->getCamera();
123  if (!camera) {
124  VP1Msg::messageDebug("AnimationSequencer::nextAnimationFrame WARNING: Could not get camera. Ignoring.");
125  return;
126  }
127 
128  rootnode->ref();
129  SoGroup * root = static_cast<SoGroup*>(rootnode);
130 
131  unsigned int i = m_c->animationFrameNumber;
132 
133 
134  //Get region:
136  // std::cout<<"Frame: "<<i<<" clipVolumePercentOfATLAS="<<f.clipVolPercent<<std::endl;
137 
138  if (f.time==0.0&&!f.camState.isEmpty())
139  {
141  QTimer::singleShot(0, this, SLOT(nextAnimationFrame()));
142  else
143  QTimer::singleShot(0, this, SLOT(abortAnimation()));
144  } else {
146  if (f.camState.isEmpty()) {
147  // std::cout<<"camState empty"<<std::endl;
148  camera->ref();
149  bool notifyenabled = root->enableNotify(false);
150  SoSphere * regionsphere = m_c->getRegionSphere(AnimationSequence::REGION(f.reg),
151  camera->getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId()));
152  camera->unrefNoDelete();
153  //Get direction:
154  SbVec3f lookat=f.dir, upvec = f.upvec;
155  root->insertChild(regionsphere,0);
156  VP1Msg::messageVerbose("nextAnimationFrame Initiating zoom to region sphere.");
157  helper = VP1CameraHelper::animatedZoomToSubTree(camera,root,regionsphere,f.time,f.clipVolPercent, m_c->last_clipVolPercent,0.1,lookat,upvec,f.variableSpeed,f.forceCircular);
158 
159  root->removeChild(regionsphere);
160 
161  if (notifyenabled) {
162  root->enableNotify(true);
163  root->touch();
164  }
165 
166  } else {
167  // std::cout<<"camState not empty"<<std::endl;
168  helper = VP1CameraHelper::animatedZoomToCameraState( camera,root,f.camState,f.time,f.clipVolPercent, m_c->last_clipVolPercent, f.variableSpeed,f.forceCircular );
169  }
170 
171  if (m_c->movieEnabled)
173 
174  connect(helper,SIGNAL(animationFinished()), this, SLOT(nextAnimationFrame()));
175  connect(helper,SIGNAL(animationFinishedAbnormally()), this, SLOT(abortAnimation()));
176  connect(helper,SIGNAL(clipVolumePercentageOfATLAS(double)), this, SIGNAL(clipVolumePercentOfATLAS(double)));
177 
178  }
179  // std::cout<<" Setting last_clipVolPercent to "<<f.clipVolPercent<<std::endl;
180  m_c->last_clipVolPercent = f.clipVolPercent;
181 
182 
183  rootnode->unrefNoDelete();
185 
186 }
187 
189 {
190  if (!sphere) {
191  sphere = new SoSphere;
192  sphere->ref();
193  }
194  double r(30);
195  switch (region) {
197  VP1Msg::messageVerbose("set sphere dimensions for vertex");
198  //r = perspective ? 0.5 : 0.5;
199  r=0.5;
200  break;
202  VP1Msg::messageVerbose("set sphere dimensions for indet");
203  r = perspective ? 13 : 7;
204  break;
206  VP1Msg::messageVerbose("set sphere dimensions for calo");
207  r = perspective ? 35 : 27;
208  break;
210  default:
211  VP1Msg::messageVerbose("set sphere dimensions for muon");
212  r = perspective ? 95 : 73;
213  break;
214  }
215  sphere->radius = r * 1000.0;
216  return sphere;
217 }
AnimationSequencer::Clockwork::viewer
VP1ExaminerViewer * viewer
Definition: AnimationSequencer.cxx:27
beamspotman.r
def r
Definition: beamspotman.py:676
python.CaloRecoConfig.f
f
Definition: CaloRecoConfig.py:127
VP1QtInventorUtils::deserializeSoCameraParameters
static bool deserializeSoCameraParameters(QByteArray &, SoCamera &)
Definition: VP1QtInventorUtils.cxx:959
VP1CameraHelper
Definition: VP1CameraHelper.h:31
AnimationSequence::INDET
@ INDET
Definition: AnimationSequence.h:26
VP1Msg.h
VP1CameraHelper.h
AnimationSequencer::Clockwork::animationSequence
AnimationSequence animationSequence
Definition: AnimationSequencer.cxx:25
fillPileUpNoiseLumi.connect
string connect
Definition: fillPileUpNoiseLumi.py:70
CSV_InDetExporter.new
new
Definition: CSV_InDetExporter.py:145
VP1QtUtils.h
AnimationSequencer::startAnimating
void startAnimating(bool skipFirstFrame=false)
Definition: AnimationSequencer.cxx:83
AnimationSequencer::Clockwork::movieFPS
int movieFPS
Definition: AnimationSequencer.cxx:33
sendEI_SPB.root
root
Definition: sendEI_SPB.py:34
AnimationSequence::MUON
@ MUON
Definition: AnimationSequence.h:26
AnimationSequencer::abortAnimation
void abortAnimation()
Definition: AnimationSequencer.cxx:90
runBeamSpotCalibration.helper
helper
Definition: runBeamSpotCalibration.py:112
VP1QtInventorUtils.h
plotting.efficiency.outdir
outdir
Definition: efficiency.py:19
AnimationSequencer.h
AnimationSequencer::setMovieParameters
void setMovieParameters(QString outdir, QString frameFileNamePrefix, int fps, int width, int height)
Definition: AnimationSequencer.cxx:46
VP1ExaminerViewer.h
VP1ExaminerViewer::getSceneGraph
virtual SoNode * getSceneGraph()
Definition: VP1ExaminerViewer.cxx:3138
lumiFormat.i
int i
Definition: lumiFormat.py:92
AnimationSequencer::Clockwork::movieEnabled
bool movieEnabled
Definition: AnimationSequencer.cxx:32
AnimationSequencer::Clockwork::movieOutdir
QString movieOutdir
Definition: AnimationSequencer.cxx:36
AnimationSequencer::animationFinishedSuccessfully
void animationFinishedSuccessfully()
AnimationSequencer::sequence
AnimationSequence & sequence()
Definition: AnimationSequencer.cxx:75
AnimationSequencer::Clockwork::last_clipVolPercent
double last_clipVolPercent
Definition: AnimationSequencer.cxx:38
AnimationSequencer::setMovie
void setMovie(bool)
Definition: AnimationSequencer.cxx:41
AnimationSequencer::Clockwork::movieWidth
int movieWidth
Definition: AnimationSequencer.cxx:34
AnimationSequence::getNumFrames
unsigned int getNumFrames() const
Definition: AnimationSequence.h:67
AnimationSequence::Frame
Definition: AnimationSequence.h:29
AnimationSequencer::Clockwork
Definition: AnimationSequencer.cxx:21
VP1CameraHelper::animatedZoomToCameraState
static VP1CameraHelper * animatedZoomToCameraState(SoCamera *camera, SoGroup *sceneroot, const QByteArray &camstate, double duration_in_secs=1.0, double clipVolPercent=100.0, double lastClipVolPercent=100.0, bool varySpeed=true, bool forceCircular=false)
Definition: VP1CameraHelper.cxx:301
AnimationSequence::VERTEX
@ VERTEX
Definition: AnimationSequence.h:26
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
VP1Msg::messageVerbose
static void messageVerbose(const QString &)
Definition: VP1Msg.cxx:84
AnimationSequencer::~AnimationSequencer
~AnimationSequencer()
Definition: AnimationSequencer.cxx:69
AnimationSequencer::Clockwork::animationFrameNumber
unsigned int animationFrameNumber
Definition: AnimationSequencer.cxx:26
AnimationSequencer::nextAnimationFrame
void nextAnimationFrame()
Definition: AnimationSequencer.cxx:96
AnimationSequence::REGION
REGION
Definition: AnimationSequence.h:26
AnimationSequence::CALO
@ CALO
Definition: AnimationSequence.h:26
AnimationSequencer::Clockwork::getRegionSphere
SoSphere * getRegionSphere(AnimationSequence::REGION, bool perspective)
Definition: AnimationSequencer.cxx:188
VP1Msg::messageDebug
static void messageDebug(const QString &)
Definition: VP1Msg.cxx:39
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
AnimationSequencer::Clockwork::sphere
SoSphere * sphere
Definition: AnimationSequencer.cxx:28
AnimationSequencer::m_c
Clockwork * m_c
Definition: AnimationSequencer.h:56
AnimationSequencer::Clockwork::movieHeight
int movieHeight
Definition: AnimationSequencer.cxx:35
AnimationSequence
Definition: AnimationSequence.h:21
AnimationSequencer::AnimationSequencer
AnimationSequencer(VP1ExaminerViewer *viewer)
Definition: AnimationSequencer.cxx:55
AnimationSequencer::Clockwork::frameFileNamePrefix
QString frameFileNamePrefix
Definition: AnimationSequencer.cxx:37
VP1CameraHelper::animatedZoomToSubTree
static VP1CameraHelper * animatedZoomToSubTree(SoCamera *camera, SoGroup *sceneroot, SoNode *subtreeroot, double duration_in_secs=1.0, double clipVolPercent=100.0, double lastClipVolPercent=100.0, double slack=1.0, const SbVec3f &lookat=SbVec3f(999, 999, 999), const SbVec3f &upvec=SbVec3f(999, 999, 999), bool varySpeed=true, bool forceCircular=false)
Definition: VP1CameraHelper.cxx:413
AnimationSequencer::clipVolumePercentOfATLAS
void clipVolumePercentOfATLAS(double)
AnimationSequence::getFrame
const Frame & getFrame(unsigned int i) const
Definition: AnimationSequence.h:70
VP1ExaminerViewer
Definition: VP1ExaminerViewer.h:30