how to speed up the replot?
Hello,
could you tell me please, how to make the replot action faster? At the moment, I delete all QwtPlotMarkers after the their coordinates were changed and create the new ones with new coordinates and replot them then (see code below). Would it be faster if I dont delete them, but only set the new x- and yValues and then replot? Or does the function "replot()" itself cause the slow draw behavior?
Thank you
best regards,
Vitali
Code:
//#############################################################
// this functions is responsible for creating circles( points) and setting their position on the plot
void mainFrame::drawIndividuals(PopulationT<double> *population){
// first delete all circles....
QList<QwtPlotItem*> topLevels;
topLevels << item;
}
qDeleteAll(topLevels);
//... then draw them all
for (unsigned i = 0; i < population->size(); ++i){
double xCoord = (*population)[ i ][ 0 ][0]; // read out the values of individuals in population
double yCoord = (*population)[ i ][ 1 ][0];
// create PlotMarkers to visualize the individuals
symb
->setBrush
(QBrush(Qt
::red, Qt
::SolidPattern));
// red, solid color symb
->setStyle
(QwtSymbol::Ellipse);
// it will be a circle symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(xCoord); // set the position of marker on the plot
mark->setYValue(yCoord);
char idx[5];
sprintf(idx,"%d", i);
mark->setTitle(idx); // set title to the marker, which afterwards helps to indicate the certain individual
//mark->setLabel(QwtText(idx));
mark->attach(d_plot);
}
d_plot->selected_Points.clear();
d_plot->selected_to_recombine.clear();
d_plot->replot();
}
Re: how to speed up the replot?
If number of markers didn't change of course it's a better idea just to change their coords and then do replot. But in any way replot() is the most time consuming part.
Re: how to speed up the replot?
Hello,
now I changed my code so that the Markers are not deleted every time, when their coords are changed, and recreated again, but just change the plot positions and then replot. Unfortunately it did not speed up the plot process. It still needs 4 seconds to replot 20 QwtPlotMarkers and a spectrogramm (which has no changes). I guess I do something wrong, because I cannot imagine that plotting 20 markers can last so long time!
Do you have other ideas or hints, how to make it faster?
Thank you
best regards,
Vitali
Code:
// this functions is responsible for creating circles( points) and setting their position on the plot
void mainFrame::drawIndividuals(PopulationT<double> *population){
// first delete redundant markers if the size of marker's list is bigger than the population size
while(list_of_markers.size() > population->size()){
list_of_markers[list_of_markers.size()-1]->detach();
list_of_markers.pop_back();
count_of_drawn--;
}
for (int i = 0; i < population->size(); ++i){
double xCoord = (*population)[ i ][ 0 ][0]; // read out the values of individuals in population
double yCoord = (*population)[ i ][ 1 ][0];
if(i > (count_of_drawn - 1)){ // if the size of plotted markers is less than the size of population, then create and plot further markers
// create PlotMarkers to visualize the individuals
symb
->setBrush
(QBrush(Qt
::red, Qt
::SolidPattern));
// red, solid color symb
->setStyle
(QwtSymbol::Ellipse);
// it will be a circle symb->setSize(5,5);
mark->setSymbol(*symb);
mark->setXValue(xCoord); // set the position of marker on the plot
mark->setYValue(yCoord);
char idx[5];
sprintf(idx,"%d", i);
mark->setTitle(idx); // set title to the marker, which afterwards helps to indicate the certain individual
//mark->setLabel(QwtText(idx));
mark->attach(d_plot);
// insert the new created marker into the marker list
list_of_markers.push_back(mark);
count_of_drawn++;
}
else{
list_of_markers[i]->setXValue(xCoord);
list_of_markers[i]->setYValue(yCoord);
}
}
d_plot->selected_Points.clear();
d_plot->selected_to_recombine.clear();
d_plot->replot();
}
Re: how to speed up the replot?
Please describe your plot composition and all elements that you have on this plot.
If plot have big amount of elements or spectrogram on it (redrawing spectrogram takes large amount of calculations and time even if value() impl. is quick then size of spectrogram is big) replot should take much time.
For spectrogram i suggest set repaint parameter to resizeOnly. As for markers and plot I suggest to draw markers on overlay widget. In this case you don't have to replot after changing their position, just redraw an overlay widget.
Re: how to speed up the replot?
Finally I have found out what was the reason for very slow plot behavior: I have set the flag
Code:
this->setAutoReplot(true);
for the QwtPlot and this was obviosly the reason for the slow replot, because after I deleted this line, the replot last far less than 1 second (in contrast to 4 seconds before). It is very fast now. Also the dragging of markers is now very fast and they are reploted all together at once, so that one cannot see the FOR loop, as it could be seen before.
best regards,
Vitali