Exemplo n.º 1
0
def update_particles(particles):
    animation_chart = QChart()
    reals = QScatterSeries()

    pen_reals = reals.pen()
    pen_reals.setBrush(QtGui.QColor("white"))
    reals.setMarkerSize(5)
    reals.setColor(QtGui.QColor("red"))
    reals.setPen(pen_reals)

    for particle in particles:
        reals.append(particle, 0)

    animation_chart.addSeries(reals)
    animation_chart.setBackgroundBrush(QtGui.QColor(41, 43, 47))
    animation_chart.createDefaultAxes()
    animation_chart.legend().hide()
    animation_chart.setContentsMargins(-10, -10, -10, -10)
    animation_chart.layout().setContentsMargins(0, 0, 0, 0)
    animation_chart.axisX().setTickCount(17)
    animation_chart.axisY().setTickCount(3)
    animation_chart.axisX().setLabelsColor(QtGui.QColor("white"))
    animation_chart.axisX().setGridLineColor(QtGui.QColor("grey"))
    animation_chart.axisX().setRange(-4, 12)
    animation_chart.axisY().setRange(-1, 1)
    animation_chart.axisY().setLabelsColor(QtGui.QColor("white"))
    animation_chart.axisY().setGridLineColor(QtGui.QColor("grey"))
    form.widget_animation.setChart(animation_chart)
Exemplo n.º 2
0
class Window(QMainWindow):
    def __init__(self, landmarkPoints, allPoints, threadEvent):
        super().__init__()
        self.title = "Lidar data points"
        #self.queue = queue
        self.color = Qt.darkRed
        self.lmrkPoints = landmarkPoints
        self.allPoints = allPoints
        self.event = threadEvent
        self.left = 500
        self.top = 500
        self.height = 480
        self.width = 640
        self.count = 0
        self.time = 0

        self.label = QLabel(self)
        self.lmrkBox = QCheckBox("Landmark points", self)
        self.ptsBox = QCheckBox("Data points", self)

        self.boxArea = QWidget()
        self.mainLayout = QGridLayout()
        self.mainLayout.addWidget(self.lmrkBox, 0, 0)
        self.mainLayout.addWidget(self.ptsBox, 1, 0)
        self.mainLayout.setVerticalSpacing(5)
        self.boxArea.setLayout(self.mainLayout)
        crote = QDockWidget("Hide", self)
        crote.setWidget(self.boxArea)
        self.addDockWidget(Qt.LeftDockWidgetArea, crote)

        dock = QDockWidget("", self)
        dock.setWidget(self.label)
        self.addDockWidget(Qt.LeftDockWidgetArea, dock)

        self.chart = QChart()
        self.config_axis()
        self.series = QScatterSeries(self.chart)
        self.allSeries = QScatterSeries(self.chart)
        self.config_series()
        #self.update()
        self.timer = QTimer(self)
        self.view = QChartView(self.chart)
        self.setCentralWidget(
            self.view
        )  # It is needed to create to view because the CentralWidget needs to be a QWidget, and a QChart is not so.
        self.initWindow()

    def config_series(self):
        self.series.setName("Landmark Points")
        self.allSeries.setName("Data Points")

        lmrkPen = self.series.pen()
        pen = self.allSeries.pen()
        lmrkPen.setWidthF(.2)
        pen.setWidthF(.2)
        self.series.setPen(lmrkPen)
        self.allSeries.setPen(pen)

        self.series.setColor(Qt.red)
        self.allSeries.setColor(Qt.blue)

        self.series.setMarkerShape(1)  # 1 - rectangle; 0 - circle

        # for good visualization, the landmark points should be bigger than normal points

        self.series.setMarkerSize(8)
        self.allSeries.setMarkerSize(5)
        self.label.move(15, 15)

    def config_axis(self):
        self.xAxis = QValueAxis()
        self.yAxis = QValueAxis()
        self.xAxis.setRange(-XRANGE, XRANGE)
        self.xAxis.setTitleText("Eixo x")
        self.yAxis.setRange(-YRANGE, YRANGE)
        self.yAxis.setTitleText("Eixo y")
        self.chart.addAxis(self.xAxis, Qt.AlignBottom)
        self.chart.addAxis(self.yAxis, Qt.AlignLeft)

    def update(self):
        self.event.wait()
        start = time.time()
        self.label.setText("FPS: {:.2f}".format(1 / (time.time() - self.time)))
        self.time = time.time()
        if self.count == 0 and self.lmrkPoints != []:
            self.series.append(self.lmrkPoints[0][:])
            self.allSeries.append(self.allPoints[0][:])
            del self.lmrkPoints[:]
            del self.allPoints[:]
            self.count = 1
        elif self.lmrkPoints != []:
            self.series.replace(self.lmrkPoints[0][:])
            self.allSeries.replace(self.allPoints[0][:])
            del self.lmrkPoints[:]
            del self.allPoints[:]
        end = time.time()
        self.event.clear()

    def hide_show_points(self):
        self.series.setVisible(not self.series.isVisible())

    def hide_show_all_points(self):
        self.allSeries.setVisible(not self.allSeries.isVisible())

    def initWindow(self):
        print("queue inside myWindow: {}".format(self.lmrkPoints))
        self.setGeometry(self.left, self.top, self.width, self.height)
        self.setWindowTitle(self.title)
        self.chart.addSeries(self.series)
        self.chart.addSeries(self.allSeries)
        self.series.attachAxis(self.xAxis)
        self.series.attachAxis(self.yAxis)
        self.allSeries.attachAxis(self.xAxis)
        self.allSeries.attachAxis(self.yAxis)

        self.timer.timeout.connect(self.update)
        self.lmrkBox.stateChanged.connect(self.hide_show_points)
        self.ptsBox.stateChanged.connect(self.hide_show_all_points)

        self.timer.start(0)
        self.show()
Exemplo n.º 3
0
def run_evolution():
    range_a = float(str(form.input_a.text()))
    range_b = float(str(form.input_b.text()))
    precision = int(str(form.input_d.text()))
    generations_number = int(str(form.input_t.text()))

    app.setOverrideCursor(QtCore.Qt.WaitCursor)

    best_reals, best_binary, best_fxs, local_fxs, _, _ = evolution(range_a, range_b, precision, generations_number, form.checkBox.isChecked())

    form.best_table.item(1,0).setText(str(best_reals[len(local_fxs)-1]))
    form.best_table.item(1,1).setText(''.join(map(str, best_binary[len(local_fxs)-1])))
    form.best_table.item(1,2).setText(str(best_fxs[len(local_fxs)-1]))
    
    chart = QChart()
    bests = QLineSeries() 

    pen_best = bests.pen()
    pen_best.setWidth(1)
    pen_best.setBrush(QtGui.QColor("red"))
    bests.setPen(pen_best)

    for i in range(0, len(local_fxs)):
        if len(local_fxs[i]) - 1 == 0:
            fxs = QScatterSeries()
            fxs.append(i + 0.99, local_fxs[i][0])
            pen = fxs.pen()
            color = QtGui.QColor(random.randint(50,255), random.randint(50,255), random.randint(50,255))
            fxs.setColor(color)
            pen.setColor(color)
            fxs.setPen(pen)
            fxs.setMarkerSize(5)

        else:
            fxs = QLineSeries()
            tick = 1 / (len(local_fxs[i]) - 1)
            for j in range(len(local_fxs[i])):
                fxs.append(i + j * tick, local_fxs[i][j])
            pen = fxs.pen()
            pen.setWidth(1)
            pen.setBrush(QtGui.QColor(random.randint(50,255), random.randint(50,255), random.randint(50,255)))
            fxs.setPen(pen)
            
        bests.append(i+1, best_fxs[i])
        chart.addSeries(fxs)

    chart.addSeries(bests)

    chart.setBackgroundBrush(QtGui.QColor(41, 43, 47))
    chart.createDefaultAxes()
    chart.legend().hide()
    chart.setContentsMargins(-10, -10, -10, -10)
    chart.layout().setContentsMargins(0, 0, 0, 0)
    chart.axisX().setTickCount(11)
    chart.axisX().setLabelsColor(QtGui.QColor("white"))
    chart.axisX().setGridLineColor(QtGui.QColor("grey"))
    chart.axisX().setLabelFormat("%i")
    chart.axisY().setRange(-2,2)
    chart.axisY().setLabelsColor(QtGui.QColor("white"))
    chart.axisY().setGridLineColor(QtGui.QColor("grey"))
    form.widget.setChart(chart)

    with open('best_history.csv', 'w', newline='', encoding='utf8') as history_csvfile:
        history_writer = csv.writer(
            history_csvfile, delimiter=';', dialect=csv.excel)
        history_writer.writerow(['Parametry'])
        history_writer.writerow(['Precyzja: 10^-%d' % precision])
        history_writer.writerow(['Iteracje: %d' % generations_number])
        history_writer.writerow(['', 'real', 'bin', 'f(real)'])

        for index, generation in enumerate(range(generations_number)):
            history_writer.writerow([index,  best_reals[generation], best_binary[generation], best_fxs[generation]])

    app.restoreOverrideCursor()