Merge branch 'mapycz-3.x-szn-markers-symbolizer-vertex-placements'

This commit is contained in:
artemp 2014-08-08 12:16:30 +01:00
commit a80782e544
20 changed files with 505 additions and 33 deletions

View file

@ -26,6 +26,8 @@
#include <mapnik/markers_placements/line.hpp>
#include <mapnik/markers_placements/point.hpp>
#include <mapnik/markers_placements/interior.hpp>
#include <mapnik/markers_placements/vertext_first.hpp>
#include <mapnik/markers_placements/vertext_last.hpp>
#include <mapnik/symbolizer_enumerations.hpp>
#include <boost/variant.hpp>
@ -41,7 +43,9 @@ class markers_placement_finder : mapnik::noncopyable
public:
using markers_placement = boost::variant<markers_point_placement<Locator, Detector>,
markers_line_placement<Locator, Detector>,
markers_interior_placement<Locator, Detector>>;
markers_interior_placement<Locator, Detector>,
markers_vertex_first_placement<Locator, Detector>,
markers_vertex_last_placement<Locator, Detector>>;
class get_point_visitor : public boost::static_visitor<bool>
{
@ -74,22 +78,14 @@ public:
{
}
/** Get a point where the marker should be placed.
* Each time this function is called a new point is returned.
* \param x Return value for x position
* \param y Return value for x position
* \param angle Return value for rotation angle
* \param ignore_placement Whether to add selected position to detector
* \return True if a place is found, false if none is found.
*/
// Get next point where the marker should be placed. Returns true if a place is found, false if none is found.
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
return boost::apply_visitor(get_point_visitor(x, y, angle, ignore_placement), placement_);
}
private:
/** Factory function for particular placement implementations.
*/
// Factory function for particular placement implementations.
static markers_placement create(marker_placement_e placement_type,
Locator &locator,
box2d<double> const& size,
@ -110,7 +106,9 @@ private:
{
{ MARKER_POINT_PLACEMENT, boost::value_factory<markers_point_placement<Locator, Detector>>() },
{ MARKER_INTERIOR_PLACEMENT, boost::value_factory<markers_interior_placement<Locator, Detector>>() },
{ MARKER_LINE_PLACEMENT, boost::value_factory<markers_line_placement<Locator, Detector>>() }
{ MARKER_LINE_PLACEMENT, boost::value_factory<markers_line_placement<Locator, Detector>>() },
{ MARKER_VERTEX_FIRST_PLACEMENT, boost::value_factory<markers_vertex_first_placement<Locator, Detector>>() },
{ MARKER_VERTEX_LAST_PLACEMENT, boost::value_factory<markers_vertex_last_placement<Locator, Detector>>() }
};
return factories.at(placement_type)(locator, size, tr, detector, spacing, max_error, allow_overlap);
}

View file

@ -206,13 +206,13 @@ private:
double last_y;
double next_x;
double next_y;
/** If a marker could not be placed at the exact point where it should
* go the next marker's distance will be a bit lower. */
// If a marker could not be placed at the exact point where it should
// go the next marker's distance will be a bit lower.
double error_;
double spacing_left_;
unsigned marker_nr_;
/** Set spacing_left_, adjusts error_ and performs sanity checks. */
// Set spacing_left_, adjusts error_ and performs sanity checks.
void set_spacing_left(double sl, bool allow_negative=false)
{
double delta_error = sl - spacing_left_;

View file

@ -55,27 +55,16 @@ public:
{
rewind();
}
virtual ~markers_point_placement() {}
/** Start again at first marker.
* \note Returns the same list of markers only works when they were NOT added
* to the detector.
*/
virtual void rewind()
// Start again at first marker. Returns the same list of markers only works when they were NOT added to the detector.
void rewind()
{
locator_.rewind(0);
done_ = false;
}
/** Get a point where the marker should be placed.
* Each time this function is called a new point is returned.
* \param x Return value for x position
* \param y Return value for x position
* \param angle Return value for rotation angle
* \param ignore_placement Whether to add selected position to detector
* \return True if a place is found, false if none is found.
*/
virtual bool get_point(double &x, double &y, double &angle, bool ignore_placement)
// Get next point where the marker should be placed. Returns true if a place is found, false if none is found.
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
if (done_)
{
@ -129,7 +118,7 @@ protected:
double marker_width_;
bool done_;
/** Rotates the size_ box and translates the position. */
// Rotates the size_ box and translates the position.
box2d<double> perform_transform(double angle, double dx, double dy)
{
double x1 = size_.minx();
@ -156,4 +145,3 @@ protected:
}
#endif // MAPNIK_MARKERS_PLACEMENTS_POINT_HPP

View file

@ -0,0 +1,98 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP
#define MAPNIK_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP
#include <mapnik/markers_placements/point.hpp>
namespace mapnik {
template <typename Locator, typename Detector>
class markers_vertex_first_placement : public markers_point_placement<Locator, Detector>
{
public:
markers_vertex_first_placement(
Locator &locator,
box2d<double> const& size,
agg::trans_affine const& tr,
Detector &detector,
double spacing,
double max_error,
bool allow_overlap)
: markers_point_placement<Locator, Detector>(
locator, size, tr, detector,
spacing, max_error, allow_overlap)
{
}
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
if (this->done_)
{
return false;
}
if (this->locator_.type() == mapnik::geometry_type::types::Point)
{
return markers_point_placement<Locator, Detector>::get_point(x, y, angle, ignore_placement);
}
double x0, y0;
if (agg::is_stop(this->locator_.vertex(&x0, &y0)))
{
this->done_ = true;
return false;
}
x = x0;
y = y0;
angle = 0;
double x1, y1;
if (agg::is_line_to(this->locator_.vertex(&x1, &y1)))
{
angle = std::atan2(y1 - y0, x1 - x0);
}
box2d<double> box = this->perform_transform(angle, x, y);
if (!this->allow_overlap_ && !this->detector_.has_placement(box))
{
return false;
}
if (!ignore_placement)
{
this->detector_.insert(box);
}
this->done_ = true;
return true;
}
};
}
#endif // MAPNIK_MARKERS_PLACEMENTS_VERTEXT_FIRST_HPP

View file

@ -0,0 +1,103 @@
/*****************************************************************************
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 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_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP
#define MAPNIK_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP
#include <mapnik/markers_placements/point.hpp>
namespace mapnik {
template <typename Locator, typename Detector>
class markers_vertex_last_placement : public markers_point_placement<Locator, Detector>
{
public:
markers_vertex_last_placement(
Locator &locator,
box2d<double> const& size,
agg::trans_affine const& tr,
Detector &detector,
double spacing,
double max_error,
bool allow_overlap)
: markers_point_placement<Locator, Detector>(
locator, size, tr, detector,
spacing, max_error, allow_overlap)
{
}
bool get_point(double &x, double &y, double &angle, bool ignore_placement)
{
if (this->done_)
{
return false;
}
double next_x, next_y;
double x0, y0;
double x1, y1;
unsigned command0, command1 = agg::path_cmd_stop;
while (!agg::is_stop(command0 = this->locator_.vertex(&next_x, &next_y)))
{
command1 = command0;
x1 = x0;
y1 = y0;
x0 = next_x;
y0 = next_y;
}
// If path stopped on the very firts vertex.
if (agg::is_stop(command1))
{
this->done_ = true;
return false;
}
x = x0;
y = y0;
if (agg::is_line_to(command1))
{
angle = std::atan2(y0 - y1, x0 - x1);
}
box2d<double> box = this->perform_transform(angle, x, y);
if (!this->allow_overlap_ && !this->detector_.has_placement(box))
{
return false;
}
if (!ignore_placement)
{
this->detector_.insert(box);
}
this->done_ = true;
return true;
}
};
}
#endif // MAPNIK_MARKERS_PLACEMENTS_VERTEXT_LAST_HPP

View file

@ -102,6 +102,8 @@ enum marker_placement_enum
MARKER_POINT_PLACEMENT,
MARKER_INTERIOR_PLACEMENT,
MARKER_LINE_PLACEMENT,
MARKER_VERTEX_FIRST_PLACEMENT,
MARKER_VERTEX_LAST_PLACEMENT,
marker_placement_enum_MAX
};

View file

@ -65,6 +65,8 @@ static const char * marker_placement_strings[] = {
"point",
"interior",
"line",
"vertex-first",
"vertex-last",
""
};

View file

@ -0,0 +1,111 @@
{
"keys": [
"",
"3",
"2",
"1"
],
"data": {},
"grid": [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ! ! ! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !!! ! !! ! !! ",
" !!! ",
" ! ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ## ",
" ############################################################################################################################### ",
" ## ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" $$ ",
" $$$ ",
" $ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
]
}

View file

@ -0,0 +1,111 @@
{
"keys": [
"",
"3",
"2",
"1"
],
"data": {},
"grid": [
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" !! ",
" ! ! !!! ",
" !! ! !! ! !!!! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" !! ! !! ! !! ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ## ",
" ############################################################################################################################## ",
" ## ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" $$ ",
" $$$ ",
" $ ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" ",
" "
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 878 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 876 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map>
<Style name="lines">
<Rule>
<LineSymbolizer stroke="#000000" />
</Rule>
</Style>
<Style name="markers">
<Rule>
<MarkersSymbolizer marker-type="ellipse" placement="[placement]" />
<DebugSymbolizer />
</Rule>
</Style>
<Layer name="layer">
<StyleName>lines</StyleName>
<StyleName>markers</StyleName>
<Datasource>
<Parameter name="type">csv</Parameter>
<Parameter name="inline">
wkt, placement
"LINESTRING(0 0)", "vertex-first"
"LINESTRING(0 1, 10 1)", "vertex-first"
"LINESTRING(0 2, 2 3, 4 2, 6 3, 8 2, 10 3)", "vertex-first"
</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE Map>
<Map>
<Style name="lines">
<Rule>
<LineSymbolizer stroke="#000000" />
</Rule>
</Style>
<Style name="markers">
<Rule>
<MarkersSymbolizer marker-type="ellipse" placement="[placement]" />
<DebugSymbolizer />
</Rule>
</Style>
<Layer name="layer">
<StyleName>lines</StyleName>
<StyleName>markers</StyleName>
<Datasource>
<Parameter name="type">csv</Parameter>
<Parameter name="inline">
wkt, placement
"LINESTRING(0 0)", "vertex-last"
"LINESTRING(0 1, 10 1)", "vertex-last"
"LINESTRING(0 2, 2 3, 4 2, 6 3, 8 2, 10 3)", "vertex-last"
</Parameter>
</Datasource>
</Layer>
</Map>

View file

@ -6,7 +6,6 @@ import mapnik
#mapnik.logger.set_severity(mapnik.severity_type.None)
#mapnik.logger.set_severity(mapnik.severity_type.Debug)
import shutil
import sys
import os.path
from compare import compare, compare_grids
@ -121,6 +120,10 @@ files = {
'marker-on-line-spacing-eq-width': {'sizes':[(600,400)]},
'marker-on-line-spacing-eq-width-overlap': {'sizes':[(600,400)]},
'marker_line_placement_on_points':{},
'marker-on-line-and-vertex-first-placement':{'sizes':[(600,400)],
'bbox': mapnik.Box2d(-1, -1, 11, 4)},
'marker-on-line-and-vertex-last-placement':{'sizes':[(600,400)],
'bbox': mapnik.Box2d(-1, -1, 11, 4)},
'marker-with-background-image-linear-comp-op': {},
'marker-with-background-image': {'sizes':[(600,400),(400,600),(257,256)]},
'marker-with-background-image-and-hsla-transform': {'sizes':[(600,400),(400,600),(257,256)]},