Merge pull request #4031 from mapycz/adaptive-smooth
[WIP] Adaptive smooth
This commit is contained in:
commit
b1185fc099
16 changed files with 440 additions and 270 deletions
23
deps/agg/include/agg_array.h
vendored
23
deps/agg/include/agg_array.h
vendored
|
@ -124,6 +124,15 @@ namespace agg
|
|||
memcpy(m_array, v.m_array, sizeof(T) * m_size);
|
||||
}
|
||||
|
||||
pod_array(self_type && rhs)
|
||||
{
|
||||
pod_allocator<T>::deallocate(m_array, m_size);
|
||||
m_array = rhs.m_array;
|
||||
m_size = rhs.m_size;
|
||||
rhs.m_array = nullptr;
|
||||
rhs.m_size = 0;
|
||||
}
|
||||
|
||||
void resize(unsigned _size)
|
||||
{
|
||||
if(_size != m_size)
|
||||
|
@ -172,6 +181,8 @@ namespace agg
|
|||
pod_vector(const pod_vector<T>&);
|
||||
const pod_vector<T>& operator = (const pod_vector<T>&);
|
||||
|
||||
pod_vector(pod_vector<T> && rhs);
|
||||
|
||||
// Set new capacity. All data is lost, size is set to zero.
|
||||
void capacity(unsigned cap, unsigned extra_tail=0);
|
||||
unsigned capacity() const { return m_capacity; }
|
||||
|
@ -272,6 +283,18 @@ namespace agg
|
|||
memcpy(m_array, v.m_array, sizeof(T) * v.m_size);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
template<class T> pod_vector<T>::pod_vector(pod_vector<T> && rhs)
|
||||
{
|
||||
pod_allocator<T>::deallocate(m_array, m_capacity);
|
||||
m_size = rhs.m_size;
|
||||
m_capacity = rhs.m_capacity;
|
||||
m_array = rhs.m_array;
|
||||
rhs.m_size = 0;
|
||||
rhs.m_capacity = 0;
|
||||
rhs.m_array = nullptr;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
template<class T> const pod_vector<T>&
|
||||
pod_vector<T>::operator = (const pod_vector<T>&v)
|
||||
|
|
3
deps/agg/include/agg_conv_adaptor_vcgen.h
vendored
3
deps/agg/include/agg_conv_adaptor_vcgen.h
vendored
|
@ -50,6 +50,9 @@ namespace agg
|
|||
m_source(&source),
|
||||
m_status(initial)
|
||||
{}
|
||||
|
||||
conv_adaptor_vcgen(conv_adaptor_vcgen<VertexSource, Generator, Markers> &&) = default;
|
||||
|
||||
void attach(VertexSource& source) { m_source = &source; }
|
||||
|
||||
Generator& generator() { return m_generator; }
|
||||
|
|
3
deps/agg/include/agg_conv_curve.h
vendored
3
deps/agg/include/agg_conv_curve.h
vendored
|
@ -62,6 +62,9 @@ namespace agg
|
|||
|
||||
explicit conv_curve(VertexSource& source) :
|
||||
m_source(&source), m_last_x(0.0), m_last_y(0.0) {}
|
||||
|
||||
conv_curve(self_type &&) = default;
|
||||
|
||||
void attach(VertexSource& source) { m_source = &source; }
|
||||
|
||||
void approximation_method(curve_approximation_method_e v)
|
||||
|
|
59
deps/agg/include/agg_conv_smooth_poly1.h
vendored
59
deps/agg/include/agg_conv_smooth_poly1.h
vendored
|
@ -28,53 +28,64 @@
|
|||
namespace agg
|
||||
{
|
||||
|
||||
//-------------------------------------------------------conv_smooth_poly1
|
||||
template<class VertexSource>
|
||||
struct conv_smooth_poly1 :
|
||||
public conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1>
|
||||
//-------------------------------------------------------conv_smooth
|
||||
template<class VertexSource, class VertexGenerator>
|
||||
struct conv_smooth :
|
||||
public conv_adaptor_vcgen<VertexSource, VertexGenerator>
|
||||
{
|
||||
typedef conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1> base_type;
|
||||
typedef conv_adaptor_vcgen<VertexSource, VertexGenerator> base_type;
|
||||
|
||||
conv_smooth_poly1(VertexSource& vs) :
|
||||
conv_adaptor_vcgen<VertexSource, vcgen_smooth_poly1>(vs)
|
||||
conv_smooth(VertexSource& vs) :
|
||||
conv_adaptor_vcgen<VertexSource, VertexGenerator>(vs)
|
||||
{
|
||||
}
|
||||
|
||||
conv_smooth(conv_smooth<VertexSource, VertexGenerator> &&) = default;
|
||||
|
||||
conv_smooth(const conv_smooth<VertexSource, VertexGenerator>&) = delete;
|
||||
const conv_smooth<VertexSource, VertexGenerator>&
|
||||
operator = (const conv_smooth<VertexSource, VertexGenerator>&) = delete;
|
||||
|
||||
void smooth_value(double v) { base_type::generator().smooth_value(v); }
|
||||
double smooth_value() const { return base_type::generator().smooth_value(); }
|
||||
unsigned type() const { return base_type::type(); }
|
||||
|
||||
private:
|
||||
conv_smooth_poly1(const conv_smooth_poly1<VertexSource>&);
|
||||
const conv_smooth_poly1<VertexSource>&
|
||||
operator = (const conv_smooth_poly1<VertexSource>&);
|
||||
};
|
||||
|
||||
template<class VertexSource>
|
||||
using conv_smooth_poly1 = conv_smooth<VertexSource, vcgen_smooth_poly1>;
|
||||
|
||||
|
||||
//-------------------------------------------------conv_smooth_poly1_curve
|
||||
template<class VertexSource>
|
||||
struct conv_smooth_poly1_curve :
|
||||
public conv_curve<conv_smooth_poly1<VertexSource> >
|
||||
//-------------------------------------------------conv_smooth_curve
|
||||
template<class VertexSource, class VertexGenerator>
|
||||
struct conv_smooth_curve :
|
||||
public conv_curve<conv_smooth<VertexSource, VertexGenerator>>
|
||||
{
|
||||
conv_smooth_poly1_curve(VertexSource& vs) :
|
||||
conv_curve<conv_smooth_poly1<VertexSource> >(m_smooth),
|
||||
conv_smooth_curve(VertexSource& vs) :
|
||||
conv_curve<conv_smooth<VertexSource, VertexGenerator>>(m_smooth),
|
||||
m_smooth(vs)
|
||||
{
|
||||
}
|
||||
|
||||
conv_smooth_curve(conv_smooth_curve<VertexSource, VertexGenerator> && rhs) :
|
||||
conv_curve<conv_smooth<VertexSource, VertexGenerator>>(std::move(rhs)),
|
||||
m_smooth(std::move(rhs.m_smooth))
|
||||
{
|
||||
this->attach(m_smooth);
|
||||
}
|
||||
|
||||
conv_smooth_curve(const conv_smooth_curve<VertexSource, VertexGenerator>&) = delete;
|
||||
const conv_smooth_curve<VertexSource, VertexGenerator>&
|
||||
operator = (const conv_smooth_curve<VertexSource, VertexGenerator>&) = delete;
|
||||
|
||||
void smooth_value(double v) { m_smooth.generator().smooth_value(v); }
|
||||
double smooth_value() const { return m_smooth.generator().smooth_value(); }
|
||||
unsigned type() const { return m_smooth.type(); }
|
||||
|
||||
private:
|
||||
conv_smooth_poly1_curve(const conv_smooth_poly1_curve<VertexSource>&);
|
||||
const conv_smooth_poly1_curve<VertexSource>&
|
||||
operator = (const conv_smooth_poly1_curve<VertexSource>&);
|
||||
|
||||
conv_smooth_poly1<VertexSource> m_smooth;
|
||||
conv_smooth<VertexSource, VertexGenerator> m_smooth;
|
||||
};
|
||||
|
||||
template<class VertexSource>
|
||||
using conv_smooth_poly1_curve = conv_smooth_curve<VertexSource, vcgen_smooth_poly1>;
|
||||
}
|
||||
|
||||
|
||||
|
|
222
deps/agg/include/agg_vcgen_smooth_poly1.h
vendored
222
deps/agg/include/agg_vcgen_smooth_poly1.h
vendored
|
@ -23,13 +23,13 @@
|
|||
namespace agg
|
||||
{
|
||||
|
||||
//======================================================vcgen_smooth_poly1
|
||||
//======================================================vcgen_smooth
|
||||
//
|
||||
// See Implementation agg_vcgen_smooth_poly1.cpp
|
||||
// Smooth polygon generator
|
||||
//
|
||||
//------------------------------------------------------------------------
|
||||
class vcgen_smooth_poly1
|
||||
template <class Calculate>
|
||||
class vcgen_smooth
|
||||
{
|
||||
enum status_e
|
||||
{
|
||||
|
@ -47,39 +47,223 @@ namespace agg
|
|||
public:
|
||||
typedef vertex_sequence<vertex_dist, 6> vertex_storage;
|
||||
|
||||
vcgen_smooth_poly1();
|
||||
vcgen_smooth() :
|
||||
m_src_vertices(),
|
||||
m_smooth_value(0.5),
|
||||
m_closed(0),
|
||||
m_status(initial),
|
||||
m_src_vertex(0) { }
|
||||
|
||||
vcgen_smooth(vcgen_smooth &&) = default;
|
||||
|
||||
void smooth_value(double v) { m_smooth_value = v * 0.5; }
|
||||
double smooth_value() const { return m_smooth_value * 2.0; }
|
||||
|
||||
// Vertex Generator Interface
|
||||
void remove_all();
|
||||
void add_vertex(double x, double y, unsigned cmd);
|
||||
void remove_all()
|
||||
{
|
||||
m_src_vertices.remove_all();
|
||||
m_closed = 0;
|
||||
m_status = initial;
|
||||
}
|
||||
|
||||
void add_vertex(double x, double y, unsigned cmd)
|
||||
{
|
||||
m_status = initial;
|
||||
if(is_move_to(cmd))
|
||||
{
|
||||
m_src_vertices.modify_last(vertex_dist(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(is_vertex(cmd))
|
||||
{
|
||||
m_src_vertices.add(vertex_dist(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_closed = get_close_flag(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Vertex Source Interface
|
||||
void rewind(unsigned path_id);
|
||||
unsigned vertex(double* x, double* y);
|
||||
void rewind(unsigned)
|
||||
{
|
||||
if(m_status == initial)
|
||||
{
|
||||
m_src_vertices.close(m_closed != 0);
|
||||
}
|
||||
m_status = ready;
|
||||
m_src_vertex = 0;
|
||||
}
|
||||
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
unsigned cmd = path_cmd_line_to;
|
||||
while(!is_stop(cmd))
|
||||
{
|
||||
switch(m_status)
|
||||
{
|
||||
case initial:
|
||||
rewind(0);
|
||||
|
||||
case ready:
|
||||
if(m_src_vertices.size() < 2)
|
||||
{
|
||||
cmd = path_cmd_stop;
|
||||
break;
|
||||
}
|
||||
|
||||
if(m_src_vertices.size() == 2)
|
||||
{
|
||||
*x = m_src_vertices[m_src_vertex].x;
|
||||
*y = m_src_vertices[m_src_vertex].y;
|
||||
m_src_vertex++;
|
||||
if(m_src_vertex == 1) return path_cmd_move_to;
|
||||
if(m_src_vertex == 2) return path_cmd_line_to;
|
||||
cmd = path_cmd_stop;
|
||||
break;
|
||||
}
|
||||
|
||||
cmd = path_cmd_move_to;
|
||||
m_status = polygon;
|
||||
m_src_vertex = 0;
|
||||
|
||||
case polygon:
|
||||
if(m_closed)
|
||||
{
|
||||
if(m_src_vertex >= m_src_vertices.size())
|
||||
{
|
||||
*x = m_src_vertices[0].x;
|
||||
*y = m_src_vertices[0].y;
|
||||
m_status = end_poly;
|
||||
return path_cmd_curve4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_src_vertex >= m_src_vertices.size() - 1)
|
||||
{
|
||||
*x = m_src_vertices[m_src_vertices.size() - 1].x;
|
||||
*y = m_src_vertices[m_src_vertices.size() - 1].y;
|
||||
m_status = end_poly;
|
||||
return path_cmd_curve3;
|
||||
}
|
||||
}
|
||||
|
||||
std::tie(m_ctrl1, m_ctrl2) = Calculate::apply(
|
||||
m_src_vertices.prev(m_src_vertex),
|
||||
m_src_vertices.curr(m_src_vertex),
|
||||
m_src_vertices.next(m_src_vertex),
|
||||
m_src_vertices.next(m_src_vertex + 1),
|
||||
m_smooth_value);
|
||||
|
||||
*x = m_src_vertices[m_src_vertex].x;
|
||||
*y = m_src_vertices[m_src_vertex].y;
|
||||
m_src_vertex++;
|
||||
|
||||
if(m_closed)
|
||||
{
|
||||
m_status = ctrl1;
|
||||
return ((m_src_vertex == 1) ?
|
||||
path_cmd_move_to :
|
||||
path_cmd_curve4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_src_vertex == 1)
|
||||
{
|
||||
m_status = ctrl_b;
|
||||
return path_cmd_move_to;
|
||||
}
|
||||
if(m_src_vertex >= m_src_vertices.size() - 1)
|
||||
{
|
||||
m_status = ctrl_e;
|
||||
return path_cmd_curve3;
|
||||
}
|
||||
m_status = ctrl1;
|
||||
return path_cmd_curve4;
|
||||
}
|
||||
break;
|
||||
|
||||
case ctrl_b:
|
||||
*x = m_ctrl2.x;
|
||||
*y = m_ctrl2.y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve3;
|
||||
|
||||
case ctrl_e:
|
||||
*x = m_ctrl1.x;
|
||||
*y = m_ctrl1.y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve3;
|
||||
|
||||
case ctrl1:
|
||||
*x = m_ctrl1.x;
|
||||
*y = m_ctrl1.y;
|
||||
m_status = ctrl2;
|
||||
return path_cmd_curve4;
|
||||
|
||||
case ctrl2:
|
||||
*x = m_ctrl2.x;
|
||||
*y = m_ctrl2.y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve4;
|
||||
|
||||
case end_poly:
|
||||
m_status = stop;
|
||||
return path_cmd_end_poly | m_closed;
|
||||
|
||||
case stop:
|
||||
return path_cmd_stop;
|
||||
}
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
private:
|
||||
vcgen_smooth_poly1(const vcgen_smooth_poly1&);
|
||||
const vcgen_smooth_poly1& operator = (const vcgen_smooth_poly1&);
|
||||
|
||||
void calculate(const vertex_dist& v0,
|
||||
const vertex_dist& v1,
|
||||
const vertex_dist& v2,
|
||||
const vertex_dist& v3);
|
||||
vcgen_smooth(const vcgen_smooth&);
|
||||
const vcgen_smooth& operator = (const vcgen_smooth&);
|
||||
|
||||
vertex_storage m_src_vertices;
|
||||
double m_smooth_value;
|
||||
unsigned m_closed;
|
||||
status_e m_status;
|
||||
unsigned m_src_vertex;
|
||||
double m_ctrl1_x;
|
||||
double m_ctrl1_y;
|
||||
double m_ctrl2_x;
|
||||
double m_ctrl2_y;
|
||||
point_d m_ctrl1;
|
||||
point_d m_ctrl2;
|
||||
};
|
||||
|
||||
struct calculate_poly1
|
||||
{
|
||||
using result_type = std::pair<point_d, point_d>;
|
||||
|
||||
static result_type apply(const vertex_dist& v0,
|
||||
const vertex_dist& v1,
|
||||
const vertex_dist& v2,
|
||||
const vertex_dist& v3,
|
||||
double smooth_value)
|
||||
{
|
||||
double k1 = v0.dist / (v0.dist + v1.dist);
|
||||
double k2 = v1.dist / (v1.dist + v2.dist);
|
||||
|
||||
double xm1 = v0.x + (v2.x - v0.x) * k1;
|
||||
double ym1 = v0.y + (v2.y - v0.y) * k1;
|
||||
double xm2 = v1.x + (v3.x - v1.x) * k2;
|
||||
double ym2 = v1.y + (v3.y - v1.y) * k2;
|
||||
|
||||
return {
|
||||
{v1.x + smooth_value * (v2.x - xm1),
|
||||
v1.y + smooth_value * (v2.y - ym1)},
|
||||
{v2.x + smooth_value * (v1.x - xm2),
|
||||
v2.y + smooth_value * (v1.y - ym2)}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
using vcgen_smooth_poly1 = vcgen_smooth<calculate_poly1>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
225
deps/agg/src/agg_vcgen_smooth_poly1.cpp
vendored
225
deps/agg/src/agg_vcgen_smooth_poly1.cpp
vendored
|
@ -1,225 +0,0 @@
|
|||
//----------------------------------------------------------------------------
|
||||
// Anti-Grain Geometry - Version 2.4
|
||||
// Copyright (C) 2002-2005 Maxim Shemanarev (http://www.antigrain.com)
|
||||
//
|
||||
// Permission to copy, use, modify, sell and distribute this software
|
||||
// is granted provided this copyright notice appears in all copies.
|
||||
// This software is provided "as is" without express or implied
|
||||
// warranty, and with no claim as to its suitability for any purpose.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
// Contact: mcseem@antigrain.com
|
||||
// mcseemagg@yahoo.com
|
||||
// http://www.antigrain.com
|
||||
//----------------------------------------------------------------------------
|
||||
//
|
||||
// Smooth polygon generator
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
#include "agg_vcgen_smooth_poly1.h"
|
||||
|
||||
namespace agg
|
||||
{
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
vcgen_smooth_poly1::vcgen_smooth_poly1() :
|
||||
m_src_vertices(),
|
||||
m_smooth_value(0.5),
|
||||
m_closed(0),
|
||||
m_status(initial),
|
||||
m_src_vertex(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void vcgen_smooth_poly1::remove_all()
|
||||
{
|
||||
m_src_vertices.remove_all();
|
||||
m_closed = 0;
|
||||
m_status = initial;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void vcgen_smooth_poly1::add_vertex(double x, double y, unsigned cmd)
|
||||
{
|
||||
m_status = initial;
|
||||
if(is_move_to(cmd))
|
||||
{
|
||||
m_src_vertices.modify_last(vertex_dist(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(is_vertex(cmd))
|
||||
{
|
||||
m_src_vertices.add(vertex_dist(x, y));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_closed = get_close_flag(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void vcgen_smooth_poly1::rewind(unsigned)
|
||||
{
|
||||
if(m_status == initial)
|
||||
{
|
||||
m_src_vertices.close(m_closed != 0);
|
||||
}
|
||||
m_status = ready;
|
||||
m_src_vertex = 0;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
void vcgen_smooth_poly1::calculate(const vertex_dist& v0,
|
||||
const vertex_dist& v1,
|
||||
const vertex_dist& v2,
|
||||
const vertex_dist& v3)
|
||||
{
|
||||
|
||||
double k1 = v0.dist / (v0.dist + v1.dist);
|
||||
double k2 = v1.dist / (v1.dist + v2.dist);
|
||||
|
||||
double xm1 = v0.x + (v2.x - v0.x) * k1;
|
||||
double ym1 = v0.y + (v2.y - v0.y) * k1;
|
||||
double xm2 = v1.x + (v3.x - v1.x) * k2;
|
||||
double ym2 = v1.y + (v3.y - v1.y) * k2;
|
||||
|
||||
m_ctrl1_x = v1.x + m_smooth_value * (v2.x - xm1);
|
||||
m_ctrl1_y = v1.y + m_smooth_value * (v2.y - ym1);
|
||||
m_ctrl2_x = v2.x + m_smooth_value * (v1.x - xm2);
|
||||
m_ctrl2_y = v2.y + m_smooth_value * (v1.y - ym2);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------------------
|
||||
unsigned vcgen_smooth_poly1::vertex(double* x, double* y)
|
||||
{
|
||||
unsigned cmd = path_cmd_line_to;
|
||||
while(!is_stop(cmd))
|
||||
{
|
||||
switch(m_status)
|
||||
{
|
||||
case initial:
|
||||
rewind(0);
|
||||
|
||||
case ready:
|
||||
if(m_src_vertices.size() < 2)
|
||||
{
|
||||
cmd = path_cmd_stop;
|
||||
break;
|
||||
}
|
||||
|
||||
if(m_src_vertices.size() == 2)
|
||||
{
|
||||
*x = m_src_vertices[m_src_vertex].x;
|
||||
*y = m_src_vertices[m_src_vertex].y;
|
||||
m_src_vertex++;
|
||||
if(m_src_vertex == 1) return path_cmd_move_to;
|
||||
if(m_src_vertex == 2) return path_cmd_line_to;
|
||||
cmd = path_cmd_stop;
|
||||
break;
|
||||
}
|
||||
|
||||
cmd = path_cmd_move_to;
|
||||
m_status = polygon;
|
||||
m_src_vertex = 0;
|
||||
|
||||
case polygon:
|
||||
if(m_closed)
|
||||
{
|
||||
if(m_src_vertex >= m_src_vertices.size())
|
||||
{
|
||||
*x = m_src_vertices[0].x;
|
||||
*y = m_src_vertices[0].y;
|
||||
m_status = end_poly;
|
||||
return path_cmd_curve4;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_src_vertex >= m_src_vertices.size() - 1)
|
||||
{
|
||||
*x = m_src_vertices[m_src_vertices.size() - 1].x;
|
||||
*y = m_src_vertices[m_src_vertices.size() - 1].y;
|
||||
m_status = end_poly;
|
||||
return path_cmd_curve3;
|
||||
}
|
||||
}
|
||||
|
||||
calculate(m_src_vertices.prev(m_src_vertex),
|
||||
m_src_vertices.curr(m_src_vertex),
|
||||
m_src_vertices.next(m_src_vertex),
|
||||
m_src_vertices.next(m_src_vertex + 1));
|
||||
|
||||
*x = m_src_vertices[m_src_vertex].x;
|
||||
*y = m_src_vertices[m_src_vertex].y;
|
||||
m_src_vertex++;
|
||||
|
||||
if(m_closed)
|
||||
{
|
||||
m_status = ctrl1;
|
||||
return ((m_src_vertex == 1) ?
|
||||
path_cmd_move_to :
|
||||
path_cmd_curve4);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(m_src_vertex == 1)
|
||||
{
|
||||
m_status = ctrl_b;
|
||||
return path_cmd_move_to;
|
||||
}
|
||||
if(m_src_vertex >= m_src_vertices.size() - 1)
|
||||
{
|
||||
m_status = ctrl_e;
|
||||
return path_cmd_curve3;
|
||||
}
|
||||
m_status = ctrl1;
|
||||
return path_cmd_curve4;
|
||||
}
|
||||
break;
|
||||
|
||||
case ctrl_b:
|
||||
*x = m_ctrl2_x;
|
||||
*y = m_ctrl2_y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve3;
|
||||
|
||||
case ctrl_e:
|
||||
*x = m_ctrl1_x;
|
||||
*y = m_ctrl1_y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve3;
|
||||
|
||||
case ctrl1:
|
||||
*x = m_ctrl1_x;
|
||||
*y = m_ctrl1_y;
|
||||
m_status = ctrl2;
|
||||
return path_cmd_curve4;
|
||||
|
||||
case ctrl2:
|
||||
*x = m_ctrl2_x;
|
||||
*y = m_ctrl2_y;
|
||||
m_status = polygon;
|
||||
return path_cmd_curve4;
|
||||
|
||||
case end_poly:
|
||||
m_status = stop;
|
||||
return path_cmd_end_poly | m_closed;
|
||||
|
||||
case stop:
|
||||
return path_cmd_stop;
|
||||
}
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
}
|
||||
|
138
include/mapnik/adaptive_smooth.hpp
Normal file
138
include/mapnik/adaptive_smooth.hpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
#ifndef MAPNIK_ADAPTIVE_SMOOTH_HPP
|
||||
#define MAPNIK_ADAPTIVE_SMOOTH_HPP
|
||||
|
||||
#include <mapnik/util/math.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
#include "agg_conv_smooth_poly1.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
namespace mapnik
|
||||
{
|
||||
|
||||
struct vcgen_smooth_calucate_adaptive
|
||||
{
|
||||
using result_type = std::pair<agg::point_d, agg::point_d>;
|
||||
using vertex_type = agg::vertex_dist;
|
||||
|
||||
static result_type apply(vertex_type const& v0,
|
||||
vertex_type const& v1,
|
||||
vertex_type const& v2,
|
||||
vertex_type const& v3,
|
||||
double smooth_value)
|
||||
{
|
||||
double k1 = v0.dist / (v0.dist + v1.dist);
|
||||
double k2 = v1.dist / (v1.dist + v2.dist);
|
||||
|
||||
double xm1 = v0.x + (v2.x - v0.x) * k1;
|
||||
double ym1 = v0.y + (v2.y - v0.y) * k1;
|
||||
double xm2 = v1.x + (v3.x - v1.x) * k2;
|
||||
double ym2 = v1.y + (v3.y - v1.y) * k2;
|
||||
|
||||
double s1 = 0;
|
||||
double s2 = 0;
|
||||
|
||||
if (v1.dist > 0.0)
|
||||
{
|
||||
if (v0.dist > 0.0)
|
||||
{
|
||||
double dot1 = (v0.x - v1.x) * (v2.x - v1.x) + (v0.y - v1.y) * (v2.y - v1.y);
|
||||
double a1 = std::acos(dot1 / (v0.dist * v1.dist));
|
||||
if (a1 >= util::pi * 0.5)
|
||||
{
|
||||
s1 = (a1 - util::pi * 0.5) / (util::pi * 0.5);
|
||||
}
|
||||
}
|
||||
|
||||
if (v2.dist > 0.0)
|
||||
{
|
||||
double dot2 = (v1.x - v2.x) * (v3.x - v2.x) + (v1.y - v2.y) * (v3.y - v2.y);
|
||||
double a2 = std::acos(dot2 / (v1.dist * v2.dist));
|
||||
if (a2 >= util::pi * 0.5)
|
||||
{
|
||||
s2 = (a2 - util::pi * 0.5) / (util::pi * 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
{v1.x + s1 * smooth_value * (v2.x - xm1),
|
||||
v1.y + s1 * smooth_value * (v2.y - ym1)},
|
||||
{v2.x + s2 * smooth_value * (v1.x - xm2),
|
||||
v2.y + s2 * smooth_value * (v1.y - ym2)}
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
using vcgen_smooth_adaptive = agg::vcgen_smooth<vcgen_smooth_calucate_adaptive>;
|
||||
|
||||
template<class VertexSource>
|
||||
using conv_smooth_adaptive = agg::conv_smooth_curve<VertexSource, vcgen_smooth_adaptive>;
|
||||
|
||||
template <typename Geometry>
|
||||
class smooth_converter
|
||||
{
|
||||
Geometry geom_;
|
||||
|
||||
using basic_impl_type = typename agg::conv_smooth_poly1_curve<Geometry>;
|
||||
using adaptive_impl_type = conv_smooth_adaptive<Geometry>;
|
||||
using impl_type = util::variant<basic_impl_type, adaptive_impl_type>;
|
||||
impl_type impl_;
|
||||
|
||||
impl_type init_impl(smooth_algorithm_enum algo, Geometry & geom) const
|
||||
{
|
||||
switch(algo)
|
||||
{
|
||||
case SMOOTH_ALGORITHM_ADAPTIVE:
|
||||
return adaptive_impl_type(geom);
|
||||
case SMOOTH_ALGORITHM_BASIC:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return basic_impl_type(geom);
|
||||
}
|
||||
|
||||
public:
|
||||
smooth_converter(Geometry & geom) :
|
||||
geom_(geom),
|
||||
impl_(std::move(init_impl(SMOOTH_ALGORITHM_BASIC, geom)))
|
||||
{}
|
||||
|
||||
void algorithm(smooth_algorithm_enum algo)
|
||||
{
|
||||
impl_ = init_impl(algo, geom_);
|
||||
}
|
||||
|
||||
void smooth_value(double v)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
impl.smooth_value(v);
|
||||
}, impl_);
|
||||
}
|
||||
|
||||
void rewind(unsigned path_id)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
return impl.rewind(path_id);
|
||||
}, impl_);
|
||||
}
|
||||
|
||||
unsigned vertex(double* x, double* y)
|
||||
{
|
||||
return util::apply_visitor([=](auto & impl) {
|
||||
return impl.vertex(x, y);
|
||||
}, impl_);
|
||||
}
|
||||
|
||||
unsigned type() const
|
||||
{
|
||||
return util::apply_visitor([](auto const& impl) {
|
||||
return impl.type();
|
||||
}, impl_);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // MAPNIK_ADAPTIVE_SMOOTH_HPP
|
|
@ -96,6 +96,7 @@ enum class property_types : std::uint8_t
|
|||
target_direction,
|
||||
target_font_feature_settings,
|
||||
target_line_pattern,
|
||||
target_smooth_algorithm,
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -191,6 +192,7 @@ ENUM_FROM_STRING( text_upright_enum )
|
|||
ENUM_FROM_STRING( direction_enum )
|
||||
ENUM_FROM_STRING( gamma_method_enum )
|
||||
ENUM_FROM_STRING( line_pattern_enum )
|
||||
ENUM_FROM_STRING( smooth_algorithm_enum )
|
||||
|
||||
// enum
|
||||
template <typename T, bool is_enum = true>
|
||||
|
|
|
@ -383,6 +383,12 @@ struct symbolizer_default<value_double, keys::extend>
|
|||
static value_double value() { return 0.0; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct symbolizer_default<smooth_algorithm_enum, keys::smooth_algorithm>
|
||||
{
|
||||
static smooth_algorithm_enum value() { return SMOOTH_ALGORITHM_BASIC; }
|
||||
};
|
||||
|
||||
} // namespace mapnik
|
||||
|
||||
#endif // MAPNIK_SYMBOLIZER_DEFAULT_VALUES_HPP
|
||||
|
|
|
@ -231,6 +231,15 @@ enum line_pattern_enum : std::uint8_t
|
|||
|
||||
DEFINE_ENUM (line_pattern_e, line_pattern_enum );
|
||||
|
||||
enum smooth_algorithm_enum : std::uint8_t
|
||||
{
|
||||
SMOOTH_ALGORITHM_BASIC = 0,
|
||||
SMOOTH_ALGORITHM_ADAPTIVE,
|
||||
smooth_algorithm_enum_MAX
|
||||
};
|
||||
|
||||
DEFINE_ENUM (smooth_algorithm_e, smooth_algorithm_enum );
|
||||
|
||||
}
|
||||
|
||||
#endif //MAPNIK_SYMBOLIZER_ENUMERATIONS_HPP
|
||||
|
|
|
@ -67,6 +67,7 @@ enum class keys : std::uint8_t
|
|||
mesh_size,
|
||||
premultiplied,
|
||||
smooth,
|
||||
smooth_algorithm,
|
||||
simplify_algorithm,
|
||||
simplify_tolerance,
|
||||
halo_rasterizer,
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <mapnik/symbolizer_keys.hpp>
|
||||
#include <mapnik/symbolizer.hpp>
|
||||
#include <mapnik/extend_converter.hpp>
|
||||
#include <mapnik/adaptive_smooth.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore_agg.hpp>
|
||||
|
@ -77,11 +78,12 @@ template <typename T>
|
|||
struct converter_traits<T, mapnik::smooth_tag>
|
||||
{
|
||||
using geometry_type = T;
|
||||
using conv_type = typename agg::conv_smooth_poly1_curve<geometry_type>;
|
||||
using conv_type = smooth_converter<geometry_type>;
|
||||
|
||||
template <typename Args>
|
||||
static void setup(geometry_type & geom, Args const& args)
|
||||
{
|
||||
geom.algorithm(get<smooth_algorithm_enum,keys::smooth_algorithm>(args.sym, args.feature, args.vars));
|
||||
geom.smooth_value(get<value_double, keys::smooth>(args.sym, args.feature, args.vars));
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1010,6 +1010,7 @@ void map_parser::parse_symbolizer_base(symbolizer_base &sym, xml_node const& nod
|
|||
set_symbolizer_property<symbolizer_base,composite_mode_e>(sym, keys::comp_op, node);
|
||||
set_symbolizer_property<symbolizer_base,transform_type>(sym, keys::geometry_transform, node);
|
||||
set_symbolizer_property<symbolizer_base,simplify_algorithm_e>(sym, keys::simplify_algorithm, node);
|
||||
set_symbolizer_property<symbolizer_base,smooth_algorithm_enum>(sym, keys::smooth_algorithm, node);
|
||||
set_symbolizer_property<symbolizer_base,double>(sym, keys::extend, node);
|
||||
}
|
||||
|
||||
|
|
|
@ -215,4 +215,12 @@ static const char * line_pattern_strings[] = {
|
|||
|
||||
IMPLEMENT_ENUM( line_pattern_e, line_pattern_strings )
|
||||
|
||||
static const char * smooth_algorithm_strings[] = {
|
||||
"basic",
|
||||
"adaptive",
|
||||
""
|
||||
};
|
||||
|
||||
IMPLEMENT_ENUM( smooth_algorithm_e, smooth_algorithm_strings )
|
||||
|
||||
} // namespace mapnik
|
||||
|
|
|
@ -95,6 +95,10 @@ static const property_meta_type key_meta[const_max_key] =
|
|||
property_meta_type{ "mesh-size", nullptr, property_types::target_double },
|
||||
property_meta_type{ "premultiplied", nullptr, property_types::target_bool },
|
||||
property_meta_type{ "smooth", nullptr, property_types::target_double },
|
||||
property_meta_type{ "smooth-algorithm",
|
||||
[](enumeration_wrapper e)
|
||||
{return enumeration<smooth_algorithm_enum,smooth_algorithm_enum_MAX>(smooth_algorithm_enum(e.value)).as_string();},
|
||||
property_types::target_smooth_algorithm },
|
||||
property_meta_type{ "simplify-algorithm",
|
||||
[](enumeration_wrapper e)
|
||||
{
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit b122c5b5b072c2e13d23ad4df2d00d77f553c81a
|
||||
Subproject commit 1bccb46badded81a9ccfb54851ece45df56c695c
|
Loading…
Reference in a new issue