From 81230b2b304a09ed06bab6572f71ee9f6ba6a8ae Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 14 Feb 2012 16:05:25 -0800 Subject: [PATCH 1/6] remove uneeded include --- bindings/python/mapnik_feature.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/bindings/python/mapnik_feature.cpp b/bindings/python/mapnik_feature.cpp index be96050e6..aa4271d89 100644 --- a/bindings/python/mapnik_feature.cpp +++ b/bindings/python/mapnik_feature.cpp @@ -31,7 +31,6 @@ #include #include #include -#include // mapnik #include From 4ad9b4d282b9a745d4291f11e6e5a6e297ab3b2a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 14 Feb 2012 16:07:23 -0800 Subject: [PATCH 2/6] formatting --- plugins/input/csv/csv_datasource.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/input/csv/csv_datasource.cpp b/plugins/input/csv/csv_datasource.cpp index f5932b978..b2848509f 100644 --- a/plugins/input/csv/csv_datasource.cpp +++ b/plugins/input/csv/csv_datasource.cpp @@ -498,7 +498,7 @@ void csv_datasource::parse_csv(T& stream, ( qi::lit("POINT") >> '(' >> double_[ref(x) = _1] - >> double_[ref(y) = _1] >> ')' + >> double_[ref(y) = _1] >> ')' ), ascii::space); From 9ad113d724edb2687bc03952715a820a6b1a3d81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Thu, 16 Feb 2012 23:46:44 +0100 Subject: [PATCH 3/6] =?UTF-8?q?na=C3=AFvely=20replace=20ci.width=20with=20?= =?UTF-8?q?ci.width=20+=20ci.format->character=5Fspacing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/placement_finder.cpp | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index e9b349bde..d01a64721 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -713,6 +713,7 @@ std::auto_ptr placement_finder::get_placement_offset(const { // grab the next character according to the orientation char_info const &ci = orientation > 0 ? info_.at(i) : info_.at(info_.num_characters() - i - 1); + double cwidth = ci.width + ci.format->character_spacing; unsigned c = ci.c; double last_character_angle = angle; @@ -728,10 +729,10 @@ std::auto_ptr placement_finder::get_placement_offset(const double end_x = 0; double end_y = 0; - if (segment_length - distance >= ci.width) + if (segment_length - distance >= cwidth) { //if the distance remaining in this segment is enough, we just go further along the segment - distance += ci.width; + distance += cwidth; end_x = old_x + dx*distance/segment_length; end_y = old_y + dy*distance/segment_length; @@ -757,11 +758,11 @@ std::auto_ptr placement_finder::get_placement_offset(const segment_length = path_distances[index]; } - while (std::sqrt(std::pow(start_x - new_x, 2) + std::pow(start_y - new_y, 2)) < ci.width); //Distance from start_ to new_ + while (std::sqrt(std::pow(start_x - new_x, 2) + std::pow(start_y - new_y, 2)) < cwidth); //Distance from start_ to new_ //Calculate the position to place the end of the character on find_line_circle_intersection( - start_x, start_y, ci.width, + start_x, start_y, cwidth, old_x, old_y, new_x, new_y, end_x, end_y); //results are stored in end_x, end_y @@ -803,8 +804,8 @@ std::auto_ptr placement_finder::get_placement_offset(const if (orientation < 0) { // rotate in place - render_x += ci.width*cosa - (char_height-2)*sina; - render_y -= ci.width*sina + (char_height-2)*cosa; + render_x += cwidth*cosa - (char_height-2)*sina; + render_y -= cwidth*sina + (char_height-2)*cosa; render_angle += M_PI; } current_placement->add_node(c,render_x - current_placement->starting_x, @@ -850,6 +851,7 @@ bool placement_finder::test_placement(const std::auto_ptr { // grab the next character according to the orientation char_info const& ci = orientation > 0 ? info_.at(i) : info_.at(info_.num_characters() - i - 1); + double cwidth = ci.width + ci.format->character_spacing; int c; double x, y, angle; char_properties *properties; @@ -863,8 +865,8 @@ bool placement_finder::test_placement(const std::auto_ptr { // rotate in place /* TODO: What's the meaning of -2? */ - x += ci.width*cosa - (string_height_-2)*sina; - y -= ci.width*sina + (string_height_-2)*cosa; + x += cwidth*cosa - (string_height_-2)*sina; + y -= cwidth*sina + (string_height_-2)*cosa; angle += M_PI; //sin(x+PI) = -sin(x) sina = -sina; @@ -879,12 +881,12 @@ bool placement_finder::test_placement(const std::auto_ptr else { // put four corners of the letter into envelope - e.init(x, y, x + ci.width*cosa, - y - ci.width*sina); + e.init(x, y, x + cwidth*cosa, + y - cwidth*sina); e.expand_to_include(x - ci.height()*sina, y - ci.height()*cosa); - e.expand_to_include(x + (ci.width*cosa - ci.height()*sina), - y - (ci.width*sina + ci.height()*cosa)); + e.expand_to_include(x + (cwidth*cosa - ci.height()*sina), + y - (cwidth*sina + ci.height()*cosa)); } if (!detector_.extent().intersects(e) || From 44beaf1bdf687b4b18f1cd2743a8603ca10dbb2a Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Fri, 17 Feb 2012 00:03:46 +0100 Subject: [PATCH 4/6] Make ShieldSymbolizer variables doubles. Refs #1078. --- include/mapnik/agg_renderer.hpp | 2 +- include/mapnik/symbolizer_helpers.hpp | 8 ++++---- src/agg/agg_renderer.cpp | 9 +++++++-- src/symbolizer_helpers.cpp | 12 ++++++------ 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/include/mapnik/agg_renderer.hpp b/include/mapnik/agg_renderer.hpp index 907de2edd..4e34cdc3b 100644 --- a/include/mapnik/agg_renderer.hpp +++ b/include/mapnik/agg_renderer.hpp @@ -70,7 +70,7 @@ public: void end_map_processing(Map const& map); void start_layer_processing(layer const& lay); void end_layer_processing(layer const& lay); - void render_marker(int x, int y, marker & marker, agg::trans_affine const& tr, double opacity); + void render_marker(double x, double y, marker & marker, agg::trans_affine const& tr, double opacity); void process(point_symbolizer const& sym, mapnik::feature_ptr const& feature, diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index 1dc80f5d3..bea0c030f 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -141,10 +141,10 @@ protected: box2d marker_ext_; boost::optional marker_; agg::trans_affine transform_; - int marker_w_; - int marker_h_; - int marker_x_; - int marker_y_; + double marker_w_; + double marker_h_; + double marker_x_; + double marker_y_; // F***ing templates... // http://womble.decadent.org.uk/c++/template-faq.html#base-lookup using text_symbolizer_helper::geometries_to_process_; diff --git a/src/agg/agg_renderer.cpp b/src/agg/agg_renderer.cpp index 04098820b..bf38b46fb 100644 --- a/src/agg/agg_renderer.cpp +++ b/src/agg/agg_renderer.cpp @@ -75,6 +75,7 @@ // boost #include #include +#include // stl #ifdef MAPNIK_DEBUG @@ -223,7 +224,7 @@ void agg_renderer::end_layer_processing(layer const&) } template -void agg_renderer::render_marker(int x, int y, marker & marker, agg::trans_affine const& tr, double opacity) +void agg_renderer::render_marker(double x, double y, marker & marker, agg::trans_affine const& tr, double opacity) { if (marker.is_vector()) { @@ -262,7 +263,11 @@ void agg_renderer::render_marker(int x, int y, marker & marker, agg::trans_af } else { - pixmap_.set_rectangle_alpha2(**marker.get_bitmap_data(), x, y, opacity); + //TODO: Add subpixel support + pixmap_.set_rectangle_alpha2(**marker.get_bitmap_data(), + boost::math::iround(x), + boost::math::iround(y), + opacity); } } diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index eb79a69dd..27da787c1 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -255,14 +255,14 @@ text_placement_info_ptr shield_symbolizer_helper::get_p // remove displacement from image label double lx = x - pos.first; double ly = y - pos.second; - marker_x_ = int(floor(lx - (0.5 * marker_w_))) + 1; - marker_y_ = int(floor(ly - (0.5 * marker_h_))) + 1; + marker_x_ = lx - 0.5 * marker_w_; + marker_y_ = ly - 0.5 * marker_h_; marker_ext_.re_center(lx, ly); } else { // center image at reference location - marker_x_ = int(floor(label_x - 0.5 * marker_w_)); - marker_y_ = int(floor(label_y - 0.5 * marker_h_)); + marker_x_ = label_x - 0.5 * marker_w_; + marker_y_ = label_y - 0.5 * marker_h_; marker_ext_.re_center(label_x, label_y); } @@ -345,8 +345,8 @@ std::pair shield_symbolizer_helper::get_marke double lx = x - pos.first; double ly = y - pos.second; - int px = int(floor(lx - (0.5*marker_w_))) + 1; - int py = int(floor(ly - (0.5*marker_h_))) + 1; + int px = lx - 0.5*marker_w_; + int py = ly - 0.5*marker_h_; marker_ext_.re_center(lx, ly); // detector_->insert(label_ext); //TODO: Is this done by placement_finder? From 7b22d69932d25376b10484c7ba1533503f42f816 Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Fri, 17 Feb 2012 00:59:20 +0100 Subject: [PATCH 5/6] Revert "+ fix shield/text positioning - we still need to floor both text and shield" floor is removed from position calculation now, resulting in better marker and text matching. Refs #1078. This reverts commit 009a1e45a75836385dd6318ac5cc9cc0d2b26c35. --- src/agg/process_shield_symbolizer.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/agg/process_shield_symbolizer.cpp b/src/agg/process_shield_symbolizer.cpp index 266d83880..6dad62d7b 100644 --- a/src/agg/process_shield_symbolizer.cpp +++ b/src/agg/process_shield_symbolizer.cpp @@ -27,9 +27,9 @@ #include #include #include + #include -// stl -#include + // boost #include @@ -57,8 +57,8 @@ void agg_renderer::process(shield_symbolizer const& sym, std::pair marker_pos = helper.get_marker_position(placement->placements[ii]); render_marker(marker_pos.first, marker_pos.second, helper.get_marker(), helper.get_transform(), sym.get_opacity()); - double x = std::floor(placement->placements[ii].starting_x); - double y = std::floor(placement->placements[ii].starting_y); + double x = placement->placements[ii].starting_x; + double y = placement->placements[ii].starting_y; ren.prepare_glyphs(&(placement->placements[ii])); ren.render(x, y); } From a5e1a66fe62097cb727ccea5e0437d6485d89516 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 16 Feb 2012 17:44:04 -0800 Subject: [PATCH 6/6] c++ style in hextree.hpp to aid in debugging - no functional change --- include/mapnik/hextree.hpp | 88 ++++++++++++++++++++++++++++---------- 1 file changed, 65 insertions(+), 23 deletions(-) diff --git a/include/mapnik/hextree.hpp b/include/mapnik/hextree.hpp index 25b9625ab..8a94293dd 100644 --- a/include/mapnik/hextree.hpp +++ b/include/mapnik/hextree.hpp @@ -75,10 +75,19 @@ class hextree : private boost::noncopyable ~node () { for (unsigned i = 0; i < 16; ++i) - if (children_[i] != 0) delete children_[i],children_[i]=0; + { + if (children_[i] != 0) + { + delete children_[i]; + children_[i]=0; + } + } } - bool is_leaf() const { return children_count == 0; } + bool is_leaf() const + { + return (children_count == 0); + } node * children_[16]; // sum of values for computing mean value using count or pixel_count double reds; @@ -101,8 +110,10 @@ class hextree : private boost::noncopyable bool operator() (const node * lhs, const node* rhs) const { if (lhs->reduce_cost != rhs->reduce_cost) - return lhs->reduce_cost > rhs->reduce_cost; - return lhs > rhs; + { + return (lhs->reduce_cost > rhs->reduce_cost); + } + return (lhs > rhs); } }; @@ -126,13 +137,13 @@ class hextree : private boost::noncopyable enum transparency_mode_t {NO_TRANSPARENCY=0, BINARY_TRANSPARENCY=1, FULL_TRANSPARENCY=2}; unsigned trans_mode_; - inline double gamma(const double &b, const double &g) const + inline double gamma(double b, double g) const { return 255 * std::pow(b/255, g); } public: - explicit hextree(unsigned max_colors=256, const double &g=2.0) + explicit hextree(unsigned max_colors=256, double g=2.0) : max_colors_(max_colors), colors_(0), has_holes_(false), @@ -142,18 +153,23 @@ public: setGamma(g); } - ~hextree() { delete root_;} + ~hextree() + { + delete root_; + } void setMaxColors(unsigned max_colors) { max_colors_ = max_colors; } - void setGamma(const double &g) + void setGamma(double g) { gamma_ = g; for (unsigned i=0; i<256; i++) + { gammaLUT_[i] = gamma(i, 1/gamma_); + } } void setTransMode(unsigned t) @@ -201,7 +217,9 @@ public: if (level == InsertPolicy::MAX_LEVELS) { if (cur_node->pixel_count == 1) + { ++colors_; + } break; } @@ -222,9 +240,13 @@ public: byte a = preprocessAlpha(c.a); unsigned ind=0; if (a < InsertPolicy::MIN_ALPHA || colors_ == 0) + { return 0; + } if (colors_ == 1) + { return pal_remap_[has_holes_?1:0]; + } rgba_hash_table::iterator it = color_hashmap_.find(c); if (it == color_hashmap_.end()) @@ -253,8 +275,10 @@ public: db = sorted_pal_[i].b - c.b; da = sorted_pal_[i].a - a; // stop criteria based on properties of used sorting - if ((dr+db+dg+da) * (dr+db+dg+da) / 4 > dist) + if (((dr+db+dg+da) * (dr+db+dg+da) / 4 > dist)) + { break; + } newdist = dr*dr + dg*dg + db*db + da*da; if (newdist < dist) { @@ -270,7 +294,9 @@ public: da = sorted_pal_[i].a - a; // stop criteria based on properties of used sorting if ((dr+db+dg+da) * (dr+db+dg+da) / 4 > dist) + { break; + } newdist = dr*dr + dg*dg + db*db + da*da; if (newdist < dist) { @@ -282,7 +308,9 @@ public: color_hashmap_[c] = ind; } else + { ind = it->second; + } return pal_remap_[ind]; } @@ -303,7 +331,7 @@ public: root_ = new node(); // sort palette for binary searching in quantization - std::sort(sorted_pal_.begin(), sorted_pal_.end(),rgba::mean_sort_cmp()); + std::sort(sorted_pal_.begin(), sorted_pal_.end(), rgba::mean_sort_cmp()); // returned palette is rearanged, so that colors with a<255 are at the begining pal_remap_.resize(sorted_pal_.size()); @@ -332,25 +360,34 @@ private: void print_tree(node *r, int d=0, int id=0) const { for (int i=0; icount>0) + { printf("%d: (+%d/%d/%.5f) (%d %d %d %d)\n", id, (int)r->count, (int)r->pixel_count, r->reduce_cost, (int)round(gamma(r->reds / r->count, gamma_)), (int)round(gamma(r->greens / r->count, gamma_)), (int)round(gamma(r->blues / r->count, gamma_)), (int)(r->alphas / r->count)); + } else + { printf("%d: (%d/%d/%.5f) (%d %d %d %d)\n", id, (int)r->count, (int)r->pixel_count, r->reduce_cost, (int)round(gamma(r->reds / r->pixel_count, gamma_)), (int)round(gamma(r->greens / r->pixel_count, gamma_)), (int)round(gamma(r->blues / r->pixel_count, gamma_)), (int)(r->alphas / r->pixel_count)); - for (unsigned idx=0; idx < 16; ++idx) if (r->children_[idx] != 0) - { - print_tree(r->children_[idx], d+1, idx); - } + } + for (unsigned idx=0; idx < 16; ++idx) + { + if (r->children_[idx] != 0) + { + print_tree(r->children_[idx], d+1, idx); + } + } } // traverse tree and search for nodes with count!=0, that represent single color. @@ -368,10 +405,13 @@ private: (byte)round(gamma(itr->greens / count, gamma_)), (byte)round(gamma(itr->blues / count, gamma_)), a)); } - for (unsigned idx=0; idx < 16; ++idx) if (itr->children_[idx] != 0) - { - create_palette_rek(palette, itr->children_[idx]); - } + for (unsigned idx=0; idx < 16; ++idx) + { + if (itr->children_[idx] != 0) + { + create_palette_rek(palette, itr->children_[idx]); + } + } } // assign value to r, representing some penalty for assigning one @@ -381,7 +421,9 @@ private: //initial small value, so that all nodes have >0 cost r->reduce_cost = r->pixel_count/1000.0; if (r->children_count==0) + { return; + } // mean color of all pixels in subtree double mean_r = r->reds / r->pixel_count; double mean_g = r->greens / r->pixel_count; @@ -421,20 +463,20 @@ private: std::set colored_leaves_heap; colored_leaves_heap.insert(root_); - while(!colored_leaves_heap.empty() && colors_ < max_colors_ && tries < 16) + while((!colored_leaves_heap.empty() && (colors_ < max_colors_) && (tries < 16))) { // select worst node to remove it from palette and replace with children node * cur_node = *colored_leaves_heap.begin(); colored_leaves_heap.erase(colored_leaves_heap.begin()); - if (cur_node->children_count + colors_ - 1 > max_colors_) + if (((cur_node->children_count + colors_ - 1) > max_colors_)) { tries++; continue; // try few times, maybe next will have less children } - tries=0; + tries = 0; // ignore leaves and also nodes with small mean error and not excessive number of pixels - if ((cur_node->reduce_cost / cur_node->pixel_count + 1) * std::log(double(cur_node->pixel_count)) > 15 - && cur_node->children_count > 0) + if (((cur_node->reduce_cost / cur_node->pixel_count + 1) * std::log(double(cur_node->pixel_count))) > 15 + && (cur_node->children_count > 0)) { colors_--; cur_node->count = 0;