PDA

View Full Version : Working with coordinates (QGraphicsScene/view)



maverick_pol
26th March 2008, 19:35
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

maverick_pol
27th March 2008, 08:15
Any ideas?

Kacper

patrik08
27th March 2008, 08:55
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 >





#define POINT_TO_CM(cm) ((cm)/28.3465058)
#define POINT_TO_MM(mm) ((mm)/2.83465058)
#define POINT_TO_DM(dm) ((dm)/283.465058)
#define POINT_TO_INCH(inch) ((inch)/72.0)
#define POINT_TO_PI(pi) ((pi)/12)
#define POINT_TO_DD(dd) ((dd)/154.08124)
#define POINT_TO_CC(cc) ((cc)/12.840103)

#define MM_TO_POINT(mm) ((mm)*2.83465058)
#define CM_TO_POINT(cm) ((cm)*28.3465058)
#define DM_TO_POINT(dm) ((dm)*283.465058)
#define INCH_TO_POINT(inch) ((inch)*72.0)
#define PI_TO_POINT(pi) ((pi)*12)
#define DD_TO_POINT(dd) ((dd)*154.08124)
#define CC_TO_POINT(cc) ((cc)*12.840103)

static inline qreal FopInt( const QString datain )
{
QString ctmp = datain;
const QString data = ctmp.replace(" ","").trimmed();
//////////qDebug() << "### request unit data->" << datain << " size->" << datain.size();
qreal points = 0;
if (data.size() < 1) {
return points;
}
if (datain == "0") {
return points;
}

if ( data.endsWith( "pt" ) || data.endsWith( "px" ) ) {
points = data.left( data.length() - 2 ).toDouble();
} else if ( data.endsWith( "cm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = CM_TO_POINT( value );
} else if ( data.endsWith( "em" ) ) {
points = data.left( data.length() - 2 ).toDouble();
} else if ( data.endsWith( "mm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = MM_TO_POINT( value );
} else if ( data.endsWith( "dm" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = DM_TO_POINT( value );
} else if ( data.endsWith( "in" ) ) {
double value = data.left( data.length() - 2 ).toDouble();
points = INCH_TO_POINT( value );
} else if ( data.endsWith( "inch" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = INCH_TO_POINT( value );
} else if ( data.endsWith( "pi" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = PI_TO_POINT( value );
} else if ( data.endsWith( "dd" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = DD_TO_POINT( value );
} else if ( data.endsWith( "cc" ) ) {
double value = data.left( data.length() - 4 ).toDouble();
points = CC_TO_POINT( value );
} else {
points = 0;
}
return points;
}




* 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

maverick_pol
27th March 2008, 09:01
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

patrik08
27th March 2008, 09:31
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/cgi-bin/util/conversion-chart.cgi?type=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....

maverick_pol
27th March 2008, 09:35
Clear enought.

THanks.

Kacper