YCurve.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of HDRip.
  2. //
  3. // HDRip is free software: you can redistribute it and/or modify it
  4. // under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, either version 3 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // HDRip is distributed in the hope that it will be useful, but
  9. // WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with HDRip. If not, see <https://www.gnu.org/licenses/>.
  15. //
  16. // HDRip project
  17. // Author : Rémi Synave
  18. // Contact : remi.synave@univ-littoral.fr
  19. #include "pch.h"
  20. #include "YCurve.hpp"
  21. #include <iostream>
  22. #include <cassert>
  23. YCurve::YCurve(const float s, const float b, const float m, const float w, const float h, const float maxChannelY)
  24. {
  25. max = maxChannelY;
  26. Eigen::RowVectorXf knots(10);
  27. knots << 0.0f, 0.0f, 0.0f, 0.2f, 0.4f, 0.6f, 0.8f, 1.0f, 1.0f, 1.0f;
  28. Eigen::MatrixXf ctrls(7, 2);
  29. ctrls << 0, 0,
  30. 10, s,
  31. 30, b,
  32. 50, m,
  33. 70, w,
  34. 90, h,
  35. max, 100;
  36. ctrls.transposeInPlace();
  37. spline = Eigen::Spline<float, 2, 2>(knots, ctrls);
  38. }
  39. Eigen::MatrixXf* YCurve::evalpts(unsigned int nb)
  40. {
  41. Eigen::MatrixXf* pts = new Eigen::MatrixXf(nb, 2);
  42. float delta = 1.0f / (nb - 1.0f);
  43. unsigned int i;
  44. float step;
  45. for (i = 0, step = 0; i < nb; i++, step += delta)
  46. {
  47. //Peut mieux faire en récupérant spline(step) dans une variable pour éviter de relancer le calcul
  48. Eigen::Spline<float, 2, 2>::PointType estim = spline(i * delta);
  49. (*pts)(i, 0) = estim[0];
  50. (*pts)(i, 1) = estim[1];
  51. }
  52. return pts;
  53. }