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

◆ apply_color_gradient()

std::vector< Nodes::LineVertex > MayaFlux::Kinesis::apply_color_gradient ( const std::vector< glm::vec3 > &  positions,
const std::vector< glm::vec3 > &  colors,
const std::vector< float > &  color_positions = {},
float  default_thickness = 1.0F 
)

Apply color interpolation to position vertices.

Parameters
positionsInput position vertices
colorsColor stops for interpolation
color_positionsNormalized positions [0,1] for each color stop
default_thicknessLine thickness for all vertices (default: 1.0)
Returns
LineVertex array with interpolated colors

Example: colors = {red, blue} color_positions = {0.0, 1.0} → Linear gradient from red to blue along path

If color_positions.empty(), distributes colors uniformly.

Definition at line 558 of file GeometryPrimitives.cpp.

563{
564 if (positions.empty() || colors.empty()) {
565 return {};
566 }
567
568 std::vector<Nodes::LineVertex> vertices;
569 vertices.reserve(positions.size());
570
571 if (colors.size() == 1) {
572 for (const auto& pos : positions) {
573 vertices.push_back({ .position = pos,
574 .color = colors[0],
575 .thickness = default_thickness });
576 }
577 return vertices;
578 }
579
580 std::vector<float> stops = color_positions;
581 if (stops.empty()) {
582 stops.reserve(colors.size());
583 for (size_t i = 0; i < colors.size(); ++i) {
584 stops.push_back(static_cast<float>(i) / static_cast<float>(colors.size() - 1));
585 }
586 }
587
588 for (size_t i = 0; i < positions.size(); ++i) {
589 float t = static_cast<float>(i) / static_cast<float>(positions.size() - 1);
590
591 glm::vec3 color;
592 if (t <= stops[0]) {
593 color = colors[0];
594 } else if (t >= stops.back()) {
595 color = colors.back();
596 } else {
597 size_t idx = 0;
598 for (size_t j = 1; j < stops.size(); ++j) {
599 if (t <= stops[j]) {
600 idx = j - 1;
601 break;
602 }
603 }
604
605 float local_t = (t - stops[idx]) / (stops[idx + 1] - stops[idx]);
606 color = glm::mix(colors[idx], colors[idx + 1], local_t);
607 }
608
609 vertices.push_back({ .position = positions[i],
610 .color = color,
611 .thickness = default_thickness });
612 }
613
614 return vertices;
615}

References apply_color_gradient().

Referenced by apply_color_gradient().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: