refactor local pattern alignment calc

This commit is contained in:
artemp 2015-03-20 10:43:42 +01:00
parent 360f920924
commit 9352d69987
3 changed files with 82 additions and 36 deletions

View file

@ -0,0 +1,68 @@
/*****************************************************************************
*
* 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_PATTERN_ALIGNMENT_HPP
#define MAPNIK_PATTERN_ALIGNMENT_HPP
#include <mapnik/geometry_impl.hpp>
namespace mapnik { namespace detail {
struct apply_local_alignment
{
apply_local_alignment(view_transform const& t,
proj_transform const& prj_trans,
box2d<double> const& clip_box,
double & x, double & y)
: t_(t),
prj_trans_(prj_trans),
clip_box_(clip_box),
x_(x),
y_(y) {}
void operator() (new_geometry::polygon_vertex_adapter & va)
{
using clipped_geometry_type = agg::conv_clip_polygon<new_geometry::polygon_vertex_adapter>;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box_.minx(),clip_box_.miny(),clip_box_.maxx(),clip_box_.maxy());
path_type path(t_, clipped, prj_trans_);
path.vertex(&x_,&y_);
}
template <typename Adapter>
void operator() (Adapter & va)
{
// no-op
}
view_transform const& t_;
proj_transform const& prj_trans_;
box2d<double> const& clip_box_;
double & x_;
double & y_;
};
}}
#endif // MAPNIK_PATTERN_ALIGNMENT_HPP

View file

@ -38,6 +38,7 @@
#include <mapnik/renderer_common/clipping_extent.hpp>
#include <mapnik/renderer_common/render_pattern.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp>
// agg
#include "agg_basics.h"
#include "agg_rendering_buffer.h"
@ -85,8 +86,8 @@ struct agg_renderer_process_visitor_p
mapnik::image_rgba8 image(bbox_image.width(), bbox_image.height());
render_pattern<buffer_type>(*ras_ptr_, marker, image_tr, 1.0, image);
using clipped_geometry_type = agg::conv_clip_polygon<vertex_adapter>;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
//using clipped_geometry_type = agg::conv_clip_polygon<vertex_adapter>;
//using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
agg::rendering_buffer buf(current_buffer_->getBytes(), current_buffer_->width(),
current_buffer_->height(), current_buffer_->getRowSize());
@ -143,16 +144,9 @@ struct agg_renderer_process_visitor_p
{
double x0 = 0;
double y0 = 0;
#if 0 // FIXME
if (feature_.num_geometries() > 0)
{
vertex_adapter va(feature_.get_geometry(0));
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box.minx(),clip_box.miny(),clip_box.maxx(),clip_box.maxy());
path_type path(common_.t_,clipped,prj_trans_);
path.vertex(&x0,&y0);
}
#endif
using apply_local_alignment = detail::apply_local_alignment;
apply_local_alignment apply(common_.t_,prj_trans_, clip_box, x0, y0);
util::apply_visitor(new_geometry::vertex_processor<apply_local_alignment>(apply), feature_.get_geometry());
offset_x = unsigned(current_buffer_->width() - x0);
offset_y = unsigned(current_buffer_->height() - y0);
}
@ -252,16 +246,10 @@ struct agg_renderer_process_visitor_p
{
double x0 = 0;
double y0 = 0;
#if 0 // FIXME
if (feature_.num_geometries() > 0)
{
vertex_adapter va(feature_.get_geometry(0));
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box.minx(),clip_box.miny(),clip_box.maxx(),clip_box.maxy());
path_type path(common_.t_,clipped,prj_trans_);
path.vertex(&x0,&y0);
}
#endif
using apply_local_alignment = detail::apply_local_alignment;
apply_local_alignment apply(common_.t_,prj_trans_, clip_box, x0, y0);
util::apply_visitor(new_geometry::vertex_processor<apply_local_alignment>(apply), feature_.get_geometry());
offset_x = unsigned(current_buffer_->width() - x0);
offset_y = unsigned(current_buffer_->height() - y0);
}

View file

@ -35,6 +35,7 @@
#include <mapnik/agg_rasterizer.hpp>
#include <mapnik/renderer_common/clipping_extent.hpp>
#include <mapnik/renderer_common/apply_vertex_converter.hpp>
#include <mapnik/renderer_common/pattern_alignment.hpp>
namespace mapnik
{
@ -111,22 +112,11 @@ void cairo_renderer<T>::process(polygon_pattern_symbolizer const& sym,
{
double x0 = 0.0;
double y0 = 0.0;
// FIXME
#if 0
if (feature.num_geometries() > 0)
{
using clipped_geometry_type = agg::conv_clip_polygon<vertex_adapter>;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
vertex_adapter va(feature.get_geometry(0));
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box.minx(), clip_box.miny(),
clip_box.maxx(), clip_box.maxy());
path_type path(common_.t_, clipped, prj_trans);
path.vertex(&x0, &y0);
}
using apply_local_alignment = detail::apply_local_alignment;
apply_local_alignment apply(common_.t_, prj_trans, clip_box, x0, y0);
util::apply_visitor(new_geometry::vertex_processor<apply_local_alignment>(apply), feature.get_geometry());
offset_x = std::abs(clip_box.width() - x0);
offset_y = std::abs(clip_box.height() - y0);
#endif
}
util::apply_visitor(cairo_renderer_process_visitor_p(context_, image_tr, offset_x, offset_y, opacity), marker);