Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
boost::polygon::voronoi_visual_utils< CT > Class Template Reference

#include <src/libslic3r/Geometry/VoronoiVisualUtils.hpp>

Static Public Member Functions

template<class InCT1 , class InCT2 , template< class > class Point, template< class > class Segment>
static enable_if< typenamegtl_and< typenamegtl_if< typenameis_point_concept< typenamegeometry_concept< Point< InCT1 > >::type >::type >::type, typenamegtl_if< typenameis_segment_concept< typenamegeometry_concept< Segment< InCT2 > >::type >::type >::type >::type, void >::type discretize (const Point< InCT1 > &point, const Segment< InCT2 > &segment, const CT max_dist, std::vector< Point< CT > > *discretization)
 

Static Private Member Functions

static CT parabola_y (CT x, CT a, CT b)
 
template<class InCT , template< class > class Point, template< class > class Segment>
static enable_if< typenamegtl_and< typenamegtl_if< typenameis_point_concept< typenamegeometry_concept< Point< int > >::type >::type >::type, typenamegtl_if< typenameis_segment_concept< typenamegeometry_concept< Segment< long > >::type >::type >::type >::type, CT >::type get_point_projection (const Point< CT > &point, const Segment< InCT > &segment)
 
template<typename InCT >
static CT cast (const InCT &value)
 

Detailed Description

template<typename CT>
class boost::polygon::voronoi_visual_utils< CT >

Member Function Documentation

◆ cast()

template<typename CT >
template<typename InCT >
static CT boost::polygon::voronoi_visual_utils< CT >::cast ( const InCT &  value)
inlinestaticprivate
178 {
179 return static_cast<CT>(value);
180 }

◆ discretize()

template<typename CT >
template<class InCT1 , class InCT2 , template< class > class Point, template< class > class Segment>
static enable_if< typenamegtl_and< typenamegtl_if< typenameis_point_concept< typenamegeometry_concept< Point< InCT1 > >::type >::type >::type, typenamegtl_if< typenameis_segment_concept< typenamegeometry_concept< Segment< InCT2 > >::type >::type >::type >::type, void >::type boost::polygon::voronoi_visual_utils< CT >::discretize ( const Point< InCT1 > &  point,
const Segment< InCT2 > &  segment,
const CT  max_dist,
std::vector< Point< CT > > *  discretization 
)
inlinestatic
61 {
62 // Apply the linear transformation to move start point of the segment to
63 // the point with coordinates (0, 0) and the direction of the segment to
64 // coincide the positive direction of the x-axis.
65 CT segm_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
66 CT segm_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
67 CT sqr_segment_length = segm_vec_x * segm_vec_x + segm_vec_y * segm_vec_y;
68
69 // Compute x-coordinates of the endpoints of the edge
70 // in the transformed space.
71 CT projection_start = sqr_segment_length *
72 get_point_projection((*discretization)[0], segment);
73 CT projection_end = sqr_segment_length *
74 get_point_projection((*discretization)[1], segment);
75 assert(projection_start != projection_end);
76
77 // Compute parabola parameters in the transformed space.
78 // Parabola has next representation:
79 // f(x) = ((x-rot_x)^2 + rot_y^2) / (2.0*rot_y).
80 CT point_vec_x = cast(x(point)) - cast(x(low(segment)));
81 CT point_vec_y = cast(y(point)) - cast(y(low(segment)));
82 CT rot_x = segm_vec_x * point_vec_x + segm_vec_y * point_vec_y;
83 CT rot_y = segm_vec_x * point_vec_y - segm_vec_y * point_vec_x;
84
85 // Save the last point.
86 Point<CT> last_point = (*discretization)[1];
87 discretization->pop_back();
88
89 // Use stack to avoid recursion.
90 std::stack<CT> point_stack;
91 point_stack.push(projection_end);
92 CT cur_x = projection_start;
93 CT cur_y = parabola_y(cur_x, rot_x, rot_y);
94
95 // Adjust max_dist parameter in the transformed space.
96 const CT max_dist_transformed = max_dist * max_dist * sqr_segment_length;
97 while (!point_stack.empty()) {
98 CT new_x = point_stack.top();
99 CT new_y = parabola_y(new_x, rot_x, rot_y);
100
101 // Compute coordinates of the point of the parabola that is
102 // furthest from the current line segment.
103 CT mid_x = (new_y - cur_y) / (new_x - cur_x) * rot_y + rot_x;
104 CT mid_y = parabola_y(mid_x, rot_x, rot_y);
105 assert(mid_x != cur_x || mid_y != cur_y);
106 assert(mid_x != new_x || mid_y != new_y);
107
108 // Compute maximum distance between the given parabolic arc
109 // and line segment that discretize it.
110 CT dist = (new_y - cur_y) * (mid_x - cur_x) -
111 (new_x - cur_x) * (mid_y - cur_y);
112 CT div = (new_y - cur_y) * (new_y - cur_y) + (new_x - cur_x) * (new_x - cur_x);
113 assert(div != 0);
114 dist = dist * dist / div;
115 if (dist <= max_dist_transformed) {
116 // Distance between parabola and line segment is less than max_dist.
117 point_stack.pop();
118 CT inter_x = (segm_vec_x * new_x - segm_vec_y * new_y) /
119 sqr_segment_length + cast(x(low(segment)));
120 CT inter_y = (segm_vec_x * new_y + segm_vec_y * new_x) /
121 sqr_segment_length + cast(y(low(segment)));
122 discretization->push_back(Point<CT>(inter_x, inter_y));
123 cur_x = new_x;
124 cur_y = new_y;
125 } else {
126 point_stack.push(mid_x);
127 }
128 }
129
130 // Update last point.
131 discretization->back() = last_point;
132 }
EIGEN_DEVICE_FUNC SegmentReturnType segment(Index start, Index n)
This is the const version of segment(Index,Index).
Definition BlockMethods.h:888
EIGEN_DEVICE_FUNC CastXpr< NewType >::Type cast() const
Definition CommonCwiseUnaryOps.h:62
static enable_if< typenamegtl_and< typenamegtl_if< typenameis_point_concept< typenamegeometry_concept< Point< int > >::type >::type >::type, typenamegtl_if< typenameis_segment_concept< typenamegeometry_concept< Segment< long > >::type >::type >::type >::type, CT >::type get_point_projection(const Point< CT > &point, const Segment< InCT > &segment)
Definition VoronoiVisualUtils.hpp:165
static CT parabola_y(CT x, CT a, CT b)
Definition VoronoiVisualUtils.hpp:136
const Scalar & y
Definition MathFunctions.h:552
T dist(const boost::polygon::point_data< T > &p1, const boost::polygon::point_data< T > &p2)
Definition Geometry.cpp:280
TCoord< P > x(const P &p)
Definition geometry_traits.hpp:297
Kernel::Point_2 Point
Definition point_areas.cpp:20

References cast(), boost::polygon::voronoi_visual_utils< CT >::get_point_projection(), boost::polygon::voronoi_visual_utils< CT >::parabola_y(), and segment().

Referenced by Slic3r::Voronoi::Internal::sample_curved_edge().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ get_point_projection()

template<typename CT >
template<class InCT , template< class > class Point, template< class > class Segment>
static enable_if< typenamegtl_and< typenamegtl_if< typenameis_point_concept< typenamegeometry_concept< Point< int > >::type >::type >::type, typenamegtl_if< typenameis_segment_concept< typenamegeometry_concept< Segment< long > >::type >::type >::type >::type, CT >::type boost::polygon::voronoi_visual_utils< CT >::get_point_projection ( const Point< CT > &  point,
const Segment< InCT > &  segment 
)
inlinestaticprivate
166 {
167 CT segment_vec_x = cast(x(high(segment))) - cast(x(low(segment)));
168 CT segment_vec_y = cast(y(high(segment))) - cast(y(low(segment)));
169 CT point_vec_x = x(point) - cast(x(low(segment)));
170 CT point_vec_y = y(point) - cast(y(low(segment)));
171 CT sqr_segment_length =
172 segment_vec_x * segment_vec_x + segment_vec_y * segment_vec_y;
173 CT vec_dot = segment_vec_x * point_vec_x + segment_vec_y * point_vec_y;
174 return vec_dot / sqr_segment_length;
175 }

References cast(), and segment().

Referenced by boost::polygon::voronoi_visual_utils< CT >::discretize().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parabola_y()

template<typename CT >
static CT boost::polygon::voronoi_visual_utils< CT >::parabola_y ( CT  x,
CT  a,
CT  b 
)
inlinestaticprivate
136 {
137 return ((x - a) * (x - a) + b * b) / (b + b);
138 }

Referenced by boost::polygon::voronoi_visual_utils< CT >::discretize().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following file: