Last active
June 21, 2021 01:49
-
-
Save superjax/8856916f09f09668e54f31b0af641b93 to your computer and use it in GitHub Desktop.
My QtCreator Debug Helpers (Eigen::Map, quat::Quat, xform::Xform)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Add the path to this file to Tools -> Options -> Debugger -> Locals & Expressions -> Extra Debugging Helpers | |
## Based on the `misctypes.py` which ships with QtCreator, and extended to add support for Maps and my geometry library | |
from dumper import * | |
# Similar to Matrix, but you have to dive into the pointer | |
def qdump__Eigen__Map(d, value): | |
innerType = value.type[0].templateArgument(0) | |
argRow = int(value.type[0].templateArgument(1)) | |
argCol = int(value.type[0].templateArgument(2)) | |
options = int(value.type[0].templateArgument(3)) | |
rowMajor = (int(options) & 0x1) | |
# if argCol != -1 and argRow != -1: | |
# nrows = argRow | |
# ncols = argCol | |
# p = value.address() | |
# else: | |
# storage = value['m_storage'] | |
nrows = value['m_rows'].integer() if argRow == -1 else argRow | |
ncols = value['m_cols'].integer() if argCol == -1 else argCol | |
p = value['m_data'].pointer() | |
innerSize = innerType.size() | |
d.putValue('(%s x %s), %s [Map]' % (nrows, ncols, ['ColMajor', 'RowMajor'][rowMajor])) | |
d.putField('keeporder', '1') | |
d.putNumChild(nrows * ncols) | |
limit = 10000 | |
nncols = min(ncols, limit) | |
nnrows = min(nrows, limit * limit / nncols) | |
if d.isExpanded(): | |
#format = d.currentItemFormat() # format == 1 is 'Transposed' | |
with Children(d, nrows * ncols, childType=innerType): | |
if ncols == 1 or nrows == 1: | |
for i in range(0, min(nrows * ncols, 10000)): | |
d.putSubItem(i, d.createValue(p + i * innerSize, innerType)) | |
elif rowMajor == 1: | |
s = 0 | |
for i in range(0, nnrows): | |
for j in range(0, nncols): | |
v = d.createValue(p + (i * ncols + j) * innerSize, innerType) | |
d.putNamedSubItem(s, v, '[%d,%d]' % (i, j)) | |
s = s + 1 | |
else: | |
s = 0 | |
for j in range(0, nncols): | |
for i in range(0, nnrows): | |
v = d.createValue(p + (i + j * nrows) * innerSize, innerType) | |
d.putNamedSubItem(s, v, '[%d,%d]' % (i, j)) | |
s = s + 1 | |
# quat::Quat, expected function name qdump__quat__Quat | |
def qdump__quat__Quat(d, value): | |
innerType = value.type[0] | |
innerSize = innerType.size() | |
d.putValue('Quat (%s)' % (innerType.name)) | |
d.putNumChild(4) | |
p = value['arr_']['m_data'].pointer() | |
if d.isExpanded(): | |
with Children(d, 4, childType=innerType): | |
d.putNamedSubItem(0, d.createValue(p, innerType), 'w') | |
d.putNamedSubItem(1, d.createValue(p+innerSize, innerType), 'x') | |
d.putNamedSubItem(2, d.createValue(p+2*innerSize, innerType), 'y') | |
d.putNamedSubItem(3, d.createValue(p+3*innerSize, innerType), 'z') | |
def qdump__xform__Xform(d, value): | |
innerType = value.type[0] | |
innerSize = innerType.size() | |
d.putValue('Xform (%s)' % (innerType.name)) | |
d.putNumChild(7) | |
p = value['arr_']['m_data'].pointer() | |
if d.isExpanded(): | |
with Children(d, 7, childType=innerType): | |
d.putNamedSubItem(0, d.createValue(p, innerType), 'tx') | |
d.putNamedSubItem(1, d.createValue(p+innerSize, innerType), 'ty') | |
d.putNamedSubItem(2, d.createValue(p+2*innerSize, innerType), 'tz') | |
d.putNamedSubItem(3, d.createValue(p+3*innerSize, innerType), 'qw') | |
d.putNamedSubItem(4, d.createValue(p+4*innerSize, innerType), 'qx') | |
d.putNamedSubItem(5, d.createValue(p+5*innerSize, innerType), 'qy') | |
d.putNamedSubItem(6, d.createValue(p+6*innerSize, innerType), 'qz') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment