I’m beginner and i just code my first vtk plot link with QT.
This plot should represent the histogram of an image.
So the input data will just be a std::vector with a size of 65 536.
The problem that i encounter is the fact that this plot slow down the code a lot.
More, when the plot is done, moving axis or zooming into the plot is also slow (something like 0.5fps).
maybe i did something wrong. If not did someone know how can i speed this plot which should be really easy and really fast normally (like with matplotlib in python).
where plotW is an Object PlotWidget* plotW.
and displayW represent just a widget which display images.
image->getHisto() return the histogram as std::vector.
yes i realised after that this->ui->qvtkWidget->setRenderWindow(view->GetRenderWindow());
but same if i delete this line, nothing change. But the problem do not come from my code:
If i comment this->plotW->plotHistogram(&image->getHisto()) the code is fast. Im not event able to see any latences by eyes. With this line, the image and the histogram is display after 2s
Also i call plotHistogram just one time and all lines in this function take in average 2ms.
Is it possible that it’s slow because i compile vtk with BUILD_SHARED_LIBS with true (as dynamical librairy)?
I tried myself, and it’s slow just as you described. BUILD_SHARED_LIBS is definitely not the problem, vtkChartXY simply can’t render 65536 bins as fast as you need. I’m not surprised that matplotlib is faster, though.
I suspect that the only way to speed things up is to create a table that has fewer values than your histogram. For example, use only every 100th value. This isn’t an ideal solution, of course, because you lose detail.
You said that vtkChartXY is not able to render 65536 bins that fast. So i changed vtkChart::BAR by vtkChart::LINE and now the code is much faster. I think they are still some small latences but it’s clearly acceptable and moving axis now is much more fluid.
I have two questions for the futur.
The first one:
Do you know some other enum of vtkChart which can even be faster? maybe scatter?
the second question (which also contain two question):
as i want that the user can be able de manually choose the dynamical range on the plot of the graph, do you know how can i interact with it via a cursor maybe, and second how can i have a better control on the movement of axis (i dont want users can move the graph just by clicking on it. i would like to set up the graph at the beginning than, allow user to make some zoom but nothing more)
Computing a histogram is a slow operation since it requires ordering the data set for binning. Also, I wonder why do you need 65k+ bins. Tens of bins are more than enough to draw conclusions. Once the histogram is computed, plotting it in 2ms is a good figure. You can get 500fps with that. I don’t see any problems.
If your dataset is large, decimating it is a good strategy to get fast histograms. In petroleum industry we do this all the time. We have seismic cubes with around a trillion data cells. Histograms with only a 0.01% sampling rate or less are quite common.
I have 65k because the flux measured by a pixels on an image is coded into 16bits (8 bits for some cameras and format) 65k is qui small data for a computer and i compute the histogram my self.
It’s ok now. histograms are just one time of representation but a simple line can also do the job and it’s faster.
thanks. I will try to make a benchmark about which type of plots are faster later.