13 #ifndef eli_geom_test_octave_helpers_hpp
14 #define eli_geom_test_octave_helpers_hpp
29 auto randchar = []() ->
char
31 const char charset[] =
33 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34 "abcdefghijklmnopqrstuvwxyz";
35 const size_t max_index = (
sizeof(charset) - 1);
36 return charset[ rand() % max_index ];
38 std::string str(length,0);
39 std::generate_n( str.begin(),
length, randchar );
45 std::cout <<
"figure(" << figno <<
");" << std::endl;
46 std::cout <<
"clf(" << figno <<
", 'reset');" << std::endl;
47 std::cout <<
"hold on;" << std::endl;
48 std::cout <<
"grid on;" << std::endl;
53 std::cout <<
"figure(" << figno <<
");" << std::endl;
54 std::cout <<
"hold off;" << std::endl;
55 std::cout <<
"rotate3d on;" << std::endl;
56 std::cout <<
"xlabel('x');" << std::endl;
57 std::cout <<
"ylabel('y');" << std::endl;
58 std::cout <<
"zlabel('z');" << std::endl;
61 template<
typename data__>
63 const std::string &name=
"",
bool show_control_points=
true)
66 typedef typename piecewise_curve_type::curve_type curve_type;
67 typedef typename piecewise_curve_type::data_type data_type;
68 typedef typename piecewise_curve_type::index_type index_type;
70 std::string nm, cpxbuf, cpybuf, cpzbuf, cxbuf, cybuf, czbuf;
88 if (show_control_points)
90 cpxbuf=nm+
"_curv_cp_x=[";
91 cpybuf=nm+
"_curv_cp_y=[";
92 cpzbuf=nm+
"_curv_cp_z=[";
93 for (pp=0; pp<ns; ++pp)
99 for (i=0; i<=bez_deg; ++i)
101 cpxbuf+=std::to_string(bez.get_control_point(i).x());
102 cpybuf+=std::to_string(bez.get_control_point(i).y());
103 cpzbuf+=std::to_string(bez.get_control_point(i).z());
104 if ((pp<(ns-1)) || ((pp==(ns-1)) && (i<bez_deg)))
119 std::vector<data__> t(nt);
122 t[i]=tmin+(tmax-tmin)*static_cast<data__>(i)/(nt-1);
126 cxbuf=nm+
"_curv_x=[";
127 cybuf=nm+
"_curv_y=[";
128 czbuf=nm+
"_curv_z=[";
131 cxbuf+=std::to_string(pc.
f(t[i]).x());
132 cybuf+=std::to_string(pc.
f(t[i]).y());
133 czbuf+=std::to_string(pc.
f(t[i]).z());
145 std::cout <<
"% curve: " << nm << std::endl;
146 std::cout <<
"figure(" << figno <<
");" << std::endl;
147 std::cout << cxbuf << std::endl;
148 std::cout << cybuf << std::endl;
149 std::cout << czbuf << std::endl;
150 if (show_control_points)
152 std::cout << cpxbuf << std::endl;
153 std::cout << cpybuf << std::endl;
154 std::cout << cpzbuf << std::endl;
156 std::cout <<
"setenv('GNUTERM', 'x11');" << std::endl;
157 std::cout <<
"plot3(" << nm <<
"_curv_x, "
159 << nm <<
"_curv_z, '-g');" << std::endl;
160 if (show_control_points)
162 std::cout <<
"plot3(" << nm <<
"_curv_cp_x', "
163 << nm <<
"_curv_cp_y', "
164 << nm <<
"_curv_cp_z', '-o', 'Color', [0 0.5 0], 'MarkerFaceColor', [0 0.5 0]);" << std::endl;
168 template<
typename data__>
171 const std::string &name=
"")
174 typedef typename piecewise_curve_type::data_type data_type;
175 typedef typename piecewise_curve_type::index_type index_type;
176 typedef typename piecewise_curve_type::tolerance_type tolerance_type;
178 std::string nm(
random_string(5)), vecxbuf, vecybuf, veczbuf, cxbuf, cybuf, czbuf;
180 index_type i, pp, ns;
181 data_type tmin, tmax;
190 if (!tol.approximately_equal(vec.
get_t0(), tmin))
194 if (!tol.approximately_equal(vec.
get_tmax(), tmax))
211 std::vector<data__> t(nt);
214 t[i]=tmin+(tmax-tmin)*static_cast<data__>(i)/(nt-1);
221 vecxbuf=nm+
"_vec_x=[";
222 vecybuf=nm+
"_vec_y=[";
223 veczbuf=nm+
"_vec_z=[";
226 cxbuf+=std::to_string(pc.
f(t[i]).x());
227 cybuf+=std::to_string(pc.
f(t[i]).y());
228 czbuf+=std::to_string(pc.
f(t[i]).z());
229 vecxbuf+=std::to_string(vec.
f(t[i]).x());
230 vecybuf+=std::to_string(vec.
f(t[i]).y());
231 veczbuf+=std::to_string(vec.
f(t[i]).z());
249 std::cout <<
"% curve: " << nm << std::endl;
250 std::cout <<
"figure(" << figno <<
");" << std::endl;
251 std::cout << cxbuf << std::endl;
252 std::cout << cybuf << std::endl;
253 std::cout << czbuf << std::endl;
254 std::cout << vecxbuf << std::endl;
255 std::cout << vecybuf << std::endl;
256 std::cout << veczbuf << std::endl;
257 std::cout <<
"setenv('GNUTERM', 'x11');" << std::endl;
258 std::cout <<
"quiver3(" << nm <<
"_loc_x, "
264 <<
"'r');" << std::endl;
267 template<
typename data__>
269 const std::string &name=
"",
bool show_control_points=
true)
272 typedef typename piecewise_surface_type::surface_type surface_type;
273 typedef typename piecewise_surface_type::data_type data_type;
274 typedef typename piecewise_surface_type::index_type index_type;
276 std::string nm, sxbuf, sybuf, szbuf;
277 std::vector<std::string> cpxbuf, cpybuf, cpzbuf;
279 index_type i, j, pp, qq, nup, nvp;
280 data_type umin, vmin, umax, vmax;
299 if (show_control_points)
301 cpxbuf.resize(nup*nvp);
302 cpybuf.resize(nup*nvp);
303 cpzbuf.resize(nup*nvp);
305 for (pp=0; pp<nup; ++pp)
307 for (qq=0; qq<nvp; ++qq)
314 cpxbuf[ppqq]=nm+
"_surf_cp"+std::to_string(pp)+std::to_string(qq)+
"_x=[";
315 cpybuf[ppqq]=nm+
"_surf_cp"+std::to_string(pp)+std::to_string(qq)+
"_y=[";
316 cpzbuf[ppqq]=nm+
"_surf_cp"+std::to_string(pp)+std::to_string(qq)+
"_z=[";
318 for (i=0; i<=bez.degree_u(); ++i)
320 for (j=0; j<=bez.degree_v(); ++j)
322 cpxbuf[ppqq]+=std::to_string(bez.get_control_point(i, j).x());
323 cpybuf[ppqq]+=std::to_string(bez.get_control_point(i, j).y());
324 cpzbuf[ppqq]+=std::to_string(bez.get_control_point(i, j).z());
326 if ((i==bez.degree_u()) && (j==bez.degree_v()))
329 else if ((j==bez.degree_v()) && (i<bez.degree_u()))
351 index_type nu(10*nup+1), nv(10*nvp+1);
352 std::vector<data__> u(nu), v(nv);
353 for (i=0; i<static_cast<index_type>(u.size()); ++i)
355 u[i]=umin+(umax-umin)*static_cast<data__>(i)/(u.size()-1);
357 for (j=0; j<static_cast<index_type>(v.size()); ++j)
359 v[j]=vmin+(vmax-vmin)*static_cast<data__>(j)/(v.size()-1);
363 sxbuf=nm+
"_surf_x=[";
364 sybuf=nm+
"_surf_y=[";
365 szbuf=nm+
"_surf_z=[";
370 sxbuf+=std::to_string(ps.
f(u[i], v[j]).x());
371 sybuf+=std::to_string(ps.
f(u[i], v[j]).y());
372 szbuf+=std::to_string(ps.
f(u[i], v[j]).z());
394 std::cout <<
"% surface: " << nm << std::endl;
395 std::cout <<
"figure(" << figno <<
");" << std::endl;
396 std::cout << sxbuf << std::endl;
397 std::cout << sybuf << std::endl;
398 std::cout << szbuf << std::endl;
399 std::cout <<
"setenv('GNUTERM', 'x11');" << std::endl;
400 std::cout <<
"mesh(" << nm <<
"_surf_x, "
403 <<
"'EdgeColor', [0 0 0]);" << std::endl;
404 if (show_control_points)
406 for (pp=0; pp<nup; ++pp)
408 for (qq=0; qq<nvp; ++qq)
413 std::cout << cpxbuf[ppqq] << std::endl;
414 std::cout << cpybuf[ppqq] << std::endl;
415 std::cout << cpzbuf[ppqq] << std::endl;
417 std::cout <<
"mesh(" << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_x', "
418 << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_y', "
419 << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_z', "
420 <<
"'EdgeColor', [0.5 0.5 0.5], 'FaceColor', 'none');" << std::endl;
421 std::cout <<
"plot3(" << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_x', "
422 << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_y', "
423 << nm <<
"_surf_cp" << std::to_string(pp) << std::to_string(qq) <<
"_z', "
424 <<
"'o', 'MarkerEdgeColor', [0.5 0.5 0.5],'MarkerFaceColor', [0.5 0.5 0.5]);" << std::endl;
void octave_print(int figno, const eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, 3 > &pc, const std::string &name="", bool show_control_points=true)
Definition: octave_helpers.hpp:62
std::string random_string(size_t length)
Definition: octave_helpers.hpp:27
void octave_start(int figno)
Definition: octave_helpers.hpp:43
data_type get_tmax() const
Definition: piecewise.hpp:333
data_type get_parameter_min() const
Definition: piecewise.hpp:366
void get_parameter_max(data_type &umax, data_type &vmax) const
Definition: piecewise.hpp:175
index_type number_segments() const
Definition: piecewise.hpp:419
error_code get(surface_type &surf, const index_type &ui, const index_type &vi) const
Definition: piecewise.hpp:487
point_type f(const data_type &u, const data_type &v) const
Definition: piecewise.hpp:897
index_type number_v_patches() const
Definition: piecewise.hpp:143
Definition: piecewise.hpp:37
Definition: piecewise.hpp:244
void octave_finish(int figno)
Definition: octave_helpers.hpp:51
void length(typename piecewise< curve__, data__, dim__, tol__ >::data_type &len, const piecewise< curve__, data__, dim__, tol__ > &pc, const typename piecewise< curve__, data__, dim__, tol__ >::data_type &tol)
Definition: length.hpp:43
void get_parameter_min(data_type &umin, data_type &vmin) const
Definition: piecewise.hpp:169
data_type get_parameter_max() const
Definition: piecewise.hpp:374
index_type number_u_patches() const
Definition: piecewise.hpp:142
data_type get_t0() const
Definition: piecewise.hpp:335
point_type f(const data_type &t) const
Definition: piecewise.hpp:1732
error_code get(curve_type &curve, const index_type &index) const
Definition: piecewise.hpp:729