From dc616bc8576ccb263ad2e09e9214e762d3b26007 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 28 Jun 2022 17:44:25 -0400 Subject: [PATCH 1/4] fit cubic bezier --- src/fit_cubic_bezier.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/fit_cubic_bezier.cpp diff --git a/src/fit_cubic_bezier.cpp b/src/fit_cubic_bezier.cpp new file mode 100644 index 00000000..c43550d2 --- /dev/null +++ b/src/fit_cubic_bezier.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include + +const char *ds_fit_cubic_bezier = R"igl_Qu8mg5v7( +Fit a cubic bezier spline (G1 continuous) to an ordered list of input +points in any dimension, according to "An algorithm for automatically +fitting digitized curves" [Schneider 1990]. + +Parameters +---------- + d #d by dim list of points along a curve to be fit with a cubic bezier + spline (should probably be roughly uniformly spaced). If d(0)==d(end), + then will treat as a closed curve. + error maximum squared distance allowed +Returns +------- + cubics #cubics list of 4 by dim lists of cubic control points + +)igl_Qu8mg5v7"; + +npe_function(fit_cubic_bezier) +npe_doc(ds_fit_cubic_bezier) + +npe_arg(d, dense_float, dense_double) +npe_arg(error, double) + +npe_begin_code() + // igl::fit_cubic_bezier is hard-coded to double, so for now copy. + Eigen::MatrixXd d_cpy = d.template cast(); + std::vector c_cpy; + igl::fit_cubic_bezier(d_cpy,error,c_cpy); + std::vector> c(c_cpy.size()); + std::transform (c_cpy.begin(), c_cpy.end(), c.begin(), + [](const Eigen::MatrixXd & ci){ return ci.cast();}); + return pybind11::detail::type_caster::cast(c, pybind11::return_value_policy::move, pybind11::none()); +npe_end_code() + From 333e4ceb1f71078455f76d07e5731bee03a9b66b Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Tue, 28 Jun 2022 18:46:40 -0400 Subject: [PATCH 2/4] output works; numpyeigen barfs to cerr --- src/fit_cubic_bezier.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/fit_cubic_bezier.cpp b/src/fit_cubic_bezier.cpp index c43550d2..780b0586 100644 --- a/src/fit_cubic_bezier.cpp +++ b/src/fit_cubic_bezier.cpp @@ -2,6 +2,9 @@ #include #include #include +#include +#include + const char *ds_fit_cubic_bezier = R"igl_Qu8mg5v7( Fit a cubic bezier spline (G1 continuous) to an ordered list of input @@ -34,6 +37,9 @@ npe_begin_code() std::vector> c(c_cpy.size()); std::transform (c_cpy.begin(), c_cpy.end(), c.begin(), [](const Eigen::MatrixXd & ci){ return ci.cast();}); + // numpyeigen's pybind11 fork `numpy_hacks_stable` is printing "Encapsulate move!" + // https://github.com/fwilliams/numpyeigen/issues/58 return pybind11::detail::type_caster::cast(c, pybind11::return_value_policy::move, pybind11::none()); + npe_end_code() From 88cc7db786b90ed7de51e438d3f6a061a8cea2f1 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Sun, 5 Feb 2023 23:45:36 -0500 Subject: [PATCH 3/4] Update fit_cubic_bezier.cpp --- src/fit_cubic_bezier.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/fit_cubic_bezier.cpp b/src/fit_cubic_bezier.cpp index 780b0586..51797e96 100644 --- a/src/fit_cubic_bezier.cpp +++ b/src/fit_cubic_bezier.cpp @@ -1,3 +1,5 @@ +// prevent termios.h from being included and defining B0 (only happening on macos with cp36) +#define _SYS_TERMIOS_H_ #include #include #include From 05d7751c94440b456518d53dc94c3c46aefd7283 Mon Sep 17 00:00:00 2001 From: Alec Jacobson Date: Mon, 6 Feb 2023 09:17:48 -0500 Subject: [PATCH 4/4] try undef --- src/fit_cubic_bezier.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/fit_cubic_bezier.cpp b/src/fit_cubic_bezier.cpp index 51797e96..c68f7c99 100644 --- a/src/fit_cubic_bezier.cpp +++ b/src/fit_cubic_bezier.cpp @@ -1,8 +1,11 @@ -// prevent termios.h from being included and defining B0 (only happening on macos with cp36) -#define _SYS_TERMIOS_H_ #include #include #include +// On macos with cp36, termios.h is getting included for some reason and it +// defines B0 +#ifdef B0 +# undef B0 +#endif #include #include #include