Пример #1
0
 def animate(self):
     self.index = 0
     catmull = self.openGLWidget.history[0]
     if len(self.openGLWidget.animationObjects) == 1:
         self.openGLWidget.animationObjects.pop()
     ellipse = Ellipse(catmull.userDefinedPoints[1].x,
                       catmull.userDefinedPoints[1].y, 10, 10)
     ellipse.compute()
     self.openGLWidget.animationObjects.append(ellipse)
     self.timer.start(self.delay)
Пример #2
0
    def mousePressEvent(self, event):
        #check the type of object we are drawing
        if self.objectType == "Rectangle":
            # create Rectangle with properties at the clicked point:
            self.object = Rectangle(event.x(), self.height - event.y(),
                                    event.x(), self.height - event.y())

        else:
            # create Ellipse with properties at the clicked point:
            self.object = Ellipse(event.x(), self.height - event.y(),
                                  event.x(), self.height - event.y())
Пример #3
0
    def __init__(self, center=Coordinate(), radius=1.0, id=None, classes=None):
        """
		@param center: A Coordinate defining the center in the SVG document
		@type center: Coordinate
		@param radius: The radius of the circle
		@param id: The unique ID to be used in the SVG document
		@type id: string
		@param classes: Classnames to be used in the SVG document
		@type classes: string or sequence of strings
		"""

        if isinstance(center, Coordinate):
            Ellipse.__init__(self, center, radius, radius, id, classes)
            self.tag = u'circle'
        else:
            raise TypeError("center must be of type 'Coordinate'")
Пример #4
0
	def __init__(self, center=Coordinate(), radius=1.0, id=None, classes=None):
		"""
		@param center: A Coordinate defining the center in the SVG document
		@type center: Coordinate
		@param radius: The radius of the circle
		@param id: The unique ID to be used in the SVG document
		@type id: string
		@param classes: Classnames to be used in the SVG document
		@type classes: string or sequence of strings
		"""
		
		if isinstance(center, Coordinate):
			Ellipse.__init__(self, center, radius, radius, id, classes)
			self.tag = u'circle'
		else:
			raise TypeError("center must be of type 'Coordinate'")
Пример #5
0
    def _detectMainEllipse(self):
        minDist = 100000
        mainBlob = None

        for blob in self.image.dilate(2).findBlobs(minsize=200):
            dist = math.sqrt((blob.x - self.image.width/2)**2 + (blob.y - self.image.height/2)**2)
            if dist < minDist:
                minDist = dist
                mainBlob = blob

        blob = mainBlob

        ellipse = Ellipse()
        ellipse.fitToData(np.array(blob.hull()))

        return ellipse
Пример #6
0
 def __init__(self):
     super().__init__()
     self.colorCounter = 1
     self.setMouseTracking(False)
     __ellipseWidth = 100
     __ellipseHeight = 450
     self.object = Ellipse(0, 0, __ellipseWidth, __ellipseHeight)
     self.theta = 0
     self.objectType = None
     self.rotationPointX = self.object.cx
     self.rotationPointY = self.object.cy
Пример #7
0
 def buildEllipse(winner, center, top_votes, num_voters, major_axis, imgSize):
     minor_axis = winner[0]
     theta = winner[1]
     theshold = 0.1
     ratio = 4
     # votes must high enough  and the major/minor rate cant be too much
     if top_votes <= num_voters*theshold or major_axis/minor_axis > ratio:  # 0.15 / 2.5
         print('[No result] {}/{} < {}, major/minor {} > {}'.format(
                 top_votes, num_voters, theshold, 
                 major_axis/minor_axis, ratio))
         e = None
         success = False
     else:
         print('[Detected] minor = {}, theta={}'.format(minor_axis, theta*pi/180))
         e = Ellipse((major_axis, minor_axis), center, theta, imgSize)
         success = True
     return success, e
Пример #8
0
class CreateObjects:
    if __name__ == '__main__':
        figure1 = Circle("red", 12)
        figure2 = Ellipse("pink", 9, 15)
        figure3 = Triangle("black", 4, 7, 10)
        figure4 = IsoscelesTriangle("none", 6, 10)
        figure5 = EquilateralTriangle("millitary", 7)
        figure6 = Square("red", 6)
        figure7 = Rectangle("green", 6, 12)

        listFigures = [
            figure1, figure2, figure3, figure3, figure4, figure5, figure6,
            figure7
        ]
        for shape in listFigures:
            print("========= Number : " + str(listFigures.index(shape) + 1) +
                  " ============")
            shape.informationAboutFigure()
Пример #9
0
from Vector import *
from Ellipse import Ellipse

C = O()
a = 2.0

b1 = 1.0
b2 = 2.0

N = 100

db = 1.0 * (b2 - b1) / (1.0 * (N - 1))

b = b1
for n in range(N):
    curve = Ellipse(a, b, C, N)
    curve.Rs()

    curve.Init_Canvas()

    fname = "Ellipse/" + ("%03d" % n) + ".svg"
    options = {
        "stroke": 'blue',
        "style": {
            "stroke-width": 2,
        }
    }

    curve.Curve_SVG_Line_Write(fname, options)
    b += db
Пример #10
0
# Simulation parameters
N, s, T = 64, 10e6, .102
h = 1. / N

dt = .00000003

Time = SimTime(dt = dt, T = T)

# Setup for saving the simulation output
SavePeriod = 100 #int((T / dt) / 120)
Save = SaveData.SaveDataControl(('EllipseRelaxation', 'Explicit'))

    
# Ellipse
X = Ellipse(2 * N, s, [.5,.5], [.8,.5], [.5,.6])
X.UseNativePython = False # If true native python code is used instead of C code

# Initialize the fluid solver
u = Fluid(dt = dt, N = [N,N], dims = [1., 1.])

# The simulation loop        
Time.StartTimer()
while Time.t < Time.T:
    Time.PrintStepInfo()

    X.CheckForExplosion()

    # The FE/BE method
    # First calculate the fiber force F (stored in X.F)
    X.CalcForceDistribution()
Пример #11
0
rectangle = Rectangle('5','8','88','99')
ROIs.append(rectangle.generateXML())

square = Square('55','99','520')
ROIs.append(square.generateXML())

xs=[1,2,3,4,5,6]
ys=[6,5,4,555,2,3]

polygon = Polygon(xs,ys)
ROIs.append(polygon.generateXML())
"""

#Como hemos comentado en el metodo, aqui solo tenemos que llamarlo y el se encarga de generar el xml esperado. Solo queda aniadirlo a la raiz
rois = [
    Ellipse('7', '8', '0.2'),
    Ellipse('55', '55', '0.222'),
    Ellipse('777', '777', '0.777')
]
ROIsofImage.append(generateXMLDocument(rois))
"""
En esta parte es donde creamos el archivo XML que tiene de contenido las regiones que hemos captado de OpenCV.
Al abrir ese archivo, si no esta se crea pero si ya esta generado se machaca el contenido que tuviera, de esta forma es conveniente
que el nombre del archivo sea diferente cada vez que queramos guardar las regiones de una foto.

"""
archi = open('datos.xml', 'w')
archi.flush()
archi.write(
    etree.tostring(ROIsofImage,
                   pretty_print=True,
Пример #12
0
def calculate(value):
  schema = Ellipse(c_aux = value)
  return schema.mas()
"""

from numpy import zeros, float64, floor, array, dot

import IB

from Fluid import Fluid
from Ellipse import Ellipse
from MatrixUtility import Stack, Unstack

# Simulation parameters
N = 128
RestrictToEulerian = False # If True we restrict the fiber points to Eulerian intersections. When done the matrix should give EXACT results.

# Create the fiber in the shape of an ellipse
X = Ellipse(2 * N, s = 10e6, c = [.5,.5], p1 = [.8,.5], p2 = [.5,.6])
if RestrictToEulerian:
    X.X = floor(X.X * N) / N 

# Initialize the fluid solver
u = Fluid(dt = 1. / N, N = [N,N], dims = [1., 1.])


# Calculate dX/dt (stored in X.U) using a fluid solve
X.CalcForceDistribution()
X.ToGrid(u)
u.UpdateFluid(u.f)
X.FromGrid(u)


# Calculate dX/dt (stored in U) using the fluid matrix
Пример #14
0
        * black background
        * white foreground
'''

import sys
import math

from Rectangle import Rectangle
from Ellipse import Ellipse
from PyQt5.QtOpenGL import QGLWidget
from PyQt5.QtCore import QSize
import OpenGL.GL as GL
import OpenGL.GLU as GLU

REC = Rectangle(0, 0, 0, 0)
ELLI = Ellipse(0, 0, 0, 0)


class GLStandardDrawingWindow(QGLWidget):
    def __init__(self):
        super().__init__()
        self.width, self.height = 500, 600
        self.resize(self.width, self.height)
        self.move(100, 100)
        self.history = []
        self.numberOfClicks = 0

    def minimumSizeHint(self):
        return QSize(50, 100)

    def sizeHint(self):
Пример #15
0
"""

from numpy import zeros, float64, floor, array, dot

import IB

from Fluid import Fluid
from Ellipse import Ellipse
from MatrixUtility import Stack, Unstack

# Simulation parameters
N = 128
RestrictToEulerian = False  # If True we restrict the fiber points to Eulerian intersections. When done the matrix should give EXACT results.

# Create the fiber in the shape of an ellipse
X = Ellipse(2 * N, s=10e6, c=[.5, .5], p1=[.8, .5], p2=[.5, .6])
if RestrictToEulerian:
    X.X = floor(X.X * N) / N

# Initialize the fluid solver
u = Fluid(dt=1. / N, N=[N, N], dims=[1., 1.])

# Calculate dX/dt (stored in X.U) using a fluid solve
X.CalcForceDistribution()
X.ToGrid(u)
u.UpdateFluid(u.f)
X.FromGrid(u)

# Calculate dX/dt (stored in U) using the fluid matrix
# First construt the fluid matrix
M = X.ConstructFluidMatrix(u)
Пример #16
0
def eval_mas(value):
  schema = Ellipse(N=N, a=a, b=b, k=k, c_aux=value, c_obs=2*c_obs)
  return schema.mas(champion=True)
Пример #17
0
def evaluation_function2(value):
  schema = Ellipse(N=N, a=a, b=b, k=k, c_aux=value, c_obs=c_obs)
  return schema.mas(champion=True)
Пример #18
0
 def test_ellipse_circle_area(self):
     ellipse = Ellipse('circle',12,12)
     self.assertEqual(round(ellipse.get_area(),1), 113.1)
Пример #19
0
 def test_ellipse_noncircle_area(self):
     ellipse = Ellipse('non-circle',12,4)
     self.assertEqual(round(ellipse.get_area(),1), 37.7)
Пример #20
0
class DrawingWindow(GLStandardDrawingWindow):
    def __init__(self):
        super().__init__()
        self.colorCounter = 1
        self.setMouseTracking(False)
        self.object = None
        self.objectType = None

    def setObjectType(self, name):
        self.objectType = name

    def mousePressEvent(self, event):
        #check the type of object we are drawing
        if self.objectType == "Rectangle":
            # create Rectangle with properties at the clicked point:
            self.object = Rectangle(event.x(), self.height - event.y(),
                                    event.x(), self.height - event.y())

        else:
            # create Ellipse with properties at the clicked point:
            self.object = Ellipse(event.x(), self.height - event.y(),
                                  event.x(), self.height - event.y())

    def mouseMoveEvent(self, event):
        #check the type of object we are re-drawing
        if type(self.object) is type(REC):
            self.object.points = []
            self.object.x1 = event.x()
            # Make square
            if event.modifiers() and QtCore.Qt.ShiftModifier:
                #length and width have to be the same
                self.object.y1 = distance(
                    self.object.y0, (distance(self.object.x0, self.object.x1)))
            else:
                self.object.y1 = distance(self.height, event.y())
            self.object.compute()

        elif type(self.object) is type(ELLI):
            self.object.points = []
            self.currentX = distance(self.object.cx, event.x())

            if event.modifiers() and QtCore.Qt.ShiftModifier:
                self.object.a = self.currentX
                self.object.b = self.currentX

            else:
                self.object.a = self.currentX
                self.object.b = distance(self.object.cy,
                                         self.height - event.y())

            self.object.bresenhamAlg()

        else:
            pass
        self.updateGL()

    def mouseReleaseEvent(self, event):
        self.history.append(self.object)

    def paintGL(self):
        '''
        paintGL
        Updates the current object that is being drawn in screen.
        Draws whatever is on the history stack as a set of points
        '''
        GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
        GL.glBegin(GL.GL_POINTS)
        if self.object:
            for point in self.object.points:
                GL.glVertex2fv(point)
        for element in self.history:
            for point in element.points:
                GL.glVertex2fv(
                    point
                )  #  #map points according to the coordinates they belong to

        GL.glEnd()
        GL.glFlush()