Class: Tracksperanto::Export::FlameStabilizer2014

Inherits:
Base
  • Object
show all
Defined in:
lib/export/flame_stabilizer_2014.rb

Direct Known Subclasses

FlameStabilizer2014Cornerpin

Constant Summary collapse

COLOR =
"50 50 50"
DATETIME_FORMAT =
'%a %b %d %H:%M:%S %Y'

Instance Attribute Summary

Attributes inherited from Base

#io

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#initialize

Methods included from ConstName

#const_name

Methods included from SimpleExport

#just_export

Constructor Details

This class inherits a constructor from Tracksperanto::Export::Base

Class Method Details

.desc_and_extensionObject


6
7
8
# File 'lib/export/flame_stabilizer_2014.rb', line 6

def self.desc_and_extension
  "flamesmoke2014.stabilizer"
end

.human_nameObject


10
11
12
# File 'lib/export/flame_stabilizer_2014.rb', line 10

def self.human_name
  "Flame/Smoke 2D Stabilizer setup (v. 2014 and above)"
end

Instance Method Details

#end_exportObject


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/export/flame_stabilizer_2014.rb', line 22

def end_export
  # Now make another writer, this time for our main IO
  @writer = FlameChannelParser::Builder.new(@io)
  
  # Now we know how many trackers we have so we can write the header
  # data along with NbTrackers
  write_header_with_number_of_trackers(@counter)
  
  # Now write everything that we accumulated earlier into the base IO
  @temp.rewind
  @io.write(@temp.read) until @temp.eof?
  @temp.close!
  
  # Send the ChannelEnd command and list the trackers
  @writer.channel_end
  @first_ref_frames.each_with_index do | ref_frame, i|
    @writer.write_unterminated_block!("tracker", i) do |t|
      t.active true
      t.color_hash!("colour", 0, 100, 0)
      t.fixed_ref true
      t.fixed_x false
      t.fixed_y false
      t.tolerance 100
      t.offsets_x 0
      t.offsets_y 0
      t.first_ref_frame ref_frame
    end
  end
  
  # Write the finalizing "End"
  @writer.write_loose!("end")
end

#end_tracker_segmentObject


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/export/flame_stabilizer_2014.rb', line 72

def end_tracker_segment
  # We write these at tracker end since we need to know in advance
  # how many keyframes they should contain
  write_shift_channel("shift/x", @x_shift_values)
  write_shift_channel("shift/y", @y_shift_values)
  
  # And finish with the offset channels. The order of channels is important!
  # (otherwise the last tracker's shift animation is not imported by Flame)
  # https://github.com/guerilla-di/tracksperanto/issues/1
  write_offset_channels
end

#export_point(frame, abs_float_x, abs_float_y, float_residual) ⇒ Object


60
61
62
63
64
65
66
67
68
69
70
# File 'lib/export/flame_stabilizer_2014.rb', line 60

def export_point(frame, abs_float_x, abs_float_y, float_residual)
  flame_frame = frame + 1
  if @write_first_frame
    export_first_point(flame_frame, abs_float_x, abs_float_y)
    # Record the first ref frame for this tracker
    @first_ref_frames << flame_frame
    @write_first_frame = false
  else
    export_remaining_point(flame_frame, abs_float_x, abs_float_y)
  end
end

#start_export(img_width, img_height) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/export/flame_stabilizer_2014.rb', line 14

def start_export( img_width, img_height)
  @counter = 0
  @first_ref_frames = []
  @width, @height = img_width, img_height
  @temp = Tracksperanto::BufferIO.new
  @writer = FlameChannelParser::Builder.new(@temp)
end

#start_tracker_segment(tracker_name) ⇒ Object


55
56
57
58
# File 'lib/export/flame_stabilizer_2014.rb', line 55

def start_tracker_segment(tracker_name)
  @counter += 1
  @write_first_frame = true
end