Code-Eli  0.3.6
piecewise_point_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_point_creator_test_suite_hpp
14 #define piecewise_point_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"
27 
28 template<typename data__>
29 class piecewise_point_creator_test_suite : public Test::Suite
30 {
31  private:
39 
40  tolerance_type tol;
41 
42  protected:
43  void AddTests(const float &)
44  {
45  // add the tests
47  }
48  void AddTests(const double &)
49  {
50  // add the tests
52  }
53  void AddTests(const long double &)
54  {
55  // add the tests
57  }
58 
59  public:
61  {
62  AddTests(data__());
63  }
65  {
66  }
67 
68  private:
69  void octave_print(int figno, const piecewise_curve_type &pc) const
70  {
71  index_type i, pp, ns;
72  data_type tmin, tmax;
73 
74  ns=pc.number_segments();
75  pc.get_parameter_min(tmin);
76  pc.get_parameter_max(tmax);
77 
78  std::cout << "figure(" << figno << ");" << std::endl;
79 
80  // get control points and print
81  std::cout << "cp_x=[";
82  for (pp=0; pp<ns; ++pp)
83  {
84  curve_type bez;
85  pc.get(bez, pp);
86  for (i=0; i<=bez.degree(); ++i)
87  {
88  std::cout << bez.get_control_point(i).x();
89  if (i<bez.degree())
90  std::cout << ", ";
91  else if (pp<ns-1)
92  std::cout << "; ";
93  }
94  std::cout << std::endl;
95  }
96  std::cout << "];" << std::endl;
97 
98  std::cout << "cp_y=[";
99  for (pp=0; pp<ns; ++pp)
100  {
101  curve_type bez;
102  pc.get(bez, pp);
103  for (i=0; i<=bez.degree(); ++i)
104  {
105  std::cout << bez.get_control_point(i).y();
106  if (i<bez.degree())
107  std::cout << ", ";
108  else if (pp<ns-1)
109  std::cout << "; ";
110  }
111  std::cout << std::endl;
112  }
113  std::cout << "];" << std::endl;
114 
115  std::cout << "cp_z=[";
116  for (pp=0; pp<ns; ++pp)
117  {
118  curve_type bez;
119  pc.get(bez, pp);
120  for (i=0; i<=bez.degree(); ++i)
121  {
122  std::cout << bez.get_control_point(i).z();
123  if (i<bez.degree())
124  std::cout << ", ";
125  else if (pp<ns-1)
126  std::cout << "; ";
127  }
128  std::cout << std::endl;
129  }
130  std::cout << "];" << std::endl;
131 
132  // initialize the t parameters
133  std::vector<data__> t(129);
134  for (i=0; i<static_cast<index_type>(t.size()); ++i)
135  {
136  t[i]=tmin+(tmax-tmin)*static_cast<data__>(i)/(t.size()-1);
137  }
138 
139  // set the surface points
140  std::cout << "surf_x=[";
141  for (i=0; i<static_cast<index_type>(t.size()); ++i)
142  {
143  std::cout << pc.f(t[i]).x();
144  if (i<static_cast<index_type>(t.size()-1))
145  std::cout << ", ";
146  }
147  std::cout << "];" << std::endl;
148 
149  std::cout << "surf_y=[";
150  for (i=0; i<static_cast<index_type>(t.size()); ++i)
151  {
152  std::cout << pc.f(t[i]).y();
153  if (i<static_cast<index_type>(t.size()-1))
154  std::cout << ", ";
155  }
156  std::cout << "];" << std::endl;
157 
158  std::cout << "surf_z=[";
159  for (i=0; i<static_cast<index_type>(t.size()); ++i)
160  {
161  std::cout << pc.f(t[i]).z();
162  if (i<static_cast<index_type>(t.size()-1))
163  std::cout << ", ";
164  }
165  std::cout << "];" << std::endl;
166 
167  std::cout << "setenv('GNUTERM', 'x11');" << std::endl;
168  std::cout << "plot3(surf_x, surf_y, surf_z, '-k');" << std::endl;
169  std::cout << "hold on;" << std::endl;
170  std::cout << "plot3(cp_x', cp_y', cp_z', '-ok', 'MarkerFaceColor', [0 0 0]);" << std::endl;
171  std::cout << "hold off;" << std::endl;
172  }
173 
175  {
176  // create point with specified parameterization
177  {
178  piecewise_curve_type pc;
179  point_creator_type pt_creator(4);
180  data_type dt0(3), dt1(2), dt2(3), dt3(2), t0(-1), dt;
181  point_type p0, ptemp;
182 
183  // set the point
184  p0 << 1, 2, 3;
185  pt_creator.set_point(p0);
186 
187  // set the times
188  pt_creator.set_t0(t0);
189  pt_creator.set_segment_dt(dt0, 0);
190  pt_creator.set_segment_dt(dt1, 1);
191  pt_creator.set_segment_dt(dt2, 2);
192  pt_creator.set_segment_dt(dt3, 3);
193 
194  // test point setting
195  ptemp=pt_creator.get_point();
196  TEST_ASSERT(p0==ptemp);
197 
198  // test time step settings
199  TEST_ASSERT(pt_creator.get_t0()==t0);
200  dt=pt_creator.get_segment_dt(0);
201  TEST_ASSERT(dt==dt0);
202  dt=pt_creator.get_segment_dt(1);
203  TEST_ASSERT(dt==dt1);
204  dt=pt_creator.get_segment_dt(2);
205  TEST_ASSERT(dt==dt2);
206  dt=pt_creator.get_segment_dt(3);
207  TEST_ASSERT(dt==dt3);
208 
209  // create the polygon
210  TEST_ASSERT(pt_creator.create(pc));
211  }
212 
213  // create point with default parameterization
214  {
215  piecewise_curve_type pc;
216  point_creator_type pt_creator(4);
217  data_type dt;
218  point_type p0, ptemp;
219 
220  // set the corners
221  p0 << 1, 0, 0;
222  pt_creator.set_point(p0);
223 
224  // test corner settings
225  ptemp=pt_creator.get_point();
226  TEST_ASSERT(p0==ptemp);
227 
228  // test time step settings
229  TEST_ASSERT(pt_creator.get_t0()==0);
230  dt=pt_creator.get_segment_dt(0);
231  TEST_ASSERT(dt==1);
232  dt=pt_creator.get_segment_dt(1);
233  TEST_ASSERT(dt==1);
234  dt=pt_creator.get_segment_dt(2);
235  TEST_ASSERT(dt==1);
236  dt=pt_creator.get_segment_dt(3);
237  TEST_ASSERT(dt==1);
238 
239  // create the polygon
240  TEST_ASSERT(pt_creator.create(pc));
241  }
242  }
243 };
244 
245 #endif
246 
void create_point_test()
Definition: piecewise_point_creator_test_suite.hpp:174
Definition: piecewise_point_creator_test_suite.hpp:29
void set_segment_dt(const data_type &dtt, const index_type &i)
Definition: piecewise_creator_base.hpp:64
void AddTests(const double &)
Definition: piecewise_point_creator_test_suite.hpp:48
void AddTests(const long double &)
Definition: piecewise_point_creator_test_suite.hpp:53
tol__ tolerance_type
Definition: piecewise.hpp:278
piecewise_curve_type::data_type data_type
Definition: piecewise_point_creator_test_suite.hpp:35
data__ data_type
Definition: piecewise.hpp:276
data_type get_parameter_min() const
Definition: piecewise.hpp:366
curve_type::index_type index_type
Definition: piecewise.hpp:271
index_type number_segments() const
Definition: piecewise.hpp:419
~piecewise_point_creator_test_suite()
Definition: piecewise_point_creator_test_suite.hpp:64
Definition: piecewise.hpp:244
piecewise_curve_type::tolerance_type tolerance_type
Definition: piecewise_point_creator_test_suite.hpp:37
eli::geom::curve::piecewise_point_creator< data__, 3, tolerance_type > point_creator_type
Definition: piecewise_point_creator_test_suite.hpp:38
curve__< data__, dim__, tol__ > curve_type
Definition: piecewise.hpp:270
void octave_print(int figno, const piecewise_curve_type &pc) const
Definition: piecewise_point_creator_test_suite.hpp:69
piecewise_curve_type::curve_type curve_type
Definition: piecewise_point_creator_test_suite.hpp:33
tolerance_type tol
Definition: piecewise_point_creator_test_suite.hpp:40
data_type get_segment_dt(const index_type &i) const
Definition: piecewise_creator_base.hpp:78
void set_point(const point_type &p)
Definition: piecewise_point_creator.hpp:46
data_type get_parameter_max() const
Definition: piecewise.hpp:374
piecewise_curve_type::index_type index_type
Definition: piecewise_point_creator_test_suite.hpp:36
point_type get_point() const
Definition: piecewise_point_creator.hpp:50
eli::geom::curve::piecewise< eli::geom::curve::bezier, data__, 3 > piecewise_curve_type
Definition: piecewise_point_creator_test_suite.hpp:32
point_type f(const data_type &t) const
Definition: piecewise.hpp:1732
piecewise_point_creator_test_suite()
Definition: piecewise_point_creator_test_suite.hpp:60
error_code get(curve_type &curve, const index_type &index) const
Definition: piecewise.hpp:729
data_type get_t0() const
Definition: piecewise_creator_base.hpp:62
void AddTests(const float &)
Definition: piecewise_point_creator_test_suite.hpp:43
curve_type::point_type point_type
Definition: piecewise.hpp:272
void set_t0(const data_type &tt0)
Definition: piecewise_creator_base.hpp:61
virtual bool create(piecewise< bezier, data_type, dim__, tolerance_type > &pc) const
Definition: piecewise_point_creator.hpp:55
Definition: piecewise_point_creator.hpp:31
piecewise_curve_type::point_type point_type
Definition: piecewise_point_creator_test_suite.hpp:34