/usr/include/mapnik/vertex_converters.hpp is in libmapnik-dev 3.0.9+ds-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 | /*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* 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
*
*****************************************************************************/
#ifndef MAPNIK_VERTEX_CONVERTERS_HPP
#define MAPNIK_VERTEX_CONVERTERS_HPP
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/attribute.hpp>
#include <mapnik/view_transform.hpp>
#include <mapnik/transform_path_adapter.hpp>
#include <mapnik/offset_converter.hpp>
#include <mapnik/simplify.hpp>
#include <mapnik/simplify_converter.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
#include <mapnik/symbolizer_keys.hpp>
#include <mapnik/symbolizer.hpp>
// agg
#include "agg_math_stroke.h"
#include "agg_trans_affine.h"
#include "agg_conv_clip_polygon.h"
#include "agg_conv_clip_polyline.h"
#include "agg_conv_smooth_poly1.h"
#include "agg_conv_stroke.h"
#include "agg_conv_dash.h"
#include "agg_conv_transform.h"
// stl
#include <type_traits>
#include <stdexcept>
#include <array>
namespace mapnik {
struct transform_tag {};
struct clip_line_tag {};
struct clip_poly_tag {};
struct smooth_tag {};
struct simplify_tag {};
struct stroke_tag {};
struct dash_tag {};
struct affine_transform_tag {};
struct offset_transform_tag {};
namespace detail {
template <typename T0, typename T1>
struct converter_traits {};
template <typename T>
struct converter_traits<T, mapnik::smooth_tag>
{
using geometry_type = T;
using conv_type = typename agg::conv_smooth_poly1_curve<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
geom.smooth_value(get<value_double, keys::smooth>(args.sym, args.feature, args.vars));
}
};
template <typename T>
struct converter_traits<T,mapnik::simplify_tag>
{
using geometry_type = T;
using conv_type = simplify_converter<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
geom.set_simplify_algorithm(get<simplify_algorithm_e,keys::simplify_algorithm>(args.sym, args.feature, args.vars));
geom.set_simplify_tolerance(get<value_double,keys::simplify_tolerance>(args.sym,args.feature, args.vars));
}
};
template <typename T>
struct converter_traits<T, mapnik::clip_line_tag>
{
using geometry_type = T;
using conv_type = typename agg::conv_clip_polyline<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
auto const& box = args.bbox;
geom.clip_box(box.minx(),box.miny(),box.maxx(),box.maxy());
}
};
template <typename T>
struct converter_traits<T, mapnik::dash_tag>
{
using geometry_type = T;
using conv_type = typename agg::conv_dash<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
auto const& sym = args.sym;
auto const& feat = args.feature;
auto const& vars = args.vars;
double scale_factor = args.scale_factor;
auto dash = get_optional<dash_array>(sym, keys::stroke_dasharray, feat, vars);
if (dash)
{
for (auto const& d : *dash)
{
geom.add_dash(d.first * scale_factor,
d.second * scale_factor);
}
}
}
};
template <typename Symbolizer, typename PathType, typename Feature>
void set_join_caps(Symbolizer const& sym, PathType & stroke, Feature const& feature, attributes const& vars)
{
line_join_enum join = get<line_join_enum,keys::stroke_linejoin>(sym, feature, vars);
switch (join)
{
case MITER_JOIN:
stroke.generator().line_join(agg::miter_join);
break;
case MITER_REVERT_JOIN:
stroke.generator().line_join(agg::miter_join);
break;
case ROUND_JOIN:
stroke.generator().line_join(agg::round_join);
break;
default:
stroke.generator().line_join(agg::bevel_join);
}
line_cap_enum cap = get<line_cap_enum,keys::stroke_linecap>(sym, feature, vars);
switch (cap)
{
case BUTT_CAP:
stroke.generator().line_cap(agg::butt_cap);
break;
case SQUARE_CAP:
stroke.generator().line_cap(agg::square_cap);
break;
default:
stroke.generator().line_cap(agg::round_cap);
}
}
template <typename T>
struct converter_traits<T, mapnik::stroke_tag>
{
using geometry_type = T;
using conv_type = typename agg::conv_stroke<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
auto const& sym = args.sym;
auto const& feat = args.feature;
auto const& vars = args.vars;
set_join_caps(sym, geom, feat, vars);
double miterlimit = get<value_double,keys::stroke_miterlimit>(sym, feat, vars);
geom.generator().miter_limit(miterlimit);
double scale_factor = args.scale_factor;
double width = get<value_double,keys::stroke_width>(sym, feat, vars);
geom.generator().width(width * scale_factor);
}
};
template <typename T>
struct converter_traits<T,mapnik::clip_poly_tag>
{
using geometry_type = T;
using conv_type = typename agg::conv_clip_polygon<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
auto const& box = args.bbox;
geom.clip_box(box.minx(),box.miny(),box.maxx(),box.maxy());
}
};
template <typename T>
struct converter_traits<T,mapnik::transform_tag>
{
using geometry_type = T;
using conv_type = transform_path_adapter<view_transform, geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
geom.set_proj_trans(args.prj_trans);
geom.set_trans(args.tr);
}
};
template <typename T>
struct converter_traits<T,mapnik::affine_transform_tag>
{
using geometry_type = T;
using conv_base_type = agg::conv_transform<geometry_type, agg::trans_affine const>;
struct conv_type : public conv_base_type
{
conv_type(geometry_type& geom)
: conv_base_type(geom, agg::trans_affine::identity) {}
};
template <typename Args>
static void setup(geometry_type & geom, Args & args)
{
geom.transformer(args.affine_trans);
}
};
template <typename T>
struct converter_traits<T,mapnik::offset_transform_tag>
{
using geometry_type = T;
using conv_type = offset_converter<geometry_type>;
template <typename Args>
static void setup(geometry_type & geom, Args const& args)
{
auto const& sym = args.sym;
auto const& feat = args.feature;
auto const& vars = args.vars;
double offset = get<value_double, keys::offset>(sym, feat, vars);
geom.set_offset(offset * args.scale_factor);
}
};
template <typename T0, typename T1>
struct is_switchable
{
static constexpr bool value = true;
};
template <typename T>
struct is_switchable<T, transform_tag>
{
static constexpr bool value = false;
};
template <typename T>
struct is_switchable<T, stroke_tag>
{
static constexpr bool value = false;
};
template <typename Dispatcher, typename... ConverterTypes>
struct converters_helper;
template <typename Dispatcher, typename Current, typename... ConverterTypes>
struct converters_helper<Dispatcher,Current,ConverterTypes...>
{
template <typename Converter>
static void set(Dispatcher & disp, std::size_t state)
{
if (std::is_same<Converter,Current>::value)
{
constexpr std::size_t index = sizeof...(ConverterTypes) ;
disp.vec_[index] = state;
}
else
{
converters_helper<Dispatcher,ConverterTypes...>:: template set<Converter>(disp, state);
}
}
template <typename Geometry, typename Processor>
static void forward(Dispatcher & disp, Geometry & geom, Processor & proc,
typename std::enable_if<detail::is_switchable<Geometry,Current>::value>::type* = 0)
{
constexpr std::size_t index = sizeof...(ConverterTypes);
if (disp.vec_[index] == 1)
{
using conv_type = typename detail::converter_traits<Geometry,Current>::conv_type;
conv_type conv(geom);
detail::converter_traits<conv_type,Current>::setup(conv,disp.args_);
converters_helper<Dispatcher, ConverterTypes...>::forward(disp, conv, proc);
}
else
{
converters_helper<Dispatcher,ConverterTypes...>::forward(disp, geom, proc);
}
}
template <typename Geometry, typename Processor>
static void forward(Dispatcher & disp, Geometry & geom, Processor & proc,
typename std::enable_if<!detail::is_switchable<Geometry,Current>::value>::type* = 0)
{
using conv_type = typename detail::converter_traits<Geometry,Current>::conv_type;
conv_type conv(geom);
detail::converter_traits<conv_type,Current>::setup(conv,disp.args_);
converters_helper<Dispatcher, ConverterTypes...>::forward(disp, conv, proc);
}
};
template <typename Dispatcher>
struct converters_helper<Dispatcher>
{
template <typename Converter>
static void set(Dispatcher &, std::size_t) {}
template <typename Geometry, typename Processor>
static void forward(Dispatcher &, Geometry & geom, Processor & proc)
{
proc.add_path(geom);
}
};
template <typename Args, std::size_t NUM_CONV>
struct dispatcher : util::noncopyable
{
using this_type = dispatcher;
using args_type = Args;
dispatcher(box2d<double> const& bbox, symbolizer_base const& sym, view_transform const& tr,
proj_transform const& prj_trans, agg::trans_affine const& affine_trans, feature_impl const& feature,
attributes const& vars, double scale_factor)
: args_(bbox,sym,tr,prj_trans,affine_trans,feature,vars,scale_factor)
{
std::fill(vec_.begin(), vec_.end(), 0);
}
std::array<std::size_t, NUM_CONV> vec_;
args_type args_;
};
struct arguments : util::noncopyable
{
arguments(box2d<double> const& _bbox, symbolizer_base const& _sym, view_transform const& _tr,
proj_transform const& _prj_trans, agg::trans_affine const& _affine_trans, feature_impl const& _feature,
attributes const& _vars, double _scale_factor)
: bbox(_bbox),
sym(_sym),
tr(_tr),
prj_trans(_prj_trans),
affine_trans(_affine_trans),
feature(_feature),
vars(_vars),
scale_factor(_scale_factor) {}
box2d<double> const& bbox;
symbolizer_base const& sym;
view_transform const& tr;
proj_transform const& prj_trans;
agg::trans_affine const& affine_trans;
feature_impl const& feature;
attributes const& vars;
double scale_factor;
};
}
template <typename... ConverterTypes >
struct vertex_converter : private util::noncopyable
{
using bbox_type = box2d<double>;
using symbolizer_type = symbolizer_base;
using trans_type = view_transform;
using proj_trans_type = proj_transform;
using affine_trans_type = agg::trans_affine;
using feature_type = feature_impl;
using args_type = detail::arguments;
using dispatcher_type = detail::dispatcher<args_type, sizeof...(ConverterTypes)>;
vertex_converter(bbox_type const& bbox,
symbolizer_type const& sym,
trans_type const& tr,
proj_trans_type const& prj_trans,
affine_trans_type const& affine_trans,
feature_type const& feature,
attributes const& vars,
double scale_factor)
: disp_(bbox,sym,tr,prj_trans,affine_trans,feature,vars,scale_factor) {}
template <typename VertexAdapter, typename Processor>
void apply(VertexAdapter & geom, Processor & proc)
{
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template forward<VertexAdapter, Processor>(disp_, geom, proc);
}
template <typename Converter>
void set()
{
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template set<Converter>(disp_, 1);
}
template <typename Converter>
void unset()
{
detail::converters_helper<dispatcher_type, ConverterTypes...>:: template set<Converter>(disp_, 0);
}
dispatcher_type disp_;
};
}
#endif // MAPNIK_VERTEX_CONVERTERS_HPP
|