Results 1 to 14 of 14

Thread: QMatrix vs QWMatrix - porting Qt3 to Qt4

  1. #1
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QMatrix vs QWMatrix - porting Qt3 to Qt4

    Qt Code:
    1. void test()
    2. {
    3. QRect selection(5,5,2,2);
    4.  
    5. #if QT3
    6. QWMatrix m;
    7. m.scale(2,5);
    8. m.invert();
    9. #else
    10. m.scale(2,5);
    11. m.inverted();
    12. #endif
    13.  
    14. QRect r = m.mapRect(selection);
    15. }
    To copy to clipboard, switch view to plain text mode 

    Qt 3.3.2
    QRect r comes out as:
    x1=10
    y1=25
    x2=12
    y2=30

    Qt 4.1.2
    QRect r comes out as:
    x1=10
    y1=25
    x2=13
    y2=34


    I'm converting an application from 3.3.2 to 4.1.2 and this seems to be where my problem is coming from.

    Does anyone know why this is different and/or how i can fix it.
    Thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    IMO the real anwer should be:
    x1=10
    y1=25
    x2=14
    y2=35

    So Qt 4 is more accurate. The difference probably comes from some round offs.

    PS. I hope you realize that QMatrix::inverted() and QWMatrix::invert() don't change the original matrix only return the inverted matrix.

  3. #3
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Qt Code:
    1. void test()
    2. {
    3. QRect selection(10, 10, 20, 20);
    4.  
    5. #if QT3
    6. QWMatrix m;
    7. m.scale(128/350, 128/350);
    8. m = m.invert();
    9. #else
    10. m.scale(128/350, 128/350);
    11. m = m.inverted();
    12. #endif
    13.  
    14. QRect r = m.mapRect(selection);
    15. bool b = true;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thanks, I did know that and forgot to use it in the example I posted.

    Tell me if I'm wrong here:

    If an image were 128 x 128 and displayed on the screen as 350 x 350 and a user selects a region from the 350 x 350 say QRect(10, 10, 20, 20) then the above QRect r would be the rectangle corresponding to the original 128 x 128 image. correct?

    If this is the case, the Qt3 and Qt4 values for r are very different.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Quote Originally Posted by bitChanger
    If an image were 128 x 128 and displayed on the screen as 350 x 350 and a user selects a region from the 350 x 350 say QRect(10, 10, 20, 20) then the above QRect r would be the rectangle corresponding to the original 128 x 128 image. correct?
    IMO the above code will enlarge the rectangle, i.e. map region from 128x128 image to a region on 350x350 image.

    If this is the case, the Qt3 and Qt4 values for r are very different.
    As I wrote before, it might be caused by rounding errors. From the example in the first post, it looks like Qt4 is more accurate.

  5. #5
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    I'm not sure I'm explaining this enough.

    Let's say I have a QPixmap that is 128 x 128 and I use the above code without the (invert) stuff to transform the image into a larger 350 x 350 QPixmap to display on screen.

    Now I allow someone to select a region from the on screen image of QRect(10, 10, 20, 20).
    This selection region corresponds to a region from the 350 x 350 enlarged image.

    Now I would like to find out what the QRect region of the original 128 x 128 image would be.
    So I perform the above with the (invert) stuff and the result QRect (r) should be just that.

    The values of r, very more than rounding, they are REALLY different.
    Last edited by bitChanger; 10th April 2006 at 19:51.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Just in case you forgotten...

    Remember that
    Qt Code:
    1. m.scale(128/350, 128/350);
    To copy to clipboard, switch view to plain text mode 
    is equal to
    Qt Code:
    1. m.scale(0, 0);
    To copy to clipboard, switch view to plain text mode 

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

    bitChanger (10th April 2006)

  8. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Quote Originally Posted by bitChanger
    So I perform the above with the (invert) stuff and the result QRect (r) should be just that.
    Qt Code:
    1. QWMatrix m;
    2. m.scale(128/350, 128/350); // scale is < 1, so it should make the rectangle smaller
    3. m = m.invert(); // inverse matrix -> it should enlarge the rectangle now
    To copy to clipboard, switch view to plain text mode 

    Quote Originally Posted by bitChanger
    The values of r very more than rounding they are REALLY different.
    It depends when those errors were introduced. Could you provide some example dimensions?

  9. #8
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Qt Code:
    1. void test()
    2. {
    3. QRect selection(10, 10, 20, 20);
    4.  
    5. #if QT3
    6. QWMatrix m;
    7. m.scale(128.0/350.0, 128.0/350.0);
    8. m = m.invert();
    9. #else
    10. m.scale(128.0/350.0, 128.0/350.0);
    11. m = m.inverted();
    12. #endif
    13.  
    14. QRect r = m.mapRect(selection);
    15. }
    To copy to clipboard, switch view to plain text mode 

    If you just run this function using 3.3.2 and then 4.1.2 you can see that the values for variable r differ greatly.
    Is this not enough code to see the problem?

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Quote Originally Posted by bitChanger
    Is this not enough code to see the problem?
    I wouldn't call it a minimal, compilable example, but I did run it under Qt 3.3.6 and Qt 4.1.2 and got this:
    Qt Code:
    1. . x y w h
    2. Qt3 27 27 53 53
    3. Qt4 27 27 55 55
    To copy to clipboard, switch view to plain text mode 
    It's not a great difference. If you do the calculations by hand, you will see that Qt4's result is closer to the right answer.

    Quote Originally Posted by jacek
    Qt Code:
    1. QWMatrix m;
    2. m.scale(128/350, 128/350); // scale is < 1, so it should make the rectangle smaller
    3. m = m.invert(); // inverse matrix -> it should enlarge the rectangle now
    To copy to clipboard, switch view to plain text mode 
    On second thought, it just does what it should do.

  11. The following user says thank you to jacek for this useful post:

    bitChanger (10th April 2006)

  12. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Quote Originally Posted by jacek
    On second thought, it just does what it should do.
    Or maybe not... If you have a bigger pixmap and some rectangle on it, than on a smaller pixmap that rectangle should be smaller. While your matrix will make it bigger.

  13. #11
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    I still think I have a QMatrix vs QWMatrix problem here, but I'm at a loss.
    Here is a complete program that demonstrates my issue.

    Compile using Qt 3 to see how the application is supposed to work.
    This is simply an image with a rectangle in the middle for a reference point.
    While holding down the mouse button, drag the image.
    In Qt 3, the image point stays under the cursor and works as expected.

    Then compile in Qt 4.
    The image moves in the opposite direction and at an increased speed.

    Thank you for any help on this issue.
    Attached Files Attached Files

  14. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    It seems that matrices are correct. With both Qt3 and Qt4 I got the same values.

    IMO the problem is here:
    Qt Code:
    1. // determine direction of x move
    2. int x = 0;
    3. if (_rubberBandRect.width() <= 0)
    4. x = _movedRect.x()+selectRect.width()-1;
    5. else
    6. x = _movedRect.x()-selectRect.width()+1;
    7.  
    8. // determine direction of y move
    9. int y = 0;
    10. if (_rubberBandRect.height() <= 0)
    11. y = _movedRect.y()+selectRect.height()-1;
    12. else
    13. y = _movedRect.y()-selectRect.height()+1;
    14.  
    15. qDebug( "x=%d y=%d", x, y );
    To copy to clipboard, switch view to plain text mode 
    I'm not sure what is wrong yet, but probably width() and height() are always positive. Edit: no, they aren't.
    Last edited by jacek; 11th April 2006 at 16:06.

  15. #13
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    I need to find a solution to this problem and have yet to come up with even a workaround.

    So, I've submitted a support request to Trolltech.

    If someone has a solution for this, please post it.
    I will post the response from support when I hear back from them.


  16. #14
    Join Date
    Jan 2006
    Posts
    70
    Thanks
    13
    Thanked 5 Times in 5 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QMatrix vs QWMatrix - porting Qt3 to Qt4

    Here's the solution that I used for this problem.

    The problem here was scaling the area instead of points
    using QRect. In Qt 3 you could use set transformation on points and
    then you could transform the points to your desired scaling factor,
    whereas when you scale areas in Qt 4 it will be scaled twice as much as
    thus the effect that pixmap moves faster then expected.

    The best approach here is to use QPoint and then move the position of
    the pixmap according to the movement of the position of the mouse.

    Thanks to:
    Amrit Pal Singh, Support Engineer
    for this solution.
    Attached Files Attached Files

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.