...

Commits (15)
 ... @@ -6,3 +6,11 @@ __pycache__/ ... @@ -6,3 +6,11 @@ __pycache__/ *.png *.png *.res *.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): x = cos * (contour[i, 0, 0]-refPoint) - sin * (contour[i, 0, 1]-refPoint) + refPoint y = sin * (contour[i, 0, 0]-refPoint) + cos * (contour[i, 0, 1]-refPoint) + refPoint 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[:])),\ round(np.mean(contours[:])) 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
This diff is collapsed.
 from PyQt5 import QtGui, QtWidgets, QtCore from PyQt5 import QtGui, QtWidgets, QtCore import numpy as np import sys import sys sys.path.append("C://Users//xbrjos//Desktop//Python") sys.path.append("C://Users//xbrjos//Desktop//Python") import gepard import gepard from gepard import dataset from gepard import dataset import helpers import helpers import numpy as np from cythonModules import rotateContour as rc class FilterView(QtWidgets.QGraphicsView): class FilterView(QtWidgets.QGraphicsView): ... @@ -14,6 +15,7 @@ class FilterView(QtWidgets.QGraphicsView): ... @@ -14,6 +15,7 @@ class FilterView(QtWidgets.QGraphicsView): self.setWindowTitle('FilterView') self.setWindowTitle('FilterView') self.dataset: dataset.DataSet = None self.dataset: dataset.DataSet = None self.rotation: int = 0 scene = QtWidgets.QGraphicsScene(self) scene = QtWidgets.QGraphicsScene(self) scene.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex) scene.setItemIndexMethod(QtWidgets.QGraphicsScene.NoIndex) ... @@ -47,6 +49,20 @@ class FilterView(QtWidgets.QGraphicsView): ... @@ -47,6 +49,20 @@ class FilterView(QtWidgets.QGraphicsView): self._update_particle_contours() self._update_particle_contours() self._fit_to_window() self._fit_to_window() @helpers.timingDecorator def update_rotation(self, newRotation: int) -> None: if newRotation != self.rotation: angle: float = np.float(newRotation-self.rotation) center: np.ndarray = np.array([self.filter.circleOffset + self.filter.diameter/2, self.filter.circleOffset + self.filter.diameter/2], dtype=np.int32) for particle in self.dataset.particleContainer.particles: particle.contour = rc.rotate_contour_around_point(particle.contour, center, angle) self._update_particle_contours() self.rotation = newRotation @helpers.timingDecorator def _update_particle_contours(self) -> None: def _update_particle_contours(self) -> None: self._remove_particle_contours() self._remove_particle_contours() if self.dataset is not None: if self.dataset is not None: ... ...