Make DouglasPeucker a free standing function

This commit is contained in:
Daniel J. Hofmann
2016-01-08 12:55:37 +01:00
committed by Patrick Niklaus
parent 23cd4d5ed2
commit c590596dbe
5 changed files with 73 additions and 70 deletions
+2 -2
View File
@@ -4,7 +4,6 @@
#include "guidance/segment_list.hpp"
#include "guidance/textual_route_annotation.hpp"
#include "engine/douglas_peucker.hpp"
#include "engine/internal_route_result.hpp"
#include "engine/object_encoder.hpp"
#include "engine/phantom_node.hpp"
@@ -261,7 +260,8 @@ ApiResponseGenerator<DataFacadeT>::BuildRouteSegments(const Segments &segment_li
(extractor::TurnInstruction::EnterRoundAbout != current_turn))
{
detail::Segment seg = {segment.name_id, static_cast<int32_t>(segment.length),
detail::Segment seg = {segment.name_id,
static_cast<int32_t>(segment.length),
static_cast<std::size_t>(result.size())};
result.emplace_back(std::move(seg));
}
+25 -27
View File
@@ -3,24 +3,16 @@
#include "engine/segment_information.hpp"
#include <array>
#include <stack>
#include <utility>
#include <vector>
#include <iterator>
namespace osrm
{
namespace engine
{
/* This class object computes the bitvector of indicating generalized input
* points according to the (Ramer-)Douglas-Peucker algorithm.
*
* Input is vector of pairs. Each pair consists of the point information and a
* bit indicating if the points is present in the generalization.
* Note: points may also be pre-selected*/
static const std::array<int, 19> DOUGLAS_PEUCKER_THRESHOLDS{{
namespace detail
{
const constexpr int DOUGLAS_PEUCKER_THRESHOLDS[19] = {
512440, // z0
256720, // z1
122560, // z2
@@ -39,22 +31,28 @@ static const std::array<int, 19> DOUGLAS_PEUCKER_THRESHOLDS{{
20, // z15
8, // z16
6, // z17
4 // z18
}};
class DouglasPeucker
{
public:
using RandomAccessIt = std::vector<SegmentInformation>::iterator;
using GeometryRange = std::pair<RandomAccessIt, RandomAccessIt>;
// Stack to simulate the recursion
std::stack<GeometryRange> recursion_stack;
public:
void Run(RandomAccessIt begin, RandomAccessIt end, const unsigned zoom_level);
void Run(std::vector<SegmentInformation> &input_geometry, const unsigned zoom_level);
4, // z18
};
const constexpr auto DOUGLAS_PEUCKER_THRESHOLDS_SIZE =
sizeof(DOUGLAS_PEUCKER_THRESHOLDS) / sizeof(*DOUGLAS_PEUCKER_THRESHOLDS);
} // ns detail
// These functions compute the bitvector of indicating generalized input
// points according to the (Ramer-)Douglas-Peucker algorithm.
//
// Input is vector of pairs. Each pair consists of the point information and a
// bit indicating if the points is present in the generalization.
// Note: points may also be pre-selected*/
void douglasPeucker(std::vector<SegmentInformation>::iterator begin,
std::vector<SegmentInformation>::iterator end,
const unsigned zoom_level);
// Convenience range-based function
inline void douglasPeucker(std::vector<SegmentInformation> &geometry, const unsigned zoom_level)
{
douglasPeucker(begin(geometry), end(geometry), zoom_level);
}
}
}
+3 -4
View File
@@ -272,14 +272,13 @@ void SegmentList<DataFacadeT>::Finalize(const bool extract_alternative,
if (allow_simplification)
{
DouglasPeucker polyline_generalizer;
polyline_generalizer.Run(segments.begin(), segments.end(), zoom_level);
douglasPeucker(segments, zoom_level);
}
std::uint32_t necessary_segments = 0; // a running index that counts the necessary pieces
via_indices.push_back(0);
const auto markNecessarySegments = [this, &necessary_segments](SegmentInformation &first,
const SegmentInformation &second)
const auto markNecessarySegments =
[this, &necessary_segments](SegmentInformation &first, const SegmentInformation &second)
{
if (!first.necessary)
return;