Class: PhotoscanOutputs::Transform

Inherits:
Object
  • Object
show all
Defined in:
lib/photoscan_outputs/camera.rb

Overview

“Transform” is the 3D homogeneous transform from camera to world. That is, T * [0 0 0 1]^T (the origin of the camera frame) yields the camera’s position in world coordinate frame

Or

sR T 0 1

Direct Known Subclasses

IncrementalTransform

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mat, opts = {}) ⇒ Transform

Returns a new instance of Transform.



69
70
71
72
73
74
75
76
# File 'lib/photoscan_outputs/camera.rb', line 69

def initialize( mat, opts = {} )
  @mat = case mat
         when Transform
           mat.mat
         else
           mat
         end
end

Instance Attribute Details

#matObject (readonly)

Returns the value of attribute mat.



67
68
69
# File 'lib/photoscan_outputs/camera.rb', line 67

def mat
  @mat
end

Class Method Details

.from_xml(xml, global = nil) ⇒ Object



111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/photoscan_outputs/camera.rb', line 111

def self.from_xml( xml, global = nil )
  m = xml.text.split(/\s/).map(&:to_f)
  raise "Not enough elements in matrix" unless m.length == 16

  arr = 4.times.map { m.shift(4) }

  if global
    IncrementalTransform.new( global.mat, Matrix.rows(arr) )
  else
    Transform.new( Matrix.rows( arr )  )
  end
end

Instance Method Details

#*(b) ⇒ Object



103
104
105
# File 'lib/photoscan_outputs/camera.rb', line 103

def *(b)
  mat * b
end

#dump(io = STDOUT) ⇒ Object



107
108
109
# File 'lib/photoscan_outputs/camera.rb', line 107

def dump( io = STDOUT )
  print_mat( mat, io )
end

#invObject



99
100
101
# File 'lib/photoscan_outputs/camera.rb', line 99

def inv
  Transform.new mat.inv
end

#r_matObject



86
87
88
89
# File 'lib/photoscan_outputs/camera.rb', line 86

def r_mat
  sc = scale
  sr_mat.map { |x| x/sc }
end

#scaleObject



82
83
84
# File 'lib/photoscan_outputs/camera.rb', line 82

def scale
  sr_mat.row_vectors.first.norm
end

#sr_matObject



78
79
80
# File 'lib/photoscan_outputs/camera.rb', line 78

def sr_mat
 Matrix.rows mat.to_a.first(3).map { |row| row.first(3) } 
end

#tObject



95
96
97
# File 'lib/photoscan_outputs/camera.rb', line 95

def t
  t_mat
end

#t_matObject



91
92
93
# File 'lib/photoscan_outputs/camera.rb', line 91

def t_mat
  Vector[ *( mat.to_a.first(3).map { |row| row.at(3) } ) ]
end