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

◆ surface_centroid()

glm::vec3 MayaFlux::Kinesis::surface_centroid ( std::span< const std::byte >  bytes,
size_t  stride,
size_t  offset,
std::span< const uint32_t >  indices 
)
inlinenoexcept

Area-weighted centroid of the triangles of an indexed mesh.

Each triangle contributes its own centroid weighted by its area, so dense tessellation does not pull the result the way a vertex mean does. A triangle with an index outside bytes is skipped.

Parameters
bytesInterleaved vertex records.
strideBytes per record.
offsetByte offset of the vec3 position within a record.
indicesTriangle list, three indices per face.
Returns
Surface centroid, or the vertex centroid when there is no triangle of nonzero area.

Definition at line 204 of file Morphology.hpp.

209{
210 glm::vec3 acc(0.0F);
211 float total = 0.0F;
212 for (size_t t = 0; t + 2 < indices.size(); t += 3) {
213 const auto a = position_at(bytes, stride, offset, indices[t]);
214 const auto b = position_at(bytes, stride, offset, indices[t + 1]);
215 const auto c = position_at(bytes, stride, offset, indices[t + 2]);
216 if (!a || !b || !c)
217 continue;
218 const float area = 0.5F * glm::length(glm::cross(*b - *a, *c - *a));
219 acc += (*a + *b + *c) * (area / 3.0F);
220 total += area;
221 }
222 return total > 0.0F ? acc / total : centroid(bytes, stride, offset);
223}
uint64_t offset
Definition Composite.cpp:10
std::vector< uint32_t > indices
uint32_t total
size_t a
size_t b
std::optional< glm::vec3 > position_at(std::span< const std::byte > bytes, size_t stride, size_t offset, size_t index) noexcept
Position of one record in interleaved vertex bytes.

References a, b, centroid(), indices, offset, position_at(), and total.

+ Here is the call graph for this function: