jet.cpp 2.4 KB

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