OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
beaconjacobian.py
1 import re
2 raw = """
3 auto v1 = m_rot[1,3]*m_beacon[3]+m_rot[1,2]*m_beacon[2]+m_beacon[1]*m_rot[1,1]+xlate[1];
4 auto v2 = m_beacon[3]*m_rot[3,3]+m_beacon[2]*m_rot[3,2]+m_beacon[1]*m_rot[3,1]+xlate[3];
5 auto v3 = 1/v2^2;
6 auto v4 = 1/v2;
7 auto v5 = m_rot[2,3]*m_beacon[3]+m_beacon[2]*m_rot[2,2]+m_beacon[1]*m_rot[2,1]+xlate[2];
8 Eigen::Matrix<double,2,3> ret;
9 ret <<
10  m_rot[1,1]*v4*fl-v1*m_rot[3,1]*v3*fl,
11  m_rot[1,2]*v4*fl-v1*m_rot[3,2]*v3*fl,
12  m_rot[1,3]*v4*fl-v1*m_rot[3,3]*v3*fl,
13  m_rot[2,1]*v4*fl-v5*m_rot[3,1]*v3*fl,
14  m_rot[2,2]*v4*fl-v5*m_rot[3,2]*v3*fl,
15  m_rot[2,3]*v4*fl-v5*m_rot[3,3]*v3*fl;
16 """
17 
18 matrixIndexPattern = re.compile(r'\[([0-9]),([0-9])]', re.VERBOSE)
19 def replaceMatrixIndices(inString):
20  def matchfunc(match):
21  return '({}, {})'.format(int(match.group(1)) - 1, int(match.group(2)) - 1)
22 
23  return matrixIndexPattern.sub(matchfunc, inString)
24 
25 vectorIndexPattern = re.compile(r'\[([0-9])]', re.VERBOSE)
26 def replaceVectorIndices(inString):
27  def matchfunc(match):
28  return '[{}]'.format(int(match.group(1)) - 1)
29  return vectorIndexPattern.sub(matchfunc, inString)
30 
31 class Chainable:
32  def __init__(self, inString):
33  self._string = replaceVectorIndices(replaceMatrixIndices(inString))
34 
35  def replace(self, old, new):
36  self._string = self._string.replace(old, new)
37  return self
38  def string(self):
39  return self._string
40 out = Chainable(raw
41  ).replace('principalPoint', 'm_cam.principalPoint'
42  ).replace('v2^2', '(v2*v2)'
43  ).replace('fl', 'm_cam.focalLength'
44  ).replace('xlate', 'm_xlate'
45  ).string()
46 print(out)
47 #print(.sub(r'(\1 - 1, \2 - 1)', input))