Code-Eli  0.3.6
piecewise_body_of_revolution_creator_test_suite.hpp
Go to the documentation of this file.
1 /*********************************************************************************
2 * Copyright (c) 2013 David D. Marshall <ddmarsha@calpoly.edu>
3 *
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * David D. Marshall - initial code and implementation
11 ********************************************************************************/
12 
13 #ifndef piecewise_body_of_revolution_creator_test_suite_hpp
14 #define piecewise_body_of_revolution_creator_test_suite_hpp
15 
16 #include <cmath> // std::pow, std::exp
17 
18 #include <typeinfo> // typeid
19 #include <string> // std::string
20 #include <sstream> // std::stringstream
21 #include <iomanip> // std::setw
22 #include <limits> // std::numeric_limits
23 
24 #include "eli/constants/math.hpp"
25 
27 
30 
31 template<typename data__>
33 {
34  private:
42 
43  tolerance_type tol;
44 
45  protected:
46  void AddTests(const float &)
47  {
48  // add the tests
50  }
51  void AddTests(const double &)
52  {
53  // add the tests
55  }
56  void AddTests(const long double &)
57  {
58  // add the tests
60  }
61 
62  public:
64  {
65  AddTests(data__());
66  }
68  {
69  }
70 
71  private:
72  void octave_print(int figno, const piecewise_surface_type &ps) const
73  {
74  index_type i, j, pp, qq, nup, nvp;
75  data_type umin, vmin, umax, vmax;
76 
77  nup=ps.number_u_patches();
78  nvp=ps.number_v_patches();
79  ps.get_parameter_min(umin, vmin);
80  ps.get_parameter_max(umax, vmax);
81 
82  std::cout << "figure(" << figno << ");" << std::endl;
83  std::cout << "cp_x=[" << std::endl;
84  for (pp=0; pp<nup; ++pp)
85  {
86  for (qq=0; qq<nvp; ++qq)
87  {
88  surface_type bez;
89  ps.get(bez, pp, qq);
90  for (i=0; i<=bez.degree_u(); ++i)
91  {
92  std::cout << bez.get_control_point(i, 0).x();
93  for (j=1; j<bez.degree_v(); ++j)
94  {
95  std::cout << ", " << bez.get_control_point(i, j).x();
96  }
97  j=bez.degree_v();
98  std::cout << ", " << bez.get_control_point(i, j).x();
99  if (i<bez.degree_u())
100  std::cout << "; ";
101  else if (pp<nup-1)
102  std::cout << "; ";
103  else if (qq<nvp-1)
104  std::cout << "; ";
105  }
106  std::cout << std::endl;
107  }
108  }
109  std::cout << "];" << std::endl;
110 
111  std::cout << "cp_y=[";
112  for (pp=0; pp<nup; ++pp)
113  {
114  for (qq=0; qq<nvp; ++qq)
115  {
116  surface_type bez;
117  ps.get(bez, pp, qq);
118  for (i=0; i<=bez.degree_u(); ++i)
119  {
120  std::cout << bez.get_control_point(i, 0).y();
121  for (j=1; j<bez.degree_v(); ++j)
122  {
123  std::cout << ", " << bez.get_control_point(i, j).y();
124  }
125  j=bez.degree_v();
126  std::cout << ", " << bez.get_control_point(i, j).y();
127  if (i<bez.degree_u())
128  std::cout << "; ";
129  else if (pp<nup-1)
130  std::cout << "; ";
131  else if (qq<nvp-1)
132  std::cout << "; ";
133  }
134  std::cout << std::endl;
135  }
136  }
137  std::cout << "];" << std::endl;
138 
139  std::cout << "cp_z=[";
140  for (pp=0; pp<nup; ++pp)
141  {
142  for (qq=0; qq<nvp; ++qq)
143  {
144  surface_type bez;
145  ps.get(bez, pp, qq);
146  for (i=0; i<=bez.degree_u(); ++i)
147  {
148  std::cout << bez.get_control_point(i, 0).z();
149  for (j=1; j<bez.degree_v(); ++j)
150  {
151  std::cout << ", " << bez.get_control_point(i, j).z();
152  }
153  j=bez.degree_v();
154  std::cout << ", " << bez.get_control_point(i, j).z();
155  if (i<bez.degree_u())
156  std::cout << "; ";
157  else if (pp<nup-1)
158  std::cout << "; ";
159  else if (qq<nvp-1)
160  std::cout << "; ";
161  }
162  std::cout << std::endl;
163  }
164  }
165  std::cout << "];" << std::endl;
166 
167  // initialize the u & v parameters
168  std::vector<data__> u(11), v(11);
169  for (i=0; i<static_cast<index_type>(u.size()); ++i)
170  {
171  u[i]=umin+(umax-umin)*static_cast<data__>(i)/(u.size()-1);
172  }
173  for (j=0; j<static_cast<index_type>(v.size()); ++j)
174  {
175  v[j]=vmin+(vmax-vmin)*static_cast<data__>(j)/(v.size()-1);
176  }
177 
178  // set the surface points
179  std::cout << "surf_x=[";
180  for (i=0; i<static_cast<index_type>(u.size()); ++i)
181  {
182  std::cout << ps.f(u[i], v[0]).x();
183  for (j=1; j<static_cast<index_type>(v.size()-1); ++j)
184  {
185  std::cout << ", " << ps.f(u[i], v[j]).x();
186  }
187  j=static_cast<index_type>(v.size()-1);
188  std::cout << ", " << ps.f(u[i], v[j]).x();
189  if (i<static_cast<index_type>(u.size()-1))
190  std::cout << "; " << std::endl;
191  }
192  std::cout << "];" << std::endl;
193 
194  std::cout << "surf_y=[";
195  for (i=0; i<static_cast<index_type>(u.size()); ++i)
196  {
197  std::cout << ps.f(u[i], v[0]).y();
198  for (j=1; j<static_cast<index_type>(v.size()-1); ++j)
199  {
200  std::cout << ", " << ps.f(u[i], v[j]).y();
201  }
202  j=static_cast<index_type>(v.size()-1);
203  std::cout << ", " << ps.f(u[i], v[j]).y();
204  if (i<static_cast<index_type>(u.size()-1))
205  std::cout << "; " << std::endl;
206  }
207  std::cout << "];" << std::endl;
208 
209  std::cout << "surf_z=[";
210  for (i=0; i<static_cast<index_type>(u.size()); ++i)
211  {
212  std::cout << ps.f(u[i], v[0]).z();
213  for (j=1; j<static_cast<index_type>(v.size()-1); ++j)
214  {
215  std::cout << ", " << ps.f(u[i], v[j]).z();
216  }
217  j=static_cast<index_type>(v.size()-1);
218  std::cout << ", " << ps.f(u[i], v[j]).z();
219  if (i<static_cast<index_type>(u.size()-1))
220  std::cout << "; " << std::endl;
221  }
222  std::cout << "];" << std::endl;
223 
224  std::cout << "setenv('GNUTERM', 'x11');" << std::endl;
225  std::cout << "mesh(surf_x, surf_y, surf_z, zeros(size(surf_z)), 'EdgeColor', [0 0 0]);" << std::endl;
226  std::cout << "hold on;" << std::endl;
227  std::cout << "plot3(cp_x, cp_y, cp_z, 'ok', 'MarkerFaceColor', [0 0 0]);" << std::endl;
228  std::cout << "hold off;" << std::endl;
229  }
230 
232  {
233  typedef typename piecewise_curve_type::curve_type curve_type;
234  typedef typename curve_type::control_point_type curve_control_point_type;
235 
236  // create geometry with default parameterizations
237  {
238  piecewise_curve_type pc;
239  curve_type c(3);
240  curve_control_point_type cp[4];
241  data_type k=4*(eli::constants::math<data_type>::sqrt_two()-1)/3;
242  index_type i;
243 
244  // create curve
245  cp[0] << 1, 0, 0;
246  cp[1] << 1, k, 0;
247  cp[2] << k, 1, 0;
248  cp[3] << 0, 1, 0;
249  for (i=0; i<4; ++i)
250  {
251  c.set_control_point(cp[i], i);
252  }
253  TEST_ASSERT(pc.push_back(c, 0.25)==piecewise_curve_type::NO_ERRORS);
254 
255  // set 2nd quadrant curve
256  cp[0] << 0, 1, 0;
257  cp[1] << -k, 1, 0;
258  cp[2] << -1, k, 0;
259  cp[3] << -1, 0, 0;
260  for (i=0; i<4; ++i)
261  {
262  c.set_control_point(cp[i], i);
263  }
264  TEST_ASSERT(pc.push_back(c, 0.25)==piecewise_curve_type::NO_ERRORS);
265 
266  piecewise_surface_type ps;
267 
268  TEST_ASSERT(eli::geom::surface::create_body_of_revolution(ps, pc, 0, true));
269 
270 // if (typeid(data_type)==typeid(double))
271 // octave_print(2, ps);
272 
273  TEST_ASSERT(ps.open_u());
274  TEST_ASSERT(ps.closed_v());
275  }
276  }
277 };
278 
279 #endif
280 
surface_type::point_type point_type
Definition: piecewise.hpp:59
~piecewise_body_of_revolution_creator_test_suite()
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:67
piecewise_surface_type::tolerance_type tolerance_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:41
tolerance_type tol
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:43
bool create_body_of_revolution(piecewise< bezier, data__, dim__, tol__ > &ps, const eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, dim__, tol__ > &pc, int axis, bool outward_normal)
Definition: piecewise_body_of_revolution_creator.hpp:36
piecewise_surface_type::point_type point_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:38
eli::geom::surface::piecewise< eli::geom::surface::bezier, data__, 3 > piecewise_surface_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:35
Definition: piecewise.hpp:281
data__ data_type
Definition: piecewise.hpp:66
error_code push_back(const curve_type &curve, const data_type &dt=1.0)
Definition: piecewise.hpp:688
piecewise_body_of_revolution_creator_test_suite()
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:63
void get_parameter_max(data_type &umax, data_type &vmax) const
Definition: piecewise.hpp:175
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
void AddTests(const long double &)
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:56
Definition: math.hpp:25
Definition: piecewise.hpp:244
void AddTests(const double &)
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:51
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:32
curve__< data__, dim__, tol__ > curve_type
Definition: piecewise.hpp:270
tol__ tolerance_type
Definition: piecewise.hpp:68
eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, 3 > piecewise_curve_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:36
void get_parameter_min(data_type &umin, data_type &vmin) const
Definition: piecewise.hpp:169
void AddTests(const float &)
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:46
surface_type::index_type index_type
Definition: piecewise.hpp:58
void create_body_of_revolution_test()
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:231
index_type number_u_patches() const
Definition: piecewise.hpp:142
piecewise_surface_type::surface_type surface_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:37
piecewise_surface_type::index_type index_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:40
surface__< data__, dim__, tol__ > surface_type
Definition: piecewise.hpp:57
void octave_print(int figno, const piecewise_surface_type &ps) const
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:72
piecewise_surface_type::data_type data_type
Definition: piecewise_body_of_revolution_creator_test_suite.hpp:39