Skip to content

Commit

Permalink
Merge pull request #2406 from skoudoro/fix-2314
Browse files Browse the repository at this point in the history
Manage Approx_polygon_track with repeated points
  • Loading branch information
Garyfallidis committed Jul 6, 2021
2 parents cdbffe7 + c48bf27 commit db90aa3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
5 changes: 3 additions & 2 deletions dipy/tracking/distances.pyx
Expand Up @@ -1115,7 +1115,7 @@ def approx_polygon_track(xyz,alpha=0.392):
float *fvec2
object characteristic_points
cnp.npy_intp t_len
double angle,tmp
double angle,tmp, denom
float vec0[3]
float vec1[3]

Expand All @@ -1135,7 +1135,8 @@ def approx_polygon_track(xyz,alpha=0.392):
#csub_3vecs(<float *> cnp.PyArray_DATA(fvec1),<float *> cnp.PyArray_DATA(fvec0),vec0)
csub_3vecs(fvec1,fvec0,vec0)
csub_3vecs(fvec2,fvec1,vec1)
tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/(cnorm_3vec(vec0)*cnorm_3vec(vec1))))
denom = cnorm_3vec(vec0)*cnorm_3vec(vec1)
tmp=<double>fabs(acos(cinner_3vecs(vec0,vec1)/ denom)) if denom else 0
if dpy_isnan(tmp) :
angle+=0.
else:
Expand Down
11 changes: 9 additions & 2 deletions dipy/tracking/tests/test_distances.py
Expand Up @@ -2,8 +2,9 @@
import warnings
import numpy as np
from dipy.testing import assert_true
from numpy.testing import (assert_array_almost_equal, assert_warns,
assert_equal, assert_almost_equal)
from numpy.testing import (assert_array_almost_equal,
assert_equal, assert_almost_equal,
assert_array_equal)
from dipy.tracking import distances as pf
from dipy.tracking.streamline import set_number_of_points
from dipy.data import get_fnames
Expand Down Expand Up @@ -212,9 +213,15 @@ def test_approx_ei_traj():
y = 5*np.sin(5*t)
z = np.zeros(x.shape)
xyz = np.vstack((x, y, z)).T

xyza = pf.approx_polygon_track(xyz)
assert_equal(len(xyza), 27)

# test repeated point
track = np.array([[1., 0., 0.], [1., 0., 0.], [3., 0., 0.], [4., 0., 0.]])
xyza = pf.approx_polygon_track(track)
assert_array_equal(xyza, np.array([[1., 0., 0.], [4., 0., 0.]]))


def test_approx_mdl_traj():

Expand Down

0 comments on commit db90aa3

Please sign in to comment.