What class or types can be used to do a real time image plot?

  • Hy everyone,
    I have a code in C that I need to upgrade, it is a seismic processing, that needs an interface and plot the seismic wave produced in real time, while processing, or every an X number of iterations. 0_1531331473632_Wave-Model-movie.gif
    Something similar to this figure as an example. As I´m new to Qt, I have no idea what plot class could do that, I believe it is possible to do it with Qt, just dont know how. Could anyone refer me some reading material, examples, codes, anything that could me point on the right direction for this project?
    The snapshots are saved as .bin files.
    Thanks a lot.

  • Lifetime Qt Champion

    The seismic wave animation might be an issue with the QtCharts/other plotting classes.
    Do you plan to have much larger image ?
    I was wondering if direct QImage manipulation would be fast enough and leaning towards a custom QPainter implementation.
    For a full blown high speed solution, OpenGLWidget comes to mind.

    How does the c code plot currently ? Direct screen buffer ?

  • @mrjj Hi, at the moment it doesn´t plot, it just creates a .bin file every 500 iterations and we have to use some other software to load and show the static image, I saw something similar done with python that plots in realtime, the guy put the plot inside the loop, and everytime the code makes a iteration it refreshes the plot.
    But my code will have to be implemented with C++ because we need performance, even planning on using OpenACC directives. I believe we cannot implement OpenACC with Qt, so I may use an interface made with Qt for setting the parameters, call the program, pick the input file etc. I have the idea of creating the .bin files with less iterations, maybe 100, then create a Qt program that could read these files from the folder and plot it as they are created. Not sure if it is the best solution.

  • Lifetime Qt Champion

    @Flavio-Mesquita said in What class or types can be used to do a real time image plot?:


    Well i think you can use it with Qt but it dubious you get accelerated gpu drawing out of the box if even possible.
    If the .bin files are some sort of image format ( like raw) , it might be possible to
    load with QImage and draw it.
    When you say , "need performance" is that on the data reading part or on the plotting part ?
    Unless saving to ramdisk, the slowest link will be the IO for the bin files.

    so goal is not live plotting but saving to bin files for later viewing?

  • @mrjj By performance I mean on the processing part, the Reverse Time Migration is quite heavy computationaly. If I use a simple input file, that is the subsurface velocity model, it is quick, lets say matter of few minutes, but if it is complicated it can take hours. Maybe live plotting is not necessary, if I have an application that keeps checking if there is a new raw .bin file on the folder and plot it, would solve the problem. So, u think QImage and Qpainter could do the job? The .bin files are not big, it ranges from 1 to 20 Mb.

  • Lifetime Qt Champion

    Ok, so the c++ speed gain would come from using threads?
    If the data input for QImage is only 20mb-ish i think it can handle it pretty well
    but it depends on your expected fps and the output size and how much pre-processing of the bin data is
    need before QImage will load it.
    It had pretty good speed with 640x480 images.

  • @mrjj said in What class or types can be used to do a real time image plot?:

    It had pretty good speed with 640x480 images.

    This size is perfect for me, do u have any examples of Qimage usage? Any book, tutorial, anything?

  • Lifetime Qt Champion


    Depending on what you need, did you consider using maybe CUDA with OpenGL to generate the images you want to show ?

    In any case, there are lots of examples using QImage in the Qt documentation. Depending on your needs the Mandelbrot example might be of interest.

  • Lifetime Qt Champion

    The docs are pretty good.
    Basically it allows direct access and depending on the format of bin files you need something like

    QImage* img = new QImage(640, 480, QImage::Format_RGB16);
    for (int y = 0; y < img->height(); y++)
        memcpy(img->scanLine(y), BinData[y], img->bytesPerLine());

    This is just pseudo code. Read about scanLine and friends in Docs
    QImage::Format_RGB16 is just one of several so there might be other that
    are closer to the .bin format layout.

    Its a often asked question on StackOverflow and also here

    but since i have zero idea of what your .bin contains its harder to suggest something direct.
    You most likely need to process the .bin to actually display it correctly.

  • @SGaist Hi, we considered using CUDA, but it is more complicated than OpenACC. We will give a try with it anyway to compare, I know it has better performance than OpenAcc, just don´t know how much better.

  • @mrjj Thanks, I´ll take a look at these examples and references, I´ll be coming with more questions soon. First thing is to put the code to run properly with C++. The interface I already have. Now it is just a matter of adapt the RTM code., when everything is set and running I´ll start the work on the plotting part.

  • Lifetime Qt Champion

    Good plan.
    also IF raw painting is too slow, its not too late there to go openGL or
    anything accelerated

Log in to reply