2011-10-12 00:25:10 +00:00
|
|
|
/*****************************************************************************
|
2011-11-14 03:54:32 +00:00
|
|
|
*
|
2011-10-12 00:25:10 +00:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
2011-10-12 00:37:44 +00:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2011-10-12 00:25:10 +00:00
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2014-08-12 17:44:11 +00:00
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
|
2013-10-23 22:42:01 +00:00
|
|
|
#include "boost_std_shared_shim.hpp"
|
|
|
|
|
2011-10-12 00:25:10 +00:00
|
|
|
#include <boost/python.hpp>
|
|
|
|
#include <boost/python/module.hpp>
|
|
|
|
#include <boost/python/def.hpp>
|
2012-12-16 20:50:36 +00:00
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
|
2011-10-12 00:25:10 +00:00
|
|
|
|
|
|
|
#include <mapnik/label_collision_detector.hpp>
|
|
|
|
#include <mapnik/map.hpp>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
using mapnik::label_collision_detector4;
|
|
|
|
using mapnik::box2d;
|
|
|
|
using mapnik::Map;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<label_collision_detector4>
|
2011-10-12 00:25:10 +00:00
|
|
|
create_label_collision_detector_from_extent(box2d<double> const &extent)
|
|
|
|
{
|
2013-09-20 13:00:11 +00:00
|
|
|
return std::make_shared<label_collision_detector4>(extent);
|
2011-10-12 00:25:10 +00:00
|
|
|
}
|
|
|
|
|
2013-09-20 13:00:11 +00:00
|
|
|
std::shared_ptr<label_collision_detector4>
|
2011-10-12 00:25:10 +00:00
|
|
|
create_label_collision_detector_from_map(Map const &m)
|
|
|
|
{
|
2011-11-14 03:54:32 +00:00
|
|
|
double buffer = m.buffer_size();
|
|
|
|
box2d<double> extent(-buffer, -buffer, m.width() + buffer, m.height() + buffer);
|
2013-09-20 13:00:11 +00:00
|
|
|
return std::make_shared<label_collision_detector4>(extent);
|
2011-10-12 00:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
boost::python::list
|
2013-09-20 13:00:11 +00:00
|
|
|
make_label_boxes(std::shared_ptr<label_collision_detector4> det)
|
2011-10-12 00:25:10 +00:00
|
|
|
{
|
2011-11-14 03:54:32 +00:00
|
|
|
boost::python::list boxes;
|
2011-10-12 00:25:10 +00:00
|
|
|
|
2011-11-14 03:54:32 +00:00
|
|
|
for (label_collision_detector4::query_iterator jtr = det->begin();
|
|
|
|
jtr != det->end(); ++jtr)
|
|
|
|
{
|
|
|
|
boxes.append<box2d<double> >(jtr->box);
|
|
|
|
}
|
2011-10-12 00:25:10 +00:00
|
|
|
|
2011-11-14 03:54:32 +00:00
|
|
|
return boxes;
|
2011-10-12 00:25:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-11-14 03:54:32 +00:00
|
|
|
void export_label_collision_detector()
|
2011-10-12 00:25:10 +00:00
|
|
|
{
|
2011-11-14 03:54:32 +00:00
|
|
|
using namespace boost::python;
|
|
|
|
|
|
|
|
// for overload resolution
|
|
|
|
void (label_collision_detector4::*insert_box)(box2d<double> const &) = &label_collision_detector4::insert;
|
|
|
|
|
2013-09-20 13:00:11 +00:00
|
|
|
class_<label_collision_detector4, std::shared_ptr<label_collision_detector4>, boost::noncopyable>
|
2011-11-14 03:54:32 +00:00
|
|
|
("LabelCollisionDetector",
|
|
|
|
"Object to detect collisions between labels, used in the rendering process.",
|
|
|
|
no_init)
|
|
|
|
|
|
|
|
.def("__init__", make_constructor(create_label_collision_detector_from_extent),
|
|
|
|
"Creates an empty collision detection object with a given extent. Note "
|
|
|
|
"that the constructor from Map objects is a sensible default and usually "
|
|
|
|
"what you want to do.\n"
|
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
|
|
|
">>> m = Map(size_x, size_y)\n"
|
|
|
|
">>> buf_sz = m.buffer_size\n"
|
|
|
|
">>> extent = mapnik.Box2d(-buf_sz, -buf_sz, m.width + buf_sz, m.height + buf_sz)\n"
|
|
|
|
">>> detector = mapnik.LabelCollisionDetector(extent)")
|
|
|
|
|
|
|
|
.def("__init__", make_constructor(create_label_collision_detector_from_map),
|
|
|
|
"Creates an empty collision detection object matching the given Map object. "
|
|
|
|
"The created detector will have the same size, including the buffer, as the "
|
|
|
|
"map object. This is usually what you want to do.\n"
|
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
|
|
|
">>> m = Map(size_x, size_y)\n"
|
|
|
|
">>> detector = mapnik.LabelCollisionDetector(m)")
|
|
|
|
|
|
|
|
.def("extent", &label_collision_detector4::extent, return_value_policy<copy_const_reference>(),
|
|
|
|
"Returns the total extent (bounding box) of all labels inside the detector.\n"
|
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
|
|
|
">>> detector.extent()\n"
|
|
|
|
"Box2d(573.252589209,494.789179821,584.261023823,496.83610261)")
|
|
|
|
|
|
|
|
.def("boxes", &make_label_boxes,
|
|
|
|
"Returns a list of all the label boxes inside the detector.")
|
|
|
|
|
|
|
|
.def("insert", insert_box,
|
|
|
|
"Insert a 2d box into the collision detector. This can be used to ensure that "
|
|
|
|
"some space is left clear on the map for later overdrawing, for example by "
|
|
|
|
"non-Mapnik processes.\n"
|
|
|
|
"\n"
|
|
|
|
"Example:\n"
|
|
|
|
">>> m = Map(size_x, size_y)\n"
|
|
|
|
">>> detector = mapnik.LabelCollisionDetector(m)"
|
|
|
|
">>> detector.insert(mapnik.Box2d(196, 254, 291, 389))")
|
|
|
|
;
|
2011-10-12 00:25:10 +00:00
|
|
|
}
|