2011-04-26 23:44:52 +02:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/grid/grid_rasterizer.hpp>
|
|
|
|
#include <mapnik/grid/grid_renderer.hpp>
|
|
|
|
#include <mapnik/grid/grid_pixfmt.hpp>
|
|
|
|
#include <mapnik/grid/grid_pixel.hpp>
|
|
|
|
#include <mapnik/grid/grid.hpp>
|
|
|
|
#include <mapnik/segment.hpp>
|
2011-12-09 12:08:50 +01:00
|
|
|
#include <mapnik/expression_evaluator.hpp>
|
2011-04-26 23:44:52 +02:00
|
|
|
|
|
|
|
// boost
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
|
|
|
// agg
|
|
|
|
#include "agg_rasterizer_scanline_aa.h"
|
|
|
|
#include "agg_renderer_scanline.h"
|
2011-05-17 08:24:49 +02:00
|
|
|
#include "agg_scanline_bin.h"
|
2011-04-26 23:44:52 +02:00
|
|
|
#include "agg_conv_stroke.h"
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
namespace mapnik
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void grid_renderer<T>::process(building_symbolizer const& sym,
|
2012-02-02 02:53:35 +01:00
|
|
|
mapnik::feature_ptr const& feature,
|
|
|
|
proj_transform const& prj_trans)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
|
|
|
typedef coord_transform2<CoordTransform,geometry_type> path_type;
|
|
|
|
typedef agg::renderer_base<mapnik::pixfmt_gray16> ren_base;
|
2011-05-17 08:24:49 +02:00
|
|
|
typedef agg::renderer_scanline_bin_solid<ren_base> renderer;
|
|
|
|
agg::scanline_bin sl;
|
2011-04-26 23:44:52 +02:00
|
|
|
|
|
|
|
grid_rendering_buffer buf(pixmap_.raw_data(), width_, height_, width_);
|
|
|
|
mapnik::pixfmt_gray16 pixf(buf);
|
|
|
|
|
|
|
|
ren_base renb(pixf);
|
|
|
|
renderer ren(renb);
|
|
|
|
|
|
|
|
ras_ptr->reset();
|
|
|
|
|
2011-12-09 12:08:50 +01:00
|
|
|
double height = 0.0;
|
|
|
|
expression_ptr height_expr = sym.height();
|
|
|
|
if (height_expr)
|
|
|
|
{
|
2012-02-02 01:37:05 +01:00
|
|
|
value_type result = boost::apply_visitor(evaluate<Feature,value_type>(*feature), *height_expr);
|
2011-12-09 12:08:50 +01:00
|
|
|
height = result.to_double() * scale_factor_;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-02-02 01:37:05 +01:00
|
|
|
for (unsigned i=0;i<feature->num_geometries();++i)
|
2011-04-26 23:44:52 +02:00
|
|
|
{
|
2012-02-02 01:37:05 +01:00
|
|
|
geometry_type const& geom = feature->get_geometry(i);
|
2011-04-26 23:44:52 +02:00
|
|
|
if (geom.num_points() > 2)
|
|
|
|
{
|
|
|
|
boost::scoped_ptr<geometry_type> frame(new geometry_type(LineString));
|
|
|
|
boost::scoped_ptr<geometry_type> roof(new geometry_type(Polygon));
|
|
|
|
std::deque<segment_t> face_segments;
|
|
|
|
double x0(0);
|
|
|
|
double y0(0);
|
|
|
|
unsigned cm = geom.vertex(&x0,&y0);
|
|
|
|
for (unsigned j=1;j<geom.num_points();++j)
|
|
|
|
{
|
|
|
|
double x(0);
|
|
|
|
double y(0);
|
|
|
|
cm = geom.vertex(&x,&y);
|
|
|
|
if (cm == SEG_MOVETO)
|
|
|
|
{
|
|
|
|
frame->move_to(x,y);
|
|
|
|
}
|
|
|
|
else if (cm == SEG_LINETO)
|
|
|
|
{
|
|
|
|
frame->line_to(x,y);
|
|
|
|
face_segments.push_back(segment_t(x0,y0,x,y));
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2011-04-26 23:44:52 +02:00
|
|
|
x0 = x;
|
|
|
|
y0 = y;
|
|
|
|
}
|
|
|
|
std::sort(face_segments.begin(),face_segments.end(), y_order);
|
|
|
|
std::deque<segment_t>::const_iterator itr=face_segments.begin();
|
|
|
|
for (;itr!=face_segments.end();++itr)
|
|
|
|
{
|
|
|
|
boost::scoped_ptr<geometry_type> faces(new geometry_type(Polygon));
|
|
|
|
faces->move_to(itr->get<0>(),itr->get<1>());
|
|
|
|
faces->line_to(itr->get<2>(),itr->get<3>());
|
|
|
|
faces->line_to(itr->get<2>(),itr->get<3>() + height);
|
|
|
|
faces->line_to(itr->get<0>(),itr->get<1>() + height);
|
|
|
|
|
|
|
|
path_type faces_path (t_,*faces,prj_trans);
|
|
|
|
ras_ptr->add_path(faces_path);
|
2012-02-02 01:37:05 +01:00
|
|
|
ren.color(mapnik::gray16(feature->id()));
|
2011-04-26 23:44:52 +02:00
|
|
|
agg::render_scanlines(*ras_ptr, sl, ren);
|
|
|
|
ras_ptr->reset();
|
|
|
|
|
|
|
|
frame->move_to(itr->get<0>(),itr->get<1>());
|
|
|
|
frame->line_to(itr->get<0>(),itr->get<1>()+height);
|
|
|
|
}
|
|
|
|
|
|
|
|
geom.rewind(0);
|
|
|
|
for (unsigned j=0;j<geom.num_points();++j)
|
|
|
|
{
|
|
|
|
double x,y;
|
|
|
|
unsigned cm = geom.vertex(&x,&y);
|
|
|
|
if (cm == SEG_MOVETO)
|
|
|
|
{
|
|
|
|
frame->move_to(x,y+height);
|
|
|
|
roof->move_to(x,y+height);
|
|
|
|
}
|
|
|
|
else if (cm == SEG_LINETO)
|
|
|
|
{
|
|
|
|
frame->line_to(x,y+height);
|
|
|
|
roof->line_to(x,y+height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
path_type path(t_,*frame,prj_trans);
|
|
|
|
agg::conv_stroke<path_type> stroke(path);
|
|
|
|
ras_ptr->add_path(stroke);
|
2012-02-02 01:37:05 +01:00
|
|
|
ren.color(mapnik::gray16(feature->id()));
|
2011-04-26 23:44:52 +02:00
|
|
|
agg::render_scanlines(*ras_ptr, sl, ren);
|
|
|
|
ras_ptr->reset();
|
|
|
|
|
|
|
|
path_type roof_path (t_,*roof,prj_trans);
|
|
|
|
ras_ptr->add_path(roof_path);
|
2012-02-02 01:37:05 +01:00
|
|
|
ren.color(mapnik::gray16(feature->id()));
|
2011-04-26 23:44:52 +02:00
|
|
|
agg::render_scanlines(*ras_ptr, sl, ren);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pixmap_.add_feature(feature);
|
|
|
|
}
|
|
|
|
|
|
|
|
template void grid_renderer<grid>::process(building_symbolizer const&,
|
2012-02-02 02:53:35 +01:00
|
|
|
mapnik::feature_ptr const&,
|
|
|
|
proj_transform const&);
|
2011-04-26 23:44:52 +02:00
|
|
|
|
|
|
|
}
|