Class: Tracksperanto::Import::ShakeScript::TrackExtractor

Inherits:
ShakeGrammar::Catcher show all
Includes:
ZipTuples
Defined in:
lib/import/shake_script.rb

Overview

Extractor. Here we define copies of Shake's standard node creation functions.

Constant Summary

Constants inherited from ShakeGrammar::Lexer

ShakeGrammar::Lexer::MAX_BUFFER_SIZE, ShakeGrammar::Lexer::MAX_STACK_DEPTH, ShakeGrammar::Lexer::STOP_TOKEN

Instance Attribute Summary

Attributes inherited from ShakeGrammar::Lexer

#sentinel, #stack

Instance Method Summary collapse

Methods included from ZipTuples

#zip_curve_tuples

Methods inherited from ShakeGrammar::Lexer

#initialize

Constructor Details

This class inherits a constructor from Tracksperanto::ShakeGrammar::Lexer

Instance Method Details

#atom_is_tracker_assignment?(a) ⇒ Boolean

An atom that is a tracker node will look like this

:assign, [:vardef, “Stabilize2”], [:retval, [:trk, <T “track1” with 116 keyframes>, <T “track2” with 116 keyframes>, <T “track3” with 116 keyframes>, <T “track4” with 89 keyframes>]]

a Stabilize though will look like this

:assign, [:vardef, “Stabilize1”], [:retval, [:trk, <T “track1” with 116 keyframes>, <T “track2” with 116 keyframes>, <T “track3” with 116 keyframes>]]

Returns:

  • (Boolean)

77
78
79
# File 'lib/import/shake_script.rb', line 77

def atom_is_tracker_assignment?(a)
  deep_include?(a, :trk)
end

#deep_include?(array_or_element, atom_name) ⇒ Boolean

Find whether the passed atom includes a [:trk] on any level

Returns:

  • (Boolean)

62
63
64
65
66
67
68
69
70
71
# File 'lib/import/shake_script.rb', line 62

def deep_include?(array_or_element, atom_name)
  return false unless array_or_element.is_a?(Array)
  return true if array_or_element[0] == atom_name
  
  array_or_element.each do | elem |
     return true if deep_include?(elem, atom_name)
  end
  
  false
end

#hermite(extrapolation_type, *keyframes) ⇒ Object

Hermite interpolation looks like this Hermite(0,@1,@2) The first value in the array is the keyframe value, the other two are tangent positions (which we discard)


95
96
97
98
99
# File 'lib/import/shake_script.rb', line 95

def hermite(extrapolation_type, *keyframes)
  report_progress("Translating Hermite curve, removing tangents")
  remap_keyframes_against_negative_at!(keyframes)
  keyframes.map{ |kf| [kf.at, kf.value[0]] }
end

#linear(extrapolation_type, *keyframes) ⇒ Object Also known as: nspline, jspline

For Linear() curve calls. If someone selected JSpline or Hermite it's his problem. We put the frame number at the beginning since it works witih oru tuple zipper


83
84
85
86
87
# File 'lib/import/shake_script.rb', line 83

def linear(extrapolation_type, *keyframes)
  report_progress("Translating Linear animation")
  remap_keyframes_against_negative_at!(keyframes)
  keyframes.map { |kf| [kf.at , kf.value] }
end

#matchmove(bgImage, fgImage, applyTransform, trackType, track1X, track1Y, matchX, matchY, track2X, track2Y, scale, rotation, track3X, track3Y, track4X, track4Y, *others) ⇒ Object

image = MatchMove(

  Background,
  Foreground,
  applyTransform,
  "trackType",
  track1X,
  track1Y,
  matchX,
  matchY,
  track2X,
  track2Y,
  scale,
  rotation,
  track3X,
  track3Y,
  track4X,
  track4Y,
  x1, 
  y1,
  x2,
  y2,
  x3,
  y3,
  x4,
  y4,
  "xFilter",
  "yFilter",
  motionBlur, 
  shutterTiming,
  shutterOffset,
  referenceFrame,
  "compositeType",
  clipMode,
 "trackRange",
  "subPixelRes",
  "matchSpace",
  float referenceTolerance,
  "referenceBehavior",
  float failureTolerance,
  "failureBehavior",
  int limitProcessing,
  ...
);

222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/import/shake_script.rb', line 222

def matchmove(bgImage, fgImage, applyTransform,
  trackType,
  track1X,
  track1Y,
  matchX,
  matchY,
  track2X,
  track2Y,
  scale,
  rotation,
  track3X,
  track3Y,
  track4X,
  track4Y, *others)
  
  report_progress("Parsing MatchMove node")
  [
    collect_stabilizer_tracker("track1", track1X, track1Y),
    collect_stabilizer_tracker("track2", track2X, track2Y),
    collect_stabilizer_tracker("track3", track3X, track3Y),
    collect_stabilizer_tracker("track4", track4X, track4Y),
  ].compact.unshift(:trk)
end

#push(atom) ⇒ Object

Normally, we wouldn't need to look for the variable name from inside of the funcall. However, in this case we DO want to take this shortcut so we know how the tracker node is called


49
50
51
52
53
54
55
56
57
58
59
# File 'lib/import/shake_script.rb', line 49

def push(atom)
  return super unless atom_is_tracker_assignment?(atom)
  
  node_name = atom[1][-1]
  trackers = atom[2][1][1..-1]
  trackers.map do | tracker |
    tracker.name = [node_name, tracker.name].join("_")
    # THIS IS THE MOST IMPORTANT THINGO
    sentinel.tracker_proc.call(tracker)
  end
end

#settimerange(str) ⇒ Object

SetTimeRange(“-5-15”) // sets time range of comp We use it to avoid producing keyframes which start at negative frames


43
44
45
# File 'lib/import/shake_script.rb', line 43

def settimerange(str)
  sentinel.start_frame = str.to_i if str.to_i < 0
end

#stabilize(imageIn, applyTransform, inverseTransform, trackType, track1X, track1Y, stabilizeX, stabilizeY, track2X, track2Y, matchScale, matchRotation, track3X, track3Y, track4X, track4Y, *useless_args) ⇒ Object

stabilize

image In,
int applyTransform,
int inverseTransform
const char * trackType,
float track1X,
float track1Y,
int stabilizeX,
int stabilizeY,
float track2X,
float track2Y,
int matchScale,
int matchRotation,
float track3X,
float track3Y,
float track4X,
float track4Y,
const char * xFilter,
const char * yFilter,
const char * transformationOrder,
float motionBlur, 
float shutterTiming,
float shutterOffset,
float referenceFrame,
float aspectRatio,
...

;


160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/import/shake_script.rb', line 160

def stabilize(imageIn, applyTransform, inverseTransform, trackType,
  track1X, track1Y,
  stabilizeX, stabilizeY,
  track2X, track2Y,
  matchScale,
  matchRotation,
  track3X, track3Y,
  track4X, track4Y,
  *useless_args)
  
  report_progress("Parsing Stabilize node")
  [
    collect_stabilizer_tracker("track1", track1X, track1Y),
    collect_stabilizer_tracker("track2", track2X, track2Y),
    collect_stabilizer_tracker("track3", track3X, track3Y),
    collect_stabilizer_tracker("track4", track4X, track4Y),
  ].compact.unshift(:trk)
end

#tracker(input, trackRange, subPixelRes, matchSpace, referenceTolerance, referenceBehavior, failureTolerance, failureBehavior, limitProcessing, referencFrame, s1, s2, s3, s4, s5, s6, *trackers) ⇒ Object

image Tracker(

 image In,
 const char * trackRange,
 const char * subPixelRes,
 const char * matchSpace,
 float referenceTolerance,
 const char * referenceBehavior,
 float failureTolerance,
 const char * failureBehavior,
 int limitProcessing,
 float referencFrame 
 ...
);

120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/import/shake_script.rb', line 120

def tracker(input, trackRange, subPixelRes, matchSpace,
    referenceTolerance, referenceBehavior, failureTolerance, failureBehavior, limitProcessing, referencFrame, 
    s1, s2, s3, s4, s5, s6, *trackers)
  flat_tracks = if (s1 == "v2.0") # The Shake version stupid Winfucks users didn't get
    trackers
  else
    [s1, s2, s3, s4, s4, s6] + trackers
  end
  
  report_progress("Parsing Tracker node")
  collect_trackers_from(flat_tracks).unshift(:trk)
end