HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CL_Track.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_Track.h ( Clip Library, C++)
7  *
8  * COMMENTS:
9  * A set of raw data
10  *
11  */
12 
13 
14 #ifndef __CL_Track__
15 #define __CL_Track__
16 
17 #include "CL_API.h"
18 #include <UT/UT_ValArray.h>
19 #include <UT/UT_FloatArray.h>
20 #include <UT/UT_StringHolder.h>
21 #include <SYS/SYS_Types.h>
22 
23 class UT_IStream;
24 class UT_OStream;
25 class CL_Clip;
26 class CL_Track;
28 
31 
32 //
33 // how to evaluate the track outside its defined range
34 //
35 
36 typedef enum {
37  CL_TRACK_HOLD, // Track is start/end value before/after
38  CL_TRACK_SLOPE, // Track extends at start/end slope
39  CL_TRACK_CYCLE, // Track wraps to defined range (repeat)
40  CL_TRACK_MIRROR, // Track wraps+reflects to defined range
41  CL_TRACK_DEFAULT, // Track is default value beyond defined range
42  CL_TRACK_CYCLE_STEP // Track is cycled and advanced
44 
46 {
51 };
52 
54 {
59 };
60 
62 {
67 };
68 
69 
71 
72 public:
73 
74  CL_Track(CL_Clip &dad, const CL_Track &from);
75  CL_Track(CL_Clip &dad, const UT_StringHolder &name);
76  ~CL_Track();
77 
78  // Use copy constructor with explicit dad for parent
79  CL_Track(const CL_Track &from) = delete;
80 
81  // Copy data without changing parent
82  CL_Track &operator= (const CL_Track &from);
83 
84  void init(CL_Clip &dad, const UT_StringHolder &name);
85 
86  int getDataCapacity() const
87  { return myData.capacity(); }
88 
90  { return myData.array(); }
91 
92  const fpreal *getData() const
93  { return myData.getRawArray(); }
94 
95  int getTrackLength() const
96  { return myData.entries(); }
97 
98  const UT_StringHolder &getName() const
99  { return myName; }
100 
101  //
102  // Warning this method must be used with extreme caution
103  void setName(const UT_StringHolder &name);
104 
105  // These methods are used for special cases, to access tracks more quickly.
106  // Normally a symboltable in CL_Clip is used to track access by name.
107  unsigned short getNameHash() const
108  { return (unsigned short)myName.hash(); }
109 
110  unsigned short getNameBaseLength() const
111  { return myNameBaseLength; }
112 
113  unsigned short getNameBaseHash() const
114  { return myNameBaseHash; }
115 
116  int getNameNumber() const
117  {
118  if (myNameNumberDirty)
119  ((CL_Track *)this)->calcNameNumber();
120  return myNameNumber;
121  }
122 
123  static void getNameComposition(const UT_StringRef &name,
124  unsigned short &base_length,
125  unsigned short &base_hash);
126 
127 
128  const char *info(fpreal t, const char *prefix = 0,
129  const char *suffix = 0) const;
130 
131  int isTimeDependent() const;
132 
133  int isWithinRange(fpreal low,fpreal hi,int completely=1) const;
134 
135  // these methods define the evaluation of the array outside
136  // its defined interval
137 
138  void setLeft(CL_TrackOutside type);
139  void setRight(CL_TrackOutside type);
140  void setDefault(fpreal value);
141 
143  { return myParent; }
144 
145  const CL_Clip *getClip() const
146  { return myParent; }
147 
148 
149  const char *getLeft() const;
150  const char *getRight() const;
151 
152  int64 getMemoryUsage(bool inclusive) const;
153 
154  void getExtendCond(CL_TrackOutside &left,
155  CL_TrackOutside &right) const;
157  { return myDefault; }
158 
159  void dupAttributes(const CL_Track *,
160  int data_too=0, int name_too=0);
161 
162  // data methods
163 
164  void reverse();
165  void constant(fpreal value=0);
166  void cycle(int howmany);
167 
168  int convolve(const CL_Track &t1, const CL_Track &t2,
169  int add = 0);
170 
171  int convolveCenter(fpreal *data2, int n2, int passes = 1);
172  int convolveCenterDirect(fpreal *data2, int n2, int passes);
173 
174  int copyStamp(const CL_Track &t1, fpreal toffset, int clr);
175 
176  int getThresholdTimes(fpreal thresh,
177  UT_FprealArray &toffsets,
178  UT_FprealArray &values) const;
179 
180  void despike(fpreal tol, fpreal effect=1.0, int maxwidth=1);
181 
182  void blend(fpreal start, const fpreal *values, int len,
183  fpreal base, const CL_SubRange *effect,
184  fpreal cycle);
185 
186  void blend(fpreal start, const fpreal *values, int len,
187  fpreal base, const CL_Track *effect_track,
188  fpreal cycle);
189 
190  void limitValues(fpreal max, fpreal min,
191  CL_TrackLimitMethod method,
192  int start, int end);
193 
194  static fpreal limitValue(fpreal max, fpreal min,
195  CL_TrackLimitMethod method, fpreal v);
196 
197  // Resample from the given source into ourselves
198 
199  int resample(const fpreal *values, int num,
200  CL_TrackResampleMethod method,
201  int constant_area, int iscycle = 0,
202  fpreal cycle = 0);
203 
204  // Resample from ourselves into the given destination
205 
206  int resample(fpreal *data, int size, int start, int end,
207  CL_TrackResampleMethod method,
208  int constant_area,
209  int iscycle = 0,
210  fpreal cycle = 0) const;
211 
212  void quantizeValue(fpreal max, fpreal min,
213  CL_QuantizeValueMethod method,
214  fpreal step, fpreal offset,
215  int clamp, int start, int end);
216 
217  void normalize();
218  void absolute();
219  void smoothRotate(fpreal delta = 180.0);
220 
221  void pitchShift(fpreal shift,int chunk,
222  const CL_Track *animate=0,
223  fpreal (*callback)(void *,int,int)=0,
224  void *node=0);
225 
226  // This actually is a DFT followed by a multipy, and an IDFT
227  void fastConvolve(int chunk,fpreal *data);
228 
229 
230  // This method allows this track to assume the same data array as 'track'.
231  // They will share the same buffer until unalias() is called. aliasTrack()
232  // may be called multiple times before unalias() is called. Both tracks
233  // must have the same number of samples.
234  void aliasTrack(CL_Track &track);
235  void unalias();
236  bool isAliased() const { return myPrevDataAlias != 0; }
237 
238  // swaps data with 'track'.
239  void swapData(CL_Track &track);
240 
241  int getIndex() const;
242 
243  static UT_StringHolder fixName(const UT_StringHolder &old);
244 
245 private:
246 
247  // should only be called by CL_Clip
248 
249  void evaluate(fpreal start_index, fpreal stop_index,
250  fpreal *data, int size) const;
251 
252 
253  // this single version is much less efficient than the range methods
254  fpreal evaluateSingle(fpreal index) const;
255 
256  // optimizied evaluations which work on a range
257  // entire range is evaluated with a particular extend condition
258 
259  void evaluatePortion(fpreal i0, fpreal i1,
260  fpreal start_index, fpreal
261  stop_index, fpreal *data, int size,
262  fpreal *fix, int portion) const;
263 
264  void evaluateCenter(fpreal start_index, fpreal stop_index,
265  fpreal *data, int size) const;
266 
267  void evaluateLeftSlope(fpreal start_index, fpreal stop_index,
268  fpreal *data, int size) const;
269  void evaluateRightSlope(fpreal start_index, fpreal stop_index,
270  fpreal *data, int size) const;
271 
272  void evaluateLeftHold(fpreal *data, int size) const;
273  void evaluateRightHold(fpreal *data, int size) const;
274 
275  void evaluateDefault(fpreal *data, int size) const;
276  void evaluateCycle(fpreal start_index, fpreal stop_index,
277  fpreal *data, int size) const;
278  void evaluateMirror(fpreal start_index, fpreal stop_index,
279  fpreal *data, int size) const;
280  void evaluateCycleStep(fpreal start_index, fpreal stop_index,
281  fpreal *data, int size) const;
282 
283  void updateName();
284  //
285  // I/O methods
286  //
287  class CL_API BinaryIO
288  {
289  public:
290  BinaryIO() : myTaintVersion(0), myOffset(0), myDoubleFlag(false) {}
291 
292  int myTaintVersion;
293  int myOffset;
294  bool myDoubleFlag;
295  };
296 
297  int save(UT_OStream &os, BinaryIO *binary_options) const;
298  bool load(UT_IStream &is, BinaryIO *binary_options,
299  const char *path = 0);
300 
301  void setDefaults();
302  void calcNameNumber();
303  void setIndex(int);
304 
305  UT_StringHolder myName;
306  UT_FprealArray myData;
307  CL_Clip *myParent;
308 
309  unsigned short myNameBaseLength;
310  unsigned short myNameNumber;
311  unsigned short myNameBaseHash;
312 
313  char myNameNumberDirty;
314 
315 
316  CL_TrackOutside myLeft; // eval method outside range
317  CL_TrackOutside myRight; // eval method outside range
318  fpreal myDefault; // used in CL_TRACK_DEFAULT
319  fpreal *myPrevDataAlias; // used by alias/unalias.
320 
321  int myIndex; // track index in the clip array.
322 
323  friend class CL_Clip;
324  friend class CL_AsciiClipReader;
325  friend class CL_AsciiClipWriter;
326  friend class CL_BinaryClipReader;
327  friend class CL_BinaryClipWriter;
328 };
329 
330 
331 #endif
const UT_StringHolder & getName() const
Definition: CL_Track.h:98
UT_ValArray< const CL_Track * > CL_TrackListC
Definition: CL_Track.h:30
GLenum clamp
Definition: glcorearb.h:1234
GLint left
Definition: glcorearb.h:2005
const GLdouble * v
Definition: glcorearb.h:837
GLuint start
Definition: glcorearb.h:475
GLsizei const GLchar *const * path
Definition: glcorearb.h:3341
GLdouble right
Definition: glad.h:2817
void reverse(I begin, I end)
Definition: pugixml.cpp:7190
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
int getNameNumber() const
Definition: CL_Track.h:116
unsigned short getNameBaseLength() const
Definition: CL_Track.h:110
#define CL_API
Definition: CL_API.h:10
vint4 blend(const vint4 &a, const vint4 &b, const vbool4 &mask)
Definition: simd.h:4784
const CL_Clip * getClip() const
Definition: CL_Track.h:145
GLintptr offset
Definition: glcorearb.h:665
bool isAliased() const
Definition: CL_Track.h:236
CL_TrackLimitMethod
Definition: CL_Track.h:45
unsigned short getNameHash() const
Definition: CL_Track.h:107
CL_QuantizeValueMethod
Definition: CL_Track.h:53
GLuint GLuint end
Definition: glcorearb.h:475
int getDataCapacity() const
Definition: CL_Track.h:86
long long int64
Definition: SYS_Types.h:116
GLint i1
Definition: glad.h:2724
GLuint const GLchar * name
Definition: glcorearb.h:786
unsigned short getNameBaseHash() const
Definition: CL_Track.h:113
GLdouble t
Definition: glad.h:2397
CL_Clip * getClip()
Definition: CL_Track.h:142
CL_TrackOutside
Definition: CL_Track.h:36
GLsizeiptr size
Definition: glcorearb.h:664
CL_TrackResampleMethod
Definition: CL_Track.h:61
int getTrackLength() const
Definition: CL_Track.h:95
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
fpreal getDefault() const
Definition: CL_Track.h:156
fpreal64 fpreal
Definition: SYS_Types.h:277
LeafData & operator=(const LeafData &)=delete
const fpreal * getData() const
Definition: CL_Track.h:92
GLuint index
Definition: glcorearb.h:786
fpreal * getData()
Definition: CL_Track.h:89
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
Definition: core.h:1131
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
UT_ValArray< CL_Track * > CL_TrackList
Definition: CL_Track.h:27
ImageBuf OIIO_API resample(const ImageBuf &src, bool interpolate=true, ROI roi={}, int nthreads=0)
type
Definition: core.h:1059
ImageBuf OIIO_API convolve(const ImageBuf &src, const ImageBuf &kernel, bool normalize=true, ROI roi={}, int nthreads=0)
Definition: format.h:895
constexpr T normalize(UT_FixedVector< T, D > &a) noexcept