HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CH_Filters.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: CH_Filters.h (CH Library, C++)
7  *
8  * COMMENTS:
9  */
10 
11 #ifndef __CH_FILTERS_H_INCLUDED__
12 #define __CH_FILTERS_H_INCLUDED__
13 
14 #include "CH_API.h"
15 #include "CH_Channel.h"
16 #include <SYS/SYS_Types.h>
17 #include <UT/UT_Array.h>
18 #include <UT/UT_NonCopyable.h>
19 
20 class CH_Channel;
21 class CH_Segment;
22 
23 // How to Bake CHOP Exports
24 // When baking a new channel is created and it overrides the channel animation on the parm.
25 // It won't override CHOP Clips.
27 {
28  CH_BAKECHOP_NONE, // Don't bake CHOP exports on channels.
29  CH_BAKECHOP_KEEP_EXPORT_FLAG, // Bake but leave the export flag on. You'll have to manually toggle the chop export flag.
30  CH_BAKECHOP_DISABLE_EXPORT_FLAG, // Bake and disable the CHOP export flags. This won't work properly if you work on a subset of the exports as it will disable all.
31  CH_BAKECHOP_CREATE_DELETE_CHOP, // Bake and create a Delete CHOP node after the CHOP export node. This enables you to bake a single channel.
32  CH_BAKECHOP_EXPRESSIONS, // Bake expression even if there is no CHOP export.
33 };
34 
35 // Builder for ranges of selected segments
36 // Abstracts the use of JIVE_Iterators/Script glob in order to reuse the
37 // code for scripting
39 {
40 public:
41  CH_FilterRangeBuilder() = default;
42  virtual ~CH_FilterRangeBuilder();
43 
45 
46  // Reset Channel and Segments
47  virtual void resetChannel() = 0;
48  virtual void resetSegment() = 0;
49 
50  //Iterate over Channels and Segments
51  virtual CH_Channel *nextChannel() = 0;
52  virtual CH_Segment *nextSegment(bool &is_selected) = 0;
53 
54  // External Undo
55  virtual void undoStart() = 0;
56  virtual void undoChannel( CH_Channel *chp) = 0;
57  virtual void undoEnd() = 0;
58 
59  // Callback to copy a dummy Chop channel back as a real channel
60  virtual void beginCopyChopChannels(CH_BakeChop mode) = 0;
61  virtual void copyChopChannel(CH_Channel *chp, fpreal global_start, fpreal global_end) = 0;
62  virtual void endCopyChopChannels() = 0;
63 };
64 
65 struct chRefitChannel;
66 
68 {
69 public:
70  CH_Filters();
71 
72  // Performs a Refitting operation to simplify the channels.
73  // This can be used to bake channel expressions.
74  // This can be used on channels with cycle extrapolation to bake the cycles.
75  void applyRefitFilter(
76  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
77  UT_Array<chRefitChannel> *refit_channels, // (optional) refit channels specifying which ranges to refit
78 
79  bool refit_on, // perform the cubic refitting using CH_Channel::refit()
80  fpreal refit_tol, // refitting tolerance in abs value.
81  bool refit_preserve_extrema, // refitting preserves extremas
82  bool refit_bezier, // set the new keyframes to bezier instead of cubic.
83  bool smooth_after_refit, // apply autoslopes to the refit channel
84 
85  bool resample_on, // do resampling before doing the refitting.
86  fpreal resample_rate, // resample rate in frames
87  fpreal resample_tol, // resample tolerance to avoid adding samples in frames.
88 
89  bool range_on, // force a global frame range, on top of the extracted ranges.
90  fpreal range_start, // start frame
91  fpreal range_end, // end frame.
92 
93  CH_BakeChop bake_chop=CH_BAKECHOP_NONE // See CH_BakeChop for description of the modes.
94  );
95 
96  // Performs only a Refitting operation to simplify the channels.
97  void applyRefitFilter(
98  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
99  UT_Array<chRefitChannel> &refit_channels, // array specifying which channels and ranges to refit
100 
101  fpreal refit_tol, // refitting tolerance in abs value.
102  bool refit_preserve_extrema, // refitting preserves extremas
103  bool refit_bezier, // set the new keyframes to bezier instead of cubic.
104  bool smooth_after_refit, // apply autoslopes to the refit channel
105 
106  bool range_on, // force a global frame range, on top of the extracted ranges.
107  fpreal range_start, // start frame
108  fpreal range_end // end frame.
109  );
110 
111  // Performs a Resample operation to bake channel expressions.
112  void applyResampleFilter(
113  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
114  UT_Array<chRefitChannel> &refit_channels, // array specifying which channels and ranges to resample
115 
116  fpreal resample_rate, // resample rate in frames
117  fpreal resample_tol, // resample tolerance to avoid adding samples in frames.
118  bool resample_snap, // snap resampled keys to whole frames
119 
120  bool range_on, // force a global frame range, on top of the extracted ranges.
121  fpreal range_start, // start frame
122  fpreal range_end // end frame.
123  );
124 
125  // Performs a Extend operation to turn channel extrapolation into real keyframes.
126  void applyExtendFilter(
127  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
128  fpreal range_start, // start frame
129  fpreal range_end // end frame.
130  );
131 
132  // Make a copy of the dummy CHOP channels on the real param
133  void applyCopyChopFilter(
134  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
135  bool range_on, // force a global frame range, on top of the extracted ranges.
136  fpreal range_start, // start frame
137  fpreal range_end, // end frame.
138  CH_BakeChop bake_chop=CH_BAKECHOP_NONE // See CH_BakeChop for description of the modes.
139  );
140 
141  void computeRefitChannels(
142  CH_FilterRangeBuilder *builder, // range builder to extract the channels and the time ranges
143  UT_Array<chRefitChannel> &refit_channels, // the refit channel array to populate
144 
145  bool range_on, // force a global frame range, on top of the extracted ranges.
146  fpreal range_start, // start frame
147  fpreal range_end, // end frame.
148  bool allow_invalid=false
149  );
150 
151 private:
152 
153  bool myFirst; // Flag to do proper undo/redo when applyRefitFilter calls the other methods
154 };
155 
156 // Helper class to build continuous ranges from selected segments
158 {
160  : myStart(0.0)
161  , myEnd(0.0)
162  , myChannel(chp)
163  , myCycleBefore(false)
164  , myCycleAfter(false)
165  , myIsCubic(false)
166  , myIsAuto(false)
167  {}
168 
169  void start( CH_Segment *segp )
170  {
171  myStart = myChannel->globalTime(segp->getStart());
172  myEnd = myChannel->globalTime(segp->getEnd());
173 
174  myTimes.clear();
175  myTimes.insert(myStart);
176  myTimes.insert(myEnd);
177  }
179  {
180  myStart = start;
181  myEnd = end;
182 
183  myTimes.clear();
184  myTimes.insert(myStart);
185  myTimes.insert(myEnd);
186  }
187  void append( CH_Segment *segp )
188  {
189  myEnd = myChannel->globalTime(segp->getEnd());
190  myTimes.insert(myEnd);
191  }
192 
194  {
195  myTimes.insert(t);
196  }
197 
198  fpreal getStart() const
199  {
200  return myStart;
201  }
202 
203  fpreal getEnd() const
204  {
205  return myEnd;
206  }
207 
209  {
210  return myTimes;
211  }
212 
213  const CH_Channel *getChannel() const { return myChannel; }
214 
215  void setCycleBefore(bool b)
216  {
217  myCycleBefore = b;
218  }
219 
220  void setCycleAfter(bool b)
221  {
222  myCycleAfter = b;
223  }
224 
225  void setIsCubic(bool b)
226  {
227  myIsCubic = b;
228  }
229 
230  void setIsAuto(bool b)
231  {
232  myIsAuto = b;
233  }
234 
236  {
237  return myCycleBefore;
238  }
239 
241  {
242  return myCycleAfter;
243  }
244 
245  bool isCubic()
246  {
247  return myIsCubic;
248  }
249 
250  bool isAuto()
251  {
252  return myIsAuto;
253  }
254 private:
255  CH_Channel *myChannel;
256  fpreal myStart;
257  fpreal myEnd;
258  UT_SortedSet<fpreal> myTimes;
259  bool myCycleBefore, myCycleAfter;
260  bool myIsCubic, myIsAuto;
261 };
262 
263 // Helper class to hold continuous ranges for a channel
265 {
267  : myChannel(p)
268  {}
269 
270  void append( const chRefitRange &r )
271  {
272  myRanges.append(r);
273  }
274 
276  {
277  return myChannel;
278  }
279 
281  {
282  myChannel = chp;
283  }
284 
286  {
287  return myRanges;
288  }
289 
290  bool isValid() const
291  {
292  return getChannel() && myRanges.entries()>0;
293  }
294 
295 private:
296  CH_Channel *myChannel;
297  UT_Array<chRefitRange> myRanges;
298 };
299 
300 #endif
void setIsCubic(bool b)
Definition: CH_Filters.h:225
GLuint start
Definition: glcorearb.h:475
fpreal globalTime(fpreal t) const
Definition: CH_Channel.h:536
chRefitRange(CH_Channel *chp)
Definition: CH_Filters.h:159
chRefitChannel(CH_Channel *p)
Definition: CH_Filters.h:266
void append(CH_Segment *segp)
Definition: CH_Filters.h:187
UT_SortedSet< fpreal > & getTimes()
Definition: CH_Filters.h:208
fpreal getStart() const
Definition: CH_Segment.h:341
GLuint GLuint end
Definition: glcorearb.h:475
CH_BakeChop
Definition: CH_Filters.h:26
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
bool isAuto()
Definition: CH_Filters.h:250
fpreal getEnd() const
Definition: CH_Filters.h:203
void start(CH_Segment *segp)
Definition: CH_Filters.h:169
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
void setCycleBefore(bool b)
Definition: CH_Filters.h:215
void start(fpreal start, fpreal end)
Definition: CH_Filters.h:178
exint append()
Definition: UT_Array.h:142
GLdouble t
Definition: glad.h:2397
GLenum mode
Definition: glcorearb.h:99
exint entries() const
Alias of size(). size() is preferred.
Definition: UT_Array.h:648
const CH_Channel * getChannel() const
Definition: CH_Filters.h:213
void insertTime(fpreal t)
Definition: CH_Filters.h:193
void setIsAuto(bool b)
Definition: CH_Filters.h:230
fpreal64 fpreal
Definition: SYS_Types.h:277
bool getCycleBefore()
Definition: CH_Filters.h:235
#define CH_API
Definition: CH_API.h:10
bool getCycleAfter()
Definition: CH_Filters.h:240
void setCycleAfter(bool b)
Definition: CH_Filters.h:220
CH_Channel * getChannel() const
Definition: CH_Filters.h:275
UT_Array< chRefitRange > & getRanges()
Definition: CH_Filters.h:285
void setChannel(CH_Channel *chp)
Definition: CH_Filters.h:280
bool isCubic()
Definition: CH_Filters.h:245
GLboolean r
Definition: glcorearb.h:1222
fpreal getStart() const
Definition: CH_Filters.h:198
bool isValid() const
Definition: CH_Filters.h:290
fpreal getEnd() const
Definition: CH_Segment.h:342
void append(const chRefitRange &r)
Definition: CH_Filters.h:270