Code-Eli  0.3.6
piecewise_general_skinning_surface_creator.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 eli_geom_surface_piecewise_general_skinning_surface_creator_hpp
14 #define eli_geom_surface_piecewise_general_skinning_surface_creator_hpp
15 
16 #include <list>
17 #include <vector>
18 #include <iterator>
19 
20 #include "eli/code_eli.hpp"
21 
22 #include "eli/util/tolerance.hpp"
23 
27 
32 
33 namespace eli
34 {
35  namespace geom
36  {
37  namespace surface
38  {
39  template<typename data__, unsigned short dim__, typename tol__>
41  {
42  public:
49 
51 
53  : piecewise_creator_base<data__, dim__, tol__>(0, 0), ribs(2),
54  max_degree(1), closed(false)
55  {
56  }
57  piecewise_general_skinning_surface_creator(const data_type &uu0, const data_type &vv0)
58  : piecewise_creator_base<data__, dim__, tol__>(uu0, vv0), ribs(2),
59  max_degree(1), closed(false)
60  {
61  }
63  : piecewise_creator_base<data_type, dim__, tolerance_type>(gs), ribs(gs.ribs),
65  {
66  }
68  {
69  }
70 
71  void set_closed() {closed=true;}
72  void set_open() {closed=false;}
73  bool is_closed() const {return closed;}
74  bool is_open() const {return !closed;}
75 
76  void set_u0(const data_type &uu0) {this->set_initial_u(uu0);}
77 
78  void set_segment_du(const data_type &duu, const index_type &i)
79  {
80  this->set_du(duu, i);
81  }
82 
83  bool set_conditions(const std::vector<rib_data_type> &rbs, const std::vector<index_type> &maxd, bool cl=false)
84  {
85  index_type i, j, nsegs(static_cast<index_type>(maxd.size())), nribs(rbs.size());
86 
87  // ensure input vectors are correct size
88  if (!cl && (nribs!=(nsegs+1)))
89  return false;
90  if (cl && (nribs!=nsegs))
91  return false;
92 
93  // check to make sure have valid end conditions
94  if (!cl)
95  {
96  if (rbs[0].use_left_fp() || rbs[0].use_left_fpp() || rbs[0].get_continuity()!=rib_data_type::C0)
97  {
98  return false;
99  }
100  if (rbs[nsegs].use_right_fp() || rbs[nsegs].use_right_fpp() || rbs[nsegs].get_continuity()!=rib_data_type::C0)
101  {
102  return false;
103  }
104  }
105 
106  // make sure ribs are in valid state
107  data_type v_start(rbs[0].get_t0()), v_end(rbs[0].get_tmax());
108  tolerance_type tol;
109  for (i=0; i<nribs; ++i)
110  {
111  if (!rbs[i].check_state())
112  return false;
113  if (!tol.approximately_equal(rbs[i].get_t0(), v_start) || !tol.approximately_equal(rbs[i].get_tmax(), v_end))
114  return false;
115  }
116 
117  // find all unique v-coordinates on joints for each rib
118  auto comp = [&tol](const data_type &x1, const data_type &x2)->bool
119  {
120  return tol.approximately_less_than(x1, x2);
121  };
122 
123  std::vector<data_type> joints;
124  data_type t0(rbs[0].get_t0()), tmax(rbs[0].get_tmax());
125 
126  rbs[0].get_joints(std::back_inserter(joints));
127  for (i=1; i<nribs; ++i)
128  {
129  // test to make sure this rib's parameterization matches rest
130  if (!tol.approximately_equal(rbs[i].get_t0(), t0) || !tol.approximately_equal(rbs[i].get_tmax(), tmax))
131  {
132  return false;
133  }
134 
135  // get the joints on the current rib
136  std::vector<data_type> rjoints, jts_out;
137  rbs[i].get_joints(std::back_inserter(rjoints));
138 
139  // merge these joints with current list of joints
140  std::set_union(joints.begin(), joints.end(), rjoints.begin(), rjoints.end(), std::back_inserter(jts_out), comp);
141  std::swap(joints, jts_out);
142  }
143 
144  // record where the joints need to be for create()
145  index_type njoints(static_cast<index_type>(joints.size()));
146 
147  // set the v-parameterization
148  this->set_number_v_segments(njoints-1);
149  this->set_initial_v(joints[0]);
150  for (j=0; j<(njoints-1); ++j)
151  {
152  this->set_dv(joints[j+1]-joints[j], j);
153  }
154 
155  // reset the number of u-segments
156  this->set_number_u_segments(nsegs);
157 
158  ribs=rbs;
159  max_degree=maxd;
160  closed=cl;
161 
162  return true;
163  }
164 
165  virtual bool create(piecewise_surface_type &ps) const
166  {
167  typedef typename piecewise_surface_type::surface_type surface_type;
168 
169  index_type nribs(this->get_number_u_segments()+1), i, j;
170  std::vector<index_type> seg_degree(nribs-1);
171  std::vector<rib_data_type> rib_states(ribs);
172  tolerance_type tol;
173 
174  // FIX: Should be able to handle closed surfaces
175  assert(!closed);
176 
177  // FIX: Need to be able to handle v-direction discontinuous fu and fuu specifications
178 
179  // reset the incoming piecewise surface
180  ps.clear();
181 
182  // split ribs so have same number of curves (with same joint parameters) for all ribs and get degree
183  index_type njoints(this->get_number_v_segments()+1);
184  std::vector<data_type> joints(njoints);
185  std::vector<index_type> max_jdegs(njoints-1,0);
186 
187  joints[0]=this->get_v0();
188  for (j=0; j<(njoints-1); ++j)
189  {
190  joints[j+1]=joints[j]+this->get_segment_dv(j);
191  }
192 
193  for (i=0; i<nribs; ++i)
194  {
195  std::vector<index_type> jdegs;
196  rib_states[i].split(joints.begin(), joints.end(), std::back_inserter(jdegs));
197  for (j=0; j<(njoints-1); ++j)
198  {
199  if (jdegs[j]>max_jdegs[j])
200  {
201  max_jdegs[j]=jdegs[j];
202  }
203  }
204  }
205 
206  // set degree in u-direction for each rib segment strip
207  for (i=0; i<nribs; ++i)
208  {
209  rib_states[i].promote(max_jdegs.begin(), max_jdegs.end());
210  }
211 
212  // resize the piecewise surface
213  index_type u, v, nu(nribs-1), nv(njoints-1);
214 
215  ps.init_uv(this->du_begin(), this->du_end(), this->dv_begin(), this->dv_end(), this->get_u0(), this->get_v0());
216 
217  // build segments based on rib information
218  // here should have everything to make an nribs x njoints piecewise surface with all
219  // of the j-degrees matching in the u-direction so that can use general curve creator
220  // techniques to create control points
221  for (v=0; v<nv; ++v)
222  {
225  typedef typename piecewise_curve_type::curve_type curve_type;
226 
227  std::vector<typename piecewise_curve_creator_type::joint_data> joints(nu+1);
228  piecewise_curve_creator_type gc;
229  piecewise_curve_type c;
230 
231  std::vector<surface_type> surfs(nu);
232 
233  for (j=0; j<=max_jdegs[v]; ++j)
234  {
235  // cycle through each rib to set corresponding joint info
236  for (u=0; u<=nu; ++u)
237  {
238  curve_type jcrv;
239 
240  joints[u].set_continuity(static_cast<typename piecewise_curve_creator_type::joint_continuity>(rib_states[u].get_continuity()));
241 
242  rib_states[u].get_f().get(jcrv, v);
243  joints[u].set_f(jcrv.get_control_point(j));
244  if (rib_states[u].use_left_fp())
245  {
246  rib_states[u].get_left_fp().get(jcrv, v);
247  joints[u].set_left_fp(jcrv.get_control_point(j));
248  }
249  if (rib_states[u].use_right_fp())
250  {
251  rib_states[u].get_right_fp().get(jcrv, v);
252  joints[u].set_right_fp(jcrv.get_control_point(j));
253  }
254  if (rib_states[u].use_left_fpp())
255  {
256  rib_states[u].get_left_fpp().get(jcrv, v);
257  joints[u].set_left_fpp(jcrv.get_control_point(j));
258  }
259  if (rib_states[u].use_right_fpp())
260  {
261  rib_states[u].get_right_fpp().get(jcrv, v);
262  joints[u].set_right_fpp(jcrv.get_control_point(j));
263  }
264  }
265 
266  // set the conditions for the curve creator
267  bool rtn_flag(gc.set_conditions(joints, max_degree, closed));
268  if (!rtn_flag)
269  {
270  return false;
271  }
272 
273  // set the parameterizations and create curve
274  gc.set_t0(this->get_u0());
275  for (u=0; u<nu; ++u)
276  {
277  gc.set_segment_dt(this->get_segment_du(u), u);
278  }
279  rtn_flag=gc.create(c);
280  if (!rtn_flag)
281  {
282  return false;
283  }
284 
285  // extract the control points from piecewise curve and set the surface control points
286  for (u=0; u<nu; ++u)
287  {
288  curve_type crv;
289 
290  c.get(crv, u);
291 
292  // resize the temp surface
293  if (j==0)
294  {
295  surfs[u].resize(crv.degree(), max_jdegs[v]);
296  }
297 
298  for (i=0; i<=crv.degree(); ++i)
299  {
300  surfs[u].set_control_point(crv.get_control_point(i), i, j);
301  }
302  }
303  }
304 
305  // put these surfaces into piecewise surface
307  for (u=0; u<nu; ++u)
308  {
309  ec=ps.set(surfs[u], u, v);
311  {
312  assert(false);
313  return false;
314  }
315  }
316  }
317 
318  return true;
319  }
320 
321  private:
322  std::vector<rib_data_type> ribs;
323  std::vector<index_type> max_degree;
324  bool closed;
325  };
326  }
327  }
328 }
329 #endif
piecewise_general_skinning_surface_creator()
Definition: piecewise_general_skinning_surface_creator.hpp:52
void set_open()
Definition: piecewise_general_skinning_surface_creator.hpp:72
Eigen::Matrix< data_type, 1, dim__ > point_type
Definition: piecewise_creator_base.hpp:37
piecewise_general_skinning_surface_creator(const data_type &uu0, const data_type &vv0)
Definition: piecewise_general_skinning_surface_creator.hpp:57
index_type get_number_u_segments() const
Definition: piecewise_creator_base.hpp:51
Definition: math.hpp:20
connection_data< data_type, dim__, tolerance_type > rib_data_type
Definition: piecewise_general_skinning_surface_creator.hpp:50
data__ data_type
Definition: piecewise_creator_base.hpp:36
bool closed
Definition: piecewise_general_skinning_surface_creator.hpp:324
Definition: piecewise_connection_data.hpp:46
data_type get_u0() const
Definition: piecewise_creator_base.hpp:61
data_type get_v0() const
Definition: piecewise_creator_base.hpp:62
void set_initial_u(const data_type &uu0)
Definition: piecewise_creator_base.hpp:166
void set_du(const data_type &duu, const index_type &i)
Definition: piecewise_creator_base.hpp:169
bool is_open() const
Definition: piecewise_general_skinning_surface_creator.hpp:74
param_iterator dv_begin() const
Definition: piecewise_creator_base.hpp:95
Definition: piecewise.hpp:37
void set_u0(const data_type &uu0)
Definition: piecewise_general_skinning_surface_creator.hpp:76
piecewise_creator_base< data__, dim__, tol__ > base_class_type
Definition: piecewise_general_skinning_surface_creator.hpp:43
Definition: piecewise_creator_base.hpp:33
tol__ tolerance_type
Definition: piecewise_creator_base.hpp:39
Definition: piecewise.hpp:244
param_iterator du_end() const
Definition: piecewise_creator_base.hpp:94
Definition: piecewise_general_skinning_surface_creator.hpp:40
param_iterator du_begin() const
Definition: piecewise_creator_base.hpp:93
bool set_conditions(const std::vector< rib_data_type > &rbs, const std::vector< index_type > &maxd, bool cl=false)
Definition: piecewise_general_skinning_surface_creator.hpp:83
Definition: piecewise_general_creator.hpp:36
void set_segment_du(const data_type &duu, const index_type &i)
Definition: piecewise_general_skinning_surface_creator.hpp:78
Definition: piecewise_connection_data.hpp:32
void set_number_v_segments(const index_type &ns)
Definition: piecewise_creator_base.hpp:106
index_type get_number_v_segments() const
Definition: piecewise_creator_base.hpp:56
void set_dv(const data_type &dvv, const index_type &j)
Definition: piecewise_creator_base.hpp:176
void clear()
Definition: piecewise.hpp:478
error_code
Definition: piecewise.hpp:69
base_class_type::piecewise_surface_type piecewise_surface_type
Definition: piecewise_general_skinning_surface_creator.hpp:48
base_class_type::data_type data_type
Definition: piecewise_general_skinning_surface_creator.hpp:44
base_class_type::point_type point_type
Definition: piecewise_general_skinning_surface_creator.hpp:45
std::vector< rib_data_type > ribs
Definition: piecewise_general_skinning_surface_creator.hpp:322
param_iterator dv_end() const
Definition: piecewise_creator_base.hpp:96
void set_closed()
Definition: piecewise_general_skinning_surface_creator.hpp:71
Definition: piecewise.hpp:71
void set_number_u_segments(const index_type &ns)
Definition: piecewise_creator_base.hpp:98
point_type::Index index_type
Definition: piecewise_creator_base.hpp:38
void set_initial_v(const data_type &vv0)
Definition: piecewise_creator_base.hpp:167
void init_uv(const index_type &nsegu, const index_type &nsegv, const data_type &du=1, const data_type &dv=1, const data_type &u0=0, const data_type &v0=0)
Definition: piecewise.hpp:219
base_class_type::index_type index_type
Definition: piecewise_general_skinning_surface_creator.hpp:46
std::vector< index_type > max_degree
Definition: piecewise_general_skinning_surface_creator.hpp:323
bool is_closed() const
Definition: piecewise_general_skinning_surface_creator.hpp:73
base_class_type::tolerance_type tolerance_type
Definition: piecewise_general_skinning_surface_creator.hpp:47
virtual ~piecewise_general_skinning_surface_creator()
Definition: piecewise_general_skinning_surface_creator.hpp:67
piecewise_general_skinning_surface_creator(const piecewise_general_skinning_surface_creator< data_type, dim__, tolerance_type > &gs)
Definition: piecewise_general_skinning_surface_creator.hpp:62
surface__< data__, dim__, tol__ > surface_type
Definition: piecewise.hpp:57
error_code set(const surface_type &surf, const index_type &ui, const index_type &vi)
Definition: piecewise.hpp:509
virtual bool create(piecewise_surface_type &ps) const
Definition: piecewise_general_skinning_surface_creator.hpp:165
data_type get_segment_dv(const index_type &i) const
Definition: piecewise_creator_base.hpp:75
data_type get_segment_du(const index_type &i) const
Definition: piecewise_creator_base.hpp:64