Results 1 to 7 of 7

Thread: how to accelerate the replot?

  1. #1
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question how to accelerate the replot?

    Hello,

    I have implemented the dragging function of some QwtPlotMarkers by using the QwtPlotPicker ( see code below), but I'm not satisfied about the speed of replot, because when I move the items they don't move fluently but with jumps and I can also see the for loop in it, because first one item is moved then the second and so on. How can I move the selected items simultaneously? Help me please.

    Thank you

    best regards,

    Vitali

    Qt Code:
    1. // this function provides the ability to move items on the plot
    2. void Plot::cursorMoved( const QwtDoublePoint& Point){
    3.  
    4. if(_mf->getMode() == mainFrame::Recombination){ // allow to move the plot items only in Recombination phase
    5.  
    6. if(!selected_Points.empty()){ //if the list with selected items is not empty, then...
    7. for(int i=0; i< selected_Points.size(); ++i) {
    8. picker->setRubberBand(QwtPicker::NoRubberBand); // switch off the rubber band during drag process
    9. double delta_x = Point.x() - clickpos->x(); // calculate the x difference
    10. double delta_y = Point.y() - clickpos->y(); // calculate the y difference
    11.  
    12. unsigned idx=_mf->objFunction;
    13. double rangex1[2] = {optProbList[idx]->range_x1[0], optProbList[idx]->range_x1[1]};
    14. double rangex2[2] = {optProbList[idx]->range_x2[0], optProbList[idx]->range_x2[1]};
    15.  
    16. // set the new coordinates to the moved item, but check first whether the movement is within the valid area
    17. if((selected_Points[i]->xValue() + delta_x) < rangex1[1] && (selected_Points[i]->xValue() + delta_x) > rangex1[0]){
    18. selected_Points[i]->setXValue(selected_Points[i]->xValue() + delta_x);
    19. }
    20. if((selected_Points[i]->yValue() + delta_y) < rangex2[1] && (selected_Points[i]->yValue() + delta_y) > rangex2[0]){
    21. selected_Points[i]->setYValue(selected_Points[i]->yValue() + delta_y);
    22. }
    23. // check which index does this selected item have
    24. int index = (selected_Points[i]->title().text().toInt()); // transform from string to integer
    25. _mf->updateChromosome( selected_Points[i]->value(),index); // update the individuals with new values
    26. }
    27. this->replot(); // replot the plot widget after the selected point was moved
    28. }
    29. else{
    30. picker->setRubberBand(QwtPicker::RectRubberBand); // switch on the rectangle rubber band
    31. }
    32. clickpos = new QwtDoublePoint(Point); // update the reference point
    33. }
    34. else return;
    35. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to accelerate the replot?

    Dragging something on a plot widget needs to be implemented as overlay widget ( like text and rubberband of a picker ). Another ( less optimal ) solution is to introduce a pixmap cache for all plot items below your marker and reimplement YourPlot::drawItems().

    The way you want to implement dragging only works fast enough for simple scenes without much data.

    Uwe

  3. #3
    Join Date
    Nov 2009
    Posts
    94
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to accelerate the replot?

    Uwe, thank you for your reply.

    You told me already, that I have to implemente it as overlay widget, but I don't know what do you mean with "overlay widget".
    By dragging a rectangle around multiple items I get the selected items in my list/vector of QwtPlotMarkers, now how should I implement the overlay widget, which will acomplish the movement of them? It would be very helpful, if you provide more details on "overlay widget". Thank you.

    best regards,

    Vitali

  4. #4
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: how to accelerate the replot?

    Overlay widget means widget which is placed and drawn above qwtplot, it is its
    children but it's not a qwtplot item. QwtPlotMarker is an plot item. So you must
    replot whole plot just to drag one item. As it was said before performance speed
    in this case should be suitable only if scene is very simple.

    1) You can create widget with transparent background, draw markers on it (or some simple models of them like crosses or dots)
    in some kind of drawing zone (like rect of your selection) or resize this widget to size of selection rect and raise() it.
    2) With mouse dragging you simply move your widget around your plot canvas (it will look like you moving copy of markers around)
    3) After mouse realease calculate coordinates, place markers there and replot the plot


    http://wiki.qtcentre.org/index.php?title=Widget_Overlay - this is example of overlay widget. Instead of simple line you can draw some kind of "markers" of your markers on this widget
    Last edited by KosyakOFF; 9th December 2009 at 14:17.

  5. The following user says thank you to KosyakOFF for this useful post:

    rambo83 (11th December 2009)

  6. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to accelerate the replot?

    Probably the easiest implementation is using one of the internal overlay widgets of a QwtPlotPicker ( f.e. reimplementing YourPicker::drawRubberband() ).

    Uwe

  7. The following user says thank you to Uwe for this useful post:

    rambo83 (11th December 2009)

  8. #6
    Join Date
    Sep 2009
    Location
    Tucson, AZ, USA
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to accelerate the replot?

    Hello,

    Can anyone tell me if there is another place where I can get access to the code for this overlay widget example? The Wiki is still down. Does anyone have the example code that they could email me?

    Thanks, rmk

  9. #7
    Join Date
    Apr 2008
    Posts
    32
    Thanks
    3
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: how to accelerate the replot?

    Type in google "qt overlay widget", second or third link should lead to this Wiki. Click on "Cached" near link to Wiki and in opened window "Text only version" (top right corner of the page).

  10. The following user says thank you to KosyakOFF for this useful post:

    rmk (17th March 2010)

Similar Threads

  1. Replies: 0
    Last Post: 23rd November 2009, 10:43
  2. Replies: 1
    Last Post: 4th November 2009, 22:14
  3. Replies: 8
    Last Post: 8th April 2009, 19:51
  4. Replot large wav file data
    By Sachtech in forum Qwt
    Replies: 1
    Last Post: 6th January 2009, 09:12
  5. Accelerate Widget Painting
    By jpujolf in forum Qt Programming
    Replies: 0
    Last Post: 23rd September 2008, 15:33

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.