MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ resample_uniform()

std::vector< glm::vec2 > MayaFlux::Kinesis::resample_uniform ( std::span< const glm::vec2 >  path,
size_t  count 
)
inline

Resample a path to a fixed point count at uniform arc length.

Parameters
pathPositions in chronological order, at least two
countOutput point count, minimum 2
Returns
count points evenly spaced along the path by distance

Removes speed from the path entirely. Two strokes tracing the same shape, one hurried through its middle and one dwelling there, produce different sample distributions in time and identical ones after this, which is the precondition for comparing them point against point.

A path whose total length is below the epsilon guard is degenerate, every sample having landed in effectively one place, and is returned as count copies of its first point rather than dividing by zero.

MotionCurves::reparameterize_by_arc_length does the same thing over an Eigen::MatrixXd with columns as points. This exists so a caller holding glm::vec2 samples does not transpose into a matrix and back for what is a linear walk.

Definition at line 45 of file PathShape.hpp.

47{
48 count = count < 2 ? 2 : count;
49 if (path.size() < 2)
50 return std::vector<glm::vec2>(count, path.empty() ? glm::vec2 { 0.0F } : path[0]);
51
52 std::vector<float> arc;
53 arc.reserve(path.size());
54 arc.push_back(0.0F);
55 float total = 0.0F;
56 for (size_t i = 1; i < path.size(); ++i) {
57 total += glm::length(path[i] - path[i - 1]);
58 arc.push_back(total);
59 }
60
61 if (total < 1e-6F)
62 return std::vector<glm::vec2>(count, path[0]);
63
64 std::vector<glm::vec2> out;
65 out.reserve(count);
66 const float step = total / static_cast<float>(count - 1);
67
68 size_t upper = 1;
69 for (size_t i = 0; i < count; ++i) {
70 const float target = static_cast<float>(i) * step;
71 while (upper < arc.size() - 1 && arc[upper] < target)
72 ++upper;
73 const size_t lower = upper - 1;
74 const float segment = arc[upper] - arc[lower];
75 const float t = (segment > 1e-9F) ? ((target - arc[lower]) / segment) : 0.0F;
76 out.push_back(glm::mix(path[lower], path[upper], t));
77 }
78 return out;
79}
uint32_t total
std::vector< float > * out
size_t count

References count, out, and total.

Referenced by shape_distance(), and turning_profile().

+ Here is the caller graph for this function: