colormap.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 Joe Graus <jgraus@gmu.edu>, Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_COLORMAP_H
  9. #define IGL_COLORMAP_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. namespace igl {
  13. // Colormap selector -- an interface to supported colormaps within igl
  14. //
  15. // Inputs:
  16. // m number of colors
  17. // cm colormap enum
  18. // Outputs:
  19. // J m by list of RGB colors between 0 and 1
  20. //
  21. // Wrapper for directly computing [r,g,b] values of the selected colormap for a given factor f between
  22. // 0 and 1
  23. //
  24. // Inputs:
  25. // f factor determining color value as if 0 was min and 1 was max
  26. // c colormap enum
  27. // Outputs:
  28. // r red value
  29. // g green value
  30. // b blue value
  31. enum ColorMapType
  32. {
  33. CM_INFERNO = 0,
  34. CM_JET = 1,
  35. CM_MAGMA = 2,
  36. CM_PARULA = 3,
  37. CM_PLASMA = 4,
  38. CM_VIRIDIS = 5
  39. };
  40. template <typename T>
  41. IGL_INLINE void colormap(const T f, T * rgb, ColorMapType cm);
  42. template <typename T>
  43. IGL_INLINE void colormap(const T f, T & r, T & g, T & b, ColorMapType cm);
  44. // Inputs:
  45. // Z #Z list of factors
  46. // normalize whether to normalize Z to be tightly between [0,1]
  47. // cm selected colormap palette to interpolate from
  48. // Outputs:
  49. // C #C by 3 list of rgb colors
  50. template <typename DerivedZ, typename DerivedC>
  51. IGL_INLINE void colormap(
  52. const Eigen::PlainObjectBase<DerivedZ> & Z,
  53. const bool normalize,
  54. Eigen::PlainObjectBase<DerivedC> & C,
  55. ColorMapType cm);
  56. // Inputs:
  57. // min_z value at black
  58. // max_z value at yellow
  59. template <typename DerivedZ, typename DerivedC>
  60. IGL_INLINE void colormap(
  61. const Eigen::PlainObjectBase<DerivedZ> & Z,
  62. const double min_Z,
  63. const double max_Z,
  64. Eigen::PlainObjectBase<DerivedC> & C,
  65. ColorMapType cm);
  66. };
  67. #ifndef IGL_STATIC_LIBRARY
  68. # include "colormap.cpp"
  69. #endif
  70. #endif