提交 b6ec4a2d 编写于 作者: 丁劲犇's avatar 丁劲犇 😸

Add comments, change pow approad to 1<<X approach.

上级 bb63f4e2
...@@ -655,13 +655,13 @@ namespace QTVOSM{ ...@@ -655,13 +655,13 @@ namespace QTVOSM{
double dperx = dMx/(cProjectionMercator::pi*cProjectionMercator::R*2); double dperx = dMx/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dpery = -dMy/(cProjectionMercator::pi*cProjectionMercator::R*2); double dpery = -dMy/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!3.Calculat the World pixel coordinats //!3.Calculat the World pixel coordinats
double dTarX = dperx * dCurrImgSize + dCurrImgSize/2; double dTarX = dperx * nCurrImgSize + nCurrImgSize/2;
double dTarY = dpery * dCurrImgSize + dCurrImgSize/2; double dTarY = dpery * nCurrImgSize + nCurrImgSize/2;
//!4.Calculat the World pixel coordinats of current view-center point //!4.Calculat the World pixel coordinats of current view-center point
double dCurrX = dCurrImgSize*m_dCenterX+dCurrImgSize/2; double dCurrX = nCurrImgSize*m_dCenterX+nCurrImgSize/2;
double dCurrY = dCurrImgSize*m_dCenterY+dCurrImgSize/2; double dCurrY = nCurrImgSize*m_dCenterY+nCurrImgSize/2;
//!5.Calculat the World pixel coordinats of current view-left-top point //!5.Calculat the World pixel coordinats of current view-left-top point
double nOffsetLT_x = (dCurrX-width()/2.0); double nOffsetLT_x = (dCurrX-width()/2.0);
double nOffsetLT_y = (dCurrY-height()/2.0); double nOffsetLT_y = (dCurrY-height()/2.0);
...@@ -689,13 +689,13 @@ namespace QTVOSM{ ...@@ -689,13 +689,13 @@ namespace QTVOSM{
return false; return false;
//!1.Current World Pixel Size, connected to nLevel //!1.Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.current DP according to center //!2.current DP according to center
double dx = X-(width()/2.0); double dx = X-(width()/2.0);
double dy = Y-(height()/2.0); double dy = Y-(height()/2.0);
//!3.Percentage -0.5 ~ 0.5 coord //!3.Percentage -0.5 ~ 0.5 coord
double dImgX = dx/dCurrImgSize+m_dCenterX; double dImgX = dx/nCurrImgSize+m_dCenterX;
double dImgY = dy/dCurrImgSize+m_dCenterY; double dImgY = dy/nCurrImgSize+m_dCenterY;
//!4.to Mercator //!4.to Mercator
double Mercator_x = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX; double Mercator_x = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
double Mercator_y = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY; double Mercator_y = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
...@@ -747,7 +747,7 @@ namespace QTVOSM{ ...@@ -747,7 +747,7 @@ namespace QTVOSM{
/*! /*!
\brief convert Mercator to World. World Points is according to current level, \brief convert Mercator to World. World Points is according to current level,
point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_MK2World \fn tilesviewer::CV_MK2World
...@@ -764,11 +764,11 @@ namespace QTVOSM{ ...@@ -764,11 +764,11 @@ namespace QTVOSM{
double dperx = mx/(cProjectionMercator::pi*cProjectionMercator::R*2); double dperx = mx/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dpery = -my/(cProjectionMercator::pi*cProjectionMercator::R*2); double dpery = -my/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.Calculat the World pixel coordinats //!2.Calculat the World pixel coordinats
*px = dperx * dCurrImgSize + dCurrImgSize/2; *px = dperx * nCurrImgSize + nCurrImgSize/2;
*py = dpery * dCurrImgSize + dCurrImgSize/2; *py = dpery * nCurrImgSize + nCurrImgSize/2;
return true; return true;
} }
...@@ -776,7 +776,7 @@ namespace QTVOSM{ ...@@ -776,7 +776,7 @@ namespace QTVOSM{
/*! /*!
\brief convert World to Mercator. World Points is according to current level, \brief convert World to Mercator. World Points is according to current level,
point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_World2MK \fn tilesviewer::CV_World2MK
...@@ -790,10 +790,10 @@ namespace QTVOSM{ ...@@ -790,10 +790,10 @@ namespace QTVOSM{
{ {
if (!pmx||!pmy) return false; if (!pmx||!pmy) return false;
//!1.Current World Pixel Size, connected to nLevel //!1.Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.Percentage -0.5 ~ 0.5 coord //!2.Percentage -0.5 ~ 0.5 coord
double dImgX = x/dCurrImgSize - .5; double dImgX = x/nCurrImgSize - .5;
double dImgY = y/dCurrImgSize - .5; double dImgY = y/nCurrImgSize - .5;
//!3.to Mercator //!3.to Mercator
*pmx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX; *pmx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
*pmy = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY; *pmy = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
...@@ -804,7 +804,7 @@ namespace QTVOSM{ ...@@ -804,7 +804,7 @@ namespace QTVOSM{
/*! /*!
\brief convert LLA to world. World Points is according to current level, \brief convert LLA to world. World Points is according to current level,
point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_LLA2World \fn tilesviewer::CV_LLA2World
...@@ -825,17 +825,17 @@ namespace QTVOSM{ ...@@ -825,17 +825,17 @@ namespace QTVOSM{
double dperx = dMx/(cProjectionMercator::pi*cProjectionMercator::R*2); double dperx = dMx/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dpery = -dMy/(cProjectionMercator::pi*cProjectionMercator::R*2); double dpery = -dMy/(cProjectionMercator::pi*cProjectionMercator::R*2);
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!3.Calculat the World pixel coordinats //!3.Calculat the World pixel coordinats
*px = dperx * dCurrImgSize + dCurrImgSize/2; *px = dperx * nCurrImgSize + nCurrImgSize/2;
*py = dpery * dCurrImgSize + dCurrImgSize/2; *py = dpery * nCurrImgSize + nCurrImgSize/2;
return true; return true;
} }
/*! /*!
\brief convert world to LLA. World Points is according to current level, \brief convert world to LLA. World Points is according to current level,
point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_World2LLA \fn tilesviewer::CV_World2LLA
...@@ -849,10 +849,10 @@ namespace QTVOSM{ ...@@ -849,10 +849,10 @@ namespace QTVOSM{
{ {
if (!plat||!plon) return false; if (!plat||!plon) return false;
//!1.Current World Pixel Size, connected to nLevel //!1.Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.Percentage -0.5 ~ 0.5 coord //!2.Percentage -0.5 ~ 0.5 coord
double dImgX = x/dCurrImgSize - .5; double dImgX = x/nCurrImgSize - .5;
double dImgY = y/dCurrImgSize - .5; double dImgY = y/nCurrImgSize - .5;
//!3.to Mercator //!3.to Mercator
double mkx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX; double mkx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
double mky = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY; double mky = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
...@@ -867,7 +867,7 @@ namespace QTVOSM{ ...@@ -867,7 +867,7 @@ namespace QTVOSM{
\brief convert Device Points to World. Device Points is according to current viewport, \brief convert Device Points to World. Device Points is according to current viewport,
point(0,0) stay at the top-left, point (width-1,height-1) in bottom-right. World Points is according point(0,0) stay at the top-left, point (width-1,height-1) in bottom-right. World Points is according
to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right, to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right,
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_DP2World \fn tilesviewer::CV_DP2World
...@@ -881,16 +881,16 @@ namespace QTVOSM{ ...@@ -881,16 +881,16 @@ namespace QTVOSM{
{ {
if (!px||!py) return false; if (!px||!py) return false;
//!1.Current World Pixel Size, connected to nLevel //!1.Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.current DP according to center //!2.current DP according to center
double dx = dX-(width()/2.0); double dx = dX-(width()/2.0);
double dy = dY-(height()/2.0); double dy = dY-(height()/2.0);
//!3.Percentage -0.5 ~ 0.5 coord //!3.Percentage -0.5 ~ 0.5 coord
double dImgX = dx/dCurrImgSize+m_dCenterX; double dImgX = dx/nCurrImgSize+m_dCenterX;
double dImgY = dy/dCurrImgSize+m_dCenterY; double dImgY = dy/nCurrImgSize+m_dCenterY;
//!4.Calculat the World pixel coordinats //!4.Calculat the World pixel coordinats
*px = dImgX * dCurrImgSize + dCurrImgSize/2; *px = dImgX * nCurrImgSize + nCurrImgSize/2;
*py = dImgY * dCurrImgSize + dCurrImgSize/2; *py = dImgY * nCurrImgSize + nCurrImgSize/2;
return true; return true;
} }
...@@ -899,7 +899,7 @@ namespace QTVOSM{ ...@@ -899,7 +899,7 @@ namespace QTVOSM{
\brief convert World to Device Points. Device Points is according to current viewport, \brief convert World to Device Points. Device Points is according to current viewport,
point(0,0) stay at the top-left, point (width-1,height-1) in bottom-right. World Points is according point(0,0) stay at the top-left, point (width-1,height-1) in bottom-right. World Points is according
to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right, to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right,
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18 the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18
This approach is devided into several steps, and it is LEVEL RELATED! This approach is devided into several steps, and it is LEVEL RELATED!
\fn tilesviewer::CV_World2DP \fn tilesviewer::CV_World2DP
...@@ -914,11 +914,11 @@ namespace QTVOSM{ ...@@ -914,11 +914,11 @@ namespace QTVOSM{
if (!pdX||!pdY) return false; if (!pdX||!pdY) return false;
//!1.Current World Pixel Size, connected to nLevel //!1.Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//!2.Calculat the World pixel coordinats of current view-center point //!2.Calculat the World pixel coordinats of current view-center point
double dCurrX = dCurrImgSize*m_dCenterX+dCurrImgSize/2; double dCurrX = nCurrImgSize*m_dCenterX+nCurrImgSize/2;
double dCurrY = dCurrImgSize*m_dCenterY+dCurrImgSize/2; double dCurrY = nCurrImgSize*m_dCenterY+nCurrImgSize/2;
//!3.Calculat the World pixel coordinats of current view-left-top point //!3.Calculat the World pixel coordinats of current view-left-top point
double nOffsetLT_x = (dCurrX-width()/2.0); double nOffsetLT_x = (dCurrX-width()/2.0);
double nOffsetLT_y = (dCurrY-height()/2.0); double nOffsetLT_y = (dCurrY-height()/2.0);
...@@ -932,7 +932,7 @@ namespace QTVOSM{ ...@@ -932,7 +932,7 @@ namespace QTVOSM{
/*! /*!
\brief convert percentage coord to world. World Points is according \brief convert percentage coord to world. World Points is according
to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right, to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right,
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18. Percentage coord is a the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18. Percentage coord is a
level-unretated coord, take a range -0.5~0.5, the world center in 0,0, -0.5.-0.5 level-unretated coord, take a range -0.5~0.5, the world center in 0,0, -0.5.-0.5
at top-left, 0.5,0.5 at bottom-right at top-left, 0.5,0.5 at bottom-right
This approach is LEVEL RELATED! This approach is LEVEL RELATED!
...@@ -959,7 +959,7 @@ namespace QTVOSM{ ...@@ -959,7 +959,7 @@ namespace QTVOSM{
/*! /*!
\brief convert world to percentage coord. World Points is according \brief convert world to percentage coord. World Points is according
to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right, to current level, point(0,0) stay at the left-top, point (SZ,SZ) in bottom-right,
SZ = pow(2.0,m_nLevel)*256, m_nLevel between 0 and 18. Percentage coord is a the pixel size is 2^m_nLevel*256, m_nLevel between 0 and 18. Percentage coord is a
level-unretated coord, take a range -0.5~0.5, the world center in 0,0, -0.5.-0.5 level-unretated coord, take a range -0.5~0.5, the world center in 0,0, -0.5.-0.5
at top-left, 0.5,0.5 at bottom-right at top-left, 0.5,0.5 at bottom-right
This approach is LEVEL RELATED! This approach is LEVEL RELATED!
...@@ -976,10 +976,10 @@ namespace QTVOSM{ ...@@ -976,10 +976,10 @@ namespace QTVOSM{
if (!px || !py) if (!px || !py)
return false; return false;
//Current World Pixel Size, connected to nLevel //Current World Pixel Size, connected to nLevel
double dCurrImgSize = pow(2.0,m_nLevel)*256; int nCurrImgSize = (1<<m_nLevel)*256;
//Percentage -0.5 ~ 0.5 coord //Percentage -0.5 ~ 0.5 coord
*px = nx/dCurrImgSize - .5; *px = nx/nCurrImgSize - .5;
*py = ny/dCurrImgSize - .5; *py = ny/nCurrImgSize - .5;
return true; return true;
} }
......
...@@ -29,6 +29,10 @@ namespace QTVP_GEOMARKER{ ...@@ -29,6 +29,10 @@ namespace QTVP_GEOMARKER{
{ {
if (vi() && nNewLevel != level()) if (vi() && nNewLevel != level())
{ {
/** Since the map is zooming from level() to current level,
* the map size zoom ratio can be calculated using pow below.
* We can get new coord for current zoom level by multiplicative.
*/
double ratio = pow(2.0,(nNewLevel - level())); double ratio = pow(2.0,(nNewLevel - level()));
QRectF rect = this->rect(); QRectF rect = this->rect();
QPointF center = rect.center(); QPointF center = rect.center();
......
...@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{ ...@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{
{ {
if (vi() && nNewLevel != level()) if (vi() && nNewLevel != level())
{ {
/** Since the map is zooming from level() to current level,
* the map size zoom ratio can be calculated using pow below.
* We can get new coord for current zoom level by multiplicative.
*/
double ratio = pow(2.0,(nNewLevel - level())); double ratio = pow(2.0,(nNewLevel - level()));
QLineF l1 = this->line(); QLineF l1 = this->line();
setLine(l1.x1() * ratio,l1.y1() * ratio,l1.x2() * ratio,l1.y2() * ratio); setLine(l1.x1() * ratio,l1.y1() * ratio,l1.x2() * ratio,l1.y2() * ratio);
......
...@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{ ...@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{
{ {
if (vi() && nNewLevel != level()) if (vi() && nNewLevel != level())
{ {
/** Since the map is zooming from level() to current level,
* the map size zoom ratio can be calculated using pow below.
* We can get new coord for current zoom level by multiplicative.
*/
double ratio = pow(2.0,(nNewLevel - level())); double ratio = pow(2.0,(nNewLevel - level()));
QPolygonF p = this->polygon(); QPolygonF p = this->polygon();
int sz = p.size(); int sz = p.size();
......
...@@ -31,6 +31,10 @@ namespace QTVP_GEOMARKER{ ...@@ -31,6 +31,10 @@ namespace QTVP_GEOMARKER{
{ {
if (vi() && ncurrLevel != level()) if (vi() && ncurrLevel != level())
{ {
/** Since the map is zooming from level() to current level,
* the map size zoom ratio can be calculated using pow below.
* We can get new coord for current zoom level by multiplicative.
*/
double ratio = pow(2.0,(ncurrLevel - level())); double ratio = pow(2.0,(ncurrLevel - level()));
QRectF rect = this->rect(); QRectF rect = this->rect();
QPointF center = rect.center(); QPointF center = rect.center();
......
...@@ -61,6 +61,13 @@ namespace QTVP_GEOMARKER{ ...@@ -61,6 +61,13 @@ namespace QTVP_GEOMARKER{
} }
/**
* @brief sequentially call virtual function geoItemBase::adjust_coords for every geoItemBase object.
*
* Since the scene coord will be zoomed in / out together with level change, all graphics items' coords should
* be recalculated in time. the method adjust_item_coords will do this automatically,
* @param newLevel the level to which current map is zoomed.
*/
void geoGraphicsScene::adjust_item_coords(int newLevel) void geoGraphicsScene::adjust_item_coords(int newLevel)
{ {
QList <QGraphicsItem * > it = this->items(); QList <QGraphicsItem * > it = this->items();
...@@ -69,7 +76,11 @@ namespace QTVP_GEOMARKER{ ...@@ -69,7 +76,11 @@ namespace QTVP_GEOMARKER{
geoItemBase * base = dynamic_cast<geoItemBase *>(t); geoItemBase * base = dynamic_cast<geoItemBase *>(t);
if (base) if (base)
{ {
//when this function is called, base->level() is the old level from which
// current map is zoomed.
base->adjust_coords(newLevel); base->adjust_coords(newLevel);
//After adjust_coords above, the item "base" is considered to
// have a valid coord corresponds to current newLevel
base->setLevel(newLevel); base->setLevel(newLevel);
} }
} }
......
...@@ -5,6 +5,20 @@ ...@@ -5,6 +5,20 @@
#include <QMap> #include <QMap>
namespace QTVP_GEOMARKER{ namespace QTVP_GEOMARKER{
class geoItemBase; class geoItemBase;
/**
* @brief geoGraphicsScene shield the common item operations, such as addEllipse
* addPolygon, and so on. It provide user several new polymorphism method,
* for special geoItemBase classes. Item name will be indexed using a QMap object m_map_items
* so that user can get item pointers as soon as possible.
*
* The scene uses World Pixel Coordinate system, which has a commection between zoom level.
* You can learn more principle about coordinates in the comments of class viewer_interface. in zoom level 0,
* world pixel size is 256x256, level 1 is 512x512, level 18 is 67108864 x 67108864
* Since the scene coord will be zoomed in / out together with level change, all graphics items' coords should
* be recalculated in time. the method adjust_item_coords will do this automatically,
* and in this function, virtual function geoItemBase::adjust_coords will be called sequentially.
*
*/
class geoGraphicsScene : public QGraphicsScene class geoGraphicsScene : public QGraphicsScene
{ {
Q_OBJECT Q_OBJECT
......
...@@ -32,6 +32,13 @@ namespace QTVP_GEOMARKER{ ...@@ -32,6 +32,13 @@ namespace QTVP_GEOMARKER{
} }
class geoGraphicsScene; class geoGraphicsScene;
/**
* @brief class geoItemBase is the root base class for all geoGraphicsItems.
* this class has several function, include:
* 1.provide properties system, include name, font, color, user-defined props using key-value mapping.
* 2.provide a LABEL mechanism, which is tooking use of by geoGraphicsScene to display props on map.
* 3.defines 2 interface, for Inheritance classes, give them optunities to maintain coordinates change when zooming.
*/
class geoItemBase class geoItemBase
{ {
friend class geoGraphicsScene; friend class geoGraphicsScene;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册