Skip to content

File point_cloud_visualization.hpp

File List > gui > point_cloud_visualization.hpp

Go to the documentation of this file

#pragma once

#include <array>
#include <cstdint>
#include <string>

enum class PointColorMode { File, Classification, Fixed };

// Single source of truth for LAS classification styling. The point shader's
// classification_color() GLSL (generated by classification_color_glsl()) and
// the UI's classification label both derive from this one table.
struct ClassificationStyle {
  uint8_t code;
  std::array<uint8_t, 3> color;
  const char* label;
};

inline constexpr std::array<ClassificationStyle, 9> CLASSIFICATION_STYLES = {{
    {2, {{160, 120, 80}}, "Ground"},
    {3, {{100, 180, 100}}, "Low vegetation"},
    {4, {{60, 140, 60}}, "Medium vegetation"},
    {5, {{30, 100, 30}}, "High vegetation"},
    {6, {{200, 80, 80}}, "Building"},
    {7, {{120, 120, 120}}, "Low point"},
    {8, {{255, 200, 0}}, "Model key point"},
    {9, {{60, 120, 220}}, "Water"},
    {17, {{180, 180, 180}}, "Bridge deck"},
}};

inline constexpr std::array<uint8_t, 3> DEFAULT_CLASSIFICATION_COLOR{{200, 200, 200}};

inline std::array<uint8_t, 3> classification_color(uint8_t classification) {
  for (const ClassificationStyle& style : CLASSIFICATION_STYLES) {
    if (style.code == classification) {
      return style.color;
    }
  }
  return DEFAULT_CLASSIFICATION_COLOR;
}

// GLSL source for `vec3 classification_color(int class_id)`, generated from the
// table so the shader palette is never a hand-maintained copy.
inline std::string classification_color_glsl() {
  const auto vec3_literal = [](const std::array<uint8_t, 3>& c) {
    return "vec3(" + std::to_string(c[0]) + ".0, " + std::to_string(c[1]) + ".0, " +
           std::to_string(c[2]) + ".0) / 255.0";
  };
  std::string src = "vec3 classification_color(int class_id) {\n";
  for (const ClassificationStyle& style : CLASSIFICATION_STYLES) {
    src += "    if (class_id == " + std::to_string(style.code) + ") return " +
           vec3_literal(style.color) + ";\n";
  }
  src += "    return " + vec3_literal(DEFAULT_CLASSIFICATION_COLOR) + ";\n}\n";
  return src;
}