VAPoR  0.1
animationparams.h
Go to the documentation of this file.
1 //************************************************************************
2 // *
3 // Copyright (C) 2004 *
4 // University Corporation for Atmospheric Research *
5 // All Rights Reserved *
6 // *
7 //************************************************************************/
8 //
9 // File: animationparams.h
10 //
11 // Author: Alan Norton
12 // National Center for Atmospheric Research
13 // PO 3000, Boulder, Colorado
14 //
15 // Date: January 2005
16 //
17 // Description: Defines the AnimationParams class
18 // This is derived from the Params class
19 // It contains all the parameters required for animation
20 
21 //
22 #ifndef ANIMATIONPARAMS_H
23 #define ANIMATIONPARAMS_H
24 
25 
26 #include "params.h"
27 #include <vapor/common.h>
28 #include "viewpointparams.h"
29 
30 
31 namespace VAPoR {
32 class ExpatParseMgr;
33 class Keyframe;
34 class XmlNode;
35 class ParamNode;
36 class animate;
45 
46 public:
49  AnimationParams(int winnum);
51  ~AnimationParams();
52 
56  if (keyframingEnabled()&&getLoadedViewpoints().size() > 0){
57  return currentInterpolatedFrame;
58  }
59  return currentTimestep;
60  }
61 
65  if (keyframingEnabled()&&getLoadedViewpoints().size() > 0){
66  return loadedTimesteps[currentInterpolatedFrame];
67  }
68  return currentTimestep;
69  }
70 
74  if (keyframingEnabled()) return startKeyframeFrame;
75  return startFrame;
76  }
77 
81  if (keyframingEnabled()) return endKeyframeFrame;
82  return endFrame;
83  }
84 
87  int getMinTimestep() {return minTimestep;}
88 
91  int getMaxTimestep() {return maxTimestep;}
92 
95  int getMinFrame() {
96  if (keyframingEnabled()) return 0;
97  return minTimestep;
98  }
99 
102  int getMaxFrame() {
103  if (keyframingEnabled()) return (loadedViewpoints.size()-1);
104  return maxTimestep;
105  }
106 
107 
110  void setMinTimestep(int minF) {minTimestep = minF;}
111 
114  void setMaxTimestep(int maxF) {maxTimestep = maxF;}
115 
116  Keyframe* getKeyframe(int index) {return keyframes[index];}
117  vector<Keyframe*>& getKeyframes() {return keyframes;}
118  void deleteKeyframe(int index);
119  void rescaleKeyframes(const float ratio[3]);
120 
121  void insertKeyframe(int index, Keyframe* keyframe);
122  void insertViewpoint(int index, Viewpoint* vp);
123 
124  int getNumKeyframes() {return keyframes.size();}
125  bool keyframingEnabled() {return useKeyframing;}
126  void enableKeyframing( bool onoff);
127 
128 
129 
130 #ifndef DOXYGEN_SKIP_THIS
131 
132  //Build vectors of viewpoints and timesteps by interpolating keyframes
133  void buildViewsAndTimes();
134  const vector<Viewpoint*> getLoadedViewpoints() {return loadedViewpoints;}
135  void clearLoadedViewpoints();
136  int getNumLoadedViewpoints(){return loadedViewpoints.size();}
137  void addViewpoint(Viewpoint* vp){loadedViewpoints.push_back(vp);}
138  void addTimestep(size_t ts){loadedTimesteps.push_back(ts);}
139  const Viewpoint* getLoadedViewpoint(int framenum){
140  return (loadedViewpoints[framenum%loadedViewpoints.size()]);
141  }
142  vector<size_t> getLoadedTimesteps() {return loadedTimesteps;}
143  //The rest is not part of the public API
144  static ParamsBase* CreateDefaultInstance() {return new AnimationParams(-1);}
145  const std::string& getShortName() {return _shortName;}
146  virtual Params* deepCopy(ParamNode* n = 0);
147 
148  virtual void restart();
149  static void setDefaultPrefs();
150  virtual bool reinit(bool doOverride);
151 
152  bool isPlaying() {return (playDirection != 0);}
153 
154 
155  int getMinTimeToRender() {return ((int)(1000.f/maxFrameRate) );}
156 
157 
158  int getPlayDirection() {return playDirection;}
159  int getFrameStepSize() {return frameStepSize;}
160  float getMaxFrameRate() {return maxFrameRate;}
161  void setCurrentInterpolatedFrame(int val){
162  currentInterpolatedFrame=val;
163  }
164  int getCurrentInterpolatedFrame(){
165  return currentInterpolatedFrame;
166  }
167  int getFrameIndex(int keyframeIndex);
168  void setCurrentFrameNumber(int val) {
169  if (keyframingEnabled())
170  currentInterpolatedFrame = val;
171  else
172  currentTimestep = val;
173  }
174  void setStartFrameNumber(int val) {
175  if (keyframingEnabled()){
176  startKeyframeFrame=val;
177  } else {
178  startFrame=val;
179  }
180  }
181  void setEndFrameNumber(int val) {
182  if (keyframingEnabled()){
183  endKeyframeFrame=val;
184  if (val == getLoadedViewpoints().size()-1) endFrameIsDefault = true;
185  else endFrameIsDefault=false;
186  } else {
187  endFrame=val;
188  }
189  }
190 
191 
192  bool isRepeating() {return repeatPlay;}
193  void setRepeating(bool onOff){repeatPlay = onOff;}
194  void setFrameStepSize(int sz){ frameStepSize = sz;}
195  void setMaxFrameRate(float val) {maxFrameRate = val;}
196  void setPlayDirection(int val){stateChanged = true; playDirection = val;}
197  bool isStateChanged() {return stateChanged;}
198  //Used when the state changes during a render:
199  void setStateChanged(bool state) {stateChanged = state;}
200 
201  static float getDefaultMaxFPS() {return defaultMaxFPS;}
202 
203  static void setDefaultMaxFPS(float val) {defaultMaxFPS = val;}
204 
205  //When rendering is finished, renderer calls this. Returns true no change (if the change bit
206  //needs to be set.
207  //It advances the currentFrame to the next one
208  bool advanceFrame();
209  //set to pause if last frame is done, return true if done.
210  bool checkLastFrame();
211  int getNextFrame(int dir); //Determine the next frame in the specified direction
212  bool usingTimestepList() {return useTimestepSampleList;}
213  void setTimestepSampleList(bool on) {useTimestepSampleList = on;}
214  std::vector<int>& getTimestepList() { return timestepList;}
215 
216  ParamNode* buildNode();
217  bool elementStartHandler(ExpatParseMgr*, int /* depth*/ , std::string& /*tag*/, const char ** /*attribs*/);
218  bool elementEndHandler(ExpatParseMgr*, int /*depth*/ , std::string& /*tag*/);
219 
220 protected:
221  vector<Viewpoint*>loadedViewpoints;
222  vector<size_t>loadedTimesteps;
223 
224  static const string _shortName;
225  static const string _repeatAttr;
226  static const string _maxRateAttr;
227  static const string _stepSizeAttr;
228  static const string _startFrameAttr;
229  static const string _endFrameAttr;
230  static const string _startKeyframeFrameAttr;
231  static const string _endKeyframeFrameAttr;
232  static const string _currentFrameAttr;
233  static const string _currentInterpFrameAttr;
234  static const string _maxWaitAttr;
235  static const string _keyframesEnabledAttr;
236  static const string _keyframeTag;
237  static const string _keySpeedAttr;
238  static const string _keyTimestepAttr;
239  static const string _keyNumFramesAttr;
240  static const string _keySynchToTimestepsAttr;
241  static const string _keyTimestepsPerFrameAttr;
242 
243 
244  int playDirection; //-1, 0, or 1
245  bool repeatPlay;
246  float maxFrameRate;
247 
248  int frameStepSize;// always 1 or greater
249  int startFrame;
250  int endFrame;
251  int startKeyframeFrame;
252  int endKeyframeFrame;
253  bool endFrameIsDefault; //indicate if endKeyframeFrame is at default values.
254  int maxTimestep, minTimestep;
255  int currentInterpolatedFrame;
256  int currentTimestep;
257  bool useTimestepSampleList;
258  std::vector<int> timestepList;
259  //If the animation state is changed, gui needs to update:
260  bool stateChanged;
261 
262  static float defaultMaxFPS;
263 
264  //Keyframing state:
265  bool useKeyframing;
266  std::vector<Keyframe*> keyframes;
267  animate* myAnimate; //used to perform keyframe interpolation
268 
269 #endif /* DOXYGEN_SKIP_THIS */
270 
271 };
272 class Keyframe{
273 public:
274  Keyframe(Viewpoint* vp, float spd, int ts, int fnum){
275  viewpoint = vp; speed = spd; timeStep = ts; numFrames = fnum; stationaryFlag = false;
276  synch = false; timestepsPerFrame = 1;
277  }
278  Viewpoint* viewpoint;
279  float speed;
280  int timeStep;
283  bool synch;
285 };
286 };
287 
288 #endif //ANIMATIONPARAMS_H
#define PARAMS_API
Definition: common.h:63
A pure virtual class for managing parameters used in visualization.
Definition: params.h:75
void setMaxTimestep(int maxF)
void setMinTimestep(int minF)
Viewpoint * viewpoint
A class that specifies parameters used in animation.
Keyframe(Viewpoint *vp, float spd, int ts, int fnum)
Keyframe * getKeyframe(int index)
vector< Keyframe * > & getKeyframes()