Skip to content

Commit

Permalink
Merge pull request #69 from SciKit-Surgery/68-quaternion-fix
Browse files Browse the repository at this point in the history
68 quaternion fix
  • Loading branch information
thompson318 committed Oct 11, 2023
2 parents 2286707 + 706a423 commit 92c61ce
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 89 deletions.
11 changes: 5 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ jobs:
fail-fast: false
matrix:
python-ver: [3.7]
os: [ubuntu-18.04, macos-latest, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
experimental: [false]
include:
- python-ver: 3.8
os: ubuntu-18.04
os: ubuntu-latest
experimental: false
- python-ver: 3.8
os: macos-latest
Expand All @@ -22,7 +22,7 @@ jobs:
os: windows-latest
experimental: true
- python-ver: 3.9
os: ubuntu-18.04
os: ubuntu-latest
experimental: true
- python-ver: 3.9
os: macos-latest
Expand Down Expand Up @@ -55,16 +55,15 @@ jobs:
coveralls
deploy:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@master
- name: Set up Python
uses: actions/setup-python@v1
with:
# TODO: python version for deploy?
python-version: 3.6
python-version: 3.9

- name: Install dependencies
run: python -m pip install wheel twine setuptools
Expand Down
6 changes: 3 additions & 3 deletions sksurgerycore/algorithms/tracking_smoothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def __init__(self, buffer_size=1):
"""
super().__init__(4, buffer_size)

def pop(self, rvector, is_quaternion = False):
def pop(self, vector, is_quaternion = False):
"""
Adds a new vector to the buffer, removing the oldest one.
Expand All @@ -128,9 +128,9 @@ def pop(self, rvector, is_quaternion = False):
"""
quaternion = None
if is_quaternion:
quaternion = rvector
quaternion = vector
else:
quaternion = _rvec_to_quaternion(rvector)
quaternion = _rvec_to_quaternion(vector)
super().pop(quaternion)

def getmean(self):
Expand Down
12 changes: 7 additions & 5 deletions sksurgerycore/baseclasses/tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def get_smooth_frame(self, port_handles):
tracking : list of 4x4 tracking matrices, rotation and position,
or if use_quaternions is true, a list of tracking quaternions,
column 0-2 is x,y,z column 3-6 is the rotation as a quaternion.
column 0-3 is the rotation as a quaternion (qw, qx, qy, qz),
column 4-6 is the translation (x,y,z).
tracking_quality : list the tracking quality, one per tool.
"""
Expand All @@ -74,9 +75,9 @@ def get_smooth_frame(self, port_handles):
smth_qual.append(self.qualities[my_index].getmean()[0])

if self.use_quaternions:
output_matrix = np.full((7,1), np.nan)
output_matrix[0:3,0] = mean_tvec
output_matrix[3:7,0] = mean_quat
output_matrix = np.full((1,7), np.nan)
output_matrix[0,0:4] = mean_quat
output_matrix[0,4:7] = mean_tvec
smth_tracking.append(output_matrix)

else:
Expand Down Expand Up @@ -155,7 +156,8 @@ def get_frame(self):
tracking : list of 4x4 tracking matrices, rotation and position,
or if use_quaternions is true, a list of tracking quaternions,
column 0-2 is x,y,z column 3-6 is the rotation as a quaternion.
column 0-3 is the rotation as a quaternion (qw, qx, qy, qz),
column 4-6 is the translation (x,y,z).
tracking_quality : list the tracking quality, one per tool.
"""
Expand Down
22 changes: 11 additions & 11 deletions tests/baseclasses/test_tracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ def test_tracker_quaternions():
test_index = port_handles_out.index("test rb")
assert time_stamps[test_index] == 1.3
assert frame_numbers[test_index] == 0
transform = np.full((7,1), np.nan)
transform = np.full((1,7), np.nan)
rotation = _rvec_to_quaternion([1.0, 0.0, 0.0])
transform[3:7,0] = rotation
transform[0:3,0] = [0.0, 100.0, 200.0]
transform[0,0:4] = rotation
transform[0,4:7] = [0.0, 100.0, 200.0]
assert np.allclose(tracking[test_index], transform)
assert tracking_quality[test_index] == 0.5

Expand Down Expand Up @@ -244,8 +244,8 @@ def test_tracker_quaternions():
assert frame_numbers[test_index] == 1

rotation = _rvec_to_quaternion([0.6, 0.0, 0.0])
transform[3:7,0] = rotation
transform[0:3,0] = [5.0, 75.0, 200.0]
transform[0,0:4] = rotation
transform[0,4:7] = [5.0, 75.0, 200.0]
assert np.allclose(tracking[test_index], transform)
assert tracking_quality[test_index] == 0.65

Expand All @@ -254,8 +254,8 @@ def test_tracker_quaternions():
assert frame_numbers[test_index] == 0

rotation = _rvec_to_quaternion([0.0, 0.0, 0.0])
transform[3:7,0] = rotation
transform[0:3,0] = [50.0, -100.0, 70.0]
transform[0,0:4] = rotation
transform[0,4:7] = [50.0, -100.0, 70.0]
assert np.allclose(tracking[test_index], transform)
assert tracking_quality[test_index] == 1.0

Expand Down Expand Up @@ -284,8 +284,8 @@ def test_tracker_quaternions():
assert time_stamps[test_index] == 1.4
assert frame_numbers[test_index] == 2
rotation = _rvec_to_quaternion([0.0, 0.45, 0.0])
transform[3:7,0] = rotation
transform[0:3,0] = [50.0, -100.0, 70.0]
transform[0,4:7] = [50.0, -100.0, 70.0]
transform[0,0:4] = rotation
assert np.allclose(tracking[test_index], transform)
assert tracking_quality[test_index] == 1.0

Expand All @@ -300,7 +300,7 @@ def test_tracker_quaternions():
assert math.isclose(time_stamps[test_index],1.4)
assert frame_numbers[test_index] == 2
rotation = _rvec_to_quaternion([0.6, 0.00, 0.0])
transform[3:7,0] = rotation
transform[0:3,0] = [3.333333, 83.33333, 166.666667]
transform[0,0:4] = rotation
transform[0,4:7] = [3.333333, 83.33333, 166.666667]
assert np.allclose(tracking[test_index], transform)
assert tracking_quality[test_index] == 0.6
65 changes: 1 addition & 64 deletions tests/pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,6 @@ unsafe-load-any-extension=no
# run arbitrary code
extension-pkg-whitelist=numpy

# Allow optimization of some AST trees. This will activate a peephole AST
# optimizer, which will apply various small optimizations. For instance, it can
# be used to obtain the result of joining multiple strings with the addition
# operator. Joining a lot of strings can lead to a maximum recursion error in
# Pylint and this flag can prevent that. It has one side effect, the resulting
# AST will be different than the one from reality. This option is deprecated
# and it will be removed in Pylint 2.0.
optimize-ast=no


[MESSAGES CONTROL]

# Only show warnings with the listed confidence levels. Leave empty to show
Expand All @@ -56,17 +46,6 @@ confidence=
# it should appear only once). See also the "--disable" option for examples.
#enable=

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifiers separated by comma (,) or put this
# option multiple times (only on the command line, not in the configuration
# file where it should appear only once).You can also use "--disable=all" to
# disable everything first and then reenable specific checks. For example, if
# you want to run only the similarities checker, you can use "--disable=all
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=long-suffix,standarderror-builtin,indexing-exception,delslice-method,unichr-builtin,dict-view-method,parameter-unpacking,unicode-builtin,cmp-builtin,intern-builtin,round-builtin,backtick,nonzero-method,xrange-builtin,coerce-method,raw_input-builtin,old-division,filter-builtin-not-iterating,old-octal-literal,input-builtin,map-builtin-not-iterating,buffer-builtin,basestring-builtin,zip-builtin-not-iterating,using-cmp-argument,unpacking-in-except,old-raise-syntax,coerce-builtin,dict-iter-method,hex-method,range-builtin-not-iterating,useless-suppression,cmp-method,print-statement,reduce-builtin,file-builtin,long-builtin,getslice-method,execfile-builtin,no-absolute-import,metaclass-assignment,oct-method,reload-builtin,import-star-module-level,suppressed-message,apply-builtin,raising-string,next-method-called,setslice-method,old-ne-operator,arguments-differ,wildcard-import,locally-disabled


[REPORTS]

Expand All @@ -75,12 +54,6 @@ disable=long-suffix,standarderror-builtin,indexing-exception,delslice-method,uni
# mypackage.mymodule.MyReporterClass.
output-format=text

# Put messages in a separate file for each module / package specified on the
# command line instead of printing them on stdout. Reports (if any) will be
# written in a file name "pylint_global.[txt|html]". This option is deprecated
# and it will be removed in Pylint 2.0.
files-output=no

# Tells whether to display a full report or only the messages
reports=yes

Expand Down Expand Up @@ -118,63 +91,33 @@ property-classes=abc.abstractproperty
# Regular expression matching correct variable names
variable-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for variable names
variable-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct class attribute names
class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Naming hint for class attribute names
class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$

# Regular expression matching correct argument names
argument-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for argument names
argument-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct module names
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Naming hint for module names
module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$

# Regular expression matching correct constant names
const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Naming hint for constant names
const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$

# Regular expression matching correct inline iteration names
inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$

# Naming hint for inline iteration names
inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$

# Regular expression matching correct method names
method-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for method names
method-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct function names
function-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for function names
function-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct attribute names
attr-rgx=[a-z_][a-z0-9_]{2,30}$

# Naming hint for attribute names
attr-name-hint=[a-z_][a-z0-9_]{2,30}$

# Regular expression matching correct class names
class-rgx=[A-Z_][a-zA-Z0-9]+$

# Naming hint for class names
class-name-hint=[A-Z_][a-zA-Z0-9]+$

# Regular expression which should only match function or class names that do
# not require a docstring.
#no-docstring-rgx=^test_
Expand Down Expand Up @@ -202,12 +145,6 @@ ignore-long-lines=^\s*(# )?<?https?://\S+>?$
# else.
single-line-if-stmt=y

# List of optional constructs for which whitespace checking is disabled. `dict-
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
# `empty-line` allows space-only lines.
no-space-check=trailing-comma,dict-separator

# Maximum number of lines in a module
max-module-lines=1000

Expand Down Expand Up @@ -404,4 +341,4 @@ analyse-fallback-blocks=no

# Exceptions that will emit a warning when being caught. Defaults to
# "Exception"
overgeneral-exceptions=Exception
overgeneral-exceptions=builtins.Exception

0 comments on commit 92c61ce

Please sign in to comment.