tippecanoe/mapbox/geometry/wagyu/process_maxima.hpp

128 lines
4.9 KiB
C++
Raw Normal View History

2016-12-07 14:14:56 -08:00
#pragma once
#include <mapbox/geometry/wagyu/active_bound_list.hpp>
#include <mapbox/geometry/wagyu/config.hpp>
#include <mapbox/geometry/wagyu/edge.hpp>
#include <mapbox/geometry/wagyu/intersect_util.hpp>
#include <mapbox/geometry/wagyu/local_minimum.hpp>
#include <mapbox/geometry/wagyu/local_minimum_util.hpp>
#include <mapbox/geometry/wagyu/process_horizontal.hpp>
#include <mapbox/geometry/wagyu/ring.hpp>
#include <mapbox/geometry/wagyu/ring_util.hpp>
#include <mapbox/geometry/wagyu/topology_correction.hpp>
#include <mapbox/geometry/wagyu/util.hpp>
namespace mapbox {
namespace geometry {
namespace wagyu {
template <typename T>
active_bound_list_itr<T> do_maxima(active_bound_list_itr<T>& bnd,
active_bound_list_itr<T>& bndMaxPair,
clip_type cliptype,
fill_type subject_fill_type,
fill_type clip_fill_type,
2018-07-31 17:32:27 -07:00
ring_manager<T>& manager,
2016-12-07 14:14:56 -08:00
active_bound_list<T>& active_bounds) {
auto bnd_next = std::next(bnd);
2018-07-31 17:32:27 -07:00
auto return_bnd = bnd;
2016-12-07 14:14:56 -08:00
bool skipped = false;
while (bnd_next != active_bounds.end() && bnd_next != bndMaxPair) {
2018-07-31 17:32:27 -07:00
if (*bnd_next == nullptr) {
++bnd_next;
continue;
}
2016-12-07 14:14:56 -08:00
skipped = true;
2018-07-31 17:32:27 -07:00
intersect_bounds(*(*bnd), *(*bnd_next), (*bnd)->current_edge->top, cliptype,
subject_fill_type, clip_fill_type, manager, active_bounds);
std::iter_swap(bnd, bnd_next);
bnd = bnd_next;
++bnd_next;
2016-12-07 14:14:56 -08:00
}
2018-07-31 17:32:27 -07:00
if ((*bnd)->ring && (*bndMaxPair)->ring) {
add_local_maximum_point(*(*bnd), *(*bndMaxPair), (*bnd)->current_edge->top, manager,
active_bounds);
} else if ((*bnd)->ring || (*bndMaxPair)->ring) {
2017-01-04 16:33:43 -08:00
throw std::runtime_error("DoMaxima error");
2016-12-07 14:14:56 -08:00
}
2018-07-31 17:32:27 -07:00
*bndMaxPair = nullptr;
*bnd = nullptr;
if (!skipped) {
++return_bnd;
2016-12-07 14:14:56 -08:00
}
2018-07-31 17:32:27 -07:00
return return_bnd;
2016-12-07 14:14:56 -08:00
}
template <typename T>
void process_edges_at_top_of_scanbeam(T top_y,
active_bound_list<T>& active_bounds,
scanbeam_list<T>& scanbeam,
local_minimum_ptr_list<T> const& minima_sorted,
local_minimum_ptr_list_itr<T>& current_lm,
2018-07-31 17:32:27 -07:00
ring_manager<T>& manager,
2016-12-07 14:14:56 -08:00
clip_type cliptype,
fill_type subject_fill_type,
fill_type clip_fill_type) {
for (auto bnd = active_bounds.begin(); bnd != active_bounds.end();) {
2018-07-31 17:32:27 -07:00
if (*bnd == nullptr) {
++bnd;
continue;
}
2016-12-07 14:14:56 -08:00
// 1. Process maxima, treating them as if they are "bent" horizontal edges,
// but exclude maxima with horizontal edges.
2017-01-04 16:33:43 -08:00
2016-12-07 14:14:56 -08:00
bool is_maxima_edge = is_maxima(bnd, top_y);
if (is_maxima_edge) {
auto bnd_max_pair = get_maxima_pair(bnd, active_bounds);
is_maxima_edge = ((bnd_max_pair == active_bounds.end() ||
!current_edge_is_horizontal<T>(bnd_max_pair)) &&
is_maxima(bnd_max_pair, top_y));
if (is_maxima_edge) {
2017-01-04 16:33:43 -08:00
bnd = do_maxima(bnd, bnd_max_pair, cliptype, subject_fill_type, clip_fill_type,
2018-07-31 17:32:27 -07:00
manager, active_bounds);
2016-12-07 14:14:56 -08:00
continue;
}
}
// 2. Promote horizontal edges.
if (is_intermediate(bnd, top_y) && next_edge_is_horizontal<T>(bnd)) {
if ((*bnd)->ring) {
2018-07-31 17:32:27 -07:00
insert_hot_pixels_in_path(*(*bnd), (*bnd)->current_edge->top, manager, false);
2016-12-07 14:14:56 -08:00
}
2018-07-31 17:32:27 -07:00
next_edge_in_bound(*(*bnd), scanbeam);
2016-12-07 14:14:56 -08:00
if ((*bnd)->ring) {
2018-07-31 17:32:27 -07:00
add_point_to_ring(*(*bnd), (*bnd)->current_edge->bot, manager);
2016-12-07 14:14:56 -08:00
}
} else {
(*bnd)->current_x = get_current_x(*((*bnd)->current_edge), top_y);
}
++bnd;
}
2018-07-31 17:32:27 -07:00
active_bounds.erase(std::remove(active_bounds.begin(), active_bounds.end(), nullptr),
active_bounds.end());
2016-12-07 14:14:56 -08:00
2018-07-31 17:32:27 -07:00
insert_horizontal_local_minima_into_ABL(top_y, minima_sorted, current_lm, active_bounds,
manager, scanbeam, cliptype, subject_fill_type,
clip_fill_type);
2016-12-07 14:14:56 -08:00
2018-07-31 17:32:27 -07:00
process_horizontals(top_y, active_bounds, manager, scanbeam, cliptype, subject_fill_type,
2016-12-07 14:14:56 -08:00
clip_fill_type);
// 4. Promote intermediate vertices
for (auto bnd = active_bounds.begin(); bnd != active_bounds.end(); ++bnd) {
if (is_intermediate(bnd, top_y)) {
if ((*bnd)->ring) {
2018-07-31 17:32:27 -07:00
add_point_to_ring(*(*bnd), (*bnd)->current_edge->top, manager);
2016-12-07 14:14:56 -08:00
}
2018-07-31 17:32:27 -07:00
next_edge_in_bound(*(*bnd), scanbeam);
2016-12-07 14:14:56 -08:00
}
}
}
}
}
}