HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CL_Clip.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: CL_Clip.h ( Clip Library, C++)
7  *
8  * COMMENTS:
9  * A collection of raw data tracks
10  */
11 
12 #ifndef __CL_Clip__
13 #define __CL_Clip__
14 
15 #include "CL_API.h"
16 #include "CL_Track.h"
17 
18 #include <UT/UT_IntArray.h>
19 #include <UT/UT_NameManager.h>
20 #include <UT/UT_SharedPtr.h>
21 #include <UT/UT_String.h>
22 #include <UT/UT_StringSet.h>
23 #include <UT/UT_StringHolder.h>
24 #include <UT/UT_ValArray.h>
25 #include <UT/UT_XformOrder.h>
26 
27 #include <SYS/SYS_Math.h>
28 #include <SYS/SYS_Types.h>
29 
30 #undef Bool
31 
32 class UT_IStream;
33 class UT_OStream;
34 class UT_InfoTree;
35 class UT_WorkBuffer;
36 class CL_ClipPrivateIO;
37 class UT_VariantMap;
38 
39 typedef void (*CL_InfoCallback)(UT_String &result, void *data, int idx);
41 
42 class CL_API CL_Clip {
43 
44 public:
45 
46  CL_Clip(int size);
47  CL_Clip(const CL_Clip &from);
48  ~CL_Clip();
49 
50  CL_Clip &operator= (const CL_Clip &v);
51 
52  // a very efficient copy constructor which checks existing
53  // data to minimize memory calls
54 
55  void copyContents(const CL_Clip &v, int data, int slerps);
56 
57 
58  // these methods when used with caution can increase efficiency
59  // when adding tracks
60 
62  { return myCheckDuplicateNames; }
63 
65  { myCheckDuplicateNames = val; }
66 
67  //
68  // access/query methods
69  //
70 
71  void clearAndDestroy();
72 
74  { myStart = start; }
75 
76  fpreal getStart(void) const
77  { return myStart; }
78 
79  fpreal getEnd(void) const
80  { return myStart + myTrackLength - 1; }
81 
82  int getTrackLength(void) const
83  { return myTrackLength; }
84 
85  void setTrackLength(int length, int clear_extra=0);
86 
87  void setSampleRate(fpreal rate)
88  { mySampleRate = SYSmax(rate, 1.0e-4); }
89 
90  fpreal getSampleRate(void) const
91  { return mySampleRate; }
92 
93  int getTrackNames(UT_ValArray<const char *> &list) const;
94  int getTracks(CL_TrackListC &list,
95  const char *pattern = 0) const;
96  int getTracks(UT_IntArray &list, const char *pat) const;
97 
98 
99  int isTimeDependent() const;
100 
101  //
102  // quaternion (slerp) methods
103  // each track can belong to at most 1 slerp triplet
104  //
105 
106  int numSlerps() const;
107 
108  int copySlerpAttributes(const CL_Clip &v,
109  int by_name = 0);
110 
111  int resetSlerps();
112 
113  int findSlerp(const CL_Track *track, int &idx) const;
114 
115  int getSlerp(int slerp_idx,
116  int &x_idx,
117  int &y_idx,
118  int &z_idx) const;
119 
120  int getSlerp(const CL_Track *track,
121  int &x_idx,
122  int &y_idx,
123  int &z_idx) const;
124 
125  void setSlerpCapacity(int capacity)
126  {
127  mySXTracks.setCapacity(capacity);
128  mySYTracks.setCapacity(capacity);
129  mySZTracks.setCapacity(capacity);
130  }
131 
132  int setSlerp(int x_idx, int y_idx, int z_idx);
133 
134  int slerpBlend(int slerp_idx,
135  const fpreal *xvalues,
136  const fpreal *yvalues,
137  const fpreal *zvalues,
138  fpreal start, int len, fpreal base,
139  const CL_Track *effect_track,
140  const UT_XformOrder &order);
141 
142  int slerpBlend(int slerp_idx,
143  const fpreal *xvalues,
144  const fpreal *yvalues,
145  const fpreal *zvalues,
146  fpreal start, int len, fpreal base,
147  const CL_SubRange *effect,
148  const UT_XformOrder &order);
149 
150  int validateSlerps();
151 
153  { mySRotOrder = o; }
154 
156  { return mySRotOrder; }
157 
158  //
159  // track access/creation
160  // returns index if name was added, else already exists and returns -1
161  //
162 
163  void removeTrack(int idx);
164 
165  void setTrackCapacity(int capacity)
166  { myTracks.setCapacity(capacity); }
167 
168  CL_Track *addTrack(const char *name);
169  CL_Track *dupTrackInfo(const CL_Track *,int data_too = 0,
170  const char *name = 0);
171 
172  int getNumTracks(void) const
173  { return myTracks.entries(); }
174 
176  { return (index >= 0 && index < myTracks.entries()) ?
177  myTracks(index) : 0; }
178 
179  const CL_Track *getTrack(int index) const
180  { return (index >= 0 && index < myTracks.entries()) ?
181  myTracks(index) : 0; }
182 
183  CL_Track *getTrack(const UT_StringRef &name, int *index = 0);
184  const CL_Track *getTrack(const UT_StringRef &name, int *index = 0) const;
185 
186 
187  //
188  // track evaluation
189  //
190 
191 
192  // These three evaluat methods should only be used when appropriate,
193  // it is much more efficient to use the range evaluations
194 
196  { return track->evaluateSingle(index - myStart); }
197 
198  fpreal evaluateSingleTime(const CL_Track *track, fpreal t) const
199  { return evaluateSingle(track, getIndex(t)); }
200 
202  fpreal f, fpreal fps) const
203  { return evaluateSingle(track, getIndexF(f, fps)); }
204 
205 
206 
207  void evaluate(const CL_Track *track,
208  fpreal start_index, fpreal stop_index,
209  fpreal *data, int size) const;
210 
211  int evaluateSlerp(int slerp_idx,
212  fpreal start_index, fpreal stop_index,
213  fpreal *xdata, fpreal *ydata, fpreal *zdata,
214  int size) const;
215 
216  void evaluateTime(const CL_Track *track,
217  fpreal start_time, fpreal stop_time,
218  fpreal *data, int size) const
219  { evaluate(track, getIndex(start_time),
220  getIndex(stop_time), data, size); }
221 
222  void resampleTime(const CL_Track *track,
223  fpreal start_time, fpreal stop_time,
224  fpreal *data, int size) const;
225 
226  // Find the max/min height of the track.
227  // If track is nil, find the min max of every track
228 
229  void getHeight(const CL_Track *track,
230  fpreal start_index, fpreal stop_index,
231  int nsamples, fpreal *imin, fpreal *imax) const;
232 
233  // Find the min max of the graph over *each* step interval
234  // data should be twice as long as size
235 
236  void evaluateHeightRange(const CL_Track *track,
237  fpreal start_index, fpreal stop_index,
238  fpreal *data, int size) const;
239 
240 
241  // This method extends the clip so that it contains a local index
242  // at time t, and returns the index. The clip may be extended
243  // or cycled to accomodate the change. If delta is given, it
244  // returns the index delta of the clips start times.
245  // Note all indices are truncated to ints
246 
247  int extendTime(fpreal t, int *delta);
248 
249 
250  //
251  // convenience methods
252  //
253 
255  { return getTime(myStart); }
256 
258  { return getTime(myStart + myTrackLength - 1); }
259 
260  void dupAttributes(const CL_Clip &);
261 
262  //
263  // unit conversion methods
264  //
265 
266  fpreal getIndex(fpreal time) const
267  { return time*mySampleRate; }
268 
270  { return index / mySampleRate; }
271 
273  { return index*fps/mySampleRate + 1;}
274 
275  fpreal getIndexF(fpreal frame, fpreal fps) const
276  { return getTimeF(frame, fps)*mySampleRate; }
277 
278  static fpreal getTimeF(fpreal frame, fpreal fps)
279  { return (frame - 1) / fps; }
280 
281  static fpreal getFrameT(fpreal time, fpreal fps)
282  { return time*fps + 1; }
283 
284 
285  //
286  // Data operations
287  //
288 
289  void trim(const CL_Clip *clip, fpreal leftpos,
290  fpreal rightpos, int discard);
291 
292  // shorten the tracklength to newlen, if add is 1 then the
293  // remaining samples are added to the beginning
294  // Returns 1 if newlen is smaller than the beginning length
295 
296  int crop(int newlen, int add);
297 
298 
299  //
300  // I/O methods
301  // Note: 0 is success, -ve is fail
302  //
303 
304  int save(UT_OStream &os,
305  const CL_ClipPrivateIO *priv = 0) const;
306  int save(UT_OStream &os, UT_StringArray& parms,
307  const CL_ClipPrivateIO *priv = 0) const;
308  int save(const char *nm) const;
309 
310  // Returns true on success and false otherwise.
311  bool load(UT_IStream &is, const char *path=0);
312 
313  int load(const char *nm);
314 
315  int64 getMemoryUsage(bool inclusive) const;
316  int info(UT_OStream &os, fpreal fps, fpreal t,
317  bool limit, CL_InfoCallback cb,
318  void *cbdata) const;
319  int info(UT_InfoTree &tree, fpreal fps, fpreal t,
320  CL_InfoCallback cb, void *cbdata) const;
321 
322  static fpreal fixedDecimal(fpreal num, int digits = 2);
323  static void printNum(UT_OStream &os,fpreal num);
324 
325  //
326  // This method will reorder our tracks given a new list
327  // Should be used with caution.
328 
329  void reorder(CL_TrackList &list);
330 
331  // Given 3 track indices compute the sets of rotations that will
332  // eliminate any discontinuites introduced by static cracking.
333  // Negative indices are considered constant 0 tracks.
334  // Optionally supply a desired beginning rotation
335 
336  void crackSmooth(int xidx, int yidx, int zidz,
337  const UT_XformOrder &order,
338  int use_hint,
339  fpreal hx, fpreal hy, fpreal hz);
340 
341  // This method will return true if the clips lie over the same
342  // range (ie, sample-to-sample correspondence
343 
344  int isSameRange(const CL_Clip &v) const;
345 
346  // These methods can be used to increase performance by reducing
347  // memory management
348 
349  void stashAll();
350  void destroyStashed();
351 
352  // Generate a new unique name based on an existing name.
353  // oldname is the string to test and the method assumes the name is already being used.
354  // This means the method will always generate a new name even if oldname was valid unique name already.
355  // newname workbuffer is used to generate and return a new name.
356  void newName(const UT_StringRef &oldname, UT_WorkBuffer& newname) const;
357 
358  void setDefaults(void);
359 
360  // Called by CL_Track to update the name hash table when loaded.
361  void trackRenamed(CL_Track *track,
362  const char *oldname);
363 
364 
365  // Attributes
366  int setAttribute( const UT_StringHolder &name, const UT_StringHolder &v, int track=-1, int sample=-1 );
367  int setAttribute( const UT_StringHolder &name, const fpreal32 &v, int track=-1, int sample=-1 );
368  int setAttribute( const UT_StringHolder &name, const fpreal64 &v, int track=-1, int sample=-1 );
369  int setAttribute( const UT_StringHolder &name, const int &v, int track=-1, int sample=-1 );
370  int setAttribute( const UT_StringHolder &name, const UT_Vector2 &v, int track=-1, int sample=-1 );
371  int setAttribute( const UT_StringHolder &name, const UT_Vector3 &v, int track=-1, int sample=-1 );
372  int setAttribute( const UT_StringHolder &name, const UT_Vector4 &v, int track=-1, int sample=-1 );
373  int setAttribute( const UT_StringHolder &name, const UT_Matrix2 &v, int track=-1, int sample=-1 );
374  int setAttribute( const UT_StringHolder &name, const UT_Matrix3 &v, int track=-1, int sample=-1 );
375  int setAttribute( const UT_StringHolder &name, const UT_Matrix4 &v, int track=-1, int sample=-1 );
376 
377  int getAttribute( const UT_StringHolder &name, UT_StringHolder &v, int track=-1, int sample=-1 ) const;
378  int getAttribute( const UT_StringHolder &name, fpreal32 &v, int track=-1, int sample=-1 ) const;
379  int getAttribute( const UT_StringHolder &name, fpreal64 &v, int track=-1, int sample=-1 ) const;
380  int getAttribute( const UT_StringHolder &name, int &v, int track=-1, int sample=-1 ) const;
381  int getAttribute( const UT_StringHolder &name, UT_Vector2 &v, int track=-1, int sample=-1 ) const;
382  int getAttribute( const UT_StringHolder &name, UT_Vector3 &v, int track=-1, int sample=-1 ) const;
383  int getAttribute( const UT_StringHolder &name, UT_Vector4 &v, int track=-1, int sample=-1 ) const;
384  int getAttribute( const UT_StringHolder &name, UT_Matrix2 &v, int track=-1, int sample=-1 ) const;
385  int getAttribute( const UT_StringHolder &name, UT_Matrix3 &v, int track=-1, int sample=-1 ) const;
386  int getAttribute( const UT_StringHolder &name, UT_Matrix4 &v, int track=-1, int sample=-1 ) const;
387 
388  const CL_ClipAttributes *getAttributes() const { return myAttributes; }
389  void setAttributes( const CL_ClipAttributes *attrs );
390  void updateAttributes( const UT_StringSet &keys, const CL_ClipAttributes *attrs );
391 
392  // Removes a single attribute instance in the attribute map.
393  int removeAttribute(const UT_StringHolder &name, int track=-1, int sample=-1);
394  static int removeAttribute(CL_ClipAttributes *&attributes, const UT_StringHolder &name, int track=-1, int sample=-1);
395 
396  // Removes a list of attributes.
397  // The string should contain space separated pairs of "attrclass:attrname"
398  // where attrclass is one of "auto clip channel channelsample sample"
399  int removeAttributes(const UT_StringHolder &names);
400  static int removeAttributes(CL_ClipAttributes *&attributes, const UT_StringHolder &names);
401 
402  // Lists the attribute names from attrclass
403  int getAttributeNames( const UT_StringHolder &attrclass, UT_StringArray &names ) const;
404 
405  // Lists the attribute names from attrclass
406  static int getAttributeNames(const CL_ClipAttributes *attributes, const UT_StringHolder &attrclass, UT_StringArray &names );
407 
408 private:
409 
410  // Attributes
411  template< class T >
412  int setAttributeT( const UT_StringHolder &name, const T &v, int track=-1, int sample=-1 );
413 
414  template< class T >
415  int getAttributeT( const UT_StringHolder &name, T &v, int track=-1, int sample=-1 ) const;
416 
417  void clearTrackNames(bool set_to_null=true);
418  fpreal mySampleRate;
419  fpreal myStart;
420 
421  int myTrackLength;
422  CL_TrackList myTracks;
423  CL_TrackList myStashedTracks;
424 
425  UT_IntArray mySXTracks; // Quaternion tracks
426  UT_IntArray mySYTracks;
427  UT_IntArray mySZTracks;
428 
429  UT_XformOrder::xyzOrder mySRotOrder;
430  CL_ClipAttributes *myAttributes;
431 
432  bool myCheckDuplicateNames;
433 
434  typedef UT_NameManager<CL_Track*> TrackNamesMap;
435  TrackNamesMap *myTrackNames;
436 
437  int myStashedTracksNext;
438 
439  bool myDisableRemovingTrackNames;
440 
441  class ClearTrackNamesTask;
442  friend class ClearTrackNamesTask;
443 
444  CL_Clip();
445 };
446 
450 
451 ///////////////////////////////////////////////////////////////////////////////
452 //
453 // Inline implementation
454 //
455 
456 inline CL_Track *
458 {
459  CL_Track *track = myTrackNames->findSymbol(name);
460  if (index)
461  *index = track ? track->getIndex() : -1;
462  return track;
463 }
464 
465 inline const CL_Track *
467 {
468  const CL_Track *track = myTrackNames->findSymbol(name);
469  if (index)
470  *index = track ? track->getIndex() : -1;
471  return track;
472 }
473 
474 #endif // __CL_Clip__
#define SYSmax(a, b)
Definition: SYS_Math.h:1365
fpreal evaluateSingleFrame(const CL_Track *track, fpreal f, fpreal fps) const
Definition: CL_Clip.h:201
static fpreal getTimeF(fpreal frame, fpreal fps)
Definition: CL_Clip.h:278
void setTrackCapacity(int capacity)
Definition: CL_Clip.h:165
const GLdouble * v
Definition: glcorearb.h:836
UT_XformOrder::xyzOrder getSlerpOrder() const
Definition: CL_Clip.h:155
GLuint start
Definition: glcorearb.h:474
void(* CL_InfoCallback)(UT_String &result, void *data, int idx)
Definition: CL_Clip.h:39
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLsizei const GLchar *const * path
Definition: glcorearb.h:3340
const CL_ClipAttributes * getAttributes() const
Definition: CL_Clip.h:388
CL_Track * getTrack(int index)
Definition: CL_Clip.h:175
UT_SharedPtr< CL_Clip > CL_ClipPtr
Definition: CL_Clip.h:449
Wrapper around hboost::shared_ptr.
Definition: UT_SharedPtr.h:27
3D Vector class.
int getIndex() const
fpreal getSampleRate(void) const
Definition: CL_Clip.h:90
fpreal getStartTime() const
Definition: CL_Clip.h:254
GLsizeiptr size
Definition: glcorearb.h:663
void evaluateTime(const CL_Track *track, fpreal start_time, fpreal stop_time, fpreal *data, int size) const
Definition: CL_Clip.h:216
#define CL_API
Definition: CL_API.h:10
long long int64
Definition: SYS_Types.h:100
GLfloat f
Definition: glcorearb.h:1925
fpreal getEnd(void) const
Definition: CL_Clip.h:79
UT_VariantMap CL_ClipAttributes
Definition: CL_Clip.h:40
int getCheckDuplicateNames() const
Definition: CL_Clip.h:61
DATA_TYPE findSymbol(const UT_StringRef &symbol) const
double fpreal64
Definition: SYS_Types.h:185
int getTrackLength(void) const
Definition: CL_Clip.h:82
fpreal evaluateSingle(const CL_Track *track, fpreal index) const
Definition: CL_Clip.h:195
fpreal getFrame(fpreal index, fpreal fps) const
Definition: CL_Clip.h:272
GLboolean * data
Definition: glcorearb.h:130
GLuint const GLchar * name
Definition: glcorearb.h:785
void setStart(fpreal start)
Definition: CL_Clip.h:73
double fpreal
Definition: SYS_Types.h:263
void setSlerpCapacity(int capacity)
Definition: CL_Clip.h:125
void setSampleRate(fpreal rate)
Definition: CL_Clip.h:87
IMATH_INTERNAL_NAMESPACE_HEADER_ENTER T clip(const T &p, const Box< T > &box)
Definition: ImathBoxAlgo.h:89
void setCheckDuplicateNames(int val)
Definition: CL_Clip.h:64
GLuint index
Definition: glcorearb.h:785
fpreal evaluateSingleTime(const CL_Track *track, fpreal t) const
Definition: CL_Clip.h:198
void setSlerpOrder(UT_XformOrder::xyzOrder o)
Definition: CL_Clip.h:152
GLuint GLfloat * val
Definition: glcorearb.h:1607
fpreal getIndex(fpreal time) const
Definition: CL_Clip.h:266
static fpreal getFrameT(fpreal time, fpreal fps)
Definition: CL_Clip.h:281
fpreal getEndTime() const
Definition: CL_Clip.h:257
png_infop png_uint_32 int num
Definition: png.h:2158
UT_ValArray< const CL_Clip * > CL_ClipListC
Definition: CL_Clip.h:448
UT_ValArray< CL_Clip * > CL_ClipList
Definition: CL_Clip.h:447
fpreal getIndexF(fpreal frame, fpreal fps) const
Definition: CL_Clip.h:275
const CL_Track * getTrack(int index) const
Definition: CL_Clip.h:179
float fpreal32
Definition: SYS_Types.h:184
fpreal getStart(void) const
Definition: CL_Clip.h:76
fpreal getTime(fpreal index) const
Definition: CL_Clip.h:269
int getNumTracks(void) const
Definition: CL_Clip.h:172
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:794