ATLAS Offline Software
Loading...
Searching...
No Matches
AnimationSequencer.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
6#include "VP1Base/VP1Msg.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
40
42{
43 m_c->movieEnabled = b;
44}
45
46void AnimationSequencer::setMovieParameters(const QString& outdir, const QString& frameFileNamePrefix, int fps, int width, int height)
47{
48 m_c->movieFPS = fps;
49 m_c->movieWidth = width;
50 m_c->movieHeight = height;
51 m_c->movieOutdir = outdir;
52 m_c->frameFileNamePrefix = frameFileNamePrefix;
53}
54
56 m_c(new Clockwork)
57{
58 m_c->animationFrameNumber=0;
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
83void 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.");
93 m_c->animationFrameNumber = m_c->animationFrameNumber>=sequence().getNumFrames() + 1;
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 {
145 VP1CameraHelper *helper(0);
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)
172 helper->setOutputImagesMode(m_c->viewer, m_c->movieOutdir, m_c->movieWidth,m_c->movieHeight, m_c->movieFPS, m_c->frameFileNamePrefix);
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();
184 m_c->animationFrameNumber++;
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}
const double width
unsigned int getNumFrames() const
const Frame & getFrame(unsigned int i) const
SoSphere * getRegionSphere(AnimationSequence::REGION, bool perspective)
void animationFinishedSuccessfully()
void setMovieParameters(const QString &outdir, const QString &frameFileNamePrefix, int fps, int width, int height)
void clipVolumePercentOfATLAS(double)
AnimationSequencer(VP1ExaminerViewer *viewer)
void startAnimating(bool skipFirstFrame=false)
AnimationSequence & sequence()
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)
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)
static void messageVerbose(const QString &)
Definition VP1Msg.cxx:84
static void messageDebug(const QString &)
Definition VP1Msg.cxx:39
static bool deserializeSoCameraParameters(QByteArray &, SoCamera &)
int r
Definition globals.cxx:22