commit
ba0bdbd07e
1 changed files with 98 additions and 99 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
*
|
*
|
||||||
* This file is part of Mapnik (c++ mapping toolkit)
|
* This file is part of Mapnik (c++ mapping toolkit)
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006 Artem Pavlenko
|
* Copyright (C) 2006 Artem Pavlenko
|
||||||
|
@ -19,8 +19,7 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
*
|
*
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
//$Id$
|
||||||
//$Id: ctrans.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
|
||||||
|
|
||||||
#ifndef CTRANS_HPP
|
#ifndef CTRANS_HPP
|
||||||
#define CTRANS_HPP
|
#define CTRANS_HPP
|
||||||
|
@ -32,78 +31,72 @@
|
||||||
#include <mapnik/coord_array.hpp>
|
#include <mapnik/coord_array.hpp>
|
||||||
#include <mapnik/proj_transform.hpp>
|
#include <mapnik/proj_transform.hpp>
|
||||||
|
|
||||||
namespace mapnik {
|
namespace mapnik
|
||||||
|
{
|
||||||
|
|
||||||
typedef coord_array<coord2d> CoordinateArray;
|
typedef coord_array<coord2d> CoordinateArray;
|
||||||
|
|
||||||
template <typename Transform,typename Geometry>
|
|
||||||
|
template <typename Transform, typename Geometry>
|
||||||
struct MAPNIK_DECL coord_transform
|
struct MAPNIK_DECL coord_transform
|
||||||
{
|
{
|
||||||
coord_transform(Transform const& t, Geometry& geom)
|
coord_transform(Transform const& t, Geometry& geom)
|
||||||
: t_(t), geom_(geom) {}
|
: t_(t), geom_(geom) {}
|
||||||
|
|
||||||
unsigned vertex(double *x , double *y) const
|
unsigned vertex(double *x, double *y) const
|
||||||
{
|
{
|
||||||
unsigned command = geom_.vertex(x,y);
|
unsigned command = geom_.vertex(x, y);
|
||||||
t_.forward(x,y);
|
t_.forward(x, y);
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind (unsigned pos)
|
void rewind(unsigned pos)
|
||||||
{
|
{
|
||||||
geom_.rewind(pos);
|
geom_.rewind(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Transform const& t_;
|
Transform const& t_;
|
||||||
Geometry& geom_;
|
Geometry& geom_;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Transform,typename Geometry>
|
|
||||||
|
template <typename Transform, typename Geometry>
|
||||||
struct MAPNIK_DECL coord_transform2
|
struct MAPNIK_DECL coord_transform2
|
||||||
{
|
{
|
||||||
typedef std::size_t size_type;
|
typedef std::size_t size_type;
|
||||||
typedef typename Geometry::value_type value_type;
|
typedef typename Geometry::value_type value_type;
|
||||||
|
|
||||||
coord_transform2(Transform const& t,
|
coord_transform2(Transform const& t,
|
||||||
Geometry const& geom,
|
Geometry const& geom,
|
||||||
proj_transform const& prj_trans)
|
proj_transform const& prj_trans)
|
||||||
: t_(t),
|
: t_(t),
|
||||||
geom_(geom),
|
geom_(geom),
|
||||||
prj_trans_(prj_trans) {}
|
prj_trans_(prj_trans) {}
|
||||||
|
|
||||||
unsigned vertex(double * x , double * y) const
|
unsigned vertex(double *x, double *y) const
|
||||||
{
|
{
|
||||||
unsigned command(SEG_MOVETO);
|
unsigned command = SEG_MOVETO;
|
||||||
bool ok = false;
|
bool ok = false;
|
||||||
bool skipped_points = false;
|
bool skipped_points = false;
|
||||||
while (!ok)
|
double z = 0;
|
||||||
|
while (!ok && command != SEG_END)
|
||||||
{
|
{
|
||||||
command = geom_.vertex(x,y);
|
command = geom_.vertex(x, y);
|
||||||
double z=0;
|
ok = prj_trans_.backward(*x, *y, z);
|
||||||
ok = prj_trans_.backward(*x,*y,z);
|
|
||||||
if (!ok) {
|
if (!ok) {
|
||||||
skipped_points = true;
|
skipped_points = true;
|
||||||
}
|
}
|
||||||
ok = ok || (command == SEG_END);
|
|
||||||
}
|
}
|
||||||
if (skipped_points && (command == SEG_LINETO))
|
if (skipped_points && (command == SEG_LINETO))
|
||||||
{
|
{
|
||||||
command = SEG_MOVETO;
|
command = SEG_MOVETO;
|
||||||
}
|
}
|
||||||
t_.forward(x,y);
|
t_.forward(x, y);
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*unsigned vertex(double * x , double * y) const
|
void rewind(unsigned pos)
|
||||||
{
|
|
||||||
unsigned command = geom_.vertex(x,y);
|
|
||||||
double z=0;
|
|
||||||
prj_trans_.backward(*x,*y,z);
|
|
||||||
t_.forward(x,y);
|
|
||||||
return command;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void rewind (unsigned pos)
|
|
||||||
{
|
{
|
||||||
geom_.rewind(pos);
|
geom_.rewind(pos);
|
||||||
}
|
}
|
||||||
|
@ -112,42 +105,42 @@ struct MAPNIK_DECL coord_transform2
|
||||||
{
|
{
|
||||||
return geom_;
|
return geom_;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Transform const& t_;
|
Transform const& t_;
|
||||||
Geometry const& geom_;
|
Geometry const& geom_;
|
||||||
proj_transform const& prj_trans_;
|
proj_transform const& prj_trans_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
template <typename Transform,typename Geometry>
|
template <typename Transform, typename Geometry>
|
||||||
struct MAPNIK_DECL coord_transform3
|
struct MAPNIK_DECL coord_transform3
|
||||||
{
|
{
|
||||||
coord_transform3(Transform const& t,
|
coord_transform3(Transform const& t,
|
||||||
Geometry const& geom,
|
Geometry const& geom,
|
||||||
proj_transform const& prj_trans,
|
proj_transform const& prj_trans,
|
||||||
int dx, int dy)
|
int dx, int dy)
|
||||||
: t_(t),
|
: t_(t),
|
||||||
geom_(geom),
|
geom_(geom),
|
||||||
prj_trans_(prj_trans),
|
prj_trans_(prj_trans),
|
||||||
dx_(dx), dy_(dy) {}
|
dx_(dx), dy_(dy) {}
|
||||||
|
|
||||||
unsigned vertex(double * x , double * y) const
|
unsigned vertex(double *x, double *y) const
|
||||||
{
|
{
|
||||||
unsigned command = geom_.vertex(x,y);
|
unsigned command = geom_.vertex(x, y);
|
||||||
double z=0;
|
double z = 0;
|
||||||
prj_trans_.backward(*x,*y,z);
|
prj_trans_.backward(*x, *y, z);
|
||||||
t_.forward(x,y);
|
t_.forward(x, y);
|
||||||
*x+=dx_;
|
*x += dx_;
|
||||||
*y+=dy_;
|
*y += dy_;
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewind (unsigned pos)
|
void rewind(unsigned pos)
|
||||||
{
|
{
|
||||||
geom_.rewind(pos);
|
geom_.rewind(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Transform const& t_;
|
Transform const& t_;
|
||||||
Geometry const& geom_;
|
Geometry const& geom_;
|
||||||
|
@ -155,7 +148,8 @@ private:
|
||||||
int dx_;
|
int dx_;
|
||||||
int dy_;
|
int dy_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class CoordTransform
|
class CoordTransform
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -166,71 +160,74 @@ private:
|
||||||
box2d<double> extent_;
|
box2d<double> extent_;
|
||||||
double offset_x_;
|
double offset_x_;
|
||||||
double offset_y_;
|
double offset_y_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CoordTransform(int width,int height,const box2d<double>& extent,
|
CoordTransform(int width, int height, const box2d<double>& extent,
|
||||||
double offset_x = 0, double offset_y = 0)
|
double offset_x = 0, double offset_y = 0)
|
||||||
:width_(width),height_(height),extent_(extent),offset_x_(offset_x),offset_y_(offset_y)
|
: width_(width), height_(height), extent_(extent),
|
||||||
|
offset_x_(offset_x), offset_y_(offset_y)
|
||||||
{
|
{
|
||||||
sx_ = (double(width_))/extent_.width();
|
sx_ = double(width_) / extent_.width();
|
||||||
sy_ = (double(height_))/extent_.height();
|
sy_ = double(height_) / extent_.height();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int width() const
|
inline int width() const
|
||||||
{
|
{
|
||||||
return width_;
|
return width_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int height() const
|
inline int height() const
|
||||||
{
|
{
|
||||||
return height_;
|
return height_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double scale_x() const
|
inline double scale_x() const
|
||||||
{
|
{
|
||||||
return sx_;
|
return sx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline double scale_y() const
|
inline double scale_y() const
|
||||||
{
|
{
|
||||||
return sy_;
|
return sy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void forward(double * x, double * y) const
|
inline void forward(double *x, double *y) const
|
||||||
{
|
{
|
||||||
*x = (*x - extent_.minx()) * sx_ - offset_x_;
|
*x = (*x - extent_.minx()) * sx_ - offset_x_;
|
||||||
*y = (extent_.maxy() - *y) * sy_ - offset_y_;
|
*y = (extent_.maxy() - *y) * sy_ - offset_y_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void backward(double * x, double * y) const
|
inline void backward(double *x, double *y) const
|
||||||
{
|
{
|
||||||
*x = extent_.minx() + (*x + offset_x_)/sx_;
|
*x = extent_.minx() + (*x + offset_x_) / sx_;
|
||||||
*y = extent_.maxy() - (*y + offset_y_)/sy_;
|
*y = extent_.maxy() - (*y + offset_y_) / sy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline coord2d& forward(coord2d& c) const
|
inline coord2d& forward(coord2d& c) const
|
||||||
{
|
{
|
||||||
forward(&c.x,&c.y);
|
forward(&c.x, &c.y);
|
||||||
return c;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline coord2d& backward(coord2d& c) const
|
|
||||||
{
|
|
||||||
backward(&c.x,&c.y);
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline box2d<double> forward(const box2d<double>& e,proj_transform const& prj_trans) const
|
inline coord2d& backward(coord2d& c) const
|
||||||
|
{
|
||||||
|
backward(&c.x, &c.y);
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline box2d<double> forward(const box2d<double>& e,
|
||||||
|
proj_transform const& prj_trans) const
|
||||||
{
|
{
|
||||||
double x0 = e.minx();
|
double x0 = e.minx();
|
||||||
double y0 = e.miny();
|
double y0 = e.miny();
|
||||||
double x1 = e.maxx();
|
double x1 = e.maxx();
|
||||||
double y1 = e.maxy();
|
double y1 = e.maxy();
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
prj_trans.backward(x0,y0,z);
|
prj_trans.backward(x0, y0, z);
|
||||||
forward(&x0,&y0);
|
forward(&x0, &y0);
|
||||||
prj_trans.backward(x1,y1,z);
|
prj_trans.backward(x1, y1, z);
|
||||||
forward(&x1,&y1);
|
forward(&x1, &y1);
|
||||||
return box2d<double>(x0,y0,x1,y1);
|
return box2d<double>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline box2d<double> forward(const box2d<double>& e) const
|
inline box2d<double> forward(const box2d<double>& e) const
|
||||||
|
@ -239,23 +236,24 @@ public:
|
||||||
double y0 = e.miny();
|
double y0 = e.miny();
|
||||||
double x1 = e.maxx();
|
double x1 = e.maxx();
|
||||||
double y1 = e.maxy();
|
double y1 = e.maxy();
|
||||||
forward(&x0,&y0);
|
forward(&x0, &y0);
|
||||||
forward(&x1,&y1);
|
forward(&x1, &y1);
|
||||||
return box2d<double>(x0,y0,x1,y1);
|
return box2d<double>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline box2d<double> backward(const box2d<double>& e,proj_transform const& prj_trans) const
|
inline box2d<double> backward(const box2d<double>& e,
|
||||||
|
proj_transform const& prj_trans) const
|
||||||
{
|
{
|
||||||
double x0 = e.minx();
|
double x0 = e.minx();
|
||||||
double y0 = e.miny();
|
double y0 = e.miny();
|
||||||
double x1 = e.maxx();
|
double x1 = e.maxx();
|
||||||
double y1 = e.maxy();
|
double y1 = e.maxy();
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
backward(&x0,&y0);
|
backward(&x0, &y0);
|
||||||
prj_trans.forward(x0,y0,z);
|
prj_trans.forward(x0, y0, z);
|
||||||
backward(&x1,&y1);
|
backward(&x1, &y1);
|
||||||
prj_trans.forward(x1,y1,z);
|
prj_trans.forward(x1, y1, z);
|
||||||
return box2d<double>(x0,y0,x1,y1);
|
return box2d<double>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline box2d<double> backward(const box2d<double>& e) const
|
inline box2d<double> backward(const box2d<double>& e) const
|
||||||
|
@ -264,28 +262,29 @@ public:
|
||||||
double y0 = e.miny();
|
double y0 = e.miny();
|
||||||
double x1 = e.maxx();
|
double x1 = e.maxx();
|
||||||
double y1 = e.maxy();
|
double y1 = e.maxy();
|
||||||
backward(&x0,&y0);
|
backward(&x0, &y0);
|
||||||
backward(&x1,&y1);
|
backward(&x1, &y1);
|
||||||
return box2d<double>(x0,y0,x1,y1);
|
return box2d<double>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CoordinateArray& forward(CoordinateArray& coords) const
|
inline CoordinateArray& forward(CoordinateArray& coords) const
|
||||||
{
|
{
|
||||||
for (unsigned i=0;i<coords.size();++i)
|
for (unsigned i = 0; i < coords.size(); ++i)
|
||||||
{
|
{
|
||||||
forward(coords[i]);
|
forward(coords[i]);
|
||||||
}
|
}
|
||||||
return coords;
|
return coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline CoordinateArray& backward(CoordinateArray& coords) const
|
inline CoordinateArray& backward(CoordinateArray& coords) const
|
||||||
{
|
{
|
||||||
for (unsigned i=0;i<coords.size();++i)
|
for (unsigned i = 0; i < coords.size(); ++i)
|
||||||
{
|
{
|
||||||
backward(coords[i]);
|
backward(coords[i]);
|
||||||
}
|
}
|
||||||
return coords;
|
return coords;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline box2d<double> const& extent() const
|
inline box2d<double> const& extent() const
|
||||||
{
|
{
|
||||||
return extent_;
|
return extent_;
|
||||||
|
|
Loading…
Reference in a new issue