From 72fae1daa18072f66ef6d3ab3f11f70387009ff0 Mon Sep 17 00:00:00 2001 From: Artem Pavlenko Date: Sun, 20 Aug 2006 18:49:22 +0000 Subject: [PATCH] 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. --- SConstruct | 5 - include/coord.hpp | 7 +- include/envelope.hpp | 69 ++--- include/geom_util.hpp | 92 +++--- include/geometry.hpp | 573 +++++++++++++++++++------------------- include/layer.hpp | 31 +-- include/map.hpp | 20 +- include/mapnik.hpp | 2 - include/params.hpp | 36 --- include/vertex_vector.hpp | 259 ++++++++--------- src/mapnik.cpp | 17 -- 11 files changed, 516 insertions(+), 595 deletions(-) diff --git a/SConstruct b/SConstruct index 735b2267c..cb7dbcbb2 100644 --- a/SConstruct +++ b/SConstruct @@ -76,11 +76,6 @@ C_LIBSHEADERS = [ BOOST_LIBSHEADERS = [ ['thread', 'boost/thread/mutex.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], ['program_options', 'boost/program_options.hpp', False] ] diff --git a/include/coord.hpp b/include/coord.hpp index 6451f31c6..c2813c9e5 100644 --- a/include/coord.hpp +++ b/include/coord.hpp @@ -26,6 +26,7 @@ #define COORD_HPP #include +#include #include namespace mapnik @@ -113,7 +114,8 @@ namespace mapnik std::basic_ostringstream s; s.copyfmt(out); s.width(0); - s<<"coord2("< s; s.copyfmt(out); s.width(0); - s<<"coord3("< #include "coord.hpp" namespace mapnik @@ -34,50 +35,52 @@ namespace mapnik template class MAPNIK_DECL Envelope { public: - typedef Envelope EnvelopeType; + typedef Envelope EnvelopeType; private: - T minx_; - T miny_; - T maxx_; - T maxy_; + T minx_; + T miny_; + T maxx_; + T maxy_; public: - Envelope(); - Envelope(T minx,T miny,T maxx,T maxy); - Envelope(const coord& c0,const coord& c1); - Envelope(const EnvelopeType& rhs); - T minx() const; - T miny() const; - T maxx() const; - T maxy() const; - T width() const; - T height() const; - void width(T w); - void height(T h); - coord center() const; - void expand_to_include(T x,T y); - void expand_to_include(const coord& c); - void expand_to_include(const EnvelopeType& other); - bool contains(const coord &c) const; - bool contains(T x,T y) const; - bool contains(const EnvelopeType &other) const; - bool intersects(const coord &c) const; - bool intersects(T x,T y) const; - bool intersects(const EnvelopeType &other) const; - EnvelopeType intersect(const EnvelopeType& other) const; - bool operator==(const EnvelopeType &other) const; - void re_center(T cx,T cy); - void init(T x0,T y0,T x1,T y1); + Envelope(); + Envelope(T minx,T miny,T maxx,T maxy); + Envelope(const coord& c0,const coord& c1); + Envelope(const EnvelopeType& rhs); + T minx() const; + T miny() const; + T maxx() const; + T maxy() const; + T width() const; + T height() const; + void width(T w); + void height(T h); + coord center() const; + void expand_to_include(T x,T y); + void expand_to_include(const coord& c); + void expand_to_include(const EnvelopeType& other); + bool contains(const coord &c) const; + bool contains(T x,T y) const; + bool contains(const EnvelopeType &other) const; + bool intersects(const coord &c) const; + bool intersects(T x,T y) const; + bool intersects(const EnvelopeType &other) const; + EnvelopeType intersect(const EnvelopeType& other) const; + bool operator==(const EnvelopeType &other) const; + void re_center(T cx,T cy); + void init(T x0,T y0,T x1,T y1); }; template inline std::basic_ostream& operator << (std::basic_ostream& out, - const Envelope& e) + const Envelope& e) { std::basic_ostringstream s; s.copyfmt(out); s.width(0); - s<<"Envelope("< - bool clip_test(T p,T q,double& tmin,double& tmax) + bool clip_test(T p,T q,double& tmin,double& tmax) { double r; bool result=true; @@ -86,78 +86,80 @@ namespace mapnik template inline bool point_inside_path(double x,double y,Iter start,Iter end) { - bool inside=false; - double x0=start->x; - double y0=start->y; - double x1,y1; - while (++start!=end) - { - if (start->cmd == SEG_MOVETO) - { - x0=start->x; - y0=start->y; - continue; - } - x1=start->x; - y1=start->y; - if ((((y1 <= y) && (y < y0)) || - ((y0 <= y) && (y < y1))) && - ( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1)) - inside=!inside; - x0=x1; - y0=y1; - } + bool inside=false; + double x0=boost::get<0>(*start); + double y0=boost::get<1>(*start); + + double x1,y1; + while (++start!=end) + { + if ( boost::get<2>(*start) == SEG_MOVETO) + { + x0 = boost::get<0>(*start); + y0 = boost::get<1>(*start); + continue; + } + x1=boost::get<0>(*start); + y1=boost::get<1>(*start); + + if ((((y1 <= y) && (y < y0)) || + ((y0 <= y) && (y < y1))) && + ( x < (x0 - x1) * (y - y1)/ (y0 - y1) + x1)) + inside=!inside; + x0=x1; + y0=y1; + } return inside; } #define TOL 0.00001 -/* + /* (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay) - s = ----------------------------- - L^2 -*/ + s = ----------------------------- + L^2 + */ inline bool point_in_circle(double x,double y,double cx,double cy,double r) { - double dx = x - cx; - double dy = y - cy; - double d2 = dx * dx + dy * dy; - return (d2 <= r * r); + double dx = x - cx; + double dy = y - cy; + double d2 = dx * dx + dy * dy; + return (d2 <= r * r); } inline bool point_on_segment(double x,double y,double x0,double y0,double x1,double y1) { - double dx = x1 - x0; - double dy = y1 - y0; - if ( fabs(dx) > TOL || fabs(dy) > TOL ) - { - double s = (y0 - y) * dx - (x0 - x) * dy; - return ( fabs (s) < TOL ) ; - } - return false; + double dx = x1 - x0; + double dy = y1 - y0; + if ( fabs(dx) > TOL || fabs(dy) > TOL ) + { + double s = (y0 - y) * dx - (x0 - x) * dy; + return ( fabs (s) < TOL ) ; + } + return false; } 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 d0 = sqrt ((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y)); - double d1 = sqrt ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); - double d2 = d0 + d1; - return ( d2 - d < 0.01); + double d = sqrt ((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)); + double d0 = sqrt ((x0 - x) * (x0 - x) + (y0 - y) * (y0 - y)); + double d1 = sqrt ((x1 - x) * (x1 - x) + (y1 - y) * (y1 - y)); + double d2 = d0 + d1; + return ( d2 - d < 0.01); } #undef TOL template inline bool point_on_path(double x,double y,Iter start,Iter end) { - return false; + return false; } template inline bool point_on_points (double x,double y,Iter start,Iter end) { - return false; + return false; } struct filter_in_box diff --git a/include/geometry.hpp b/include/geometry.hpp index 888deb62d..ccfb48d77 100644 --- a/include/geometry.hpp +++ b/include/geometry.hpp @@ -45,333 +45,334 @@ namespace mapnik class geometry : private boost::noncopyable { public: - typedef T vertex_type; - typedef typename vertex_type::type value_type; + typedef T vertex_type; + typedef typename vertex_type::type value_type; private: - int srid_; + int srid_; public: - geometry (int srid=-1) - : srid_(srid) {} + geometry (int srid=-1) + : srid_(srid) {} - int srid() const - { - return srid_; - } + int srid() const + { + return srid_; + } - Envelope envelope() - { - Envelope result; - double x,y; - for (unsigned i=0;i envelope() + { + Envelope result; + double x,y; + for (unsigned i=0;i class point : public geometry { - typedef geometry geometry_base; - typedef typename geometry::vertex_type vertex_type; - typedef typename geometry::value_type value_type; + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry::value_type value_type; private: - vertex_type pt_; + vertex_type pt_; public: - point(int srid) - : geometry(srid) - {} + point(int srid) + : geometry(srid) + {} - int type() const - { - return Point; - } - void label_position(double *x, double *y) const - { - *x = pt_.x; - *y = pt_.y; - } + int type() const + { + return Point; + } + void label_position(double *x, double *y) const + { + *x = pt_.x; + *y = pt_.y; + } - void move_to(value_type x,value_type y) - { - pt_.x = x; - pt_.y = y; - } + void move_to(value_type x,value_type y) + { + pt_.x = x; + pt_.y = y; + } - void line_to(value_type ,value_type ) {} + void line_to(value_type ,value_type ) {} - void transform(const mapnik::CoordTransform& t) - { - t.forward_x(&pt_.x); - 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 class Container=vertex_vector> - class polygon : public geometry - { - typedef geometry geometry_base; - typedef typename geometry::vertex_type vertex_type; - typedef typename geometry_base::value_type value_type; - typedef Container 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); - } - } + void transform(const mapnik::CoordTransform& t) + { + t.forward_x(&pt_.x); + t.forward_y(&pt_.y); + } unsigned num_points() const - { - return cont_.size(); - } + { + return 1; + } - unsigned vertex(double* x, double* y) - { - return cont_.get_vertex(itr_++,x,y); - } + unsigned vertex(double* x, double* y) + { + *x = pt_.x; + *y = pt_.y; + return SEG_LINETO; + } - void rewind(unsigned ) - { - itr_=0; - } + void rewind(unsigned ) {} - bool hit_test(value_type x,value_type y) const - { - return false; - } - void set_capacity(size_t size) - { - cont_.set_capacity(size); - } - virtual ~polygon() {} + bool hit_test(value_type x,value_type y) const + { + return false; + } + void set_capacity(size_t) {} + virtual ~point() {} + }; + + template class Container=vertex_vector2> + class polygon : public geometry + { + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry_base::value_type value_type; + typedef Container 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 class Container=vertex_vector> class line_string : public geometry { - typedef geometry geometry_base; - typedef typename geometry_base::value_type value_type; - typedef typename geometry::vertex_type vertex_type; - typedef Container container_type; + typedef geometry geometry_base; + typedef typename geometry_base::value_type value_type; + typedef typename geometry::vertex_type vertex_type; + typedef Container container_type; private: - container_type cont_; - mutable unsigned itr_; + container_type cont_; + mutable unsigned itr_; public: - line_string(int srid) - : geometry_base(srid), - itr_(0) - {} + line_string(int srid) + : geometry_base(srid), + itr_(0) + {} - int type() const - { - return LineString; - } + int type() const + { + return LineString; + } void label_position(double *x, double *y) const - { - // calculate mid point on line string - double x0=0; - double y0=0; - double x1=0; - double y1=0; + { + // calculate mid point on line string + double x0=0; + double y0=0; + double x1=0; + double y1=0; - unsigned size = cont_.size(); - if (size == 1) - { - cont_.get_vertex(0,x,y); - } - else if (size == 2) - { + unsigned size = cont_.size(); + if (size == 1) + { + cont_.get_vertex(0,x,y); + } + else if (size == 2) + { - cont_.get_vertex(0,&x0,&y0); - cont_.get_vertex(1,&x1,&y1); - *x = 0.5 * (x1 + x0); - *y = 0.5 * (y1 + y0); - } - else - { - double len=0.0; - for (unsigned pos = 1; pos < size; ++pos) - { - cont_.get_vertex(pos-1,&x0,&y0); - cont_.get_vertex(pos,&x1,&y1); - double dx = x1 - x0; - double dy = y1 - y0; - len += sqrt(dx * dx + dy * dy); - } - double midlen = 0.5 * len; - double dist = 0.0; - for (unsigned pos = 1; pos < size;++pos) - { - cont_.get_vertex(pos-1,&x0,&y0); - cont_.get_vertex(pos,&x1,&y1); - double dx = x1 - x0; - double dy = y1 - y0; - double seg_len = sqrt(dx * dx + dy * dy); - if (( dist + seg_len) >= midlen) - { - double r = (midlen - dist)/seg_len; - *x = x0 + (x1 - x0) * r; - *y = y0 + (y1 - y0) * r; - break; - } - dist += seg_len; - } - } + cont_.get_vertex(0,&x0,&y0); + cont_.get_vertex(1,&x1,&y1); + *x = 0.5 * (x1 + x0); + *y = 0.5 * (y1 + y0); + } + else + { + double len=0.0; + for (unsigned pos = 1; pos < size; ++pos) + { + cont_.get_vertex(pos-1,&x0,&y0); + cont_.get_vertex(pos,&x1,&y1); + double dx = x1 - x0; + double dy = y1 - y0; + len += sqrt(dx * dx + dy * dy); + } + double midlen = 0.5 * len; + double dist = 0.0; + for (unsigned pos = 1; pos < size;++pos) + { + cont_.get_vertex(pos-1,&x0,&y0); + cont_.get_vertex(pos,&x1,&y1); + double dx = x1 - x0; + double dy = y1 - y0; + double seg_len = sqrt(dx * dx + dy * dy); + if (( dist + seg_len) >= midlen) + { + double r = (midlen - dist)/seg_len; + *x = x0 + (x1 - x0) * r; + *y = y0 + (y1 - y0) * r; + break; + } + dist += seg_len; + } + } - } - void line_to(value_type x,value_type y) - { - cont_.push_back(x,y,SEG_LINETO); - } + } + 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 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); - } - } + 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(); - } + { + return cont_.size(); + } - unsigned vertex(double* x, double* y) - { - return cont_.get_vertex(itr_++,x,y); - } + unsigned vertex(double* x, double* y) + { + return cont_.get_vertex(itr_++,x,y); + } - void rewind(unsigned ) - { - itr_=0; - } + void rewind(unsigned ) + { + itr_=0; + } - bool hit_test(value_type x,value_type y) const - { - return false; - } + bool hit_test(value_type x,value_type y) const + { + return false; + } - void set_capacity(size_t size) - { - cont_.set_capacity(size); - } - virtual ~line_string() {} + void set_capacity(size_t size) + { + cont_.set_capacity(size); + } + virtual ~line_string() {} }; typedef point point_impl; diff --git a/include/layer.hpp b/include/layer.hpp index bb3de47ba..7d6269032 100644 --- a/include/layer.hpp +++ b/include/layer.hpp @@ -15,10 +15,11 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - * - *****************************************************************************/ + * #include +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 $ #ifndef LAYER_HPP @@ -28,27 +29,11 @@ #include "feature.hpp" #include "datasource.hpp" #include -#include namespace mapnik { class MAPNIK_DECL Layer { - friend class boost::serialization::access; - template - 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_; std::string name_; std::string title_; @@ -102,10 +87,4 @@ namespace mapnik }; } -BOOST_CLASS_IMPLEMENTATION(std::vector, boost::serialization::object_serializable) -BOOST_CLASS_TRACKING(std::vector, 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 diff --git a/include/map.hpp b/include/map.hpp index 70f839cef..9f458419a 100644 --- a/include/map.hpp +++ b/include/map.hpp @@ -24,8 +24,6 @@ #ifndef MAP_HPP #define MAP_HPP -#include -#include #include "feature_type_style.hpp" namespace mapnik @@ -33,17 +31,7 @@ namespace mapnik class Layer; class MAPNIK_DECL Map - { - friend class boost::serialization::access; - template - 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 MAX_MAPSIZE=2048; unsigned width_; @@ -94,10 +82,4 @@ namespace mapnik }; } -BOOST_CLASS_IMPLEMENTATION(std::vector, boost::serialization::object_serializable) -BOOST_CLASS_TRACKING(std::vector, 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 diff --git a/include/mapnik.hpp b/include/mapnik.hpp index e19f13b50..5cc0c9d25 100644 --- a/include/mapnik.hpp +++ b/include/mapnik.hpp @@ -79,8 +79,6 @@ 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 diff --git a/include/params.hpp b/include/params.hpp index a45411156..e61ff304e 100644 --- a/include/params.hpp +++ b/include/params.hpp @@ -44,36 +44,6 @@ namespace mapnik class parameters : public param_map { - friend class boost::serialization::access; - - template - 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 - void load(Archive & ar, const unsigned int /*version*/) - { - size_t size; - ar & boost::serialization::make_nvp("size",size); - for (size_t i=0;i class vertex_vector : private boost::noncopyable { - typedef typename T::type value_type; - typedef vertex vertex_type; - enum { - block_shift = 8, - block_size = 1< vertex_type; + enum { + block_shift = 8, + block_size = 1<> block_shift; - if (block >= num_blocks_) - { - allocate_block(block); - } - value_type* vertex = vertexs_[block] + ((pos_ & block_mask) << 1); - unsigned char* cmd= commands_[block] + (pos_ & block_mask); + void push_back (value_type x,value_type y,unsigned command) + { + unsigned block = pos_ >> block_shift; + if (block >= num_blocks_) + { + allocate_block(block); + } + value_type* vertex = vertexs_[block] + ((pos_ & block_mask) << 1); + unsigned char* cmd= commands_[block] + (pos_ & block_mask); - *cmd = static_cast(command); - *vertex++ = x; - *vertex = y; - ++pos_; - } - unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const - { - if (pos >= pos_) return SEG_END; - unsigned block = pos >> block_shift; - const value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); - *x = (*vertex++); - *y = (*vertex); - return commands_[block] [pos & block_mask]; - } + *cmd = static_cast(command); + *vertex++ = x; + *vertex = y; + ++pos_; + } + unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const + { + if (pos >= pos_) return SEG_END; + unsigned block = pos >> block_shift; + const value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); + *x = (*vertex++); + *y = (*vertex); + return commands_[block] [pos & block_mask]; + } - void transform_at(unsigned pos,const CoordTransform& t) - { - if (pos >= pos_) return; - unsigned block = pos >> block_shift; - value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); - t.forward_x(vertex); - ++vertex; - t.forward_y(vertex); - } - void set_capacity(size_t) - { - //do nothing - } + void transform_at(unsigned pos,const CoordTransform& t) + { + if (pos >= pos_) return; + unsigned block = pos >> block_shift; + value_type* vertex = vertexs_[block] + (( pos & block_mask) << 1); + t.forward_x(vertex); + ++vertex; + t.forward_y(vertex); + } + void set_capacity(size_t) + { + //do nothing + } private: - void allocate_block(unsigned block) - { - if (block >= max_blocks_) - { - value_type** new_vertexs = new value_type* [(max_blocks_ + grow_by) * 2]; - unsigned char** new_commands = (unsigned char**)(new_vertexs + max_blocks_ + grow_by); - if (vertexs_) - { - std::memcpy(new_vertexs,vertexs_,max_blocks_ * sizeof(value_type*)); - std::memcpy(new_commands,commands_,max_blocks_ * sizeof(unsigned char*)); - delete [] vertexs_; - } - vertexs_ = new_vertexs; - commands_ = new_commands; - max_blocks_ += grow_by; - } - vertexs_[block] = new value_type [block_size * 2 + block_size / (sizeof(value_type))]; - commands_[block] = (unsigned char*)(vertexs_[block] + block_size*2); - ++num_blocks_; - } + void allocate_block(unsigned block) + { + if (block >= max_blocks_) + { + value_type** new_vertexs = new value_type* [(max_blocks_ + grow_by) * 2]; + unsigned char** new_commands = (unsigned char**)(new_vertexs + max_blocks_ + grow_by); + if (vertexs_) + { + std::memcpy(new_vertexs,vertexs_,max_blocks_ * sizeof(value_type*)); + std::memcpy(new_commands,commands_,max_blocks_ * sizeof(unsigned char*)); + delete [] vertexs_; + } + vertexs_ = new_vertexs; + commands_ = new_commands; + max_blocks_ += grow_by; + } + vertexs_[block] = new value_type [block_size * 2 + block_size / (sizeof(value_type))]; + commands_[block] = (unsigned char*)(vertexs_[block] + block_size*2); + ++num_blocks_; + } }; template struct vertex_vector2 : boost::noncopyable { - typedef typename T::type value_type; - typedef boost::tuple vertex_type; - vertex_vector2() {} - unsigned size() const - { - return cont_.size(); - } + typedef typename T::type value_type; + typedef boost::tuple vertex_type; + typedef typename std::vector::const_iterator const_iterator; + vertex_vector2() {} + unsigned size() const + { + return cont_.size(); + } - void push_back (value_type x,value_type y,unsigned command) - { - cont_.push_back(vertex_type(x,y,command)); - } - unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const - { - if (pos >= cont_.size()) return SEG_END; - vertex_type const& c = cont_[pos]; - *x = boost::get<0>(c); - *y = boost::get<1>(c); - return boost::get<2>(c); - } - - 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); - } + void push_back (value_type x,value_type y,unsigned command) + { + cont_.push_back(vertex_type(x,y,command)); + } + unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const + { + if (pos >= cont_.size()) return SEG_END; + vertex_type const& c = cont_[pos]; + *x = boost::get<0>(c); + *y = boost::get<1>(c); + return boost::get<2>(c); + } + + const_iterator begin() const + { + return cont_.begin(); + } + + const_iterator end() const + { + return cont_.end(); + } + + 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: - std::vector cont_; + std::vector cont_; }; } diff --git a/src/mapnik.cpp b/src/mapnik.cpp index 90a088088..11c467494 100644 --- a/src/mapnik.cpp +++ b/src/mapnik.cpp @@ -23,27 +23,10 @@ //$Id$ #include -#include -#include #include "mapnik.hpp" 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); - } }