MayaFlux 0.4.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 568 of file GeometryPrimitives.cpp.

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

References apply_color_gradient(), and color.

Referenced by apply_color_gradient().

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