void MainWindow::draw_points(const int activeDistributionNumber, QGraphicsScene * scene)
{
    if (distributions.isEmpty())
        return;

    if (!distributions[activeDistribution[activeDistributionNumber]].selection.RowNo())
        return;

    QPen pen;
    pen.setWidth(2);

    for (size_t i = 0; i < distributions[activeDistribution[activeDistributionNumber]].selection.RowNo(); ++i)
    {
        //wrong recognized points draw in red color
        if (ui.checkBoxRecognized->isChecked() &&
            (distributions[activeDistribution[activeDistributionNumber]].selectionVectorsInfo[i].recognizedDistribution !=
             distributions[activeDistribution[activeDistributionNumber]].selectionVectorsInfo[i].trueDistribution))
            pen.setColor(QColor(255, 0, 0, 255));
        else
            pen.setColor(actualColors[activeDistributionNumber]);

        scene->addLine(plot_x(distributions[activeDistribution[activeDistributionNumber]].selection(i, activeComponent[0])),
                       plot_y(distributions[activeDistribution[activeDistributionNumber]].selection(i, activeComponent[1])),
                       plot_x(distributions[activeDistribution[activeDistributionNumber]].selection(i, activeComponent[0])),
                       plot_y(distributions[activeDistribution[activeDistributionNumber]].selection(i, activeComponent[1])),
                       pen);
    }
}
void MainWindow::draw_ellipse(QPainterPath &path, double p)
{

    double width = boundingRect.right() - boundingRect.left();
    width /= 100.0;
    double left = boundingRect.left();

    bool first = true;
    for (int i = 0; i <= 100; ++i)
    {
        double currentX = left + static_cast<double>(i)*width;
        double currentY = calculate_y1(currentX, p);
        if (first)
        {
            if (!(isnan(currentY) || isinf(currentY)))
            {
                path.moveTo(plot_x(currentX), plot_y(currentY));
                first = false;
            }
        }
        else
            if (!(isnan(currentY) || isinf(currentY)))
                path.lineTo(plot_x(currentX), plot_y(currentY));
    }

    for (int i = 100; i >= 0; --i)
    {
        double currentX = left + static_cast<double>(i)*width;
        double currentY = calculate_y2(currentX, p);
        if (!(isnan(currentY) || isinf(currentY)))
            path.lineTo(plot_x(currentX), plot_y(currentY));
    }
    path.connectPath(path);
}
void MainWindow::draw_axises(QGraphicsScene * scene)
{
    QPen pen;
    pen.setColor(QColor(10, 155, 10, 255));
    pen.setWidth(1);

    scene->addLine(plot_x(-1.0), plot_y(0.0), plot_x(1.0), plot_y(0.0), pen);
    scene->addLine(plot_x(0.0), plot_y(-1.0), plot_x(0.0), plot_y(1.0), pen);
}
void MainWindow::draw_middle_point(const int activeDistributionNumber, QGraphicsScene * scene)
{
    QPen pen;
    pen.setColor(QColor(10, 155, 10, 255));
    pen.setWidth(2);

    scene->addLine(plot_x(distributions[activeDistribution[activeDistributionNumber]].info.middle(0, activeComponent[0])),
                   plot_y(distributions[activeDistribution[activeDistributionNumber]].info.middle(0, activeComponent[1])),
                   plot_x(distributions[activeDistribution[activeDistributionNumber]].info.middle(0, activeComponent[0])),
                   plot_y(distributions[activeDistribution[activeDistributionNumber]].info.middle(0, activeComponent[1])), pen);
}
void MainWindow::draw_ellipse(const int activeDistributionNumber, QPainterPath &path, double p)
{
    const int STEP_OF_GRID = 300;

    QRectF boundingRect(distributions[activeDistribution[activeDistributionNumber]].calculate_bounding_box(activeComponent[0], activeComponent[1]));

    double width = boundingRect.width();
    width /= static_cast<double>(STEP_OF_GRID);
    double left = boundingRect.left();

    bool first = true;
    for (int i = 0; i <= STEP_OF_GRID; ++i)
    {
        double currentX = left + static_cast<double>(i)*width;
        double currentY = distributions[activeDistribution[activeDistributionNumber]].calculate_y1(activeComponent[0], activeComponent[1], r[activeDistributionNumber], currentX, p);
        if (unlikely(first))
        {
            if (!(isnan(currentY) || isinf(currentY)))
            {
                path.moveTo(plot_x(currentX), plot_y(currentY));
                first = false;
            }
        }
        else
            if (!(isnan(currentY) || isinf(currentY)))
                path.lineTo(plot_x(currentX), plot_y(currentY));
    }

    for (int i = STEP_OF_GRID; --i; )
    {
        double currentX = left + static_cast<double>(i)*width;
        double currentY = distributions[activeDistribution[activeDistributionNumber]].calculate_y2(activeComponent[0], activeComponent[1], r[activeDistributionNumber], currentX, p);
        if (!(isnan(currentY) || isinf(currentY)))
            path.lineTo(plot_x(currentX), plot_y(currentY));
    }
    path.connectPath(path);
}
Beispiel #6
0
int main() {
  int i;

	gen_sinus_table(LEN, 0.5, 0.005, 0, buffer_first);
	gen_sinus_table(LEN, 0.5, 0.05, 0, buffer_second);

	
	for (i = 0; i < LEN; i++) {
		buffer[i] = buffer_first[i] + buffer_second[i];
	}
	
	plot_file((double *)buffer, LEN, sizeof(Int16), "test.pcm");

	plot_y((double *)buffer, LEN, sizeof(Int16));

	//plot_fft_y((double *)buffer, LEN, sizeof(Int16));

  return 0;
}
void MainWindow::draw()
{
    if (scene)
    {
        delete scene;
        scene = NULL;
    }

    int vec1 = ui.component1->value() - 1;
    int vec2 = ui.component2->value() - 1;

    calculate_bounding_rect(vec1, vec2);

    shiftX = 0.0;
    shiftY = 0.0;
    QPen pen;

//    scene = new QGraphicsScene(boundingRect, this);
    scene = new QGraphicsScene(this);

    //draw axies lines
    pen.setColor(QColor(0, 0, 0, 255));
    pen.setWidth(1);
    scene->addLine(plot_x(0.0), plot_y(0.0), plot_x(1.0), plot_y(0.0), pen);
    scene->addLine(plot_x(0.0), plot_y(0.0), plot_x(0.0), plot_y(1.0), pen);

    //draw all points
    if (ui.checkBoxSelection->isChecked())
    {
        pen.setColor(QColor(255, 0, 0, 255));
        pen.setWidth(2);
        for (int i = 0; i < selectionSize; ++i)
            scene->addLine(plot_x(x[i][vec1]), plot_y(x[i][vec2]), plot_x(x[i][vec1]), plot_y(x[i][vec2]), pen);
    }

    //draw middle point
    if (ui.checkBoxMiddle->isChecked())
    {
        pen.setColor(QColor(0, 0, 255, 255));
        pen.setWidth(3);
        scene->addLine(plot_x(middleX), plot_y(middleY), plot_x(middleX), plot_y(middleY), pen);
    }

    //draw isolines
    if (ui.checkBoxIsolines->isChecked())
    {
        pen.setColor(QColor(0, 0, 255, 255));
        pen.setWidth(1);
        QPainterPath path1;
        QPainterPath path2;
        QPainterPath path3;
        draw_ellipse(path1, 0.3);
        draw_ellipse(path2, 0.6);
        draw_ellipse(path3, 0.9);
        scene->addPath(path1, pen);
        scene->addPath(path2, pen);
        scene->addPath(path3, pen);
    }

    scene->setBackgroundBrush(QBrush(QColor(0, 255, 0, 255)));
    ui.graphicsView->setScene(scene);
    ui.graphicsView->show();
}