jet.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "jet.h"
  2. #include "colon.h"
  3. #ifndef IGL_NO_EIGEN
  4. //void igl::jet(const int m, Eigen::MatrixXd & J)
  5. //{
  6. // using namespace Eigen;
  7. // using namespace igl;
  8. // // Applications/MATLAB_R2012b.app/toolbox/matlab/graph3d/jet.m
  9. // const int n = ceil(m/4);
  10. // // resize output
  11. // J.resize(m,3);
  12. // // u = [(1:1:n)/n ones(1,n-1) (n:-1:1)/n]';
  13. // VectorXd u(n*3-1);
  14. // u.block(0,0,n-1,1) = colon(1,n)/double(n);
  15. // VectorXd g;
  16. // colon(0,n*3-1-1,g);
  17. // g.array() = g.array() + ceil(n/2) - int((m%4)==1);
  18. // VectorXd r = (g.array() + n).eval().matrix();
  19. // VectorXd b = (g.array() - n).eval().matrix();
  20. // int ri = 0;
  21. // int gi = 0;
  22. // int sb = 0;
  23. // // count number of indices in b
  24. // for(int j = 0;j<g.rows();j++)
  25. // {
  26. // sb += b(j)<m;
  27. // }
  28. //
  29. // for(int j = 0;j<g.rows();j++)
  30. // {
  31. // if(r(j)<m)
  32. // {
  33. // J(r(j),0) = u(ri++);
  34. // }
  35. // if(g(j)<m)
  36. // {
  37. // J(g(j),1) = u(gi++);
  38. // }
  39. // if(b(j)<m)
  40. // {
  41. // //J(b(j),2) = u(m- --sb);
  42. // }
  43. // }
  44. //}
  45. #endif
  46. template <typename T>
  47. void igl::jet(const T x, T * rgb)
  48. {
  49. igl::jet(x,rgb[0],rgb[1],rgb[2]);
  50. }
  51. template <typename T>
  52. void igl::jet(const T x, T & r, T & g, T & b)
  53. {
  54. // Only important if the number of colors is small. In which case the rest is
  55. // still wrong anyway
  56. // x = linspace(0,1,jj)' * (1-1/jj) + 1/jj;
  57. //
  58. const double rone = 0.8;
  59. const double gone = 1.0;
  60. const double bone = 1.0;
  61. if(x<1./8.)
  62. {
  63. r = 0;
  64. g = 0;
  65. b = bone*(0.5+(x)/(1./8.)*0.5);
  66. }else if(x<3./8.)
  67. {
  68. r = 0;
  69. g = gone*(x-1./8.)/(3./8.-1./8.);
  70. b = bone;
  71. }else if(x<5./8.)
  72. {
  73. r = rone*(x-3./8.)/(5./8.-3./8.);
  74. g = gone;
  75. b = (bone-(x-3./8.)/(5./8.-3./8.));
  76. }else if(x<7./8.)
  77. {
  78. r = rone;
  79. g = (gone-(x-5./8.)/(7./8.-5./8.));
  80. b = 0;
  81. }else
  82. {
  83. r = (bone-(x-7./8.)/(1.-7./8.)*0.5);
  84. g = 0;
  85. b = 0;
  86. }
  87. }
  88. #ifndef IGL_NO_HEADER
  89. template void igl::jet<double>(double, double*);
  90. template void igl::jet<double>(double, double&, double&, double&);
  91. #endif