Class: Panomosity::Image
- Inherits:
-
Object
- Object
- Panomosity::Image
- Defined in:
- lib/panomosity/image.rb
Constant Summary collapse
- @@attributes =
i(w h f v Ra Rb Rc Rd Re Eev Er Eb r p y TrX TrY TrZ Tpy Tpp j a b c d e g t Va Vb Vc Vd Vx Vy Vm n)
- @@equaled_attributes =
i(v Ra Rb Rc Rd Re a b c d e Va Vb Vc Vd Vx Vy)
Class Method Summary collapse
- .all ⇒ Object
- .calculate_dimensions(fov = nil) ⇒ Object
- .panosphere ⇒ Object
- .parse(pto_file) ⇒ Object
- .parse_line(line, id = 0) ⇒ Object
- .x_offset ⇒ Object
- .y_offset ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #attributes ⇒ Object
- #column ⇒ Object
-
#convert_position! ⇒ Object
Gets the value of TrX and TrY and sets them as d and e.
-
#initialize(attributes) ⇒ Image
constructor
A new instance of Image.
- #normal_x ⇒ Object
- #normal_y ⇒ Object
- #row ⇒ Object
- #to_cartesian(x1, y1) ⇒ Object
- #to_s(options = {}) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Image
Returns a new instance of Image.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/panomosity/image.rb', line 66 def initialize(attributes) @attributes = attributes # conform data types @attributes.each do |key, value| next if i(n id raw).include?(key) if value.respond_to?(:include?) && value.include?('.') @attributes[key] = value.to_f else @attributes[key] = value.to_i end end end |
Class Method Details
.all ⇒ Object
31 32 33 |
# File 'lib/panomosity/image.rb', line 31 def self.all @images end |
.calculate_dimensions(fov = nil) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/panomosity/image.rb', line 23 def self.calculate_dimensions(fov = nil) @fov = fov || 45.2 lam = (90 - (@fov / 2.0)) * (Math::PI / 180.0) @panosphere = (Math.tan(lam) * 0.5 * 0.5) _, @x_offset = @images.map(&:TrX).minmax _, @y_offset = @images.map(&:TrY).minmax end |
.panosphere ⇒ Object
35 36 37 |
# File 'lib/panomosity/image.rb', line 35 def self.panosphere @panosphere end |
.parse(pto_file) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/panomosity/image.rb', line 9 def self.parse(pto_file) id = 0 @images = pto_file.each_line.map do |line| image = parse_line(line, id) if image id += 1 image end end.compact calculate_dimensions @images end |
.parse_line(line, id = 0) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/panomosity/image.rb', line 47 def self.parse_line(line, id = 0) parts = line.split(' ') if parts.first == 'i' data = parts.each_with_object({}) do |part, hash| attribute = @@attributes.find { |attr| part[0..(attr.to_s.length-1)] == attr.to_s } next unless attribute hash[attribute] = part.sub(attribute.to_s, '') end # Sanitization data.each { |key, value| data[key] = value.sub(/\A=/, '') } data[:n] = data[:n].gsub('"', '') data[:id] = id data[:raw] = line new data end end |
.x_offset ⇒ Object
39 40 41 |
# File 'lib/panomosity/image.rb', line 39 def self.x_offset @x_offset end |
.y_offset ⇒ Object
43 44 45 |
# File 'lib/panomosity/image.rb', line 43 def self.y_offset @y_offset end |
Instance Method Details
#[](key) ⇒ Object
79 80 81 |
# File 'lib/panomosity/image.rb', line 79 def [](key) @attributes[key] end |
#[]=(key, value) ⇒ Object
83 84 85 |
# File 'lib/panomosity/image.rb', line 83 def []=(key, value) @attributes[key] = value end |
#attributes ⇒ Object
171 172 173 174 175 |
# File 'lib/panomosity/image.rb', line 171 def attributes attributes = @attributes.keep_if { |k, _| !i(raw).include?(k) } attributes.merge!(column: column || 0, row: row || 0) attributes end |
#column ⇒ Object
161 162 163 164 |
# File 'lib/panomosity/image.rb', line 161 def column return unless name =~ /c(\d+)_r(\d+)\.jpg/ name.scan(/c(\d+)_r(\d+)\.jpg/).flatten.map(&:to_i).first end |
#convert_position! ⇒ Object
Gets the value of TrX and TrY and sets them as d and e
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/panomosity/image.rb', line 127 def convert_position! trx = self[:TrX] try = self[:TrY] self[:TrX] = 0 self[:TrY] = 0 self[:TrZ] = 0 # To fix an issue with pto reading files ignoring attributes that have a =0 trx = '0.0' if trx == 0.0 try = '0.0' if try == 0.0 self[:d] = trx self[:e] = try self end |
#normal_x ⇒ Object
101 102 103 |
# File 'lib/panomosity/image.rb', line 101 def normal_x self[:TrX] * self.class.panosphere * width end |
#normal_y ⇒ Object
105 106 107 |
# File 'lib/panomosity/image.rb', line 105 def normal_y self[:TrY] * self.class.panosphere * height end |
#row ⇒ Object
166 167 168 169 |
# File 'lib/panomosity/image.rb', line 166 def row return unless name =~ /c(\d+)_r(\d+)\.jpg/ name.scan(/c(\d+)_r(\d+)\.jpg/).flatten.map(&:to_i).last end |
#to_cartesian(x1, y1) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/panomosity/image.rb', line 144 def to_cartesian(x1, y1) px = (w / 2.0) - x1 + d py = (h / 2.0) - y1 + e rad = (w / 2.0) / Math.tan((v * Math::PI / 180) / 2) r = self.r * Math::PI / 180 p = self.p * Math::PI / 180 y = self.y * Math::PI / 180 # Derived from multiplication of standard roll, pitch, and yaw matrices by the point vector (rad, px, py) point = [Math.cos(p) * Math.cos(y) * rad - Math.sin(y) * Math.cos(p) * px + Math.sin(p) * py, Math.sin(r) * Math.sin(p) * Math.cos(y) * rad + Math.sin(y) * Math.cos(r) * rad - Math.sin(r) * Math.sin(p) * Math.sin(y) * px + Math.cos(r) * Math.cos(y) * px - Math.sin(r) * Math.cos(p) * py, -Math.sin(p) * Math.cos(r) * Math.cos(y) * rad + Math.sin(r) * Math.sin(y) * rad + Math.sin(p) * Math.sin(y) * Math.cos(r) * px + Math.sin(r) * Math.cos(y) * px + Math.cos(r) * Math.cos(p) * py] magnitude = Math.sqrt(point[0] ** 2 + point[1] ** 2 + point[2] ** 2) normalized_point = [point[0] / magnitude, point[1] / magnitude, point[2] / magnitude] normalized_point end |
#to_s(options = {}) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/panomosity/image.rb', line 109 def to_s( = {}) subline_values = (@@attributes - i(Vm n)).map do |attribute| value = self.send(attribute) if @@equaled_attributes.include?(attribute) && ![:without_equal_signs] # Floats are distinctly not equaled attributes if value == 0 && value.is_a?(Integer) "#{attribute}=#{value.to_i}" else "#{attribute}#{value}" end else "#{attribute}#{value}" end end %Q(i #{subline_values.join(' ')} Vm#{self[:Vm]} n"#{self[:n]}"\n) end |