morph.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* morph.cpp - bezier morph node
  2. * Copyright (C) 2017-2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <core/node_info/macros.h>
  18. #include <core/node/new_node.h>
  19. #include <geom_helpers/knots.h>
  20. #include <morphing/morphing.h>
  21. namespace rainynite::core::nodes {
  22. class BezierMorph :
  23. public NewNode<
  24. BezierMorph,
  25. Geom::BezierKnots,
  26. types::Only<Geom::BezierKnots>,
  27. types::Only<Geom::BezierKnots>,
  28. types::Only<double>
  29. >
  30. {
  31. DOC_STRING(
  32. ""
  33. )
  34. NODE_PROPERTIES("a", "b", "progress")
  35. DEFAULT_VALUES(Geom::BezierKnots{}, Geom::BezierKnots{}, 0.0)
  36. PROPERTY(a)
  37. PROPERTY(b)
  38. PROPERTY(progress)
  39. protected:
  40. Geom::BezierKnots get(shared_ptr<Context> ctx) const override {
  41. auto a = a_value<Geom::BezierKnots>(ctx);
  42. auto b = b_value<Geom::BezierKnots>(ctx);
  43. if (a != cached_a || b != cached_b) {
  44. morphing::prepare_average(a, b, avg_a, avg_b);
  45. cached_a = a;
  46. cached_b = b;
  47. }
  48. auto t = progress_value<double>(ctx);
  49. return morphing::simple_average(avg_a, avg_b, t);
  50. }
  51. private:
  52. mutable Geom::BezierKnots cached_a;
  53. mutable Geom::BezierKnots cached_b;
  54. mutable Geom::BezierKnots avg_a;
  55. mutable Geom::BezierKnots avg_b;
  56. };
  57. REGISTER_NODE(BezierMorph);
  58. } // namespace rainynite::core::nodes