cubic_split.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "cubic_split.h"
  2. template <
  3. typename DerivedC,
  4. typename DerivedK>
  5. IGL_INLINE void igl::cubic_split(
  6. const Eigen::MatrixBase<DerivedC>& C,
  7. const typename DerivedC::Scalar & t,
  8. Eigen::PlainObjectBase<DerivedK>& C01,
  9. Eigen::PlainObjectBase<DerivedK>& C012,
  10. Eigen::PlainObjectBase<DerivedK>& C0123,
  11. Eigen::PlainObjectBase<DerivedK>& C123,
  12. Eigen::PlainObjectBase<DerivedK>& C23)
  13. {
  14. const auto C0 = C.row(0);
  15. const auto C1 = C.row(1);
  16. const auto C2 = C.row(2);
  17. const auto C3 = C.row(3);
  18. C01 = (C1 - C0) * t + C0;
  19. const auto C12 = ((C2 - C1) * t + C1).eval();
  20. C23 = (C3 - C2) * t + C2;
  21. C012 = (C12 - C01) * t + C01;
  22. C123 = (C23 - C12) * t + C12;
  23. C0123 = (C123 - C012) * t + C012;
  24. }
  25. template <
  26. typename DerivedC,
  27. typename DerivedK>
  28. IGL_INLINE void igl::cubic_split(
  29. const Eigen::MatrixBase<DerivedC>& C,
  30. const typename DerivedC::Scalar & t,
  31. Eigen::PlainObjectBase<DerivedK>& C1,
  32. Eigen::PlainObjectBase<DerivedK>& C2)
  33. {
  34. using Scalar = typename DerivedC::Scalar;
  35. typedef Eigen::Matrix<Scalar,1,DerivedC::ColsAtCompileTime> RowVectorS;
  36. RowVectorS C01,C012,C0123,C123,C23;
  37. igl::cubic_split(C,t,C01,C012,C0123,C123,C23);
  38. C1.resize(4,C.cols());
  39. C1 << C.row(0),
  40. C01,
  41. C012,
  42. C0123;
  43. C2.resize(4,C.cols());
  44. C2 << C0123,
  45. C123,
  46. C23,
  47. C.row(3);
  48. }
  49. #ifdef IGL_STATIC_LIBRARY
  50. // Explicit template instantiation
  51. // generated by autoexplicit.sh
  52. template void igl::cubic_split<Eigen::Matrix<double, 4, -1, 1, 4, -1>, Eigen::Matrix<double, 4, 2, 1, 4, 2>>(Eigen::MatrixBase<Eigen::Matrix<double, 4, -1, 1, 4, -1>> const&, Eigen::Matrix<double, 4, -1, 1, 4, -1>::Scalar const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&);
  53. // generated by autoexplicit.sh
  54. template void igl::cubic_split<Eigen::Matrix<double, 4, 2, 1, 4, 2>, Eigen::Matrix<double, 4, 2, 1, 4, 2>>(Eigen::MatrixBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>> const&, Eigen::Matrix<double, 4, 2, 1, 4, 2>::Scalar const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&);
  55. // generated by autoexplicit.sh
  56. template void igl::cubic_split<Eigen::Matrix<double, 4, 2, 0, 4, 2>, Eigen::Matrix<double, 4, 2, 1, 4, 2>>(Eigen::MatrixBase<Eigen::Matrix<double, 4, 2, 0, 4, 2>> const&, Eigen::Matrix<double, 4, 2, 0, 4, 2>::Scalar const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 1, 4, 2>>&);
  57. template void igl::cubic_split<Eigen::Matrix<double, 4, 2, 0, 4, 2>, Eigen::Matrix<double, 4, 2, 0, 4, 2>>(Eigen::MatrixBase<Eigen::Matrix<double, 4, 2, 0, 4, 2>> const&, Eigen::Matrix<double, 4, 2, 0, 4, 2>::Scalar const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 0, 4, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 4, 2, 0, 4, 2>>&);
  58. template void igl::cubic_split<Eigen::Matrix<double, 4, 2, 0, 4, 2>, Eigen::Matrix<double, 1, 2, 1, 1, 2>>(Eigen::MatrixBase<Eigen::Matrix<double, 4, 2, 0, 4, 2>> const&, Eigen::Matrix<double, 4, 2, 0, 4, 2>::Scalar const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2>>&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2>>&);
  59. #endif