Skip to content

Commit

Permalink
Revert "fixed ellipsoid vector sorting"
Browse files Browse the repository at this point in the history
This reverts commit 386207c.

Revert "sort vectors according to length"

This reverts commit a1d8855.
  • Loading branch information
jo-mueller committed Sep 27, 2023
1 parent 7e5ea52 commit 2ec6d7f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
7 changes: 1 addition & 6 deletions src/napari_stress/_approximation/fit_ellipsoid.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@ def least_squares_ellipsoid(points: PointsData
VectorsData: Major/minor axis of the ellipsoid
"""
from .._utils.coordinate_conversion import polynomial_to_parameters3D
coefficients = _solve_ellipsoid_polynomial(points)
coefficients = _solve_ellipsoid_polynomial(points)

# convert results to VectorsData
center, axes, R, R_inverse = polynomial_to_parameters3D(
coefficients=coefficients)
direction = R * axes[:, None]

# sort from longest to shortes vector
direction = direction[np.argsort(np.linalg.norm(direction, axis=1))][::-1]

# assemble vector
origin = np.stack(3 * [center]) # cheap repeat
vector = np.stack([origin, direction]).transpose((1, 0, 2))

Expand Down
18 changes: 7 additions & 11 deletions src/napari_stress/_tests/test_approximation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ def test_lsq_ellipsoid():

fitted_points = approximation.expand_points_on_ellipse(ellipsoid, pointcloud)

assert np.linalg.norm(ellipsoid[:, 1, 1:], axis=1)[0] > np.linalg.norm(ellipsoid[:, 1, 1:], axis=1)[1]
assert np.linalg.norm(ellipsoid[:, 1, 1:], axis=1)[1] > np.linalg.norm(ellipsoid[:, 1, 1:], axis=1)[2]


def test_lsq_ellipsoid2():
import vedo
from napari_stress import approximation
Expand All @@ -23,10 +19,10 @@ def test_lsq_ellipsoid2():

from scipy.spatial.transform import Rotation as R

center = np.zeros((3, 3))
l1 = 3
center = np.zeros((3,3))
l1 = 1
l2 = 2
l3 = 1
l3 = 3
a1 = np.array([l1, 0, 0])
a2 = np.array([0, l2, 0])
a3 = np.array([0, 0, l3])
Expand All @@ -51,9 +47,9 @@ def test_lsq_ellipsoid2():
lengths = _axes_lengths_from_ellipsoid(fitted_ellipsoid)

assert np.allclose(center, x0, atol=0.01)
assert np.allclose(l1 / 2, lengths[0])
assert np.allclose(l2 / 2, lengths[1])
assert np.allclose(l3 / 2, lengths[2])
assert np.allclose(l2/2, lengths[0])
assert np.allclose(l1/2, lengths[1])
assert np.allclose(l3/2, lengths[2])

rotation_matrix = R.from_euler('xz', [45, 45], degrees=True).as_matrix()
rotated_points = np.dot(points, rotation_matrix)
Expand All @@ -64,7 +60,6 @@ def test_lsq_ellipsoid2():

assert np.allclose(rotated_points, expanded_points)


def test_ellipse_normals():
from napari_stress import approximation, get_droplet_point_cloud
pointcloud = get_droplet_point_cloud()[0][0][:, 1:]
Expand All @@ -89,3 +84,4 @@ def test_curvature_on_ellipsoid(make_napari_viewer):
assert types._METADATAKEY_H_E123_ELLIPSOID in results[1]['metadata'].keys()
assert types._METADATAKEY_H0_ELLIPSOID in results[1]['metadata'].keys()
assert types._METADATAKEY_MEAN_CURVATURE in results[1]['features'].keys()

0 comments on commit 2ec6d7f

Please sign in to comment.