Guest User

Untitled

a guest
Feb 21st, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. struct coloriser
  2. {
  3. explicit coloriser(mapnik::Color const& c)
  4. : c_(c) {}
  5.  
  6. template <typename PixelType>
  7. void operator() ( PixelType & p)
  8. {
  9. // use c to modify p
  10. p[0] = c_.red();
  11. p[1] = c_.green();
  12. p[2] = c_.blue();
  13. }
  14. mapnik::Color const& c_;
  15. };
  16.  
  17. template <typename T>
  18. void agg_renderer<T>::process(point_symbolizer const& sym,
  19. Feature const& feature,
  20. proj_transform const& prj_trans)
  21. {
  22. double x;
  23. double y;
  24. double z=0;
  25. boost::shared_ptr<ImageData32> const& data = sym.get_image();
  26. if ( data )
  27. {
  28. ImageData32 target(int(floor(data->width() * sym.get_scale())),int(floor(data->height() * sym.get_scale())));
  29. scale_image<ImageData32>(target,*data);
  30.  
  31. // creating a lightweight view from rgba
  32. boost::gil::rgba8_view_t view = interleaved_view(target.width(),target.height(),
  33. (boost::gil::rgba8_pixel_t*)target.getData(),
  34. target.width() * 4);
  35.  
  36. mapnik::Color c(255,0,0);
  37. coloriser op(c);
  38. for_each_pixel(view,coloriser<ImageData32::pixel_type>(c));
  39.  
  40. for (unsigned i=0;i<feature.num_geometries();++i)
  41. {
  42. geometry2d const& geom = feature.get_geometry(i);
  43.  
  44. geom.label_position(&x,&y);
  45. prj_trans.backward(x,y,z);
  46. t_.forward(&x,&y);
  47.  
  48. int w = target.width();
  49. int h = target.height();
  50. std::clog << "scale=" << sym.get_scale() << "w=" << w << "h=" << h << "\n";
  51. int px=int(floor(x - 0.5 * w));
  52. int py=int(floor(y - 0.5 * h));
  53. Envelope<double> label_ext (floor(x - 0.5 * w),
  54. floor(y - 0.5 * h),
  55. ceil (x + 0.5 * w),
  56. ceil (y + 0.5 * h));
  57. if (sym.get_allow_overlap() ||
  58. detector_.has_placement(label_ext))
  59. {
  60. pixmap_.set_rectangle_alpha2(target,px,py,sym.get_opacity());
  61. detector_.insert(label_ext);
  62. }
  63. }
  64. }
  65. }
Add Comment
Please, Sign In to add comment