Gradient.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef GRADIENT_H
  2. #define GRADIENT_H
  3. #include <vector>
  4. #include <string>
  5. #include "Color.h"
  6. #include <tuple>
  7. #include <cinttypes>
  8. class Gradient
  9. {
  10. std::vector<std::pair<RGBColor, float>> points;
  11. /// the colors of this gradient stored in linear RGB format
  12. /// so they can be easily interpolated
  13. std::vector<RGBColorf> colors;
  14. float max;
  15. bool repeat;
  16. public:
  17. Gradient(void);
  18. Gradient(std::vector<std::pair<RGBColor, float>> colors, bool repeat = false, int precalcSteps = -1);
  19. const std::vector<std::pair<RGBColor, float>>& getPoints(void) const;
  20. static Gradient defaultGradient(void);
  21. //static Gradient readXml(const std::string& xml);
  22. /*!
  23. * \brief get a color at a specific position in this gradient
  24. * \param x the position
  25. * \return the color in sRGB format
  26. */
  27. RGBColor get(float x) const;
  28. private:
  29. static RGBColorf lerpColors(RGBColorf a, RGBColorf b, float val);
  30. static RGBColor lerpColors(RGBColor a, RGBColor b, float val);
  31. std::tuple<RGBColor, RGBColor, float> getNeighbors(float x) const;
  32. };
  33. #endif // GRADIENT_H