13 #ifndef eli_geom_surface_bezier_hpp
14 #define eli_geom_surface_bezier_hpp
20 #include "eli/code_eli.hpp"
37 template<
typename data__,
unsigned short dim__,
typename tol__=eli::util::tolerance<data__> >
52 typedef Eigen::Map<Eigen::Matrix<data_type, Eigen::Dynamic, dim__>,
55 typedef Eigen::Map<Eigen::Matrix<data_type, Eigen::Dynamic, dim__>,
64 u_control_point_matrix_container
B_u;
65 v_control_point_matrix_container
B_v;
73 bezier(
const index_type &u_dim,
const index_type &v_dim) : point_data(dim__*(u_dim+1)*(v_dim+1))
104 if (B_u.size()!=bs.
B_u.size())
107 if (B_v.size()!=bs.
B_v.size())
118 if (B_u.size()!=bs.
B_u.size())
121 if (B_v.size()!=bs.
B_v.size())
125 for (j=0; j<=degv; ++j)
127 for (i=0; i<=degu; ++i)
146 index_type
degree_u()
const {
return static_cast<index_type
>(B_v.size())-1;}
147 index_type
degree_v()
const {
return static_cast<index_type
>(B_u.size())-1;}
161 data_type
get_umin()
const {
return static_cast<data_type
>(0);}
162 data_type
get_vmin()
const {
return static_cast<data_type
>(0);}
163 data_type
get_umax()
const {
return static_cast<data_type
>(1);}
164 data_type
get_vmax()
const {
return static_cast<data_type
>(1);}
166 void resize(
const index_type &u_dim,
const index_type &v_dim)
169 point_data.resize(dim__*(u_dim+1)*(v_dim+1));
181 return B_u[0].row(0);
185 assert(B_u[j].row(i)==B_v[i].row(j));
187 return B_u[j].row(i);
195 for (i=0; i<=degu; ++i)
197 for (j=0; j<=degv; ++j)
199 bb.
add(B_u[j].row(i));
204 void rotate(
const rotation_matrix_type &rmat)
207 for (j=0; j<=degv; ++j)
209 B_u[j]*=rmat.transpose();
213 void rotate(
const rotation_matrix_type &rmat,
const point_type &rorig)
223 for (j=0; j<=degv; ++j)
225 for (i=0; i<=degu; ++i)
227 B_u[j].row(i)+=trans;
235 for (j=0; j<=degv; ++j)
237 for (i=0; i<=degu; ++i)
279 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
280 typedef std::vector<control_col_type, Eigen::aligned_allocator<control_col_type> > control_col_collection_type;
283 control_col_collection_type current_col(n+1, control_col_type(m+1, dim__));
287 current_col[i]=B_v[i];
292 B_v[i]=current_col[n-i];
298 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
299 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
302 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
306 current_row[i]=B_u[i];
311 B_u[i]=current_row[m-i];
317 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
318 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
321 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
325 current_row[i]=B_u[i];
348 assert((u>=0) && (u<=1));
369 assert((v>=0) && (v<=1));
382 point_type
f(
const data_type &u,
const data_type &v)
const
385 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp;
393 assert((u>=0) && (u<=1));
394 assert((v>=0) && (v<=1));
398 temp_cp.resize(m+1, dim__);
409 temp_cp.resize(n+1, dim__);
422 point_type
f_u(
const data_type &u,
const data_type &v)
const
432 assert((u>=0) && (u<=1));
433 assert((v>=0) && (v<=1));
441 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_up(n+1-1, dim__);
445 temp_cp.resize(m+1, dim__);
458 temp_cp.resize(n+1, dim__);
473 point_type
f_v(
const data_type &u,
const data_type &v)
const
483 assert((u>=0) && (u<=1));
484 assert((v>=0) && (v<=1));
492 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_vp(m+1-1, dim__);
496 temp_cp.resize(m+1, dim__);
509 temp_cp.resize(n+1, dim__);
524 point_type
f_uu(
const data_type &u,
const data_type &v)
const
534 assert((u>=0) && (u<=1));
535 assert((v>=0) && (v<=1));
543 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_upp(n+1-2, dim__);
547 temp_cp.resize(m+1, dim__);
560 temp_cp.resize(n+1, dim__);
576 point_type
f_uv(
const data_type &u,
const data_type &v)
const
586 assert((u>=0) && (u<=1));
587 assert((v>=0) && (v<=1));
595 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_up(n+1-1, dim__), B_vp(m+1-1, dim__);
599 temp_cp.resize(m+1, dim__);
614 temp_cp.resize(n+1, dim__);
631 point_type
f_vv(
const data_type &u,
const data_type &v)
const
641 assert((u>=0) && (u<=1));
642 assert((v>=0) && (v<=1));
650 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_vpp(m+1-2, dim__);
654 temp_cp.resize(m+1, dim__);
667 temp_cp.resize(n+1, dim__);
682 point_type
f_uuu(
const data_type &u,
const data_type &v)
const
693 assert((u>=0) && (u<=1));
694 assert((v>=0) && (v<=1));
702 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_uppp(n+1-3, dim__);
706 temp_cp.resize(m+1, dim__);
719 temp_cp.resize(n+1, dim__);
735 point_type
f_uuv(
const data_type &u,
const data_type &v)
const
745 assert((u>=0) && (u<=1));
746 assert((v>=0) && (v<=1));
754 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_upp(n+1-2, dim__), B_vp(m+1-1, dim__);
758 temp_cp.resize(m+1, dim__);
773 temp_cp.resize(n+1, dim__);
790 point_type
f_uvv(
const data_type &u,
const data_type &v)
const
800 assert((u>=0) && (u<=1));
801 assert((v>=0) && (v<=1));
809 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_up(n+1-1, dim__), B_vpp(m+1-2, dim__);
813 temp_cp.resize(m+1, dim__);
828 temp_cp.resize(n+1, dim__);
845 point_type
f_vvv(
const data_type &u,
const data_type &v)
const
855 assert((u>=0) && (u<=1));
856 assert((v>=0) && (v<=1));
864 Eigen::Matrix<data_type, Eigen::Dynamic, dim__> temp_cp, B_vppp(m+1-3, dim__);
868 temp_cp.resize(m+1, dim__);
881 temp_cp.resize(n+1, dim__);
896 point_type
normal(
const data_type &u,
const data_type &v)
const
898 point_type n=
f_u(u, v).cross(
f_v(u, v));
899 data_type nlen(n.norm());
907 if (tol.approximately_equal(nlen, 0))
909 point_type S_u, S_v, S_uu, S_uv, S_vv, N_u, N_v;
910 data_type du(1), dv(1);
918 N_u=S_uu.cross(S_v)+S_u.cross(S_uv);
919 N_v=S_uv.cross(S_v)+S_u.cross(S_vv);
924 if (tol.approximately_equal(nlen, 0))
926 point_type S_uuu, S_uuv, S_uvv, S_vvv, N_uu, N_uv, N_vv;
932 N_uu=S_uuu.cross(S_v)+2*S_uu.cross(S_uv)+S_u.cross(S_uuv);
933 N_uv=S_uuv.cross(S_v)+S_uu.cross(S_vv)+S_uv.cross(S_uv)+S_u.cross(S_uvv);
934 N_vv=S_uvv.cross(S_v)+2*S_uv.cross(S_vv)+S_u.cross(S_vvv);
935 n=0.5*(N_uu*du*du+2*N_uv*du*dv+N_vv*dv*dv);
939 if (tol.approximately_equal(nlen, 0))
953 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
954 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
957 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
961 current_row[i]=B_u[i];
967 control_row_type tmp_cp(n+2, dim__);
977 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
978 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
981 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
986 current_row[i]=B_u[i];
993 control_row_type tmp_cp(target_degree+1, dim__);
1003 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
1004 typedef std::vector<control_col_type, Eigen::aligned_allocator<control_col_type> > control_col_collection_type;
1007 control_col_collection_type current_col(n+1, control_col_type(m+1, dim__));
1010 for (i=0; i<=n; ++i)
1012 current_col[i]=B_v[i];
1019 control_col_type tmp_cp(m+2, dim__);
1020 for (i=0; i<=n; ++i)
1029 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
1030 typedef std::vector<control_col_type, Eigen::aligned_allocator<control_col_type> > control_col_collection_type;
1033 control_col_collection_type current_col(n+1, control_col_type(m+1, dim__));
1036 for (i=0; i<=n; ++i)
1038 current_col[i]=B_v[i];
1042 resize(n, target_degree);
1045 control_col_type tmp_cp(target_degree+1, dim__);
1046 for (i=0; i<=n; ++i)
1055 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
1056 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
1059 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
1063 switch(u_continuity_degree)
1086 for (i=0; i<=m; ++i)
1087 current_row[i]=B_u[i];
1093 control_row_type tmp_cp(n, dim__);
1094 for (i=0; i<=m; ++i)
1105 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
1106 typedef std::vector<control_col_type, Eigen::aligned_allocator<control_col_type> > control_col_collection_type;
1109 control_col_collection_type current_col(n+1, control_col_type(m+1, dim__));
1113 switch(v_continuity_degree)
1136 for (i=0; i<=n; ++i)
1137 current_col[i]=B_v[i];
1143 control_col_type tmp_cp(m, dim__);
1144 for (i=0; i<=n; ++i)
1155 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
1156 typedef std::vector<control_row_type, Eigen::aligned_allocator<control_row_type> > control_row_collection_type;
1159 control_row_collection_type current_row(m+1, control_row_type(n+1, dim__));
1162 for (i=0; i<=m; ++i)
1164 current_row[i]=B_u[i];
1171 control_row_type tmp_cp(4, dim__);
1172 for (i=0; i<=m; ++i)
1181 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
1182 typedef std::vector<control_col_type, Eigen::aligned_allocator<control_col_type> > control_col_collection_type;
1185 control_col_collection_type current_col(n+1, control_col_type(m+1, dim__));
1188 for (i=0; i<=n; ++i)
1190 current_col[i]=B_v[i];
1197 control_col_type tmp_cp(4, dim__);
1198 for (i=0; i<=n; ++i)
1207 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_row_type;
1210 control_row_type cp_lo(n+1, dim__), cp_hi(n+1, dim__);
1213 assert((u0>=0) && (u0<=1));
1220 for (j=0; j<=m; ++j)
1223 for (i=0; i<=n; ++i)
1233 typedef Eigen::Matrix<data_type, Eigen::Dynamic, dim__> control_col_type;
1236 control_col_type cp_lo(m+1, dim__), cp_hi(m+1, dim__);
1239 assert((v0>=0) && (v0<=1));
1246 for (i=0; i<=n; ++i)
1249 for (j=0; j<=m; ++j)
1262 surf_type bsa(*
this);
1266 index_type n(bsa.degree_u()), m(bsa.degree_v());
1267 if(bsb.degree_u() > n)
1272 if(bsb.degree_v() > m)
1278 bsa.promote_u_to(n);
1279 bsa.promote_v_to(m);
1281 bsb.promote_u_to(n);
1282 bsb.promote_v_to(m);
1286 data_type d, maxd(0);
1287 for (i=0; i<=n; ++i)
1289 for (j=0; j<=m; ++j)
1291 d = (bsa.get_control_point(i, j) - bsb.get_control_point(i, j)).norm();
1307 for (index_type j=0; j<=m; ++j)
1309 #ifdef ELI_NO_VECTOR_DATA
1310 new (&(B_u.at(0))+j)
control_point_matrix_type(&(point_data.at(0))+j*(n+1)*dim__, n+1, dim__, Eigen::Stride<1, dim__>());
1317 for (index_type i=0; i<=n; ++i)
1319 #ifdef ELI_NO_VECTOR_DATA
std::vector< data_type > control_point_container
Definition: bezier.hpp:58
void set_control_point(const point_type &cp, const index_type &i, const index_type &j)
Definition: bezier.hpp:265
point_type f_uuv(const data_type &u, const data_type &v) const
Definition: bezier.hpp:735
Eigen::Map< Eigen::Matrix< data_type, Eigen::Dynamic, dim__ >, Eigen::Unaligned, Eigen::Stride< 1, dim__ > > control_point_matrix_type
Definition: bezier.hpp:54
point_type f_uuu(const data_type &u, const data_type &v) const
Definition: bezier.hpp:682
bool operator==(const bezier< data_type, dim__, tol__ > &bs) const
Definition: bezier.hpp:96
Definition: continuity.hpp:26
point_type f_vvv(const data_type &u, const data_type &v) const
Definition: bezier.hpp:845
Eigen::Map< Eigen::Matrix< data_type, Eigen::Dynamic, dim__ >, Eigen::Unaligned, Eigen::Stride< 1, Eigen::Dynamic > > v_dir_control_point_matrix_type
Definition: bezier.hpp:57
void bezier_split_control_points(Eigen::MatrixBase< Derived1 > &cp_lo, Eigen::MatrixBase< Derived1 > &cp_hi, const Eigen::MatrixBase< Derived2 > &cp_in, const typename Derived2::Scalar &t)
Definition: bezier.hpp:291
void clear()
Definition: bounding_box.hpp:106
bezier< double, 2 > bezier2d
Definition: bezier.hpp:1329
Definition: continuity.hpp:28
data_type get_vmax() const
Definition: bezier.hpp:164
Definition: bounding_box.hpp:27
void promote_v_to(index_type target_degree)
Definition: bezier.hpp:1027
point_type f_uu(const data_type &u, const data_type &v) const
Definition: bezier.hpp:524
bool closed_u() const
Definition: bezier.hpp:245
void bezier_control_points_to_cubic(Eigen::MatrixBase< Derived1 > &cp_out, const Eigen::MatrixBase< Derived2 > &cp_in)
Definition: bezier.hpp:142
bool operator!=(const bezier< data_type, dim__, tol__ > &bs) const
Definition: bezier.hpp:139
void bezier_ppp_control_point(Eigen::MatrixBase< Derived1 > &cp_ppp, const Eigen::MatrixBase< Derived2 > &cp)
Definition: bezier.hpp:78
std::vector< control_point_matrix_type > u_control_point_matrix_container
Definition: bezier.hpp:59
data_type eqp_distance_bound(const bezier< data_type, dim__, tol__ > &bs) const
Definition: bezier.hpp:1257
static dimension_type dimension()
Definition: bezier.hpp:144
point_type normal(const data_type &u, const data_type &v) const
Definition: bezier.hpp:896
Definition: bezier.hpp:38
bool demote_u(const geom::general::continuity &u_continuity_degree=geom::general::C0)
Definition: bezier.hpp:1053
void to_cubic_u()
Definition: bezier.hpp:1153
bezier< double, 3 > bezier3d
Definition: bezier.hpp:1330
void get_bounding_box(bounding_box_type &bb) const
Definition: bezier.hpp:190
~bezier()
Definition: bezier.hpp:83
bezier(const index_type &u_dim, const index_type &v_dim)
Definition: bezier.hpp:73
void resize(const index_type &u_dim, const index_type &v_dim)
Definition: bezier.hpp:166
control_point_container point_data
Definition: bezier.hpp:63
Eigen::Matrix< data_type, dim__, dim__ > rotation_matrix_type
Definition: bezier.hpp:47
point_type f_uvv(const data_type &u, const data_type &v) const
Definition: bezier.hpp:790
void scale(const data_type &s)
Definition: bezier.hpp:232
void de_casteljau(Eigen::MatrixBase< Derived1 > &p, const Eigen::MatrixBase< Derived2 > &cp, const typename Derived2::Scalar &t)
Definition: bezier.hpp:27
bezier< long double, 3 > bezier3ld
Definition: bezier.hpp:1332
index_type degree_u() const
Definition: bezier.hpp:146
bool closed_v() const
Definition: bezier.hpp:255
void get_uconst_curve(curve_type &bc, const data_type &u) const
Definition: bezier.hpp:340
bezier(const bezier< data_type, dim__, tol__ > &bs)
Definition: bezier.hpp:78
void reverse_v()
Definition: bezier.hpp:296
Definition: continuity.hpp:27
point_type f_u(const data_type &u, const data_type &v) const
Definition: bezier.hpp:422
bool open_v() const
Definition: bezier.hpp:254
bezier()
Definition: bezier.hpp:68
eli::geom::curve::bezier< data_type, dim__, tolerance_type > curve_type
Definition: bezier.hpp:49
data_type get_umax() const
Definition: bezier.hpp:163
void bezier_promote_control_points(Eigen::MatrixBase< Derived1 > &cp_out, const Eigen::MatrixBase< Derived2 > &cp_in)
Definition: bezier.hpp:93
point_type get_control_point(const index_type &i, const index_type &j) const
Definition: bezier.hpp:175
void rotate(const rotation_matrix_type &rmat)
Definition: bezier.hpp:204
bool add(const point_type &p)
Definition: bounding_box.hpp:113
data_type get_vmin() const
Definition: bezier.hpp:162
unsigned short dimension_type
Definition: bezier.hpp:41
Eigen::Matrix< data_type, 1, dim__ > point_type
Definition: bezier.hpp:43
bool abouteq(const bezier< data_type, dim__, tol__ > &bs, const data_type &ttol2) const
Definition: bezier.hpp:113
eli::geom::general::bounding_box< data_type, dim__, tolerance_type > bounding_box_type
Definition: bezier.hpp:48
void rotate(const rotation_matrix_type &rmat, const point_type &rorig)
Definition: bezier.hpp:213
bezier & operator=(const bezier< data_type, dim__, tol__ > &bs)
Definition: bezier.hpp:85
data__ data_type
Definition: bezier.hpp:42
void bezier_pp_control_point(Eigen::MatrixBase< Derived1 > &cp_pp, const Eigen::MatrixBase< Derived2 > &cp)
Definition: bezier.hpp:63
point_type f(const data_type &u, const data_type &v) const
Definition: bezier.hpp:382
bool open_u() const
Definition: bezier.hpp:244
void swap_uv()
Definition: bezier.hpp:315
tol__ tolerance_type
Definition: bezier.hpp:46
void reverse_u()
Definition: bezier.hpp:277
void split_v(bezier< data_type, dim__, tol__ > &bs_lo, bezier< data_type, dim__, tol__ > &bs_hi, const data_type &v0) const
Definition: bezier.hpp:1231
void bezier_demote_control_points(Eigen::MatrixBase< Derived1 > &cp_out, const Eigen::MatrixBase< Derived2 > &cp_in, int ncon)
Definition: bezier.hpp:179
control_point_type::Index index_type
Definition: bezier.hpp:45
void get_vconst_curve(curve_type &bc, const data_type &v) const
Definition: bezier.hpp:361
void resize(const index_type &t_dim)
Definition: bezier.hpp:186
bezier< long double, 2 > bezier2ld
Definition: bezier.hpp:1331
void set_control_point(const control_point_type &cp, const index_type &i)
Definition: bezier.hpp:201
void bezier_p_control_point(Eigen::MatrixBase< Derived1 > &cp_p, const Eigen::MatrixBase< Derived2 > &cp)
Definition: bezier.hpp:48
void to_cubic_v()
Definition: bezier.hpp:1179
void split_u(bezier< data_type, dim__, tol__ > &bs_lo, bezier< data_type, dim__, tol__ > &bs_hi, const data_type &u0) const
Definition: bezier.hpp:1205
void promote_u_to(index_type target_degree)
Definition: bezier.hpp:975
bool demote_v(const geom::general::continuity &v_continuity_degree=geom::general::C0)
Definition: bezier.hpp:1103
void set_Bs(index_type n, index_type m)
Definition: bezier.hpp:1303
continuity
Definition: continuity.hpp:24
bool equivalent_curves(const bezier< data__, dim__, tol__ > &c0, const bezier< data__, dim__, tol__ > &c1)
Definition: equivalent_curves.hpp:27
std::vector< v_dir_control_point_matrix_type > v_control_point_matrix_container
Definition: bezier.hpp:60
void promote_u()
Definition: bezier.hpp:951
void get_parameter_max(data_type &umax, data_type &vmax) const
Definition: bezier.hpp:155
Derived1__::Scalar distance2(const Eigen::MatrixBase< Derived1__ > &p1, const Eigen::MatrixBase< Derived2__ > &p2)
Definition: distance.hpp:27
void translate(const point_type &trans)
Definition: bezier.hpp:220
index_type degree_v() const
Definition: bezier.hpp:147
void bezier_promote_control_points_to(Eigen::MatrixBase< Derived1 > &cp_out, const Eigen::MatrixBase< Derived2 > &cp_in)
Definition: bezier.hpp:108
point_type f_vv(const data_type &u, const data_type &v) const
Definition: bezier.hpp:631
Definition: bezier.hpp:109
void get_parameter_min(data_type &umin, data_type &vmin) const
Definition: bezier.hpp:149
point_type f_v(const data_type &u, const data_type &v) const
Definition: bezier.hpp:473
v_control_point_matrix_container B_v
Definition: bezier.hpp:65
point_type control_point_type
Definition: bezier.hpp:44
Definition: continuity.hpp:29
u_control_point_matrix_container B_u
Definition: bezier.hpp:64
void promote_v()
Definition: bezier.hpp:1001
bezier< float, 3 > bezier3f
Definition: bezier.hpp:1328
data_type get_umin() const
Definition: bezier.hpp:161
point_type f_uv(const data_type &u, const data_type &v) const
Definition: bezier.hpp:576