lib/pipeline/base.rb in tracksperanto-2.1.1 vs lib/pipeline/base.rb in tracksperanto-2.2.0
- old
+ new
@@ -114,50 +114,58 @@
io_with_progress = Tracksperanto::ProgressiveIO.new(tracker_data_io) do | offset, of_total |
percent_complete = (50.0 / of_total) * offset
end
@ios << io_with_progress
- accumulator = Tracksperanto::Accumulator.new
- importer.receiver = accumulator
+ @accumulator = Tracksperanto::Accumulator.new
+ importer.io = io_with_progress
+ importer.each {|t| @accumulator.push(t) }
- importer.stream_parse(io_with_progress)
+ # OBSOLETE - for this version we are going to permit it
+ if importer.respond_to?(:stream_parse)
+ importer.receiver = @accumulator
+ importer.stream_parse(io_with_progress)
+ end
- report_progress(percent_complete = 50.0, "Validating #{accumulator.length} imported trackers")
- if accumulator.num_objects.zero?
+ report_progress(percent_complete = 50.0, "Validating #{@accumulator.size} imported trackers")
+ if @accumulator.size.zero?
raise "Could not recover any non-empty trackers from this file. Wrong import format maybe?"
end
report_progress(percent_complete, "Starting export")
- percent_per_tracker = (100.0 - percent_complete) / accumulator.num_objects
+ percent_per_tracker = (100.0 - percent_complete) / @accumulator.size
# Use the width and height provided by the parser itself
exporter.start_export(importer.width, importer.height)
- accumulator.each_object_with_index do | t, tracker_idx |
- raise "Not a Tracker" unless t.is_a?(Tracksperanto::Tracker)
+
+ # Now send each tracker through the middleware chain
+ @accumulator.each_with_index do | t, tracker_idx |
kf_weight = percent_per_tracker / t.keyframes.length
points += 1
exporter.start_tracker_segment(t.name)
t.each_with_index do | kf, idx |
keyframes += 1
exporter.export_point(kf.frame, kf.abs_x, kf.abs_y, kf.residual)
report_progress(
percent_complete += kf_weight,
- "Writing keyframe #{idx+1} of #{t.name.inspect}, #{accumulator.num_objects - tracker_idx} trackers to go"
+ "Writing keyframe #{idx+1} of #{t.name.inspect}, #{@accumulator.size - tracker_idx} trackers to go"
)
end
exporter.end_tracker_segment
end
exporter.end_export
report_progress(100.0, "Wrote #{points} points and #{keyframes} keyframes")
[points, keyframes]
ensure
+ @accumulator.clear
@ios.map!{|e| e.close! rescue e.close }
@ios = []
+ @accumulator = nil
end
# Setup output files and return a single output
# that replays to all of them
def setup_outputs_for(input_file_path)
@@ -174,6 +182,6 @@
# Open the file for writing and register it to be closed automatically
def open_owned_export_file(path_to_file)
@ios ||= []
@ios.push(File.open(path_to_file, "wb"))[-1]
end
-end
+end
\ No newline at end of file