| 1628 | } |
| 1629 | |
| 1630 | void DemoCustomPerPointStyle() { |
| 1631 | IMGUI_DEMO_MARKER("Custom/Custom Per-Point Style"); |
| 1632 | ImGui::BulletText("Demonstrates per-point coloring using colormap sampling."); |
| 1633 | ImGui::BulletText("A different color is sampled for each point."); |
| 1634 | ImGui::BulletText("All points share the same label for a single legend entry."); |
| 1635 | |
| 1636 | static float marker_size = 4.0f; |
| 1637 | static ImPlot3DColormap cmap = ImPlot3DColormap_Viridis; |
| 1638 | |
| 1639 | ImGui::SliderFloat("Marker Size", &marker_size, 2.0f, 10.0f); |
| 1640 | if (ImGui::BeginCombo("Colormap", ImPlot3D::GetColormapName(cmap))) { |
| 1641 | ImPlot3DContext& gp = *GImPlot3D; |
| 1642 | for (int i = 0; i < ImPlot3D::GetColormapCount(); i++) { |
| 1643 | // Only show continuous colormaps |
| 1644 | if (!gp.ColormapData.IsQual(i)) { |
| 1645 | if (ImGui::Selectable(ImPlot3D::GetColormapName(i), cmap == i)) |
| 1646 | cmap = i; |
| 1647 | } |
| 1648 | } |
| 1649 | ImGui::EndCombo(); |
| 1650 | } |
| 1651 | |
| 1652 | // Generate three stacked toruses with different color patterns |
| 1653 | static float torus_data[3][400][4]; // 3 toruses, 400 points each, XYZT per point |
| 1654 | static bool initialized = false; |
| 1655 | if (!initialized) { |
| 1656 | const float R = 0.6f; // Major radius |
| 1657 | const float r = 0.2f; // Minor radius |
| 1658 | const int u_samples = 20; |
| 1659 | const int v_samples = 20; |
| 1660 | |
| 1661 | for (int torus = 0; torus < 3; torus++) { |
| 1662 | float z_offset = (2 - torus) * 0.6f; |
| 1663 | int idx = 0; |
| 1664 | |
| 1665 | for (int i = 0; i < u_samples; i++) { |
| 1666 | float u = (float)i / u_samples * 2.0f * IM_PI; |
| 1667 | for (int j = 0; j < v_samples; j++) { |
| 1668 | float v = (float)j / v_samples * 2.0f * IM_PI; |
| 1669 | |
| 1670 | // Parametric torus equations |
| 1671 | float x = (R + r * ImCos(v)) * ImCos(u); |
| 1672 | float y = (R + r * ImCos(v)) * ImSin(u); |
| 1673 | float z = r * ImSin(v) + z_offset; |
| 1674 | |
| 1675 | // Different color pattern for each torus |
| 1676 | float t; |
| 1677 | if (torus == 0) { |
| 1678 | // Color by height (Z coordinate) |
| 1679 | // Normalize Z to [0, 1] range for this torus |
| 1680 | t = (z - (z_offset - r)) / (2.0f * r); |
| 1681 | } else if (torus == 1) { |
| 1682 | // Color by radial distance from tube center |
| 1683 | // V parameter directly gives us position around tube |
| 1684 | // Map from [-r, +r] to [0, 1] |
| 1685 | t = (ImCos(v) + 1.0f) / 2.0f; |
| 1686 | } else { |
| 1687 | // Angular pattern: varies smoothly around the major circle |
nothing calls this directly
no test coverage detected