HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_TimeUtils.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: UT_TimeUtils.h ( UT Library, C++)
7  *
8  * COMMENTS:
9  *
10  * This is a collection of utilities useful for dealing with times and time
11  * ranges.
12  *
13  */
14 #ifndef __UT_TimeUtils_h__
15 #define __UT_TimeUtils_h__
16 
17 #include "UT_API.h"
18 #include <SYS/SYS_Math.h>
19 #include <SYS/SYS_Types.h>
20 #include "UT_Assert.h"
21 
22 // Given a start frame, an end frame and a step, this method will return
23 // the number of frames involved. Be careful not to pass a zero step size.
24 // Optionally, this method can also compute the ending frame of the sequence.
25 template <typename T>
26 int UTgetNumberOfFrames(T start_frame, T end_frame,
27  T step, T *new_end_frame=0)
28 {
29  int nframes = 0;
30  T t, t1;
31  T inc;
32 
33  UT_ASSERT(!SYSequalZero(step)); // step of 0 is invalid
34  if (SYSequalZero(step))
35  return 0; // could also have returned INT_MAX
36 
37  if (new_end_frame)
38  *new_end_frame = end_frame;
39 
40  // Check to see that we're going the right way (careful if s == e)
41  if ((end_frame - start_frame) / step < 0.5)
42  return 1; // nframes + 1
43  else
44  {
45  if (end_frame > start_frame)
46  {
47  inc = step;
48  t1 = end_frame + inc * 0.01;
49  t = start_frame + inc;
50  }
51  else
52  {
53  inc = -step;
54  t1 = start_frame + inc * 0.01;
55  t = end_frame + inc;
56  }
57  for (; t1 - t > 0; t += inc)
58  nframes++;
59 
60  // Remember to compute new_end_frame with the number of frames - 1.
61  if (new_end_frame)
62  *new_end_frame = start_frame + step * (fpreal64)nframes;
63 
64  // Up to here we've computed nframes - 1;
65  }
66  return nframes + 1;
67 }
68 
69 
70 #endif
double fpreal64
Definition: SYS_Types.h:201
GLdouble t
Definition: glad.h:2397
bool SYSequalZero(const UT_Vector3T< T > &v)
Definition: UT_Vector3.h:1069
int UTgetNumberOfFrames(T start_frame, T end_frame, T step, T *new_end_frame=0)
Definition: UT_TimeUtils.h:26
#define UT_ASSERT(ZZ)
Definition: UT_Assert.h:156