...

Commits (14)
 ... ... @@ -6,3 +6,11 @@ __pycache__/ *.png *.res cythonModules/build/ *.c *.pyd *.html
 import numpy as np cimport numpy as np cimport cython DTYPE = np.float ctypedef np.int32_t INT32_t 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... 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) :return: Array of the rotated point, [:, 0, 0] = x, [:, 0, 1] = y """ cdef int i cdef double theta, sin, cos, x, y 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) for i in range(contour.shape[0]): 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
 # try: from setuptools import setup from setuptools import Extension from Cython.Build import cythonize import numpy as np import sys if len(sys.argv) == 1: sys.argv.append("build_ext") sys.argv.append("--inplace") ext = Extension("rotateContour", ["rotateContour.pyx"], extra_compile_args=['-O3'],) setup( name="rotate contour around reference point", ext_modules=cythonize([ext], annotate=True), # accepts a glob pattern include_dirs=[np.get_include()] ) \ No newline at end of file
 import copy import numpy as np import sys sys.path.append("C://Users//xbrjos//Desktop//Python") from gepard.analysis.particleContainer import ParticleContainer from cythonModules import rotateContour class ParticleVariations(object): def __init__(self, particleContainer: ParticleContainer, numVariations: int = 10) -> None: super(ParticleVariations, self).__init__() self.origParticleContainer = particleContainer self.numVariations = numVariations def get_particleContainer_variations(self) -> ParticleContainer: if self.numVariations > 0: partContainer: ParticleContainer = self.origParticleContainer contours: list = partContainer.getParticleContours() center: tuple = round(np.mean(contours[:][0][0])),\ round(np.mean(contours[:][0][1])) center: np.ndarray = np.array(center, dtype=np.int32) angles = self._get_angles() for i in range(self.numVariations): if i > 0: partContainer = copy.deepcopy(self.origParticleContainer) for particle in partContainer.particles: contour = np.int32(particle.contour) particle.contour = rotateContour.rotate_contour_around_point(contour, center, np.float(angles[i])) yield partContainer def _get_angles(self) -> np.ndarray: angleIncrement: float = 360 / self.numVariations return np.arange(self.numVariations) * angleIncrement