1. removed dependency on boost_serialization ( we don't really need it) at this time.

2. coord and envelope operator<< to use 16 digit precision.
3. added 'inside polygon' method impl.
This commit is contained in:
Artem Pavlenko 2006-08-20 18:49:22 +00:00
parent 0bb121a747
commit 72fae1daa1
11 changed files with 516 additions and 595 deletions

View file

@ -76,11 +76,6 @@ C_LIBSHEADERS = [
BOOST_LIBSHEADERS = [ BOOST_LIBSHEADERS = [
['thread', 'boost/thread/mutex.hpp', True], ['thread', 'boost/thread/mutex.hpp', True],
['filesystem', 'boost/filesystem/operations.hpp', True], ['filesystem', 'boost/filesystem/operations.hpp', True],
['serialization', ['boost/archive/text_oarchive.hpp',
'boost/archive/text_iarchive.hpp',
'boost/archive/xml_oarchive.hpp',
'boost/archive/xml_iarchive.hpp'], True
],
['regex', 'boost/regex.hpp', True], ['regex', 'boost/regex.hpp', True],
['program_options', 'boost/program_options.hpp', False] ['program_options', 'boost/program_options.hpp', False]
] ]

View file

@ -26,6 +26,7 @@
#define COORD_HPP #define COORD_HPP
#include <iostream> #include <iostream>
#include <iomanip>
#include <sstream> #include <sstream>
namespace mapnik namespace mapnik
@ -113,7 +114,8 @@ namespace mapnik
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"coord2("<<c.x<<","<<c.y<<")"; s << "coord2(" << std::setprecision(16)
<< c.x << "," << c.y<< ")";
out << s.str(); out << s.str();
return out; return out;
} }
@ -126,7 +128,8 @@ namespace mapnik
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"coord3("<<c.x<<","<<c.y<<","<<c.z<<")"; s << "coord3(" << std::setprecision(16)
<< c.x << "," << c.y<< "," << c.z<<")";
out << s.str(); out << s.str();
return out; return out;
} }

View file

@ -26,6 +26,7 @@
#define ENVELOPE_HPP #define ENVELOPE_HPP
#include "config.hpp" #include "config.hpp"
#include <iomanip>
#include "coord.hpp" #include "coord.hpp"
namespace mapnik namespace mapnik
@ -34,50 +35,52 @@ namespace mapnik
template <class T> class MAPNIK_DECL Envelope template <class T> class MAPNIK_DECL Envelope
{ {
public: public:
typedef Envelope<T> EnvelopeType; typedef Envelope<T> EnvelopeType;
private: private:
T minx_; T minx_;
T miny_; T miny_;
T maxx_; T maxx_;
T maxy_; T maxy_;
public: public:
Envelope(); Envelope();
Envelope(T minx,T miny,T maxx,T maxy); Envelope(T minx,T miny,T maxx,T maxy);
Envelope(const coord<T,2>& c0,const coord<T,2>& c1); Envelope(const coord<T,2>& c0,const coord<T,2>& c1);
Envelope(const EnvelopeType& rhs); Envelope(const EnvelopeType& rhs);
T minx() const; T minx() const;
T miny() const; T miny() const;
T maxx() const; T maxx() const;
T maxy() const; T maxy() const;
T width() const; T width() const;
T height() const; T height() const;
void width(T w); void width(T w);
void height(T h); void height(T h);
coord<T,2> center() const; coord<T,2> center() const;
void expand_to_include(T x,T y); void expand_to_include(T x,T y);
void expand_to_include(const coord<T,2>& c); void expand_to_include(const coord<T,2>& c);
void expand_to_include(const EnvelopeType& other); void expand_to_include(const EnvelopeType& other);
bool contains(const coord<T,2> &c) const; bool contains(const coord<T,2> &c) const;
bool contains(T x,T y) const; bool contains(T x,T y) const;
bool contains(const EnvelopeType &other) const; bool contains(const EnvelopeType &other) const;
bool intersects(const coord<T,2> &c) const; bool intersects(const coord<T,2> &c) const;
bool intersects(T x,T y) const; bool intersects(T x,T y) const;
bool intersects(const EnvelopeType &other) const; bool intersects(const EnvelopeType &other) const;
EnvelopeType intersect(const EnvelopeType& other) const; EnvelopeType intersect(const EnvelopeType& other) const;
bool operator==(const EnvelopeType &other) const; bool operator==(const EnvelopeType &other) const;
void re_center(T cx,T cy); void re_center(T cx,T cy);
void init(T x0,T y0,T x1,T y1); void init(T x0,T y0,T x1,T y1);
}; };
template <class charT,class traits,class T> template <class charT,class traits,class T>
inline std::basic_ostream<charT,traits>& inline std::basic_ostream<charT,traits>&
operator << (std::basic_ostream<charT,traits>& out, operator << (std::basic_ostream<charT,traits>& out,
const Envelope<T>& e) const Envelope<T>& e)
{ {
std::basic_ostringstream<charT,traits> s; std::basic_ostringstream<charT,traits> s;
s.copyfmt(out); s.copyfmt(out);
s.width(0); s.width(0);
s<<"Envelope("<<e.minx()<<","<<e.miny()<<","<<e.maxx()<<","<<e.maxy()<<")"; s <<"Envelope(" << std::setprecision(16)
<< e.minx() << "," << e.miny() <<","
<< e.maxx() << "," << e.maxy() <<")";
out << s.str(); out << s.str();
return out; return out;
} }

View file

@ -31,7 +31,7 @@ namespace mapnik
{ {
template <typename T> template <typename T>
bool clip_test(T p,T q,double& tmin,double& tmax) bool clip_test(T p,T q,double& tmin,double& tmax)
{ {
double r; double r;
bool result=true; bool result=true;
@ -86,78 +86,80 @@ namespace mapnik
template <typename Iter> template <typename Iter>
inline bool point_inside_path(double x,double y,Iter start,Iter end) inline bool point_inside_path(double x,double y,Iter start,Iter end)
{ {
bool inside=false; bool inside=false;
double x0=start->x; double x0=boost::get<0>(*start);
double y0=start->y; double y0=boost::get<1>(*start);
double x1,y1;
while (++start!=end) double x1,y1;
{ while (++start!=end)
if (start->cmd == SEG_MOVETO) {
{ if ( boost::get<2>(*start) == SEG_MOVETO)
x0=start->x; {
y0=start->y; x0 = boost::get<0>(*start);
continue; y0 = boost::get<1>(*start);
} continue;
x1=start->x; }
y1=start->y; x1=boost::get<0>(*start);
if ((((y1 <= y) && (y < y0)) || y1=boost::get<1>(*start);
((y0 <= y) && (y < y1))) &&
( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1)) if ((((y1 <= y) && (y < y0)) ||
inside=!inside; ((y0 <= y) && (y < y1))) &&
x0=x1; ( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1))
y0=y1; inside=!inside;
} x0=x1;
y0=y1;
}
return inside; return inside;
} }
#define TOL 0.00001 #define TOL 0.00001
/* /*
(Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay) (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
s = ----------------------------- s = -----------------------------
L^2 L^2
*/ */
inline bool point_in_circle(double x,double y,double cx,double cy,double r) inline bool point_in_circle(double x,double y,double cx,double cy,double r)
{ {
double dx = x - cx; double dx = x - cx;
double dy = y - cy; double dy = y - cy;
double d2 = dx * dx + dy * dy; double d2 = dx * dx + dy * dy;
return (d2 <= r * r); return (d2 <= r * r);
} }
inline bool point_on_segment(double x,double y,double x0,double y0,double x1,double y1) inline bool point_on_segment(double x,double y,double x0,double y0,double x1,double y1)
{ {
double dx = x1 - x0; double dx = x1 - x0;
double dy = y1 - y0; double dy = y1 - y0;
if ( fabs(dx) > TOL || fabs(dy) > TOL ) if ( fabs(dx) > TOL || fabs(dy) > TOL )
{ {
double s = (y0 - y) * dx - (x0 - x) * dy; double s = (y0 - y) * dx - (x0 - x) * dy;
return ( fabs (s) < TOL ) ; return ( fabs (s) < TOL ) ;
} }
return false; return false;
} }
inline bool point_on_segment2(double x,double y,double x0,double y0,double x1,double y1) inline bool point_on_segment2(double x,double y,double x0,double y0,double x1,double y1)
{ {
double d = sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); double d = sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
double d0 = sqrt ((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y)); double d0 = sqrt ((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y));
double d1 = sqrt ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); double d1 = sqrt ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y));
double d2 = d0 + d1; double d2 = d0 + d1;
return ( d2 - d < 0.01); return ( d2 - d < 0.01);
} }
#undef TOL #undef TOL
template <typename Iter> template <typename Iter>
inline bool point_on_path(double x,double y,Iter start,Iter end) inline bool point_on_path(double x,double y,Iter start,Iter end)
{ {
return false; return false;
} }
template <typename Iter> template <typename Iter>
inline bool point_on_points (double x,double y,Iter start,Iter end) inline bool point_on_points (double x,double y,Iter start,Iter end)
{ {
return false; return false;
} }
struct filter_in_box struct filter_in_box

View file

@ -45,333 +45,334 @@ namespace mapnik
class geometry : private boost::noncopyable class geometry : private boost::noncopyable
{ {
public: public:
typedef T vertex_type; typedef T vertex_type;
typedef typename vertex_type::type value_type; typedef typename vertex_type::type value_type;
private: private:
int srid_; int srid_;
public: public:
geometry (int srid=-1) geometry (int srid=-1)
: srid_(srid) {} : srid_(srid) {}
int srid() const int srid() const
{ {
return srid_; return srid_;
} }
Envelope<double> envelope() Envelope<double> envelope()
{ {
Envelope<double> result; Envelope<double> result;
double x,y; double x,y;
for (unsigned i=0;i<num_points();++i) for (unsigned i=0;i<num_points();++i)
{ {
vertex(&x,&y); vertex(&x,&y);
if (i==0) if (i==0)
{ {
result.init(x,y,x,y); result.init(x,y,x,y);
} }
else else
{ {
result.expand_to_include(x,y); result.expand_to_include(x,y);
} }
} }
return result; return result;
} }
virtual int type() const=0; virtual int type() const=0;
virtual bool hit_test(value_type x,value_type y) const=0; virtual bool hit_test(value_type x,value_type y) const=0;
virtual void label_position(double *x, double *y) const=0; virtual void label_position(double *x, double *y) const=0;
virtual void move_to(value_type x,value_type y)=0; virtual void move_to(value_type x,value_type y)=0;
virtual void line_to(value_type x,value_type y)=0; virtual void line_to(value_type x,value_type y)=0;
virtual void transform(const mapnik::CoordTransform& t)=0; virtual void transform(const mapnik::CoordTransform& t)=0;
virtual unsigned num_points() const = 0; virtual unsigned num_points() const = 0;
virtual unsigned vertex(double* x, double* y)=0; virtual unsigned vertex(double* x, double* y)=0;
virtual void rewind(unsigned )=0; virtual void rewind(unsigned )=0;
virtual void set_capacity(size_t size)=0; virtual void set_capacity(size_t size)=0;
virtual ~geometry() {} virtual ~geometry() {}
}; };
template <typename T> template <typename T>
class point : public geometry<T> class point : public geometry<T>
{ {
typedef geometry<T> geometry_base; typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type; typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry<T>::value_type value_type; typedef typename geometry<T>::value_type value_type;
private: private:
vertex_type pt_; vertex_type pt_;
public: public:
point(int srid) point(int srid)
: geometry<T>(srid) : geometry<T>(srid)
{} {}
int type() const int type() const
{ {
return Point; return Point;
} }
void label_position(double *x, double *y) const void label_position(double *x, double *y) const
{ {
*x = pt_.x; *x = pt_.x;
*y = pt_.y; *y = pt_.y;
} }
void move_to(value_type x,value_type y) void move_to(value_type x,value_type y)
{ {
pt_.x = x; pt_.x = x;
pt_.y = y; pt_.y = y;
} }
void line_to(value_type ,value_type ) {} void line_to(value_type ,value_type ) {}
void transform(const mapnik::CoordTransform& t) void transform(const mapnik::CoordTransform& t)
{ {
t.forward_x(&pt_.x); t.forward_x(&pt_.x);
t.forward_y(&pt_.y); t.forward_y(&pt_.y);
} }
unsigned num_points() const
{
return 1;
}
unsigned vertex(double* x, double* y)
{
*x = pt_.x;
*y = pt_.y;
return SEG_LINETO;
}
void rewind(unsigned ) {}
bool hit_test(value_type x,value_type y) const
{
return false;
}
void set_capacity(size_t) {}
virtual ~point() {}
};
template <typename T, template <typename> class Container=vertex_vector>
class polygon : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
polygon(int srid)
: geometry_base(srid),
itr_(0)
{}
int type() const
{
return Polygon;
}
void label_position(double *x, double *y) const
{
unsigned size = cont_.size();
if (size < 3)
{
cont_.get_vertex(0,x,y);
return;
}
double ai;
double atmp = 0;
double xtmp = 0;
double ytmp = 0;
double x0 =0;
double y0 =0;
double x1 =0;
double y1 =0;
unsigned i,j;
for (i = size-1,j = 0; j < size; i = j, ++j)
{
cont_.get_vertex(i,&x0,&y0);
cont_.get_vertex(j,&x1,&y1);
ai = x0 * y1 - x1 * y0;
atmp += ai;
xtmp += (x1 + x0) * ai;
ytmp += (y1 + y0) * ai;
}
if (atmp != 0)
{
*x = xtmp/(3*atmp);
*y = ytmp /(3*atmp);
return;
}
*x=x0;
*y=y0;
}
void line_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_LINETO);
}
void move_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_MOVETO);
}
void transform(mapnik::CoordTransform const& t)
{
unsigned size = cont_.size();
for (unsigned pos=0; pos < size; ++pos)
{
cont_.transform_at(pos,t);
}
}
unsigned num_points() const unsigned num_points() const
{ {
return cont_.size(); return 1;
} }
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
return cont_.get_vertex(itr_++,x,y); *x = pt_.x;
} *y = pt_.y;
return SEG_LINETO;
}
void rewind(unsigned ) void rewind(unsigned ) {}
{
itr_=0;
}
bool hit_test(value_type x,value_type y) const bool hit_test(value_type x,value_type y) const
{ {
return false; return false;
} }
void set_capacity(size_t size) void set_capacity(size_t) {}
{ virtual ~point() {}
cont_.set_capacity(size); };
}
virtual ~polygon() {} template <typename T, template <typename> class Container=vertex_vector2>
class polygon : public geometry<T>
{
typedef geometry<T> geometry_base;
typedef typename geometry<T>::vertex_type vertex_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
polygon(int srid)
: geometry_base(srid),
itr_(0)
{}
int type() const
{
return Polygon;
}
void label_position(double *x, double *y) const
{
unsigned size = cont_.size();
if (size < 3)
{
cont_.get_vertex(0,x,y);
return;
}
double ai;
double atmp = 0;
double xtmp = 0;
double ytmp = 0;
double x0 =0;
double y0 =0;
double x1 =0;
double y1 =0;
unsigned i,j;
for (i = size-1,j = 0; j < size; i = j, ++j)
{
cont_.get_vertex(i,&x0,&y0);
cont_.get_vertex(j,&x1,&y1);
ai = x0 * y1 - x1 * y0;
atmp += ai;
xtmp += (x1 + x0) * ai;
ytmp += (y1 + y0) * ai;
}
if (atmp != 0)
{
*x = xtmp/(3*atmp);
*y = ytmp /(3*atmp);
return;
}
*x=x0;
*y=y0;
}
void line_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_LINETO);
}
void move_to(value_type x,value_type y)
{
cont_.push_back(x,y,SEG_MOVETO);
}
void transform(mapnik::CoordTransform const& t)
{
unsigned size = cont_.size();
for (unsigned pos=0; pos < size; ++pos)
{
cont_.transform_at(pos,t);
}
}
unsigned num_points() const
{
return cont_.size();
}
unsigned vertex(double* x, double* y)
{
return cont_.get_vertex(itr_++,x,y);
}
void rewind(unsigned )
{
itr_=0;
}
bool hit_test(value_type x,value_type y) const
{
return point_inside_path(x,y,cont_.begin(),cont_.end());
}
void set_capacity(size_t size)
{
cont_.set_capacity(size);
}
virtual ~polygon() {}
}; };
template <typename T, template <typename> class Container=vertex_vector> template <typename T, template <typename> class Container=vertex_vector>
class line_string : public geometry<T> class line_string : public geometry<T>
{ {
typedef geometry<T> geometry_base; typedef geometry<T> geometry_base;
typedef typename geometry_base::value_type value_type; typedef typename geometry_base::value_type value_type;
typedef typename geometry<T>::vertex_type vertex_type; typedef typename geometry<T>::vertex_type vertex_type;
typedef Container<vertex_type> container_type; typedef Container<vertex_type> container_type;
private: private:
container_type cont_; container_type cont_;
mutable unsigned itr_; mutable unsigned itr_;
public: public:
line_string(int srid) line_string(int srid)
: geometry_base(srid), : geometry_base(srid),
itr_(0) itr_(0)
{} {}
int type() const int type() const
{ {
return LineString; return LineString;
} }
void label_position(double *x, double *y) const void label_position(double *x, double *y) const
{ {
// calculate mid point on line string // calculate mid point on line string
double x0=0; double x0=0;
double y0=0; double y0=0;
double x1=0; double x1=0;
double y1=0; double y1=0;
unsigned size = cont_.size(); unsigned size = cont_.size();
if (size == 1) if (size == 1)
{ {
cont_.get_vertex(0,x,y); cont_.get_vertex(0,x,y);
} }
else if (size == 2) else if (size == 2)
{ {
cont_.get_vertex(0,&x0,&y0); cont_.get_vertex(0,&x0,&y0);
cont_.get_vertex(1,&x1,&y1); cont_.get_vertex(1,&x1,&y1);
*x = 0.5 * (x1 + x0); *x = 0.5 * (x1 + x0);
*y = 0.5 * (y1 + y0); *y = 0.5 * (y1 + y0);
} }
else else
{ {
double len=0.0; double len=0.0;
for (unsigned pos = 1; pos < size; ++pos) for (unsigned pos = 1; pos < size; ++pos)
{ {
cont_.get_vertex(pos-1,&x0,&y0); cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1); cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0; double dx = x1 - x0;
double dy = y1 - y0; double dy = y1 - y0;
len += sqrt(dx * dx + dy * dy); len += sqrt(dx * dx + dy * dy);
} }
double midlen = 0.5 * len; double midlen = 0.5 * len;
double dist = 0.0; double dist = 0.0;
for (unsigned pos = 1; pos < size;++pos) for (unsigned pos = 1; pos < size;++pos)
{ {
cont_.get_vertex(pos-1,&x0,&y0); cont_.get_vertex(pos-1,&x0,&y0);
cont_.get_vertex(pos,&x1,&y1); cont_.get_vertex(pos,&x1,&y1);
double dx = x1 - x0; double dx = x1 - x0;
double dy = y1 - y0; double dy = y1 - y0;
double seg_len = sqrt(dx * dx + dy * dy); double seg_len = sqrt(dx * dx + dy * dy);
if (( dist + seg_len) >= midlen) if (( dist + seg_len) >= midlen)
{ {
double r = (midlen - dist)/seg_len; double r = (midlen - dist)/seg_len;
*x = x0 + (x1 - x0) * r; *x = x0 + (x1 - x0) * r;
*y = y0 + (y1 - y0) * r; *y = y0 + (y1 - y0) * r;
break; break;
} }
dist += seg_len; dist += seg_len;
} }
} }
} }
void line_to(value_type x,value_type y) void line_to(value_type x,value_type y)
{ {
cont_.push_back(x,y,SEG_LINETO); cont_.push_back(x,y,SEG_LINETO);
} }
void move_to(value_type x,value_type y) void move_to(value_type x,value_type y)
{ {
cont_.push_back(x,y,SEG_MOVETO); cont_.push_back(x,y,SEG_MOVETO);
} }
void transform(mapnik::CoordTransform const& t) void transform(mapnik::CoordTransform const& t)
{ {
unsigned size = cont_.size(); unsigned size = cont_.size();
for (unsigned pos=0; pos < size; ++pos) for (unsigned pos=0; pos < size; ++pos)
{ {
cont_.transform_at(pos,t); cont_.transform_at(pos,t);
} }
} }
unsigned num_points() const unsigned num_points() const
{ {
return cont_.size(); return cont_.size();
} }
unsigned vertex(double* x, double* y) unsigned vertex(double* x, double* y)
{ {
return cont_.get_vertex(itr_++,x,y); return cont_.get_vertex(itr_++,x,y);
} }
void rewind(unsigned ) void rewind(unsigned )
{ {
itr_=0; itr_=0;
} }
bool hit_test(value_type x,value_type y) const bool hit_test(value_type x,value_type y) const
{ {
return false; return false;
} }
void set_capacity(size_t size) void set_capacity(size_t size)
{ {
cont_.set_capacity(size); cont_.set_capacity(size);
} }
virtual ~line_string() {} virtual ~line_string() {}
}; };
typedef point<vertex2d> point_impl; typedef point<vertex2d> point_impl;

View file

@ -15,10 +15,11 @@
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * #include <boost/serialization/serialization.hpp>
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA License along with this library; if not, write to the Free Software
* * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/ *
*****************************************************************************/
//$Id: layer.hpp 39 2005-04-10 20:39:53Z pavlenko $ //$Id: layer.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef LAYER_HPP #ifndef LAYER_HPP
@ -28,27 +29,11 @@
#include "feature.hpp" #include "feature.hpp"
#include "datasource.hpp" #include "datasource.hpp"
#include <boost/shared_ptr.hpp> #include <boost/shared_ptr.hpp>
#include <boost/serialization/serialization.hpp>
namespace mapnik namespace mapnik
{ {
class MAPNIK_DECL Layer class MAPNIK_DECL Layer
{ {
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int /*version*/)
{
ar & boost::serialization::make_nvp("name",name_)
& boost::serialization::make_nvp("title",title_)
& boost::serialization::make_nvp("abstract",abstract_)
& boost::serialization::make_nvp("params",params_)
& boost::serialization::make_nvp("min_zoom",minZoom_)
& boost::serialization::make_nvp("max_zoom",maxZoom_)
& boost::serialization::make_nvp("active",active_)
& boost::serialization::make_nvp("selectable",selectable_)
& boost::serialization::make_nvp("styles",styles_)
;
}
parameters params_; parameters params_;
std::string name_; std::string name_;
std::string title_; std::string title_;
@ -102,10 +87,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(std::vector<std::string>, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(std::vector<std::string>, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::Layer, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::Layer, boost::serialization::track_never)
#endif //LAYER_HPP #endif //LAYER_HPP

View file

@ -24,8 +24,6 @@
#ifndef MAP_HPP #ifndef MAP_HPP
#define MAP_HPP #define MAP_HPP
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/vector.hpp>
#include "feature_type_style.hpp" #include "feature_type_style.hpp"
namespace mapnik namespace mapnik
@ -34,16 +32,6 @@ namespace mapnik
class MAPNIK_DECL Map class MAPNIK_DECL Map
{ {
friend class boost::serialization::access;
template <typename Archive>
void serialize(Archive & ar, const unsigned int /*version*/)
{
ar & boost::serialization::make_nvp("width",width_)
& boost::serialization::make_nvp("height",height_)
& boost::serialization::make_nvp("srid",srid_)
& boost::serialization::make_nvp("layers",layers_);
}
static const unsigned MIN_MAPSIZE=16; static const unsigned MIN_MAPSIZE=16;
static const unsigned MAX_MAPSIZE=2048; static const unsigned MAX_MAPSIZE=2048;
unsigned width_; unsigned width_;
@ -94,10 +82,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(std::vector<mapnik::Layer>, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(std::vector<mapnik::Layer>, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::Map, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::Map, boost::serialization::track_never)
#endif //MAP_HPP #endif //MAP_HPP

View file

@ -79,8 +79,6 @@
namespace mapnik namespace mapnik
{ {
void MAPNIK_DECL save_to_xml(Map const& map,const char* filename);
void MAPNIK_DECL load_from_xml(Map & map, const char * filename);
} }
#endif //MAPNIK_HPP #endif //MAPNIK_HPP

View file

@ -44,36 +44,6 @@ namespace mapnik
class parameters : public param_map class parameters : public param_map
{ {
friend class boost::serialization::access;
template <typename Archive>
void save(Archive & ar, const unsigned int /*version*/) const
{
const size_t size = param_map::size();
ar & boost::serialization::make_nvp("count",size);
param_map::const_iterator itr;
for (itr=param_map::begin();itr!=param_map::end();++itr)
{
ar & boost::serialization::make_nvp("name",itr->first);
ar & boost::serialization::make_nvp("value",itr->second);
}
}
template <typename Archive>
void load(Archive & ar, const unsigned int /*version*/)
{
size_t size;
ar & boost::serialization::make_nvp("size",size);
for (size_t i=0;i<size;++i)
{
std::string name;
std::string value;
ar & boost::serialization::make_nvp("name",name);
ar & boost::serialization::make_nvp("value",value);
param_map::insert(make_pair(name,value));
}
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
public: public:
parameters() {} parameters() {}
@ -89,10 +59,4 @@ namespace mapnik
}; };
} }
BOOST_CLASS_IMPLEMENTATION(mapnik::parameter, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::parameter, boost::serialization::track_never)
BOOST_CLASS_IMPLEMENTATION(mapnik::parameters, boost::serialization::object_serializable)
BOOST_CLASS_TRACKING(mapnik::parameters, boost::serialization::track_never)
#endif //PARAMS_HPP #endif //PARAMS_HPP

View file

@ -42,146 +42,157 @@ namespace mapnik
template <typename T> template <typename T>
class vertex_vector : private boost::noncopyable class vertex_vector : private boost::noncopyable
{ {
typedef typename T::type value_type; typedef typename T::type value_type;
typedef vertex<value_type,2> vertex_type; typedef vertex<value_type,2> vertex_type;
enum { enum {
block_shift = 8, block_shift = 8,
block_size = 1<<block_shift, block_size = 1<<block_shift,
block_mask = block_size - 1, block_mask = block_size - 1,
grow_by = 256 grow_by = 256
}; };
private: private:
unsigned num_blocks_; unsigned num_blocks_;
unsigned max_blocks_; unsigned max_blocks_;
value_type** vertexs_; value_type** vertexs_;
unsigned char** commands_; unsigned char** commands_;
unsigned pos_; unsigned pos_;
public: public:
vertex_vector() vertex_vector()
: num_blocks_(0), : num_blocks_(0),
max_blocks_(0), max_blocks_(0),
vertexs_(0), vertexs_(0),
commands_(0), commands_(0),
pos_(0) {} pos_(0) {}
~vertex_vector() ~vertex_vector()
{ {
if ( num_blocks_ ) if ( num_blocks_ )
{ {
value_type** vertexs=vertexs_ + num_blocks_ - 1; value_type** vertexs=vertexs_ + num_blocks_ - 1;
while ( num_blocks_-- ) while ( num_blocks_-- )
{ {
delete [] *vertexs; delete [] *vertexs;
--vertexs; --vertexs;
} }
delete [] vertexs_; delete [] vertexs_;
} }
} }
unsigned size() const unsigned size() const
{ {
return pos_; return pos_;
} }
void push_back (value_type x,value_type y,unsigned command) void push_back (value_type x,value_type y,unsigned command)
{ {
unsigned block = pos_ >> block_shift; unsigned block = pos_ >> block_shift;
if (block >= num_blocks_) if (block >= num_blocks_)
{ {
allocate_block(block); allocate_block(block);
} }
value_type* vertex = vertexs_[block] + ((pos_ & block_mask) << 1); value_type* vertex = vertexs_[block] + ((pos_ & block_mask) << 1);
unsigned char* cmd= commands_[block] + (pos_ & block_mask); unsigned char* cmd= commands_[block] + (pos_ & block_mask);
*cmd = static_cast<unsigned char>(command); *cmd = static_cast<unsigned char>(command);
*vertex++ = x; *vertex++ = x;
*vertex = y; *vertex = y;
++pos_; ++pos_;
} }
unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const
{ {
if (pos >= pos_) return SEG_END; if (pos >= pos_) return SEG_END;
unsigned block = pos >> block_shift; unsigned block = pos >> block_shift;
const value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); const value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1);
*x = (*vertex++); *x = (*vertex++);
*y = (*vertex); *y = (*vertex);
return commands_[block] [pos & block_mask]; return commands_[block] [pos & block_mask];
} }
void transform_at(unsigned pos,const CoordTransform& t) void transform_at(unsigned pos,const CoordTransform& t)
{ {
if (pos >= pos_) return; if (pos >= pos_) return;
unsigned block = pos >> block_shift; unsigned block = pos >> block_shift;
value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1);
t.forward_x(vertex); t.forward_x(vertex);
++vertex; ++vertex;
t.forward_y(vertex); t.forward_y(vertex);
} }
void set_capacity(size_t) void set_capacity(size_t)
{ {
//do nothing //do nothing
} }
private: private:
void allocate_block(unsigned block) void allocate_block(unsigned block)
{ {
if (block >= max_blocks_) if (block >= max_blocks_)
{ {
value_type** new_vertexs = new value_type* [(max_blocks_ + grow_by) * 2]; value_type** new_vertexs = new value_type* [(max_blocks_ + grow_by) * 2];
unsigned char** new_commands = (unsigned char**)(new_vertexs + max_blocks_ + grow_by); unsigned char** new_commands = (unsigned char**)(new_vertexs + max_blocks_ + grow_by);
if (vertexs_) if (vertexs_)
{ {
std::memcpy(new_vertexs,vertexs_,max_blocks_ * sizeof(value_type*)); std::memcpy(new_vertexs,vertexs_,max_blocks_ * sizeof(value_type*));
std::memcpy(new_commands,commands_,max_blocks_ * sizeof(unsigned char*)); std::memcpy(new_commands,commands_,max_blocks_ * sizeof(unsigned char*));
delete [] vertexs_; delete [] vertexs_;
} }
vertexs_ = new_vertexs; vertexs_ = new_vertexs;
commands_ = new_commands; commands_ = new_commands;
max_blocks_ += grow_by; max_blocks_ += grow_by;
} }
vertexs_[block] = new value_type [block_size * 2 + block_size / (sizeof(value_type))]; vertexs_[block] = new value_type [block_size * 2 + block_size / (sizeof(value_type))];
commands_[block] = (unsigned char*)(vertexs_[block] + block_size*2); commands_[block] = (unsigned char*)(vertexs_[block] + block_size*2);
++num_blocks_; ++num_blocks_;
} }
}; };
template <typename T> template <typename T>
struct vertex_vector2 : boost::noncopyable struct vertex_vector2 : boost::noncopyable
{ {
typedef typename T::type value_type; typedef typename T::type value_type;
typedef boost::tuple<value_type,value_type,char> vertex_type; typedef boost::tuple<value_type,value_type,char> vertex_type;
vertex_vector2() {} typedef typename std::vector<vertex_type>::const_iterator const_iterator;
unsigned size() const vertex_vector2() {}
{ unsigned size() const
return cont_.size(); {
} return cont_.size();
}
void push_back (value_type x,value_type y,unsigned command) void push_back (value_type x,value_type y,unsigned command)
{ {
cont_.push_back(vertex_type(x,y,command)); cont_.push_back(vertex_type(x,y,command));
} }
unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const
{ {
if (pos >= cont_.size()) return SEG_END; if (pos >= cont_.size()) return SEG_END;
vertex_type const& c = cont_[pos]; vertex_type const& c = cont_[pos];
*x = boost::get<0>(c); *x = boost::get<0>(c);
*y = boost::get<1>(c); *y = boost::get<1>(c);
return boost::get<2>(c); return boost::get<2>(c);
} }
void transform_at(unsigned pos,const CoordTransform& t) const_iterator begin() const
{ {
if (pos >= cont_.size()) return; return cont_.begin();
vertex_type & c = cont_[pos]; }
t.forward_x(&boost::get<0>(c));
t.forward_y(&boost::get<1>(c)); const_iterator end() const
} {
void set_capacity(size_t size) return cont_.end();
{ }
cont_.reserve(size);
} void transform_at(unsigned pos,const CoordTransform& t)
{
if (pos >= cont_.size()) return;
vertex_type & c = cont_[pos];
t.forward_x(&boost::get<0>(c));
t.forward_y(&boost::get<1>(c));
}
void set_capacity(size_t size)
{
cont_.reserve(size);
}
private: private:
std::vector<vertex_type> cont_; std::vector<vertex_type> cont_;
}; };
} }

View file

@ -23,27 +23,10 @@
//$Id$ //$Id$
#include <fstream> #include <fstream>
#include <boost/archive/xml_iarchive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include "mapnik.hpp" #include "mapnik.hpp"
namespace mapnik namespace mapnik
{ {
void save_to_xml(Map const& m,const char* filename)
{
std::ofstream ofs(filename);
assert(ofs.good());
boost::archive::xml_oarchive oa(ofs);
oa << boost::serialization::make_nvp("map",m);
}
void load_from_xml(Map & m,const char* filename)
{
std::ifstream ifs(filename);
assert(ifs.good());
boost::archive::xml_iarchive ia(ifs);
ia >> boost::serialization::make_nvp("map",m);
}
} }