示例#1
3
void WindPlot::updatePlot()
{
    clearPlottables();
    clearItems();

    // Return now if plot empty
    if (mMainWindow->dataSize() == 0) return;

    double lower = mMainWindow->rangeLower();
    double upper = mMainWindow->rangeUpper();

    QVector< double > t, x, y;

    double xMin, xMax;
    double yMin, yMax;

    int start = mMainWindow->findIndexBelowT(lower) + 1;
    int end   = mMainWindow->findIndexAboveT(upper);

    bool first = true;
    for (int i = start; i < end; ++i)
    {
        const DataPoint &dp = mMainWindow->dataPoint(i);

        t.append(dp.t);

        if (mMainWindow->units() == PlotValue::Metric)
        {
            x.append(dp.velE * MPS_TO_KMH);
            y.append(dp.velN * MPS_TO_KMH);
        }
        else
        {
            x.append(dp.velE * MPS_TO_MPH);
            y.append(dp.velN * MPS_TO_MPH);
        }

        if (first)
        {
            xMin = xMax = x.back();
            yMin = yMax = y.back();

            first = false;
        }
        else
        {
            if (x.back() < xMin) xMin = x.back();
            if (x.back() > xMax) xMax = x.back();

            if (y.back() < yMin) yMin = y.back();
            if (y.back() > yMax) yMax = y.back();
        }
    }

    QCPCurve *curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::lightGray, mMainWindow->lineThickness()));

    setViewRange(xMin, xMax, yMin, yMax);

    if (mMainWindow->markActive())
    {
        const DataPoint &dpEnd = mMainWindow->interpolateDataT(mMainWindow->markEnd());

        t.clear();
        x.clear();
        y.clear();

        QVector< double > xMark, yMark;

        if (mMainWindow->units() == PlotValue::Metric)
        {
            xMark.append(dpEnd.velE * MPS_TO_KMH);
            yMark.append(dpEnd.velN * MPS_TO_KMH);
        }
        else
        {
            xMark.append(dpEnd.velE * MPS_TO_MPH);
            yMark.append(dpEnd.velN * MPS_TO_MPH);
        }

        QCPGraph *graph = addGraph();
        graph->setData(xMark, yMark);
        graph->setPen(QPen(Qt::black, mMainWindow->lineThickness()));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle::ssDisc);
    }

    updateWind(start, end);

    QVector< double > xMark, yMark;

    if (mMainWindow->units() == PlotValue::Metric)
    {
        xMark.append(mWindE * MPS_TO_KMH);
        yMark.append(mWindN * MPS_TO_KMH);
    }
    else
    {
        xMark.append(mWindE * MPS_TO_MPH);
        yMark.append(mWindN * MPS_TO_MPH);
    }

    QCPGraph *graph = addGraph();
    graph->setData(xMark, yMark);
    graph->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    graph->setLineStyle(QCPGraph::lsNone);
    graph->setScatterStyle(QCPScatterStyle::ssDisc);

    const double x0 = mWindE;
    const double y0 = mWindN;
    const double r = mVelAircraft;

    QVector< double > tCircle, xCircle, yCircle;

    for (int i = 0; i <= 100; ++i)
    {
        tCircle.append(i);

        const double x = x0 + r * cos((double) i / 100 * 2 * M_PI);
        const double y = y0 + r * sin((double) i / 100 * 2 * M_PI);

        if (mMainWindow->units() == PlotValue::Metric)
        {
            xCircle.append(x * MPS_TO_KMH);
            yCircle.append(y * MPS_TO_KMH);
        }
        else
        {
            xCircle.append(x * MPS_TO_MPH);
            yCircle.append(y * MPS_TO_MPH);
        }
    }

    curve = new QCPCurve(xAxis, yAxis);
    curve->setData(tCircle, xCircle, yCircle);
    curve->setPen(QPen(Qt::red, mMainWindow->lineThickness()));

    // Add label to show best fit
    QCPItemText *textLabel = new QCPItemText(this);

    const double factor = (mMainWindow->units() == PlotValue::Metric) ? MPS_TO_KMH : MPS_TO_MPH;
    const QString units = (mMainWindow->units() == PlotValue::Metric) ? "km/h" : "mph";

    double direction = atan2(-mWindE, -mWindN) / M_PI * 180.0;
    if (direction < 0) direction += 360.0;

    QPainter painter(this);
    double mmPerPix = (double) painter.device()->widthMM() / painter.device()->width();

    double xRatioPerPix = 1.0 / axisRect()->width();
    double xRatioPerMM = xRatioPerPix / mmPerPix;

    double yRatioPerPix = 1.0 / axisRect()->height();
    double yRatioPerMM = yRatioPerPix / mmPerPix;

    textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignRight);
    textLabel->setTextAlignment(Qt::AlignRight);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(1 - 5 * xRatioPerMM,
                                   1 - 5 * yRatioPerMM);
    textLabel->setText(
                QString("Wind speed = %1 %2\nWind direction = %3 deg\nAircraft speed = %4 %5")
                    .arg(sqrt(mWindE * mWindE + mWindN * mWindN) * factor)
                    .arg(units)
                    .arg(direction)
                    .arg(mVelAircraft * factor)
                    .arg(units));

    replot();
}
示例#2
0
/*! \brief Add a Graph to the current Plotter
    \param index the index of the graph
    \param title the title of the graph
    \param color the color of the graph
    \param type the type of the graph (bar, lines, points)
    \param the tickness of the graph
    \param graph_y_scale to multiply the all data points for a scale factor
*/
Graph * Plotter::addGraph(QString remotePort,QString localPort,int index, QString title, QString color, QString type, int size, double graph_y_scale)
{
    Graph *graph = NULL;
    graph = new Graph(index,title,color,type,size,graph_y_scale,this->size);


    for(int i=0;i<graphList.count();i++) {
        Graph *g = (Graph *)graphList.at(i);
        Connection *con = g->getConnetion();
        if(!con){
            continue;
        }
        if(con->remotePortName == remotePort && con->localPortName == localPort){
            graph->curr_connection = g->curr_connection;
            graph->deleteConnection = false;
            break;
        }
    }
    graphList.append(graph);


    QCPGraph *customGraph = customPlot.addGraph(); // line
    customGraph->setPen(QPen(QColor(color),size));
    customGraph->setAntialiased(false);
    customGraph->setLineStyle(QCPGraph::lsLine);

    if(type == "points"){
        customGraph->setLineStyle(QCPGraph::lsNone);
        customGraph->setScatterStyle(QCPScatterStyle::ssDot);
    }

    if(type == "bars"){
        customGraph->setLineStyle(QCPGraph::lsImpulse);
        customGraph->setScatterStyle(QCPScatterStyle::ssNone);
    }


    QCPGraph *customGraphPoint = customPlot.addGraph(); // dot
    customGraphPoint->setPen(QPen(QColor(color)));
    customGraphPoint->setLineStyle(QCPGraph::lsNone);
    customGraphPoint->setScatterStyle(QCPScatterStyle::ssDisc);

    graph->setCustomGraph(customGraph);
    graph->setCustomGraphPoint(customGraphPoint);
    customPlot.replot();


    return graph;
}
示例#3
0
void ScatterWidget::setData(const std::vector<PointD> &data, string legend)
{
    QCPGraph *graph = NULL;
    int nG = ui->scatter->graphCount();
    for(int i=0; i<nG; i++)
    {
        if(ui->scatter->graph(i)->name() == QString::fromStdString(legend))
        {
            graph = ui->scatter->graph(i);
            break;
        }
    }

    if(!graph)
    {
        graph = ui->scatter->addGraph();
        // ----------------------- Scatter Configuration ---------------------------
        graph->setName(QString::fromStdString(legend));
        QColor color_ = colorManager.getNewDifferentColor();
        graph->setPen(QPen(color_));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, 4));
        ui->scatter->legend->setVisible(true);
    }

    double min_x =  INFINITY, min_y =  INFINITY;
    double max_x = -INFINITY, max_y = -INFINITY;

    QVector<QCPGraphData> q_data(data.size());
    for(unsigned int i=0; i<data.size(); i++)
    {
        q_data[i] = QCPGraphData(data[i].x, data[i].y);

        if(ui->recButton->isChecked())
        {
            vector<double> vec2_double(2);
            vec2_double[0] = data[i].x;
            vec2_double[1] = data[i].y;
            vector<string> vec2_string(2);
            vec2_string[0] = legend + "_x";
            vec2_string[1] = legend + "_y";
            logger.addLogCsv(graph->dataCount(), vec2_string, vec2_double);
        }

        max_x = qMax(data[i].x, ui->scatter->xAxis->range().upper);
        min_x = qMin(data[i].x, ui->scatter->xAxis->range().lower);
        max_y = qMax(data[i].y, ui->scatter->yAxis->range().upper);
        min_y = qMin(data[i].y, ui->scatter->yAxis->range().lower);
    }

    graph->data()->set(q_data);
    ui->scatter->xAxis->setRange(min_x, max_x);
    ui->scatter->yAxis->setRange(min_y, max_y);
    ui->scatter->replot();
}
示例#4
0
void RealTimePlot::updateChannel(int index)
{
    Channel *chan = channels[index];

    // Get parameters from channel
    QCPGraph *line = chan->getPtrGraphLine();
    QCPGraph *marker = chan->getPtrGraphMarker();
    QColor color = chan->getGraphColor();

    // Set parameters of line graph
    line->setPen(QPen(color));
    line->setLineStyle(QCPGraph::lsLine);
    line->setVisible(chan->getVisible(LINE));

    // Set parameters of marker graph
    marker->setName(chan->getName());
    marker->setPen(QPen(color));
    marker->setLineStyle(QCPGraph::lsNone);
    marker->setScatterStyle(chan->getMarkerStyle());
    marker->setVisible(chan->getVisible(MARKER));
}
示例#5
0
void ScatterWidget::addPacket(const ScatterPacket &packet)
{
    QCPGraph *graph = NULL;
    int nG = ui->scatter->graphCount();
    for(int i=0; i<nG; i++)
    {
        if(ui->scatter->graph(i)->name() == QString::fromStdString(packet.legend))
        {
            graph = ui->scatter->graph(i);
            break;
        }
    }

    if(!graph)
    {
        graph = ui->scatter->addGraph();
        // ----------------------- Scatter Configuration ---------------------------
        graph->setName(QString::fromStdString(packet.legend));
        QColor color_ = colorManager.getNewDifferentColor();
        graph->setPen(QPen(color_));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssPlusCircle, 4));
        ui->scatter->legend->setVisible(true);
    }

    graph->addData(packet.point.x, packet.point.y);
    //if(packet.point.x > ui->scatter->xAxis->max)

    double max_x = qMax(packet.point.x, ui->scatter->xAxis->range().upper);
    double min_x = qMin(packet.point.x, ui->scatter->xAxis->range().lower);
    double max_y = qMax(packet.point.y, ui->scatter->yAxis->range().upper);
    double min_y = qMin(packet.point.y, ui->scatter->yAxis->range().lower);

    ui->scatter->xAxis->setRange(min_x, max_x);
    ui->scatter->yAxis->setRange(min_y, max_y);

    if(realTimePlot)
        ui->scatter->replot();
    else
        ui->scatter->replot(QCustomPlot::rpQueuedReplot);

    if(ui->recButton->isChecked())
    {
        vector<double> vec2_double(2);
        vec2_double[0] = packet.point.x;
        vec2_double[1] = packet.point.y;
        vector<string> vec2_string(2);
        vec2_string[0] = packet.legend + "_x";
        vec2_string[1] = packet.legend + "_y";
        logger.addLogCsv(graph->dataCount(), vec2_string, vec2_double);
    }
}
示例#6
0
	QCPGraph* SensorDashboard::createGraph(const QString& name, const QColor& color)
	{
		QPen pen;
		pen.setBrush(color);

		QCPGraph *graph = mPlot->addGraph();
		graph->setName(name);
		graph->setLineStyle(QCPGraph::lsLine);
		graph->setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssNone));
		graph->setPen(pen);

		return graph;
	}
示例#7
0
void ConvertProfile(TProfile* prof, QCPGraph &graph){
  //how we put the profile histogram in Qt.
  //passing the graph to alter is just easier :)
  QVector<double> xvals,yvals,xerrs, yerrs;
  int nbins = prof->GetNbinsX();
  //get the values
  for(int i=0; i<nbins;++i){
    xvals.push_back(prof->GetBinCenter(i+1));
    yvals.push_back(prof->GetBinContent(i+1));
    xerrs.push_back(prof->GetBinWidth(i+1)/2.);
    yerrs.push_back(prof->GetBinError(i+1));
  }
  
  graph.setData(xvals, yvals);
  graph.setDataValueError(xvals, yvals, yerrs);//symmetric errors, only in y.
  graph.setScatterStyle(QCPScatterStyle(QCPScatterStyle::ssCircle, QPen(Qt::black, 1.5), QBrush(Qt::white), 9));
  graph.setPen(QPen(QColor(120, 120, 120), 2));
  graph.setLineStyle(QCPGraph::LineStyle::lsNone);
  return;
}
示例#8
0
QCPGraph* tva::postProc::vec2Chart( const postProc::policyChart& policy, const tva::opVecReal& opVx, const tva::vecReal& vy, QCustomPlot *plot )
{
	if (policy.needClear)
	{
		/*int n=*/ plot->clearGraphs();
	}
	size_t size = vy.size();
	tva::vecReal vx;
	// generate data:
	if (opVx.isSettled())
	{
		vx = opVx.get();
	}
	else
	{
		for (size_t i=0; i<size; ++i)
		{
			vx.push_back(i);//index
		}
	}

	//const auto& mx = vx_vy.first;
	//const auto& my = vx_vy.second;
	QVector<double> x, y;
	for (size_t i=0; i<size; ++i)
	{
		x.push_back(vx[i]);//index
		y.push_back(vy[i]);//value
	}

	// create graph and assign data to it:
	QCPGraph * graph;
	if (policy.leftAxis)
	{
		graph	= plot->addGraph();
	}
	else
	{
		graph = plot->addGraph(plot->xAxis, plot->yAxis2);
		plot->yAxis2->setVisible(true);
	}

	//auto * graph = plot->addPlottable();

	{//set graph
		QPen graphPen;

		if (policy.lStyle.isSettled())
		{
			graph->setLineStyle(policy.lStyle.get().style);
			graph->setScatterStyle(policy.lStyle.get().scatter);

			if (policy.lStyle.get().name.isSettled())
			{
				graph->setName(policy.lStyle.get().name.get());
			}

			if (policy.lStyle.get().color.isSettled())
			{
				graphPen.setColor(policy.lStyle.get().color.get());
			}
			else
			{
				graphPen.setColor(QColor(rand()%245+10, rand()%245+10, rand()%245+10));
			}

			//graphPen.setWidthF(rand()/(double)RAND_MAX*2+1);
		}
		else
		{
			tva::chartSetup::lineStyle ls;
			graph->setLineStyle(ls.style);
		}

		graph->setPen(graphPen);
	}

	graph->setData(x, y);

	QCPAxis* xAxis= plot->xAxis;
	QCPAxis* yAxis;// = plot->yAxis;
	if (policy.leftAxis)
	{
		yAxis = plot->yAxis;
	}
	else
	{
		yAxis = plot->yAxis2;
	}

	if (policy.style.isSettled())
	{
		plot->setTitle(policy.style.get().title);
	}

	tva::chartSetup::setupAxisesStyle(policy.style, xAxis, yAxis);
	//
	plot->replot();
	return graph;
}
示例#9
0
  void DataBrokerPlotter::createNewPlot() {
    char text[50];
    // create first curve
    std::string cfgName = name;
    std::string tmpString;
    Plot *newPlot = new Plot;
    QCPGraph *newCurve = qcPlot->addGraph();

    newCurve->setAntialiasedFill(false);

    newPlot->dpId = nextPlotId++;
    sprintf(text, "graph%02d", newPlot->dpId);
    newPlot->name = std::string(text);

    cfgName.append("/");
    cfgName.append(newPlot->name);
    cfgName.append("/");

    newCurve->setPen( QPen(colors[(newPlot->dpId-1) % 8], 0.5) );
    newCurve->setLineStyle( QCPGraph::lsLine );

    newPlot->curve = newCurve;
    
    plots.push_back(newPlot);

    // add datapackage for first plot
    mars::data_broker::DataPackage dbPackageX;// = new mars::data_broker::DataPackage;
    mars::data_broker::DataPackage dbPackageY;// = new mars::data_broker::DataPackage;
    dbPackageX.add("xvalue", (double)0.0);
    dbPackageY.add("yvalue", (double)0.0);
    //dbPackage->add("yvalue", (double)0.0);

    tmpString = name;
    tmpString.append("/");
    tmpString.append(text);
    tmpString.append("/xvalue");
    dataBroker->pushData("data_broker_plotter", tmpString,
                         dbPackageX, this,
                         mars::data_broker::DATA_PACKAGE_READ_WRITE_FLAG);
    dataBroker->registerSyncReceiver(this, "data_broker_plotter",
                                     tmpString, newPlot->dpId*10);
    tmpString = name;
    tmpString.append("/");
    tmpString.append(text);
    tmpString.append("/yvalue");
    dataBroker->pushData("data_broker_plotter", tmpString,
                         dbPackageY, this,
                         mars::data_broker::DATA_PACKAGE_READ_WRITE_FLAG);
    dataBroker->registerSyncReceiver(this, "data_broker_plotter",
                                     tmpString, newPlot->dpId*10+1);
    newPlot->gotData = 0;
    
    tmpString = cfgName;
    tmpString.append("sTime");
    newPlot->sTime = cfg->getOrCreateProperty("DataBrokerPlotter",
                                              tmpString.c_str(),
                                              (double)0.0, this);
    tmpString = cfgName;
    tmpString.append("xRange");
    newPlot->xRange = cfg->getOrCreateProperty("DataBrokerPlotter",
                                               tmpString.c_str(),
                                               (double)0.0, this);
    tmpString = cfgName;
    tmpString.append("yScale");
    newPlot->yScale = cfg->getOrCreateProperty("DataBrokerPlotter",
                                               tmpString.c_str(),
                                               (double)1.0, this);
    tmpString = cfgName;
    tmpString.append("yOffset");
    newPlot->yOffset = cfg->getOrCreateProperty("DataBrokerPlotter",
                                                tmpString.c_str(),
                                                (double)0.0, this);

    cfgParamIdToPlot[newPlot->sTime.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->xRange.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->yScale.paramId] = newPlot;
    cfgParamIdToPlot[newPlot->yOffset.paramId] = newPlot;
    newPlot->cfgParamIdProp[newPlot->sTime.paramId] = &newPlot->sTime;
    newPlot->cfgParamIdProp[newPlot->xRange.paramId] = &newPlot->xRange;
    newPlot->cfgParamIdProp[newPlot->yScale.paramId] = &newPlot->yScale;
    newPlot->cfgParamIdProp[newPlot->yOffset.paramId] = &newPlot->yOffset;
  }
示例#10
0
void ScatterPlotWidget::updatePlot(){
    ui->customPlot->clearGraphs();//clearPlottables();

    if(selectedTrips == NULL)
        return;

    //
    ExtraField field;
    switch(attrib1){
    case(FARE_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Fare Amount (US$)"));
        break;
    case(TIP_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Tip Amount (US$)"));
        break;
    case(DURATION):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Duration (min)"));
        break;
    case(DISTANCE):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Distance (mi)"));
        break;
    case(TOLL_AMOUNT):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Toll Amount (US$)"));
        break;
    case(AVG_SPEED):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)"));
        break;
    case(TIME_OF_DAY):
        ui->customPlot->xAxis->setLabel(QString::fromStdString("Hour of day"));
        break;
    case(FIELD1):
        field = Global::getInstance()->getExtraField(0);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD2):
        field = Global::getInstance()->getExtraField(1);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD3):
        field = Global::getInstance()->getExtraField(2);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    case(FIELD4):
        field = Global::getInstance()->getExtraField(3);
        ui->customPlot->xAxis->setLabel(field.axisLabel);
        break;
    default:
        assert(false);
        break;
    }

    //
    switch(attrib2){
    case(FARE_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Fare Amount (US$)"));
        break;
    case(TIP_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Tip Amount (US$)"));
        break;
    case(DURATION):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Duration (min)"));
        break;
    case(DISTANCE):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Distance (mi)"));
        break;
    case(TOLL_AMOUNT):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Toll Amount (US$)"));
        break;
    case(AVG_SPEED):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Avg Speed (mi/h)"));
        break;
    case(TIME_OF_DAY):
        ui->customPlot->yAxis->setLabel(QString::fromStdString("Hour of day"));
        break;
    case(FIELD1):
        field = Global::getInstance()->getExtraField(0);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD2):
        field = Global::getInstance()->getExtraField(1);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD3):
        field = Global::getInstance()->getExtraField(2);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    case(FIELD4):
        field = Global::getInstance()->getExtraField(3);
        ui->customPlot->yAxis->setLabel(field.axisLabel);
        break;
    default:
        assert(false);
        break;
    }

    //
    bool buildGlobalPlot = (selectionGraph->isEmpty());

    set<Group> groups;
    map<Group,vector<SelectionGraphNode*> > mapGroupToNodes;
    map<Group,vector<SelectionGraphEdge*> > mapGroupToEdges;
    set<Group>::iterator groupIterator;
    selectionGraph->groupNodesAndEdgeByColor(groups,mapGroupToNodes,mapGroupToEdges);
    map<Group,QCPGraph*> mapGroupGraph;

    //
    set<Group> notEmptyGroups;
    map<Group,vector<SelectionGraphNode*> > tempMapGroupToNodes;

    if(buildGlobalPlot){
        QPen pen;
        QCPGraph* graph = ui->customPlot->addGraph();
        QColor color(0,0,0);
        mapGroupGraph[Group(color)] = graph;
        color.setAlphaF(0.05);
        pen.setColor(color);
        graph->setPen(pen);
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCP::ssDisc);
        graph->setScatterSize(10);
    }
    else{
        //
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            vector<SelectionGraphNode*> &groupNodes = mapGroupToNodes[*groupIterator];
            vector<SelectionGraphNode*> validGroupNodes;
            int numGroupNodes = groupNodes.size();

            for(int i = 0 ; i < numGroupNodes ; ++i){
                SelectionGraphNode* node = groupNodes.at(i);
                if(node->inDegree() + node->outDegree() == 0)
                    validGroupNodes.push_back(node);
            }

            vector<SelectionGraphEdge*> &groupEdges = mapGroupToEdges[*groupIterator];
            if(groupEdges.size() + validGroupNodes.size() > 0){
                notEmptyGroups.insert(*groupIterator);
                tempMapGroupToNodes[*groupIterator] = validGroupNodes;
            }
        }

        groups.clear();
        groups = notEmptyGroups;
        mapGroupToNodes.clear();
        mapGroupToNodes = tempMapGroupToNodes;

        //
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            QPen pen;
            QCPGraph* graph = ui->customPlot->addGraph();
            graph->setLineStyle(QCPGraph::lsNone);
            graph->setScatterStyle(QCP::ssDisc);
            graph->setScatterSize(10);

            Group group = *groupIterator;

            QColor color = group.getColor();
            mapGroupGraph[group] = graph;
            color.setAlphaF(0.3);
            pen.setColor(color);
            graph->setPen(pen);
        }
    }

    //int numberOfTrip = selectedTrips->size();
    map<Group,pair<QVector<double>,QVector<double> > > mapGroupData;
    if(buildGlobalPlot){
        int numberOfTrips = selectedTrips->size();
        //QVector<double> x(numberOfTrips), y(numberOfTrips);
        QVector<double> x, y;
        mapGroupData[QColor(0,0,0)] = make_pair(x,y);
    }
    else{
        QVector<double> x, y;
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            Group group = *groupIterator;

            mapGroupData[group.getColor()] = make_pair(x,y);

        }
    }

    // add graphs with different scatter styles:
    KdTrip::TripSet::iterator it = selectedTrips->begin();
    for (; it != selectedTrips->end(); ++it) {
        const KdTrip::Trip * trip = *it;
        QPointF coords = getCoords(trip);

        if(buildGlobalPlot){
            pair<QVector<double>,QVector<double> > &data =
                    mapGroupData[QColor(0,0,0)];
            QVector<double> &x = data.first;
            QVector<double> &y = data.second;
            x << coords.x();
            y << coords.y();
        }
        else{
            for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
                Group currentGroup = *groupIterator;

                assert(mapGroupToNodes.count(currentGroup) > 0 && mapGroupToEdges.count(currentGroup) > 0);

                if(tripSatisfiesConstraints(trip, mapGroupToNodes[currentGroup],mapGroupToEdges[currentGroup])){
                    pair<QVector<double>,QVector<double> > &data =
                            mapGroupData[currentGroup.getColor()];
                    QVector<double> &x = data.first;
                    QVector<double> &y = data.second;
                    x << coords.x();
                    y << coords.y();
                    continue; // make sure the point is only added once
                }
            }
        }
    }

    if(buildGlobalPlot){
        pair<QVector<double>,QVector<double> > &data =
                mapGroupData[QColor(0,0,0)];
        QVector<double> &x = data.first;
        QVector<double> &y = data.second;
        QCPGraph* graph = mapGroupGraph[QColor(0,0,0)];
        graph->setData(x, y);
        graph->rescaleAxes(true);
    }
    else{
        for(groupIterator = groups.begin() ; groupIterator != groups.end() ; ++groupIterator){
            Group currentGroup = *groupIterator;
            pair<QVector<double>,QVector<double> > &data =
                    mapGroupData[currentGroup.getColor()];
            QVector<double> &x = data.first;
            QVector<double> &y = data.second;
            QCPGraph* graph = mapGroupGraph[currentGroup.getColor()];
            graph->setData(x, y);
            graph->rescaleAxes(true);
        }
    }

    //
    int numGraphs = ui->customPlot->graphCount();
    for(int i = 0 ; i < numGraphs ; ++i){
        ui->customPlot->graph(i)->rescaleAxes(false,true);
    }
    //ui->customPlot->yAxis->scaleRange(1.1, ui->customPlot->yAxis->range().center());
    ui->customPlot->setRangeDrag(Qt::Horizontal|Qt::Vertical);
    ui->customPlot->setRangeZoom(Qt::Horizontal|Qt::Vertical);
    ui->customPlot->setInteractions(QCustomPlot::iRangeDrag | QCustomPlot::iRangeZoom | QCustomPlot::iSelectAxes |
                                    QCustomPlot::iSelectLegend | QCustomPlot::iSelectPlottables | QCustomPlot::iSelectTitle);

    //
    ui->customPlot->replot();
}
示例#11
0
void LiftDragPlot::updatePlot()
{
    clearPlottables();
    clearItems();

    xAxis->setLabel(tr("Drag Coefficient"));
    yAxis->setLabel(tr("Lift Coefficient"));

    double lower = mMainWindow->rangeLower();
    double upper = mMainWindow->rangeUpper();

    QVector< double > t, x, y;

    double xMin, xMax;
    double yMin, yMax;

    int start = mMainWindow->findIndexBelowT(lower) + 1;
    int end   = mMainWindow->findIndexAboveT(upper);

    double s10 = 0, s01 = 0, s20 = 0, s11 = 0;
    double s21 = 0, s30 = 0, s40 = 0;

    bool first = true;
    for (int i = start; i < end; ++i)
    {
        const DataPoint &dp = mMainWindow->dataPoint(i);

        t.append(dp.t);
        x.append(dp.drag);
        y.append(dp.lift);

        if (first)
        {
            xMax = x.back();
            yMax = y.back();

            first = false;
        }
        else
        {
            if (x.back() > xMax) xMax = x.back();
            if (y.back() > yMax) yMax = y.back();
        }

        s10 += dp.lift;
        s01 += dp.drag;
        s20 += dp.lift * dp.lift;
        s11 += dp.lift * dp.drag;
        s21 += dp.lift * dp.lift * dp.drag;
        s30 += dp.lift * dp.lift * dp.lift;
        s40 += dp.lift * dp.lift * dp.lift * dp.lift;
    }

    QCPCurve *curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::lightGray, mMainWindow->lineThickness()));
    curve->setLineStyle(QCPCurve::lsNone);
    curve->setScatterStyle(QCPScatterStyle::ssDisc);
    addPlottable(curve);

    setViewRange(xMax, yMax);

    // Update plot limits
    xMin = xAxis->range().lower;
    xMax = xAxis->range().upper;

    yMin = yAxis->range().lower;
    yMax = yAxis->range().upper;

    if (mMainWindow->markActive())
    {
        int i1 = mMainWindow->findIndexBelowT(mMainWindow->markEnd()) + 1;
        int i2 = mMainWindow->findIndexAboveT(mMainWindow->markEnd()) - 1;

        const DataPoint &dp1 = mMainWindow->dataPoint(i1);
        const DataPoint &dp2 = mMainWindow->dataPoint(i2);

        QVector< double > xMark, yMark;

        if (mMainWindow->markEnd() - dp1.t < dp2.t - mMainWindow->markEnd())
        {
            xMark.append(dp1.drag);
            yMark.append(dp1.lift);
        }
        else
        {
            xMark.append(dp2.drag);
            yMark.append(dp2.lift);
        }

        QCPGraph *graph = addGraph();
        graph->setData(xMark, yMark);
        graph->setPen(QPen(Qt::black, mMainWindow->lineThickness()));
        graph->setLineStyle(QCPGraph::lsNone);
        graph->setScatterStyle(QCPScatterStyle::ssDisc);
    }

    // x = ay^2 + c
    const double m = 1 / mMainWindow->maxLD();
    const double c = mMainWindow->minDrag();
    const double a = m * m / (4 * c);

    // Draw tangent line
    const double yt = sqrt(c / a);

    if (a != 0)
    {
        x.clear();
        y.clear();

        x << m * yMin << m * yMax;
        y << yMin << yMax;

        QCPGraph *graph = addGraph();
        graph->setData(x, y);
        graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));
    }

    // Draw minimum drag
    x.clear();
    y.clear();

    x << mMainWindow->minDrag() << mMainWindow->minDrag();
    y << yMin << yMax;

    QCPGraph *graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));

    // Draw maximum lift
    x.clear();
    y.clear();

    x << xMin << xMax;
    y << mMainWindow->maxLift() << mMainWindow->maxLift();

    graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::blue, mMainWindow->lineThickness(), Qt::DashLine));

    // Draw saved curve
    t.clear();
    x.clear();
    y.clear();

    for (int i = 0; i <= 100; ++i)
    {
        const double yy = yMin + (yMax - yMin) / 100 * i;

        t.append(yy);
        x.append(a * yy * yy + c);
        y.append(yy);
    }

    curve = new QCPCurve(xAxis, yAxis);
    curve->setData(t, x, y);
    curve->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    addPlottable(curve);

    // Draw dot at maximum L/D
    x.clear();
    y.clear();

    x << a * yt * yt + c;
    y << yt;

    graph = addGraph();
    graph->setData(x, y);
    graph->setPen(QPen(Qt::red, mMainWindow->lineThickness()));
    graph->setLineStyle(QCPGraph::lsNone);
    graph->setScatterStyle(QCPScatterStyle::ssDisc);

    // Add label to show equation for saved curve
    QCPItemText *textLabel = new QCPItemText(this);
    addItem(textLabel);

    QPainter painter(this);
    double mmPerPix = (double) painter.device()->widthMM() / painter.device()->width();

    double xRatioPerPix = 1.0 / axisRect()->width();
    double xRatioPerMM = xRatioPerPix / mmPerPix;

    double yRatioPerPix = 1.0 / axisRect()->height();
    double yRatioPerMM = yRatioPerPix / mmPerPix;

    textLabel->setPositionAlignment(Qt::AlignBottom|Qt::AlignRight);
    textLabel->setTextAlignment(Qt::AlignRight);
    textLabel->position->setType(QCPItemPosition::ptAxisRectRatio);
    textLabel->position->setCoords(1 - 5 * xRatioPerMM,
                                   1 - 5 * yRatioPerMM);
    textLabel->setText(
                QString("Minimum drag = %1\nMaximum lift = %2\nMaximum L/D = %3")
                    .arg(fabs(c))
                    .arg(mMainWindow->maxLift())
                    .arg(1/ m));

    replot();
}
示例#12
0
void MainWindow::setupExportTest(QCustomPlot *customPlot)
{
	QDir dir("./");
	dir.mkdir("export-test");
	dir.cd("export-test");

	// test cosmetic/non-cosmetic pen and scaling of export functions:
	int n = 10;
	for (int penWidth=0; penWidth<5; ++penWidth)
	{
		QVector<double> x(n), y(n);
		for (int i=0; i<n; ++i)
		{
			x[i] = i;
			y[i] = qSin(i/2.0)+penWidth;
		}
		customPlot->addGraph();
		customPlot->graph()->setData(x, y);
		customPlot->graph()->setPen(QPen(Qt::blue, penWidth));
	}
	customPlot->rescaleAxes();
	qDebug() << customPlot->savePdf(dir.filePath("exportTest_cosmetic.pdf"), false, 500, 400);
	qDebug() << customPlot->savePdf(dir.filePath("exportTest_noncosmetic.pdf"), true, 500, 400);
	qDebug() << customPlot->savePng(dir.filePath("exportTest_1x.png"), 500, 400);
	qDebug() << customPlot->savePng(dir.filePath("exportTest_2x.png"), 500, 400, 2);
	qDebug() << customPlot->saveJpg(dir.filePath("exportTest_1x.jpg"), 500, 400);
	qDebug() << customPlot->saveJpg(dir.filePath("exportTest_2x.jpg"), 500, 400, 2);
	customPlot->clearPlottables();

	// test floating-point precision of vectorized (pdf) export:
	QCPGraph *graph = customPlot->addGraph();
	QVector<double> x, y;
	for (int i=1; i<100; ++i)
	{
		x << 1.0 - 1.0/(double)i;
		y << i;
	}
	x << 0.3 << 0.6; // point that should perfectly match grid
	y << 15 << 45; // point that should perfectly match grid
	graph->setData(x, y);
	graph->setLineStyle(QCPGraph::lsNone);
	graph->setScatterStyle(QCPScatterStyle::ssPlus);
	customPlot->xAxis->setRange(0, 1.1);
	customPlot->yAxis->setRange(0, 101);
	//customPlot->setAntialiasedElements(QCP::aeAll);
	qDebug() << customPlot->savePng(dir.filePath("float-precision-raster0.2x.png"), 500, 400, 0.2);
	qDebug() << customPlot->savePng(dir.filePath("float-precision-raster1x.png"), 500, 400);
	qDebug() << customPlot->savePng(dir.filePath("float-precision-raster5x.png"), 500, 400, 5);
	qDebug() << customPlot->savePdf(dir.filePath("float-precision-vector.pdf"), false, 500, 400);
	customPlot->clearPlottables();

	// test transparent/colored background:
	customPlot->addGraph();
	x.clear();
	y.clear();
	for (int i=0; i<100; ++i)
	{
		x << i;
		y << qSin(i/20.0);
	}
	customPlot->graph()->setData(x, y);
	customPlot->rescaleAxes();
	customPlot->setBackground(Qt::transparent);
	qDebug() << customPlot->savePng(dir.filePath("exportTest_bg_transparent.png"), 500, 400);
	qDebug() << customPlot->savePdf(dir.filePath("exportTest_bg_transparent.pdf"), true, 500, 400);
	customPlot->setBackground(QColor(100, 100, 155));
	qDebug() << customPlot->savePng(dir.filePath("exportTest_bg_color.png"), 500, 400);
	qDebug() << customPlot->savePdf(dir.filePath("exportTest_bg_color.pdf"), true, 500, 400);
	customPlot->clearPlottables();

	QTimer::singleShot(100, qApp, SLOT(quit()));
}