Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Painting on qimage or qpixmap taking time in real time plotting

Painting on qimage or qpixmap taking time in real time plotting

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 7.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sushmars
    wrote on last edited by
    #1

    if i plot ECG graph on qimage or qpixmap, i wont get proper heart beat (for 180 i will get 237 --- data is missing, painting taking time). If i comment draw graph, i am getting proper heart beat value. How to synchronize my application with graph. Which method makes less time consume.

    Thanks in advance...

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kxyu
      wrote on last edited by
      #2

      You should provide some code, it seems that you are doing something wrong as it should not take a lot of time to draw a simple graph (basically just put some pixels). the thing you can try is to separate reading a storing data from drawing graph into different threads.

      BTW if heartbeat is 237 instead of 180 doesn't it meant that a graph is kind of being drawn FASTER then it should be? maybe you just messed with an x axis

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sushmars
        wrote on last edited by
        #3

        from one thread i am getting ecg data through SPI and writing to pipe, calculating heart beat value . on another thread i am reading from that pipe and giving signal to slot. in slot i am calling DrawECG function which has painting things.
        in GUI (ui) i have qlable--ANSiscope_Graph_label

        in constructor i am declaring painter and pixmap

        @
        ECGImagePainter = new QPainter;
        ecgpixmap = new QPixmap(236,97);
        ecgpixmap->fill(Qt::white);

        in DrawECG(int data) function i am plotting ECG graph
        {
        ansiscopeMainWindow->ui->ANSiscope_Graph_label->setPixmap(*ecgpixmap);
        ECGImagePainter->begin(ecgpixmap);
        if(firstTimeECG)
        {
        ECGImagePainter->setPen(Qt::black);
        firstTimeECG = 0;
        }

            ECGgraph.Ypos = (ECGgraph.rightbottom.Y - ECGgraph.lefttop.Y) - (ECGgraph.Yunit * (data - ECGgraph.lYMin));
            ECGgraph.currentplot.X=ECGgraph.currentplot.X+1;
            ECGgraph.currentplot.Y=(int)ECGgraph.Ypos  ;
        
            if(ECGgraph.currentplot.X >= ECGgraph.rightbottom.X)
            {
                ECGgraph.currentplot.X = 0;
                ECGgraph.lastplot.X = 0;
                 ecgpixmap->fill(Qt::white);
        
            }
            ECGImagePainter->drawLine(ECGgraph.currentplot.X,ECGgraph.currentplot.Y,ECGgraph.lastplot.X,ECGgraph.lastplot.Y);
           
        
            ECGgraph.lastplot.X = ECGgraph.currentplot.X;
            ECGgraph.lastplot.Y = ECGgraph.currentplot.Y;
            ECGImagePainter->end();
        

        }
        @


        two threads are in while(1), switching by sched_yield()

        if i comment drawECG function in slot i will get proper results. if i plot ecg, ill get improper heart beat value.

        calling once setpixmap statement in a drawecg function, i will get result but no graph on screen.

        which is a real time plotting 1200 samples per second

        [EDIT: code formatting, please wrap in @-tags, Volker]

        1 Reply Last reply
        0
        • F Offline
          F Offline
          Franzk
          wrote on last edited by
          #4

          Best piece of advice: Don't try plotting at 1200 Hz. Gather your data and draw at a maximum of 60 Hz. 30 Hz may even be sufficient for proper data. Don't assume the operating system will provide you with the timing you need. As long as you're sure you get all your data, store it somewhere until the next drawing moment has arrived. Getting real-time graphs is all about knowing when not to draw.

          You can also optimize your drawing a bit by queueing up all lines you are going to draw, and feed them to QPainter::drawLines(), which is best practice in doing your own drawing anyway.

          "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • S Offline
            S Offline
            swhweng
            wrote on last edited by
            #5

            Greetings sushmars,

            I am working on a similar task these days - trying to accomplish best quality plot for ECG signal from

            physionet.org signals database.

            Have you succeed to plot the data as required ?

            Can you share the code for your application ? ( here or in private message )

            If not, could that be purchased if yes how much does it cost ?

            Thanks,
            Paul
            swdev@ovi.com

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved