OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
alternateincrotjacobian.py
1 import re
2 raw = """
3 auto v1 = 1/2-incrotOP[2,3]/24;
4 auto v2 = 2*m_incRot[1]*v1;
5 auto v3 = -incrotOP[2,3]/6;
6 auto v4 = incrotOP[2,3]/6;
7 auto v5 = -(incrotOP[2,2]*m_incRot[3])/24;
8 auto v6 = m_objExtRot[1]*(v5+v4)+m_objExtRot[2]*(v3+v2+1);
9 auto v7 = -incrotOP[1,3]/6;
10 auto v8 = v7+1;
11 auto v9 = 1/2-incrotOP[1,3]/24;
12 auto v10 = incrotOP[2,2]*v9;
13 auto v11 = v3+1;
14 auto v12 = incrotOP[1,1]*v1;
15 auto v13 = m_objExtRot[1]*(v10-m_incRot[2]*v8)+m_objExtRot[2]*(v12+m_incRot[1]*v11)+m_objExtRot[3]+m_xlate[3];
16 auto v14 = 1/v13^2;
17 auto v15 = -incrotOP[1,2]/6;
18 auto v16 = v15+1;
19 auto v17 = 1/2-incrotOP[1,2]/24;
20 auto v18 = incrotOP[3,3]*v17;
21 auto v19 = m_objExtRot[3]*(m_incRot[2]*v8+v10)+m_objExtRot[2]*(v18-m_incRot[3]*v16)+m_objExtRot[1]+m_xlate[1];
22 auto v20 = 1/v13;
23 auto v21 = -(m_incRot[2]*incrotOP[3,3])/24;
24 auto v22 = 2*m_incRot[2]*v9;
25 auto v23 = incrotOP[1,3]/6;
26 auto v24 = -(m_incRot[1]*incrotOP[3,3])/24;
27 auto v25 = -(incrotOP[1,1]*m_incRot[3])/24;
28 auto v26 = m_objExtRot[2]*(v7+v25)+m_objExtRot[1]*(v23+v22-1);
29 auto v27 = incrotOP[1,2]/6;
30 auto v28 = 2*m_incRot[3]*v17;
31 auto v29 = -(m_incRot[1]*incrotOP[2,2])/24;
32 auto v30 = -(incrotOP[1,1]*m_incRot[2])/24;
33 auto v31 = m_objExtRot[2]*(v30+v15)+m_objExtRot[1]*(v29+v27);
34 auto v32 = m_objExtRot[1]*(v18+m_incRot[3]*v16)+m_objExtRot[3]*(v12-m_incRot[1]*v11)+m_objExtRot[2]+m_xlate[2];
35 Eigen::Matrix<double,2,3> ret;
36 ret <<
37  v20*(m_objExtRot[2]*(v21+v4)+(v5+v3)*m_objExtRot[3])*fl-v6*v14*v19*fl,
38  v20*(m_objExtRot[2]*(v24+v23)+(v22+v7+1)*m_objExtRot[3])*fl-v26*v14*v19*fl,
39  v20*((v29+v15)*m_objExtRot[3]+m_objExtRot[2]*(v28+v27-1))*fl-v31*v14*v19*fl,
40  v20*(m_objExtRot[1]*(v21+v3)+(v4+v2-1)*m_objExtRot[3])*fl-v6*v14*v32*fl,
41  v20*(m_objExtRot[1]*(v24+v7)+(v25+v23)*m_objExtRot[3])*fl-v26*v14*v32*fl,
42  v20*((v30+v27)*m_objExtRot[3]+m_objExtRot[1]*(v28+v15+1))*fl-v31*v14*v32*fl;
43 return ret;
44 """
45 
46 matrixIndexPattern = re.compile(r'\[([0-9]),([0-9])]', re.VERBOSE)
47 def replaceMatrixIndices(inString):
48  def matchfunc(match):
49  return '({}, {})'.format(int(match.group(1)) - 1, int(match.group(2)) - 1)
50 
51  return matrixIndexPattern.sub(matchfunc, inString)
52 
53 vectorIndexPattern = re.compile(r'\[([0-9])]', re.VERBOSE)
54 def replaceVectorIndices(inString):
55  def matchfunc(match):
56  return '[{}]'.format(int(match.group(1)) - 1)
57  return vectorIndexPattern.sub(matchfunc, inString)
58 
59 class Chainable:
60  def __init__(self, inString):
61  self._string = replaceVectorIndices(replaceMatrixIndices(inString))
62 
63  def replace(self, old, new):
64  self._string = self._string.replace(old, new)
65  return self
66  def string(self):
67  return self._string
68 out = Chainable(raw
69  ).replace('fl', 'm_cam.focalLength'
70  ).replace('1/2', '0.5'
71  ).replace('v13^2', '(v13*v13)'
72  ).string()
73 print(out)