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* getAnyKeyframe(int index) {return keyframes[index];}
117  void setAnyKeyframe(int index, Keyframe* k){ keyframes[index] = k;}
118  Keyframe* getEditableKeyframe(int editableIndex) {return keyframes[mapEditableIndex[editableIndex]];}
119  vector<Keyframe*>& getAllKeyframes() {return keyframes;}
120  //Delete an arbitrary keyframe, editable or not.
121  void deleteAnyKeyframe(int index);
122  //Delete an editable keyframe, plus any other keyframes between the following and previous editable keyframes
123  void deleteEditableKeyframe(int editableIndex);
124  void rescaleKeyframes(const float ratio[3]);
125  //Insert an editable Keyframe after an editable index.
126  void insertEditableKeyframe(int editableIndex, Keyframe* keyframe);
127  //Insert a hidden keyframe after an arbitrary index
128  void insertHiddenKeyframe(int index, Keyframe* keyframe);
129  int getTotalKeyframeIndex(int editableIndex) {
130  assert(mapEditableIndex[0] == 0);
131  return mapEditableIndex[editableIndex];
132  }
133  //Convert an index to an editable index, return -1 if it's not editable.
134  int getEditableIndex(int index);
135 
136  int getTotalNumKeyframes() {return keyframes.size();}
137  bool keyframingEnabled() {return useKeyframing;}
138  void enableKeyframing( bool onoff);
139  int getNumEditableKeyframes() {return mapEditableIndex.size();}
140 
141 
142 
143 #ifndef DOXYGEN_SKIP_THIS
144 
145  //Build vectors of viewpoints and timesteps by interpolating keyframes
146  void buildViewsAndTimes();
147  const vector<Viewpoint*> getLoadedViewpoints() {return loadedViewpoints;}
148  void clearLoadedViewpoints();
149  int getNumLoadedViewpoints(){return loadedViewpoints.size();}
150 
151  const Viewpoint* getLoadedViewpoint(int framenum){
152  return (loadedViewpoints[framenum%loadedViewpoints.size()]);
153  }
154  vector<size_t> getLoadedTimesteps() {return loadedTimesteps;}
155  //The rest is not part of the public API
156  static ParamsBase* CreateDefaultInstance() {return new AnimationParams(-1);}
157  const std::string& getShortName() {return _shortName;}
158  virtual Params* deepCopy(ParamNode* n = 0);
159 
160  virtual void restart();
161  static void setDefaultPrefs();
162  virtual bool reinit(bool doOverride);
163 
164  bool isPlaying() {return (playDirection != 0);}
165 
166 
167  int getMinTimeToRender() {return ((int)(1000.f/maxFrameRate) );}
168 
169 
170  int getPlayDirection() {return playDirection;}
171  int getFrameStepSize() {return frameStepSize;}
172  float getMaxFrameRate() {return maxFrameRate;}
173  void setCurrentInterpolatedFrame(int val){
174  currentInterpolatedFrame=val;
175  }
176  int getCurrentInterpolatedFrame(){
177  return currentInterpolatedFrame;
178  }
179  int getFrameIndex(int keyframeIndex);
180  void setCurrentFrameNumber(int val) {
181  if (keyframingEnabled())
182  currentInterpolatedFrame = val;
183  else
184  currentTimestep = val;
185  }
186  void setStartFrameNumber(int val) {
187  if (keyframingEnabled()){
188  startKeyframeFrame=val;
189  } else {
190  startFrame=val;
191  }
192  }
193  void setEndFrameNumber(int val) {
194  if (keyframingEnabled()){
195  endKeyframeFrame=val;
196  if (val == getLoadedViewpoints().size()-1) endFrameIsDefault = true;
197  else endFrameIsDefault=false;
198  } else {
199  endFrame=val;
200  }
201  }
202 
203 
204  bool isRepeating() {return repeatPlay;}
205  void setRepeating(bool onOff){repeatPlay = onOff;}
206  void setFrameStepSize(int sz){ frameStepSize = sz;}
207  void setMaxFrameRate(float val) {maxFrameRate = val;}
208  void setPlayDirection(int val){stateChanged = true; playDirection = val;}
209  bool isStateChanged() {return stateChanged;}
210  //Used when the state changes during a render:
211  void setStateChanged(bool state) {stateChanged = state;}
212 
213  static float getDefaultMaxFPS() {return defaultMaxFPS;}
214 
215  static void setDefaultMaxFPS(float val) {defaultMaxFPS = val;}
216 
217  //When rendering is finished, renderer calls this. Returns true no change (if the change bit
218  //needs to be set.
219  //It advances the currentFrame to the next one
220  bool advanceFrame();
221  //set to pause if last frame is done, return true if done.
222  bool checkLastFrame();
223  int getNextFrame(int dir); //Determine the next frame in the specified direction
224  bool usingTimestepList() {return useTimestepSampleList;}
225  void setTimestepSampleList(bool on) {useTimestepSampleList = on;}
226  std::vector<int>& getTimestepList() { return timestepList;}
227 
228  ParamNode* buildNode();
229  bool elementStartHandler(ExpatParseMgr*, int /* depth*/ , std::string& /*tag*/, const char ** /*attribs*/);
230  bool elementEndHandler(ExpatParseMgr*, int /*depth*/ , std::string& /*tag*/);
231 
232 protected:
233  vector<Viewpoint*>loadedViewpoints;
234  vector<size_t>loadedTimesteps;
235 
236  static const string _shortName;
237  static const string _repeatAttr;
238  static const string _maxRateAttr;
239  static const string _stepSizeAttr;
240  static const string _startFrameAttr;
241  static const string _endFrameAttr;
242  static const string _startKeyframeFrameAttr;
243  static const string _endKeyframeFrameAttr;
244  static const string _currentFrameAttr;
245  static const string _currentInterpFrameAttr;
246  static const string _maxWaitAttr;
247  static const string _keyframesEnabledAttr;
248  static const string _keyframeTag;
249  static const string _keySpeedAttr;
250  static const string _keyTimestepAttr;
251  static const string _keyNumFramesAttr;
252  static const string _keySynchToTimestepsAttr;
253  static const string _keyTimestepsPerFrameAttr;
254  static const string _editableKeyMapTag;
255 
256 
257  int playDirection; //-1, 0, or 1
258  bool repeatPlay;
259  float maxFrameRate;
260 
261  int frameStepSize;// always 1 or greater
262  int startFrame;
263  int endFrame;
264  int startKeyframeFrame;
265  int endKeyframeFrame;
266  bool endFrameIsDefault; //indicate if endKeyframeFrame is at default values.
267  int maxTimestep, minTimestep;
268  int currentInterpolatedFrame;
269  int currentTimestep;
270  bool useTimestepSampleList;
271  std::vector<int> timestepList;
272  //If the animation state is changed, gui needs to update:
273  bool stateChanged;
274 
275  static float defaultMaxFPS;
276 
277  //Keyframing state:
278  bool useKeyframing;
279  std::vector<Keyframe*> keyframes;
280  // Identify the keyframe index of the editable indices.
281  std::vector<long> mapEditableIndex;
282  animate* myAnimate; //used to perform keyframe interpolation
283 
284 #endif /* DOXYGEN_SKIP_THIS */
285 
286 };
287 class Keyframe{
288 public:
289  Keyframe(Viewpoint* vp, float spd, int ts, int fnum){
290  viewpoint = vp; speed = spd; timeStep = ts; numFrames = fnum; stationaryFlag = false;
291  synch = true; timestepsPerFrame = 1;
292  }
293  Viewpoint* viewpoint;
294  float speed;
295  int timeStep;
298  bool synch;
300 };
301 };
302 
303 #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)
Keyframe * getAnyKeyframe(int index)
Viewpoint * viewpoint
A class that specifies parameters used in animation.
Keyframe(Viewpoint *vp, float spd, int ts, int fnum)
Keyframe * getEditableKeyframe(int editableIndex)
void setAnyKeyframe(int index, Keyframe *k)
int getTotalKeyframeIndex(int editableIndex)
vector< Keyframe * > & getAllKeyframes()