jet.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #include "jet.h"
  9. #include "colormap.h"
  10. template <typename T>
  11. IGL_INLINE void igl::jet(const T x, T * rgb)
  12. {
  13. igl::colormap(igl::COLOR_MAP_TYPE_JET, x, rgb);
  14. }
  15. template <typename T>
  16. IGL_INLINE void igl::jet(const T x_in, T & r, T & g, T & b)
  17. {
  18. // Only important if the number of colors is small. In which case the rest is
  19. // still wrong anyway
  20. // x = linspace(0,1,jj)' * (1-1/jj) + 1/jj;
  21. //
  22. const double rone = 0.8;
  23. const double gone = 1.0;
  24. const double bone = 1.0;
  25. T x = x_in;
  26. x = (x_in<0 ? 0 : (x>1 ? 1 : x));
  27. if (x<1. / 8.)
  28. {
  29. r = 0;
  30. g = 0;
  31. b = bone*(0.5 + (x) / (1. / 8.)*0.5);
  32. } else if (x<3. / 8.)
  33. {
  34. r = 0;
  35. g = gone*(x - 1. / 8.) / (3. / 8. - 1. / 8.);
  36. b = bone;
  37. } else if (x<5. / 8.)
  38. {
  39. r = rone*(x - 3. / 8.) / (5. / 8. - 3. / 8.);
  40. g = gone;
  41. b = (bone - (x - 3. / 8.) / (5. / 8. - 3. / 8.));
  42. } else if (x<7. / 8.)
  43. {
  44. r = rone;
  45. g = (gone - (x - 5. / 8.) / (7. / 8. - 5. / 8.));
  46. b = 0;
  47. } else
  48. {
  49. r = (rone - (x - 7. / 8.) / (1. - 7. / 8.)*0.5);
  50. g = 0;
  51. b = 0;
  52. }
  53. }
  54. template <typename DerivedZ, typename DerivedC>
  55. IGL_INLINE void igl::jet(
  56. const Eigen::MatrixBase<DerivedZ> & Z,
  57. const bool normalize,
  58. Eigen::PlainObjectBase<DerivedC> & C)
  59. {
  60. igl::colormap(igl::COLOR_MAP_TYPE_JET,Z, normalize, C);
  61. }
  62. template <typename DerivedZ, typename DerivedC>
  63. IGL_INLINE void igl::jet(
  64. const Eigen::MatrixBase<DerivedZ> & Z,
  65. const double min_z,
  66. const double max_z,
  67. Eigen::PlainObjectBase<DerivedC> & C)
  68. {
  69. igl::colormap(igl::COLOR_MAP_TYPE_JET, Z, min_z, max_z, C);
  70. }
  71. #ifdef IGL_STATIC_LIBRARY
  72. // Explicit template instantiation
  73. // generated by autoexplicit.sh
  74. template void igl::jet<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  75. template void igl::jet<double>(double, double*);
  76. template void igl::jet<double>(double, double&, double&, double&);
  77. template void igl::jet<float>(float, float*);
  78. template void igl::jet<Eigen::Array<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Array<double, -1, 1, 0, -1, 1> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  79. template void igl::jet<Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  80. template void igl::jet<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  81. template void igl::jet<float>(float, float&, float&, float&);
  82. template void igl::jet<Eigen::Matrix<float, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 1, 0, -1, 1> > const&, double, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  83. template void igl::jet<Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, double, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  84. template void igl::jet<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, double, double, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  85. template void igl::jet<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, bool, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&);
  86. #endif