82 :
Cloud(npoints, seed, bbox) {};
104 Path(
const std::vector<float> &x,
const std::vector<float> &y)
115 Path(
const std::vector<float> &x,
116 const std::vector<float> &y,
117 const std::vector<float> &v)
131 Path(
const std::vector<glm::ivec2> &indices,
132 const glm::ivec2 &shape,
134 :
Cloud(indices, shape, bbox) {};
139 Path(
const std::vector<glm::vec3> &xyv) :
Cloud(xyv) {};
221 std::vector<float>
get_x()
const;
234 std::vector<float>
get_xy()
const;
245 std::vector<float>
get_y()
const;
398 const std::vector<float> *p_arc =
nullptr,
399 glm::vec2 *p_tangent =
nullptr)
const;
433 const BBox2D &bbox = BBox2D{},
434 bool filled =
false)
const;
438 const BBox2D &bbox = BBox2D{},
439 bool filled =
false)
const;
443 const BBox2D &bbox = BBox2D{},
444 bool filled =
false)
const;
460 void to_png(std::string fname, glm::ivec2 shape = {512, 512});
463 enum class PathClosure :
int
467 } path_closure = PathClosure::PT_OPEN;
499 float curvature_ratio = 0.3f,
500 int edge_divisions = 10,
527 float curvature_ratio = 0.3f,
528 int edge_divisions = 10,
558 int edge_divisions = 10,
583 int edge_divisions = 10,
614 int edge_divisions = 10,
681 float persistence = 1.f,
682 Array *p_control_field =
nullptr,
684 bool bounded =
false);
737 float noise_ratio = 0.1f,
738 std::uint32_t seed = 1,
740 int edge_divisions = 10,
762 const Array *p_noise_x =
nullptr,
763 const Array *p_noise_y =
nullptr,
764 bool use_bvh =
true);
770 const Array *p_noise_x =
nullptr,
771 const Array *p_noise_y =
nullptr);
776 const Array *p_noise_x =
nullptr,
777 const Array *p_noise_y =
nullptr);
796 const Array *p_noise_x =
nullptr,
797 const Array *p_noise_y =
nullptr,
798 bool use_bvh =
true);
803 const Array *p_noise_x =
nullptr,
804 const Array *p_noise_y =
nullptr);
809 const Array *p_noise_x =
nullptr,
810 const Array *p_noise_y =
nullptr);
819 const Array *p_noise_x =
nullptr,
820 const Array *p_noise_y =
nullptr);
826 const Array *p_noise_x =
nullptr,
827 const Array *p_noise_y =
nullptr);
910 float averaging_intensity = 1.f,
911 float inertia = 0.f);
948 std::uint32_t seed = 0,
949 float height_ratio = 0.5f,
951 const Array *p_weights =
nullptr,
952 const Array *p_mask =
nullptr,
977 std::uint32_t seed = 0,
978 float branch_probability = 0.3f,
979 int max_branches = 8,
980 float height_ratio = 0.5f,
982 const Array *p_weights =
nullptr,
983 const Array *p_mask =
nullptr,
997 const std::vector<Path> &existing_paths);
1017 bool verbose =
false);
Header file for boundary condition functions and utilities.
Array class, helper to manipulate 2D float array with "(i, j)" indexing.
Definition array.hpp:31
Represents a collection of unordered points in 2D space.
Definition cloud.hpp:61
Cloud()
Default constructor for the Cloud class.
std::vector< Point > points
Points of the cloud.
Definition cloud.hpp:663
Represents an ordered set of points in 2D, forming a polyline (open or closed).
Definition path.hpp:43
std::vector< float > get_arc_length() const
Get the arc length of the path.
Definition path.cpp:166
std::vector< Point > get_edge_centers() const
Compute midpoints of path edges.
Definition path.cpp:231
std::vector< float > get_xy() const
Get the coordinates of the points as a single vector.
Definition path.cpp:318
Path(const std::vector< Point > &points)
Construct a new Path object based on a list of points. Initializes a path with the specified points a...
Definition path.hpp:89
Path()=default
Construct a new Path object with default properties. Initializes an empty path with the closed proper...
bool is_closed() const
Check whether the path is closed.
Definition path.cpp:345
Path(const Cloud &cloud)
Construct a new Path object based on a cloud of points.
Definition path.hpp:65
Path(const std::vector< float > &x, const std::vector< float > &y, const std::vector< float > &v)
Construct a new Path object based on x, y coordinates, and values. Initializes a path with the specif...
Definition path.hpp:115
void enforce_monotonic_values(bool decreasing=true)
Enforces monotonicity on the values of the points in the path.
Definition path.cpp:59
EdgeDivisionMode
Definition path.hpp:46
@ EDM_PER_EDGE
Definition path.hpp:47
@ EDM_FULL_ARC
Definition path.hpp:48
void to_array(Array &array, const BBox2D &bbox=BBox2D{}, bool filled=false) const
Project path points to an array.
Definition path.cpp:547
std::vector< float > get_values() const
Get the values assigned to the points on the path.
Definition path.cpp:298
void resample_by_spacing(float delta, InterpolationMethod1D itp_method=InterpolationMethod1D::LINEAR)
Resample the path to achieve an approximately constant distance between points.
Definition path.cpp:398
void to_array_mask(Array &array, const BBox2D &bbox=BBox2D{}, bool filled=false) const
See hmap::to_array.
Definition path.cpp:605
Path(int npoints, std::uint32_t seed, const BBox2D &bbox=BBox2D{})
Construct a new Path object with random positions and values. Initializes a path with a specified num...
Definition path.hpp:81
void resample_uniform(InterpolationMethod1D itp_method=InterpolationMethod1D::LINEAR)
Resample the path to achieve fairly uniform distance between consecutive points.
Definition path.cpp:447
void divide()
Divide the path by adding a point between each pair of consecutive points.
Definition path.cpp:32
void subsample(int step)
Subsample the path by keeping only every n-th point.
Definition path.cpp:526
Path(Cloud &&cloud) noexcept
Move-construct a new Path object based on a cloud of points.
Definition path.hpp:71
std::vector< float > get_cumulative_distance() const
Get the cumulative distance of the path.
Definition path.cpp:186
void to_png(std::string fname, glm::ivec2 shape={512, 512})
Export path as PNG image file.
Definition path.cpp:614
std::vector< float > get_curvature(bool normalized=false) const
Computes the signed curvature at each point of the path.
Definition path.cpp:203
void reverse()
Reverse the order of points in the path.
Definition path.cpp:471
std::vector< float > get_y() const
Get the y coordinates of the points on the path.
Definition path.cpp:335
glm::vec3 sample_at(float t, const std::vector< float > *p_arc=nullptr, glm::vec2 *p_tangent=nullptr) const
Sample the path using normalized arc-length parameterization.
Definition path.cpp:476
std::vector< float > get_x() const
Get the x coordinates of the points on the path.
Definition path.cpp:308
std::vector< glm::vec2 > get_normals() const
Computes unit normals at each point of the path.
Definition path.cpp:251
void reorder_nns(int start_index=0)
Reorder points using a nearest neighbor search.
Definition path.cpp:350
void clear()
Clear the path data.
Definition path.cpp:27
std::vector< glm::vec2 > get_tangents() const
Computes unit tangents at each point of the path.
Definition path.cpp:261
Path(const std::vector< float > &x, const std::vector< float > &y)
Construct a new Path object based on x and y coordinates. Initializes a path with the specified x and...
Definition path.hpp:104
void set_closed(bool new_value)
Set whether the path is closed.
Definition path.cpp:521
Path(const std::vector< glm::vec3 > &xyv)
Constructs a new Path object from lists of xyz data as glm::vec3.
Definition path.hpp:139
void rasterize_capsules(Array &out_dist_sq, float radius, const BBox2D &bbox=BBox2D{}) const
Rasterize path segments as capsules with a given radius onto a distance map.
Definition path.cpp:81
Path(std::vector< Point > &&points) noexcept
Move-construct a new Path object based on a list of points.
Definition path.hpp:95
Path(const std::vector< glm::ivec2 > &indices, const glm::ivec2 &shape, const BBox2D &bbox=BBox2D{})
Construct a point cloud from grid indices mapped to a bounding box.
Definition path.hpp:131
void resample_interp(int npoints, InterpolationMethod1D itp_method=InterpolationMethod1D::CUBIC)
Resamples the path using cubic interpolation along arc length.
Definition path.cpp:408
Definition of the Cloud class for manipulating sets of 2D points.
Defines a 1D interpolation class using the GSL (GNU Scientific Library).
Definition array_blending.hpp:225
Array path_sdf_to_array(const Path &path, glm::ivec2 shape, const UvRect &uv_rect_array=UvRect::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
See hmap::path_sdf_to_array.
Definition sdf_2d_polyline_gpu.cpp:75
Array path_sdf_bezier_to_array(const Path &path, glm::ivec2 shape, const UvRect &uv_rect_array=UvRect::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
See hmap::path_sdf_bezier_to_array.
Definition sdf_2d_polyline_gpu.cpp:166
Array path_sdf_bezier_to_array_brute_force(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Definition path_functions.cpp:436
Array step(glm::ivec2 shape, float angle, float slope, const Array *p_ctrl_param=nullptr, const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, glm::vec2 center={0.5f, 0.5f}, const UvRect &uv_rect=UvRect::unit())
Return a step function (Heaviside with an optional talus slope at the transition).
Definition primitives.cpp:424
bool has_duplicates(const Cloud &cloud, float eps=1e-9f, bool xy_only=true)
Checks whether the point cloud contains duplicate points.
Definition cloud_functions.cpp:65
Path bspline(const Path &path, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Smooth the path using B-Spline curves.
Definition path_functions.cpp:142
Path bezier_round(const Path &path, float curvature_ratio=0.3f, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Smooth the path using Bezier curves (alternative method).
Definition path_functions.cpp:95
Array path_sdf_to_array(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, bool use_bvh=true)
Compute a distance field from a point path.
Definition path_functions.cpp:462
Array normalized(const Array &array, NormalizationMethod method)
Returns a normalized copy of an array.
Definition normalize.cpp:51
Array path_sdf_to_array_bvh(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Definition path_functions.cpp:540
InterpolationMethod1D
Enumeration of the available 1D interpolation methods.
Definition interpolate1d.hpp:36
@ CUBIC
Cubic spline interpolation.
Definition interpolate1d.hpp:39
@ LINEAR
Linear interpolation.
Definition interpolate1d.hpp:41
Path meanderize(const Path &path, float ratio, float noise_ratio=0.1f, std::uint32_t seed=1, int iterations=1, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Add "meanders" to the path.
Definition path_functions.cpp:356
Array path_sdf_to_array_brute_force(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Definition path_functions.cpp:479
Path squiggle(const Path &path, int iterations=4, std::uint32_t seed=0, float height_ratio=0.5f, int orientation=0, const Array *p_weights=nullptr, const Array *p_mask=nullptr, const BBox2D &bbox=BBox2D{})
Generates a continuous, non-self-intersecting squiggle curve by applying the squiggle recursive trian...
Definition path_squiggle.cpp:182
bool assert_start_end_points(const Path &path1, const Path &path2, float tol=1e-6f, bool verbose=false)
Asserts that the start and end points of two paths are within a specified tolerance.
Definition path_verification.cpp:17
std::vector< Path > squiggle_branches(const Path &path, int iterations=4, std::uint32_t seed=0, float branch_probability=0.3f, int max_branches=8, float height_ratio=0.5f, int orientation=0, const Array *p_weights=nullptr, const Array *p_mask=nullptr, const BBox2D &bbox=BBox2D{})
Generates squiggle paths with secondary tributary branches along each edge.
Definition path_squiggle.cpp:296
Path remove_geometric_loops(const Path &path)
Removes geometric loops in a 2D path caused by self-intersections.
Definition path_functions.cpp:681
Path inflate(const Path &path, float strength, bool resample=true)
Inflate (offset) a path along its normals using curvature.
Definition path_functions.cpp:326
Cloud scale(const Cloud &cloud, glm::vec2 scale, glm::vec2 center={0.5f, 0.5f})
Scales the point coordinates in a cloud relative to a center point.
Definition cloud_functions.cpp:163
Path decimate_vw(const Path &path, int n_points_target=3)
Simplifies the current path using the Visvalingam-Whyatt algorithm.
Definition path_functions.cpp:206
Path catmullrom(const Path &path, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Smooth the path using Catmull-Rom curves.
Definition path_functions.cpp:162
Array path_sdf_bezier_to_array_bvh(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr)
Definition path_functions.cpp:449
float chamfer_distance(const Path &a, const Path &b)
Calculate the chamfer distance between two paths.
Definition path_verification.cpp:43
Path fractalize(const Path &path, int iterations, std::uint32_t seed, float sigma=0.2f, int orientation=0, float persistence=1.f, Array *p_control_field=nullptr, const BBox2D &bbox=BBox2D{}, bool bounded=false)
Applies fractalization to the path by adding points and randomly displacing their positions.
Definition path_functions.cpp:235
Path bezier(const Path &path, float curvature_ratio=0.3f, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Smooth the path using Bezier curves.
Definition path_functions.cpp:51
Path truncate_at_first_intersection(const Path &path, const std::vector< Path > &existing_paths)
Truncates a path at its first intersection with any path in a given set of existing paths....
Definition path_functions.cpp:823
Path smooth(const Path &path, int navg=1, float averaging_intensity=1.f, float inertia=0.f)
Applies a smoothing operation to the path points using a moving average filter.
Definition path_functions.cpp:732
Array path_sdf_bezier_to_array(const Path &path, glm::ivec2 shape, const BBox2D &bbox_array=BBox2D::unit(), const Array *p_noise_x=nullptr, const Array *p_noise_y=nullptr, bool use_bvh=true)
Converts a 2D path treated as a piecewise quadratic Bezier curve to a signed distance field (SDF) arr...
Definition path_functions.cpp:421
Path decasteljau(const Path &path, int edge_divisions=10, Path::EdgeDivisionMode edm=Path::EdgeDivisionMode::EDM_PER_EDGE)
Smooth the path using De Casteljau curves.
Definition path_functions.cpp:184
Axis-aligned 2D bounding box in world coordinates.
Definition bbox2d.hpp:25
static constexpr BBox2D unit()
Definition bbox2d.hpp:39
static constexpr UvRect unit()
Definition uv_rect.hpp:46