Sha256: ce79cef76697485a8c7f38ec2691223527a74528f626b2209ab4d60b5c19f1d8

Contents?: true

Size: 1.16 KB

Versions: 26

Compression:

Stored size: 1.16 KB

Contents

# -*- encoding : utf-8 -*-
# For Syntheyes, zero is at the
# optical center of the image, and goes positive right and up. The corners get the [-1..1] coordinates
# respectively. Since Tracksperanto works in absolute pixels we need to convert to and from these cords.
# Note that Syntheyes actually assumes the center of the first pixel to be at -1,1 so a small
# adjustment is necessary to maintain subpixel accuracy.
module Tracksperanto::UVCoordinates
  
  # Convert absoilute X and Y values off the BL corner into Syntheyes UV coordinates
  def absolute_to_uv(abs_x, abs_y, w, h)
    [convert_to_uv(abs_x, w), convert_to_uv(abs_y, h) * -1]
  end
  
  # Convert absoilute pixel value off the BL corner into Syntheyes UV coordinate
  def convert_to_uv(abs_value, absolute_side)
    uv_value = (((abs_value.to_f - 0.5) / (absolute_side.to_f - 1)) - 0.5) * 2.0
  end

  # Convert Syntheyes UV value into absoilute pixel value off the BL corner
  def convert_from_uv(uv_value, absolute_side)
    # Account for the fact that Syntheyes assumes the
    # pixel values to be at the center of the pixel
    abs_value = (((uv_value.to_f / 2.0) + 0.5) * (absolute_side.to_f - 1)) + 0.5
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
tracksperanto-3.5.9 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.8 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.7 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.6 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.5 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.4 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.2 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.1 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.5.0 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.4.1 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.4.0 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.13 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.12 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.11 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.10 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.9 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.8 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.7 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.6 lib/tracksperanto/uv_coordinates.rb
tracksperanto-3.3.0.pre lib/tracksperanto/uv_coordinates.rb