Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::ChaikinSmoothing Class Reference

Chaikin corner-cutting subdivision for polygon smoothing. More...

#include <geom_algorithms.H>

Public Member Functions

Array< Pointoperator() (const Array< Point > &polyline, size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4)) const
 Smooth an open polyline.
 
Array< Pointoperator() (const DynList< Point > &polyline, size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4)) const
 Overload accepting DynList.
 

Static Public Member Functions

static Polygon smooth_polygon (const Polygon &poly, size_t iterations, const Geom_Number &ratio=Geom_Number(1, 4))
 Smooth a closed polygon.
 

Static Private Member Functions

static Array< Pointsmooth_open_once (const Array< Point > &pts, const Geom_Number &r)
 
static Array< Pointsmooth_closed_once (const Array< Point > &pts, const Geom_Number &r)
 

Detailed Description

Chaikin corner-cutting subdivision for polygon smoothing.

Each iteration replaces every edge (P_i, P_{i+1}) with two new points at fractions ratio and 1 - ratio along the edge. After k iterations the result converges toward a quadratic B-spline curve.

  • Closed polygon with n vertices -> n * 2^k vertices after k iterations.
  • Open polyline preserves first and last vertices.

Complexity: O(n * 2^k) where n = input size, k = iterations.

Definition at line 12805 of file geom_algorithms.H.

Member Function Documentation

◆ operator()() [1/2]

Array< Point > Aleph::ChaikinSmoothing::operator() ( const Array< Point > &  polyline,
size_t  iterations,
const Geom_Number ratio = Geom_Number(1, 4) 
) const
inline

Smooth an open polyline.

First and last vertices are preserved.

Parameters
polylineOrdered sequence of vertices.
iterationsNumber of subdivision iterations (>= 1).
ratioCutting fraction in (0, 0.5). Default 1/4.
Returns
Smoothed vertex array.

Definition at line 12857 of file geom_algorithms.H.

References ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), k, and smooth_open_once().

◆ operator()() [2/2]

Array< Point > Aleph::ChaikinSmoothing::operator() ( const DynList< Point > &  polyline,
size_t  iterations,
const Geom_Number ratio = Geom_Number(1, 4) 
) const
inline

◆ smooth_closed_once()

static Array< Point > Aleph::ChaikinSmoothing::smooth_closed_once ( const Array< Point > &  pts,
const Geom_Number r 
)
inlinestaticprivate

◆ smooth_open_once()

static Array< Point > Aleph::ChaikinSmoothing::smooth_open_once ( const Array< Point > &  pts,
const Geom_Number r 
)
inlinestaticprivate

Definition at line 12808 of file geom_algorithms.H.

References Aleph::Array< T >::append(), Aleph::divide_and_conquer_partition_dp(), and r.

Referenced by operator()().

◆ smooth_polygon()

static Polygon Aleph::ChaikinSmoothing::smooth_polygon ( const Polygon poly,
size_t  iterations,
const Geom_Number ratio = Geom_Number(1, 4) 
)
inlinestatic

Smooth a closed polygon.

All vertices participate in corner cutting (cyclic).

Parameters
polyThe closed polygon.
iterationsNumber of subdivision iterations (>= 1).
ratioCutting fraction in (0, 0.5). Default 1/4.
Returns
A new smoothed polygon.

Definition at line 12893 of file geom_algorithms.H.

References Aleph::Polygon::add_vertex(), ah_domain_error_if, Aleph::divide_and_conquer_partition_dp(), Aleph::GeomPolygonUtils::extract_vertices(), k, and smooth_closed_once().

Referenced by main(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), TEST_F(), and Aleph::visualize_chaikin_smoothing().


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