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

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

上级 bb63f4e2
......@@ -655,13 +655,13 @@ namespace QTVOSM{
double dperx = dMx/(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
double dTarX = dperx * dCurrImgSize + dCurrImgSize/2;
double dTarY = dpery * dCurrImgSize + dCurrImgSize/2;
double dTarX = dperx * nCurrImgSize + nCurrImgSize/2;
double dTarY = dpery * nCurrImgSize + nCurrImgSize/2;
//!4.Calculat the World pixel coordinats of current view-center point
double dCurrX = dCurrImgSize*m_dCenterX+dCurrImgSize/2;
double dCurrY = dCurrImgSize*m_dCenterY+dCurrImgSize/2;
double dCurrX = nCurrImgSize*m_dCenterX+nCurrImgSize/2;
double dCurrY = nCurrImgSize*m_dCenterY+nCurrImgSize/2;
//!5.Calculat the World pixel coordinats of current view-left-top point
double nOffsetLT_x = (dCurrX-width()/2.0);
double nOffsetLT_y = (dCurrY-height()/2.0);
......@@ -689,13 +689,13 @@ namespace QTVOSM{
return false;
//!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
double dx = X-(width()/2.0);
double dy = Y-(height()/2.0);
//!3.Percentage -0.5 ~ 0.5 coord
double dImgX = dx/dCurrImgSize+m_dCenterX;
double dImgY = dy/dCurrImgSize+m_dCenterY;
double dImgX = dx/nCurrImgSize+m_dCenterX;
double dImgY = dy/nCurrImgSize+m_dCenterY;
//!4.to Mercator
double Mercator_x = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
double Mercator_y = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
......@@ -747,7 +747,7 @@ namespace QTVOSM{
/*!
\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
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!
\fn tilesviewer::CV_MK2World
......@@ -764,11 +764,11 @@ namespace QTVOSM{
double dperx = mx/(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
*px = dperx * dCurrImgSize + dCurrImgSize/2;
*py = dpery * dCurrImgSize + dCurrImgSize/2;
*px = dperx * nCurrImgSize + nCurrImgSize/2;
*py = dpery * nCurrImgSize + nCurrImgSize/2;
return true;
}
......@@ -776,7 +776,7 @@ namespace QTVOSM{
/*!
\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
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!
\fn tilesviewer::CV_World2MK
......@@ -790,10 +790,10 @@ namespace QTVOSM{
{
if (!pmx||!pmy) return false;
//!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
double dImgX = x/dCurrImgSize - .5;
double dImgY = y/dCurrImgSize - .5;
double dImgX = x/nCurrImgSize - .5;
double dImgY = y/nCurrImgSize - .5;
//!3.to Mercator
*pmx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
*pmy = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
......@@ -804,7 +804,7 @@ namespace QTVOSM{
/*!
\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
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!
\fn tilesviewer::CV_LLA2World
......@@ -825,17 +825,17 @@ namespace QTVOSM{
double dperx = dMx/(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
*px = dperx * dCurrImgSize + dCurrImgSize/2;
*py = dpery * dCurrImgSize + dCurrImgSize/2;
*px = dperx * nCurrImgSize + nCurrImgSize/2;
*py = dpery * nCurrImgSize + nCurrImgSize/2;
return true;
}
/*!
\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
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!
\fn tilesviewer::CV_World2LLA
......@@ -849,10 +849,10 @@ namespace QTVOSM{
{
if (!plat||!plon) return false;
//!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
double dImgX = x/dCurrImgSize - .5;
double dImgY = y/dCurrImgSize - .5;
double dImgX = x/nCurrImgSize - .5;
double dImgY = y/nCurrImgSize - .5;
//!3.to Mercator
double mkx = cProjectionMercator::pi*cProjectionMercator::R*2*dImgX;
double mky = -cProjectionMercator::pi*cProjectionMercator::R*2*dImgY;
......@@ -867,7 +867,7 @@ namespace QTVOSM{
\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
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!
\fn tilesviewer::CV_DP2World
......@@ -881,16 +881,16 @@ namespace QTVOSM{
{
if (!px||!py) return false;
//!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
double dx = dX-(width()/2.0);
double dy = dY-(height()/2.0);
//!3.Percentage -0.5 ~ 0.5 coord
double dImgX = dx/dCurrImgSize+m_dCenterX;
double dImgY = dy/dCurrImgSize+m_dCenterY;
double dImgX = dx/nCurrImgSize+m_dCenterX;
double dImgY = dy/nCurrImgSize+m_dCenterY;
//!4.Calculat the World pixel coordinats
*px = dImgX * dCurrImgSize + dCurrImgSize/2;
*py = dImgY * dCurrImgSize + dCurrImgSize/2;
*px = dImgX * nCurrImgSize + nCurrImgSize/2;
*py = dImgY * nCurrImgSize + nCurrImgSize/2;
return true;
}
......@@ -899,7 +899,7 @@ namespace QTVOSM{
\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
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!
\fn tilesviewer::CV_World2DP
......@@ -914,11 +914,11 @@ namespace QTVOSM{
if (!pdX||!pdY) return false;
//!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
double dCurrX = dCurrImgSize*m_dCenterX+dCurrImgSize/2;
double dCurrY = dCurrImgSize*m_dCenterY+dCurrImgSize/2;
double dCurrX = nCurrImgSize*m_dCenterX+nCurrImgSize/2;
double dCurrY = nCurrImgSize*m_dCenterY+nCurrImgSize/2;
//!3.Calculat the World pixel coordinats of current view-left-top point
double nOffsetLT_x = (dCurrX-width()/2.0);
double nOffsetLT_y = (dCurrY-height()/2.0);
......@@ -932,7 +932,7 @@ namespace QTVOSM{
/*!
\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,
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
at top-left, 0.5,0.5 at bottom-right
This approach is LEVEL RELATED!
......@@ -959,7 +959,7 @@ namespace QTVOSM{
/*!
\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,
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
at top-left, 0.5,0.5 at bottom-right
This approach is LEVEL RELATED!
......@@ -976,10 +976,10 @@ namespace QTVOSM{
if (!px || !py)
return false;
//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
*px = nx/dCurrImgSize - .5;
*py = ny/dCurrImgSize - .5;
*px = nx/nCurrImgSize - .5;
*py = ny/nCurrImgSize - .5;
return true;
}
......
......@@ -29,6 +29,10 @@ namespace QTVP_GEOMARKER{
{
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()));
QRectF rect = this->rect();
QPointF center = rect.center();
......
......@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{
{
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()));
QLineF l1 = this->line();
setLine(l1.x1() * ratio,l1.y1() * ratio,l1.x2() * ratio,l1.y2() * ratio);
......
......@@ -51,6 +51,10 @@ namespace QTVP_GEOMARKER{
{
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()));
QPolygonF p = this->polygon();
int sz = p.size();
......
......@@ -31,6 +31,10 @@ namespace QTVP_GEOMARKER{
{
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()));
QRectF rect = this->rect();
QPointF center = rect.center();
......
......@@ -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)
{
QList <QGraphicsItem * > it = this->items();
......@@ -69,7 +76,11 @@ namespace QTVP_GEOMARKER{
geoItemBase * base = dynamic_cast<geoItemBase *>(t);
if (base)
{
//when this function is called, base->level() is the old level from which
// current map is zoomed.
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);
}
}
......
......@@ -5,6 +5,20 @@
#include <QMap>
namespace QTVP_GEOMARKER{
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
{
Q_OBJECT
......
......@@ -32,6 +32,13 @@ namespace QTVP_GEOMARKER{
}
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
{
friend class geoGraphicsScene;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册