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

◆ centroid() [2/3]

template<typename T , std::invocable< const T & > PosFn, std::invocable< const T & > WeightFn>
requires std::convertible_to<std::invoke_result_t<PosFn, const T&>, glm::vec3> && std::convertible_to<std::invoke_result_t<WeightFn, const T&>, float>
glm::vec3 MayaFlux::Kinesis::centroid ( std::span< T >  pts,
PosFn  pos,
WeightFn  weight 
)
noexcept

Fully explicit weighted centroid for arbitrary point types.

Neither PositionCarrying nor any field convention is required. Both the position and the weight are extracted via caller-supplied callables. Use this overload for Nexus QueryResult spans, CV observation structs, Eigen column references, or any type that does not follow the vertex convention.

Falls back to the zero vector when total weight is zero or the span is empty.

Template Parameters
TElement type. No concept constraint.
PosFnCallable: const T& -> glm::vec3 (or convertible).
WeightFnCallable: const T& -> float (or convertible).
Parameters
ptsNon-owning span of elements.
posPosition extractor.
weightWeight extractor.
Returns
Weighted mean position.

Definition at line 107 of file Morphology.hpp.

108{
109 if (pts.empty())
110 return glm::vec3(0.0F);
111 glm::vec3 acc(0.0F);
112 float total = 0.0F;
113 for (const auto& p : pts) {
114 const auto w = static_cast<float>(std::invoke(weight, p));
115 acc += static_cast<glm::vec3>(std::invoke(pos, p)) * w;
116 total += w;
117 }
118 return total > 0.0F ? acc / total : glm::vec3(0.0F);
119}
double weight

References weight.