fit_cubic_bezier.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 Alec Jacobson <[email protected]>
  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. #ifndef FIT_CUBIC_BEZIER_H
  9. #define FIT_CUBIC_BEZIER_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <vector>
  13. namespace igl
  14. {
  15. /// Fit a cubic bezier spline (G1 continuous) to an ordered list of input
  16. /// points in any dimension, according to "An algorithm for automatically
  17. /// fitting digitized curves" [Schneider 1990].
  18. ///
  19. /// @param[in] d #d by dim list of points along a curve to be fit with a cubic bezier
  20. /// spline (should probably be roughly uniformly spaced). If d(0)==d(end),
  21. /// then will treat as a closed curve.
  22. /// @param[in] error maximum squared distance allowed
  23. /// @param[out] cubics #cubics list of 4 by dim lists of cubic control points
  24. IGL_INLINE void fit_cubic_bezier(
  25. const Eigen::MatrixXd & d,
  26. const double error,
  27. std::vector<Eigen::MatrixXd> & cubics);
  28. /// Recursive helper function for fit_cubic_bezier
  29. ///
  30. /// \fileinfo
  31. ///
  32. /// @param[in] first index of first point in d of substring
  33. /// @param[in] last index of last point in d of substring
  34. /// @param[in] tHat1 tangent to use at beginning of spline
  35. /// @param[in] tHat2 tangent to use at end of spline
  36. /// @param[in] error see above
  37. /// @param[in] force_split whether to force a split (i.e., force a recursive call)
  38. /// @param[in] cubics running list of cubics so far
  39. /// @param[out] cubics running list of cubics so far (new cubics appended)
  40. IGL_INLINE void fit_cubic_bezier_substring(
  41. const Eigen::MatrixXd & d,
  42. const int first,
  43. const int last,
  44. const Eigen::RowVectorXd & tHat1,
  45. const Eigen::RowVectorXd & tHat2,
  46. const double error,
  47. const bool force_split,
  48. std::vector<Eigen::MatrixXd> & cubics);
  49. }
  50. #ifndef IGL_STATIC_LIBRARY
  51. #include "fit_cubic_bezier.cpp"
  52. #endif
  53. #endif