Commit f83f5d56 authored by Josef Brandt's avatar Josef Brandt

Fix in Cython...

parent 4250c8d1
......@@ -3,13 +3,11 @@ cimport numpy as np
cimport cython
DTYPE = np.float
ctypedef np.float_t DTYPE_t
ctypedef np.int32_t INT32_t
def rotate_contour_around_point(np.ndarray[DTYPE_t, ndim=3] contour, np.ndarray[DTYPE_t, ndim=1] refPoint, np.float angleDegree):
# def rotate_contour_around_point(contour: np.ndarray, refPoint: tuple, angleDegree: float) -> np.ndarray:
def rotate_contour_around_point(np.ndarray[INT32_t, ndim=3] contour, np.ndarray[INT32_t, ndim=1] refPoint, np.float angleDegree):
"""
Rotates a point around another one...
Rotates a point around another one... All coordinates in pixel space (integers)
:param contour: Array of points to be rotated, [:, 0, 0] = x, [:, 0, 1] = y
:param refPoint: The referemce point around which the first point is rotated, tuple of x and y
:param angleDegree: The angle in degree to rotate (counter-clockwise)
......@@ -17,16 +15,16 @@ def rotate_contour_around_point(np.ndarray[DTYPE_t, ndim=3] contour, np.ndarray[
"""
cdef int i
cdef double theta, sin, cos, x, y
cdef np.ndarray[DTYPE_t, ndim=3] newContour
cdef np.ndarray[INT32_t, ndim=3] newContour
theta = np.deg2rad(angleDegree)
sin = np.sin(theta)
cos = np.cos(theta)
newContour = np.zeros_like(contour, dtype=np.float)
newContour = np.zeros_like(contour)
for i in range(contour.shape[0]):
x: float = cos * (contour[i, 0, 0]-refPoint[0]) - sin * (contour[i, 0, 1]-refPoint[1]) + refPoint[0]
y: float = sin * (contour[i, 0, 0]-refPoint[0]) + cos * (contour[i, 0, 1]-refPoint[1]) + refPoint[1]
newContour[i, 0, 0] = x
newContour[i, 0, 1] = y
x = cos * (contour[i, 0, 0]-refPoint[0]) - sin * (contour[i, 0, 1]-refPoint[1]) + refPoint[0]
y = sin * (contour[i, 0, 0]-refPoint[0]) + cos * (contour[i, 0, 1]-refPoint[1]) + refPoint[1]
newContour[i, 0, 0] = round(x)
newContour[i, 0, 1] = round(y)
return newContour
......@@ -54,11 +54,10 @@ class FilterView(QtWidgets.QGraphicsView):
if newRotation != self.rotation:
angle: float = np.float(newRotation-self.rotation)
center: np.ndarray = np.array([self.filter.circleOffset[0] + self.filter.diameter/2,
self.filter.circleOffset[1] + self.filter.diameter/2], dtype=np.float)
self.filter.circleOffset[1] + self.filter.diameter/2], dtype=np.int32)
for particle in self.dataset.particleContainer.particles:
contour: np.ndarray = particle.contour.astype(np.float)
particle.contour = rc.rotate_contour_around_point(contour, center, angle)
particle.contour = rc.rotate_contour_around_point(particle.contour, center, angle)
self._update_particle_contours()
self.rotation = newRotation
......
......@@ -7,8 +7,8 @@ class CythonTester(unittest.TestCase):
def test_rotate_contour(self):
contour: np.ndarray = np.array([[[0, 5]],
[[5, 5]],
[[5, 0]]], dtype=np.float)
refPoint: np.ndarray = np.array([0, 0], dtype=np.float)
[[5, 0]]], dtype=np.int32)
refPoint: np.ndarray = np.array([0, 0], dtype=np.int32)
angle: float = 90.0
newContour: np.ndarray = rc.rotate_contour_around_point(contour, refPoint, angle)
......@@ -37,7 +37,7 @@ class CythonTester(unittest.TestCase):
self.assertAlmostEqual(newContour[2, 0, 0], 0)
self.assertAlmostEqual(newContour[2, 0, 1], -5)
refPoint = np.array([5, 5], dtype=np.float)
refPoint = np.array([5, 5], dtype=np.int32)
angle: float = 90.0
newContour = rc.rotate_contour_around_point(contour, refPoint, angle)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment