Class: TrackerDataParser
- Inherits:
-
Object
- Object
- TrackerDataParser
- Defined in:
- lib/b1trackerdata/b1_data_parser.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#fix_marker_twist ⇒ Object
method to fix the direction of the marker, if it has been worn wrong.
- #getannotationdata(timestamp, matrix, polarity) ⇒ Object
-
#getbackofhanddirection(data) ⇒ Object
function computing back of hand direction.
-
#getpalmdirection(data) ⇒ Object
function computing palm direction.
-
#getwristextend(data) ⇒ Object
function computing wrist extend.
-
#getwristposition(data) ⇒ Object
function computing wrist position.
-
#initialize(trial, test = false) ⇒ TrackerDataParser
constructor
A new instance of TrackerDataParser.
-
#operate ⇒ Object
main controller function.
-
#parsetrackerdata(trackerdata) ⇒ Object
method parsing tracking data from the db and loading it into an hash(organized by timestamp).
Constructor Details
#initialize(trial, test = false) ⇒ TrackerDataParser
Returns a new instance of TrackerDataParser.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 18 def initialize trial,test=false @trial = trial tablename = "Tracker#{trial}" tablename = "TrackerTest" if test dlog "Trying to connect to table: #{tablename}" #get our rows @rows = DB[tablename.to_sym] @highpass = 0.25 #for later filtering dlog "Table has #{@rows.count} rows." #processed data will end up here @data = {:left => {}, :right => {}} #do we know that one marker has been worn wrong? @data[:left_twist] = false @data[:right_twist] = false #get and parse the tracker data operate end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
16 17 18 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 16 def data @data end |
Instance Method Details
#fix_marker_twist ⇒ Object
method to fix the direction of the marker, if it has been worn wrong
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 202 def fix_marker_twist #left hand @data[:left_polarity] = NMatrix.float(4,4).unit if @data[:left_twist] p = NMatrix.float(4,4).unit #if y direction of tracker is WRONG we need to rotate around z axis by 180 deg p[0,0], p[0,1], p[1,0], p[1,1] = Math.cos(Math::PI),-Math.sin(Math::PI),Math.sin(Math::PI),Math.cos(Math::PI) ilog "Will multiply left hand with this polarity matrix: #{p.inspect}" @data[:left_polarity] = p end #and the right hand @data[:right_polarity] = NMatrix.float(4,4).unit if @data[:right_twist] p = NMatrix.float(4,4).unit #if y direction of tracker is WRONG we need to rotate around z axis by 180 deg p[0,0], p[0,1], p[1,0], p[1,1] = Math.cos(Math::PI),-Math.sin(Math::PI),Math.sin(Math::PI),Math.cos(Math::PI) ilog "Will multiply right hand with this polarity matrix: #{p.inspect}" @data[:right_polarity] = p end end |
#getannotationdata(timestamp, matrix, polarity) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 79 def getannotationdata ,matrix,polarity annotationdata = {} reference = @data[:reference][][1] relative = reference.inverse * matrix * polarity annotationdata[:timestamp] = annotationdata[:reference] = reference annotationdata[:data] = matrix annotationdata[:relative] = relative annotationdata[:boh] = getbackofhanddirection relative annotationdata[:pd] = getpalmdirection relative annotationdata[:wp] = getwristposition relative annotationdata[:we] = getwristextend relative return annotationdata end |
#getbackofhanddirection(data) ⇒ Object
function computing back of hand direction
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 110 def getbackofhanddirection data #ok, it looks like the markers y axis is the boh direction #you should check the data in the visualization to be sure x,y,z = data[1,0],data[1,1],data[1,2] result = [] result << "BAB" if z < -@highpass result << "BDN" if y < -@highpass result << "BTB" if z > @highpass result << "BTL" if x < -@highpass result << "BTR" if x > @highpass result << "BUP" if y > @highpass return result.join("/") end |
#getpalmdirection(data) ⇒ Object
function computing palm direction
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 95 def getpalmdirection data #negative z seems to be the palm direction #you should check the data in the visualization to be sure x,y,z = (-1)*data[2,0],(-1)*data[2,1],(-1)*data[2,2] result = [] result << "PAB" if z < -@highpass result << "PDN" if y < -@highpass result << "PTB" if z > @highpass result << "PTL" if x < -@highpass result << "PTR" if x > @highpass result << "PUP" if y > @highpass return result.join("/") end |
#getwristextend(data) ⇒ Object
function computing wrist extend
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 125 def getwristextend data result = "aight!" x,y,z = data[3,0],data[3,1],data[3,2] #puts "wp: x '#{x}', y '#{y}', z '#{z}'" zf = 100 #normalizing factor (100 = SH standard human) xf = 100 #normalizing factor (100 = SH standard human) x = x*xf z = z*zf r = Math.sqrt(x*x + z*z) #ok, need to put real values in here (look at the annotationmanual) result = "D-GTO" if r > 80 #greater than length of outstretched arm in front away result = "D-KO" if r <= 80 #between knee and length of outstretched arm in front away result = "D-EK" if r < 65 #between elbow and knee result = "D-CE" if r < 45 #between body and elbows length away result = "D-C" if r < 20 #in contact with body #puts "extend is '#{result}'" return result end |
#getwristposition(data) ⇒ Object
function computing wrist position
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 145 def getwristposition data result = "aight!" #negative z seems to be palm direction #you should check the data in the visualization to be sure x,y,z = data[3,0],data[3,1],data[3,2] yf = 100 xf = 100 x = x*xf y = y*yf #puts "wp: x '#{x}', y '#{y}', z '#{z}'" #will not be rock solid, so we go from outwards->inwards #extreme periphery eperiphery = "EP-" eperiphery += "UP" if(y > 30 && x.abs <= 19) eperiphery += "UL" if(y > 17 && x < -19) eperiphery += "UR" if(y > 17 && x > 19) eperiphery += "LT" if(y <= 17 && y > -17 && x < -31.5) eperiphery += "RT" if(y <= 17 && y > -17 && x > 31.5) eperiphery += "LW" if(y < -30 && x.abs <= 19) eperiphery += "LL" if(y < -17 && x < -19) eperiphery += "LR" if(y < -17 && x > 19) result = eperiphery unless eperiphery.eql?("EP-") #periphery if (x.abs <= 31.5 && y.abs <= 30) periphery = "P-" periphery += "UP" if(y > 17 && x.abs <= 13) periphery += "UL" if(y > 9 && x < -13) periphery += "UR" if(y > 9 && x > 13) periphery += "LT" if(y <= 9 && y > -10 && x < -21) periphery += "RT" if(y <= 9 && y > -10 && x > 21) periphery += "LW" if(y <= -10 && y > -30 && x.abs <= 13) periphery += "LL" if(y <= -10 && y > -30 && x < -13) periphery += "LR" if(y <= -10 && y > -30 && x > 13) result = periphery unless periphery.eql?("P-") end #center if (x.abs <= 21 && y.abs <= 17) center = "C-" center += "UP" if(y > 9 && x.abs <= 10) center += "UL" if(y > 4.5 && x < -10) center += "UR" if(y > 4.5 && x > 10) center += "LT" if(y <= 4.5 && y > -7 && x < -13) center += "RT" if(y <= 4.5 && y > -7 && x > 13) center += "LW" if(y <= -7 && y > -17 && x.abs <= 10) center += "LL" if(y <= -7 && y > -17 && x < -10) center += "LR" if(y <= -7 && y > -17 && x > 10) result = center unless center.eql?("C-") end #center-center if (x.abs <= 13 && y.abs <= 9) result = "CC" end #puts "result #{result}" return result end |
#operate ⇒ Object
main controller function
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 37 def operate @data[:reference] = (parsetrackerdata @rows.filter(:identifier => "Neck")).sort dlog "Parsed neckdata count is #{@data[:reference].length}" left_raw = (parsetrackerdata @rows.filter(:identifier => "Left_Hand")).sort dlog "Left hand quality is #{(Float(left_raw.length)/Float(@data[:reference].length))*100}%" right_raw = (parsetrackerdata @rows.filter(:identifier => "Right_Hand")).sort dlog "Right hand quality is #{(Float(right_raw.length)/Float(@data[:reference].length))*100}%" #sometimes people are wearing the tracker wrong, need to fix this fix_marker_twist #now parse the tracker data for both hands left_raw.each do |,matrix| d = getannotationdata ,matrix,@data[:left_polarity] @data[:left][] = d unless d.nil? end right_raw.each do |,matrix| d = getannotationdata ,matrix,@data[:right_polarity] @data[:right][] = d unless d.nil? end #Debug and info ilog "Statistics for trial #{@trial}:" ilog " Left hand - parsed: #{@data[:left].length}" ilog " Right hand - parsed: #{@data[:right].length}" end |
#parsetrackerdata(trackerdata) ⇒ Object
method parsing tracking data from the db and loading it into an hash(organized by timestamp)
64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/b1trackerdata/b1_data_parser.rb', line 64 def parsetrackerdata trackerdata parseddata = {} trackerdata.each do |d| m = NMatrix.float(4,4) #that's how the coordinates would look if the matrix was transposed (now the bottom is 0,0,0,1) m[0,0],m[0,1],m[0,2],m[0,3] = d[:m00], d[:m01], d[:m02], d[:m03] m[1,0],m[1,1],m[1,2],m[1,3] = d[:m10], d[:m11], d[:m12], d[:m13] m[2,0],m[2,1],m[2,2],m[2,3] = d[:m20], d[:m21], d[:m22], d[:m23] m[3,0],m[3,1],m[3,2],m[3,3] = d[:m30], d[:m31], d[:m32], d[:m33] m = m.transpose #matrix data in the db are transposed parseddata[Float(d[:timestamp])] = m end return parseddata end |