lib/pipeline/base.rb in tracksperanto-2.9.4 vs lib/pipeline/base.rb in tracksperanto-2.9.5

- old
+ new

@@ -12,11 +12,11 @@ class DimensionsRequiredError < RuntimeError def message; "Width and height must be provided for this importer"; end end class NoTrackersRecoveredError < RuntimeError - def message; + def message; "Could not recover any non-empty trackers from this file.\n" + "Wrong import format maybe?\n" + "Note that PFTrack will only export trackers from the solved segment of the shot."; end end @@ -38,12 +38,11 @@ EXTENSION = /\.([^\.]+)$/ #:nodoc: PERMITTED_OPTIONS = [:importer, :width, :height] include Tracksperanto::BlockInit - # How many points have been converted. In general, the pipeline does not preserve the parsed tracker objects - # after they have been exported + # How many points have been converted attr_reader :converted_points # How many keyframes have been converted attr_reader :converted_keyframes @@ -51,11 +50,11 @@ # When it's assigned, the pipeline will pass the status reports # of all the importers and exporters to the block, together with # percent complete attr_accessor :progress_block - # Assign an array of exporters to use them instead of the standard ones + # Assign an array of exporter classes to use them instead of the default "All" attr_accessor :exporters # Contains arrays of the form ["MiddewareName", {:param => value}] attr_accessor :middleware_tuples @@ -63,10 +62,12 @@ def initialize(*any) super @ios = [] end + # Will scan the middleware_tuples attribute and create a processing chain. + # Middlewares will be instantiated and wrap each other, starting with the first one def wrap_output_with_middlewares(output) return output unless (middleware_tuples && middleware_tuples.any?) middleware_tuples.reverse.inject(output) do | wrapped, (middleware_name, options) | Tracksperanto.get_middleware(middleware_name).new(wrapped, options || {}) @@ -75,11 +76,12 @@ # Runs the whole pipeline. Accepts the following options # * width - The comp width, for the case that the format does not support auto size # * height - The comp height, for the case that the format does not support auto size # * parser - The parser class, for the case that it can't be autodetected from the file name - def run(from_input_file_path, passed_options = {}) #:yields: *all_middlewares + # Returns the number of trackers and the number of keyframes processed during the run + def run(from_input_file_path, passed_options = {}) # Check for empty files raise EmptySourceFileError if File.stat(from_input_file_path).size.zero? # Reset stats @@ -146,11 +148,11 @@ importer.progress_block = progress_lambda # Wrap the input in a progressive IO, setup a lambda that will spy on the reader and # update the percentage. We will only broadcast messages that come from the parser # though (complementing it with a percentage) - io_with_progress = Tracksperanto::ProgressiveIO.new(tracker_data_io) do | offset, of_total | + io_with_progress = ProgressiveIO.new(tracker_data_io) do | offset, of_total | percent_complete = (50.0 / of_total) * offset # Some importers do not signal where they are and do not send nice reports. The way we can help that in the interim # would be just to indicate where we are in the input, but outside of the exporter. We do not want to flood # the logs though so what we WILL do instead is report some progress going on every 2-3 percent @@ -161,17 +163,11 @@ @accumulator = Obuf.new begin - if importer.respond_to?(:each) - importer.io = io_with_progress - importer.each {|t| @accumulator.push(t) unless t.empty? } - else # OBSOLETE - for this version we are going to permit it. - 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) - end + importer.io = io_with_progress + importer.each {|t| @accumulator.push(t) unless t.empty? } report_progress(percent_complete = 50.0, "Validating #{@accumulator.size} imported trackers") raise NoTrackersRecoveredError if @accumulator.size.zero? report_progress(percent_complete, "Starting export")