lib/pipeline/base.rb in tracksperanto-2.2.4 vs lib/pipeline/base.rb in tracksperanto-2.3.0

- old
+ new

@@ -138,55 +138,57 @@ percent_complete = (50.0 / of_total) * offset end @ios.push(io_with_progress) @accumulator = Tracksperanto::Accumulator.new + begin - # OBSOLETE - for this version we are going to permit it. - if importer.respond_to?(:stream_parse) - STDERR.puts "Import::Base#stream_parse(io) is obsolete, please rewrite your importer to use each instead" - importer.receiver = @accumulator - importer.stream_parse(io_with_progress) - else - importer.io = io_with_progress - importer.each {|t| @accumulator.push(t) unless t.empty? } - end + # OBSOLETE - for this version we are going to permit it. + if importer.respond_to?(:stream_parse) + STDERR.puts "Import::Base#stream_parse(io) is obsolete, please rewrite your importer to use each instead" + importer.receiver = @accumulator + importer.stream_parse(io_with_progress) + else + importer.io = io_with_progress + importer.each {|t| @accumulator.push(t) unless t.empty? } + end - report_progress(percent_complete = 50.0, "Validating #{@accumulator.size} imported trackers") - raise NoTrackersRecoveredError if @accumulator.size.zero? + report_progress(percent_complete = 50.0, "Validating #{@accumulator.size} imported trackers") + raise NoTrackersRecoveredError if @accumulator.size.zero? - report_progress(percent_complete, "Starting export") + report_progress(percent_complete, "Starting export") - percent_per_tracker = (100.0 - percent_complete) / @accumulator.size + 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) + # Use the width and height provided by the parser itself + exporter.start_export(importer.width, importer.height) - # Now send each tracker through the middleware chain - @accumulator.each_with_index do | t, tracker_idx | + # 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.size - tracker_idx} trackers to go" - ) + 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.size - tracker_idx} trackers to go" + ) + end + exporter.end_tracker_segment end - exporter.end_tracker_segment - end - exporter.end_export + exporter.end_export - report_progress(100.0, "Wrote #{points} points and #{keyframes} keyframes") + report_progress(100.0, "Wrote #{points} points and #{keyframes} keyframes") - [points, keyframes] - ensure - @accumulator.clear - @ios.map!{|e| e.close! rescue e.close } - @ios.clear + [points, keyframes] + ensure + @accumulator.clear + @ios.map!{|e| e.close! rescue e.close } + @ios.clear + end end # Setup output files and return a single output # that replays to all of them def setup_outputs_for(input_file_path) \ No newline at end of file