Results 1 to 6 of 6

Thread: Working with coordinates (QGraphicsScene/view)

  1. #1
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Working with coordinates (QGraphicsScene/view)

    Hi guys,

    I have a widget which is my GraphicsView's child. If the widget show 500 Nautical Miles than means the widget height is the same as 500NM in the scene. Whenever the user zooms in/out the scale unit has to change and the widget height must be appropriate(if the user scales few times the scale unit changes to 50NM(more less) and the widget height must be the same as 50NM in the scene, etc).

    For the time being I am trying to use coordinate maping:
    1) I take always the same 2 points(different only by one unit of one coordinate -> P1(10,10),P2(10,11)) from the view and map them to scene coordinates.
    2) Using the mapped coordinates I can calculate the distance of that 2 points in the scene and I get the relation between one viewport unit = NM;
    3) Unfortunately, this attitude has some errors.
    For example, while zooming in the distance between coordinates equals(more less):
    18666,7642,400,3000.. ???? (why 400? etc)
    At some point the distance is wrong; I checked it and found that the the distance calculation is ok, but the point mapping is wrong(when the user zooms in the distance (at some scale) is longer??)

    Do you agree that I am going in the good direction?
    Do you have an idea how calculate: viewport unit <-> scene unit in a different way?

    THANK YOU FOR ANY HELP

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  2. #2
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with coordinates (QGraphicsScene/view)

    Any ideas?

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  3. #3
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with coordinates (QGraphicsScene/view)

    Quote Originally Posted by maverick_pol View Post
    Any ideas?

    Kacper
    I have the experience made that the point and pixel not always correct display on QGraphicsView depending on screen resulution ... 1024 or more ...

    if i swap metric unit mm the result is better after i only set a zoom faktor to display it
    example :
    #define _FAKTOR_PIX_POINT_ 1.3
    result X _FAKTOR_PIX_POINT_ and the view is acceptable...
    on export unit / _FAKTOR_PIX_POINT_ to become mm

    if you print a A4 page on OpenOffice arial 10pt and a page QGraphicsView arial 10pt to become the same result the faktor is more as 1.1 >



    Qt Code:
    1. #define POINT_TO_CM(cm) ((cm)/28.3465058)
    2. #define POINT_TO_MM(mm) ((mm)/2.83465058)
    3. #define POINT_TO_DM(dm) ((dm)/283.465058)
    4. #define POINT_TO_INCH(inch) ((inch)/72.0)
    5. #define POINT_TO_PI(pi) ((pi)/12)
    6. #define POINT_TO_DD(dd) ((dd)/154.08124)
    7. #define POINT_TO_CC(cc) ((cc)/12.840103)
    8.  
    9. #define MM_TO_POINT(mm) ((mm)*2.83465058)
    10. #define CM_TO_POINT(cm) ((cm)*28.3465058)
    11. #define DM_TO_POINT(dm) ((dm)*283.465058)
    12. #define INCH_TO_POINT(inch) ((inch)*72.0)
    13. #define PI_TO_POINT(pi) ((pi)*12)
    14. #define DD_TO_POINT(dd) ((dd)*154.08124)
    15. #define CC_TO_POINT(cc) ((cc)*12.840103)
    16.  
    17. static inline qreal FopInt( const QString datain )
    18. {
    19. QString ctmp = datain;
    20. const QString data = ctmp.replace(" ","").trimmed();
    21. //////////qDebug() << "### request unit data->" << datain << " size->" << datain.size();
    22. qreal points = 0;
    23. if (data.size() < 1) {
    24. return points;
    25. }
    26. if (datain == "0") {
    27. return points;
    28. }
    29.  
    30. if ( data.endsWith( "pt" ) || data.endsWith( "px" ) ) {
    31. points = data.left( data.length() - 2 ).toDouble();
    32. } else if ( data.endsWith( "cm" ) ) {
    33. double value = data.left( data.length() - 2 ).toDouble();
    34. points = CM_TO_POINT( value );
    35. } else if ( data.endsWith( "em" ) ) {
    36. points = data.left( data.length() - 2 ).toDouble();
    37. } else if ( data.endsWith( "mm" ) ) {
    38. double value = data.left( data.length() - 2 ).toDouble();
    39. points = MM_TO_POINT( value );
    40. } else if ( data.endsWith( "dm" ) ) {
    41. double value = data.left( data.length() - 2 ).toDouble();
    42. points = DM_TO_POINT( value );
    43. } else if ( data.endsWith( "in" ) ) {
    44. double value = data.left( data.length() - 2 ).toDouble();
    45. points = INCH_TO_POINT( value );
    46. } else if ( data.endsWith( "inch" ) ) {
    47. double value = data.left( data.length() - 4 ).toDouble();
    48. points = INCH_TO_POINT( value );
    49. } else if ( data.endsWith( "pi" ) ) {
    50. double value = data.left( data.length() - 4 ).toDouble();
    51. points = PI_TO_POINT( value );
    52. } else if ( data.endsWith( "dd" ) ) {
    53. double value = data.left( data.length() - 4 ).toDouble();
    54. points = DD_TO_POINT( value );
    55. } else if ( data.endsWith( "cc" ) ) {
    56. double value = data.left( data.length() - 4 ).toDouble();
    57. points = CC_TO_POINT( value );
    58. } else {
    59. points = 0;
    60. }
    61. return points;
    62. }
    To copy to clipboard, switch view to plain text mode 


    * Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm
    * Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm
    * Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm

    Algorythm for calculating 0.377mm pixel from 1024x768 19 inch screen" ???

    from http://en.wikipedia.org/wiki/Pixel

  4. The following user says thank you to patrik08 for this useful post:

    maverick_pol (27th March 2008)

  5. #4
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with coordinates (QGraphicsScene/view)

    Hi,

    Interesting chunk of code. Just give me a bit of time to go throught it.
    My app can work on screens (14'',15'',17'',19'',21'',25'',27'',32''); default resolution is 1024x768, but can be bigger/smaller.
    Any other code/explanations appreciated.

    Correct me if I am wrong, but these are the sample results:
    * Screen Res: 1024x768, Diagonal Size: 19", Pixel size: 0.377mm
    * Screen Res: 800x600, Diagonal Size: 17", Pixel size: 0.4318mm
    * Screen Res: 640x480, Diagonal Size: 15", Pixel size: 0.4763mm
    Ok. Let's say I map view's PV(x1,y1) and get as the result scene coordinates PS(x2,y2). At some point PS(x2,y2) are not correct(not precise), then I should calculate the PS using the code above?
    So the faktor has to be more than 1.1 and that's why you define as fallows:
    #define _FAKTOR_PIX_POINT_ 1.3
    I am not 100% sure if totally understand the idea.

    THanks.

    Kacper
    Last edited by maverick_pol; 27th March 2008 at 08:17.
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

  6. #5
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with coordinates (QGraphicsScene/view)

    Quote Originally Posted by maverick_pol View Post
    Hi,
    I am not 100% sure if totally understand the idea.
    THanks.
    Kacper
    one Nautical Miles is 6526.37758266 point
    take from
    http://www.metric-conversions.org/cg...2&from=10&to=3

    now you can only find your zoom depending on how many NM you wand to display on a 1024 screen....

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

    maverick_pol (27th March 2008)

  8. #6
    Join Date
    May 2007
    Location
    Lublin, Poland
    Posts
    345
    Thanks
    40
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Working with coordinates (QGraphicsScene/view)

    Clear enought.

    THanks.

    Kacper
    Qt allows you to use everything you want
    wysota
    --------------------------------------------------------------------------------
    #if defined(Q_OS_UNIX) && defined(QT_DEBUG)
    abort(); // trap; generates core dump
    #else
    exit(1); // goodbye cruel world
    #endif

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.