Code-Eli  0.3.6
piecewise_body_of_revolution_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_body_of_revolution_creator_hpp
14 #define eli_geom_surface_piecewise_body_of_revolution_creator_hpp
15 
16 #include <list>
17 #include <iterator>
18 
19 #include "eli/code_eli.hpp"
20 
21 #include "eli/util/tolerance.hpp"
22 
25 
28 
29 namespace eli
30 {
31  namespace geom
32  {
33  namespace surface
34  {
35  template<typename data__, unsigned short dim__, typename tol__>
38  int axis, bool outward_normal)
39  {
40  typedef piecewise<bezier, data__, dim__, tol__> piecewise_surface_type;
43  typedef typename piecewise_curve_type::curve_type curve_type;
44  typedef typename piecewise_surface_type::surface_type surface_type;
45  typedef typename curve_type::point_type point_type;
46  typedef typename curve_type::data_type data_type;
47  typedef typename curve_type::index_type index_type;
48 
49  curve_type c, arc;
50  surface_type s[4];
51  piecewise_curve_type pc_circle;
52  point_type origin, normal, start;
53  data_type du, dv;
54  index_type i, j, pp, qq, nu=pc.number_segments(), nv=4, udim, vdim;
55 
56  // resize the surface
57  ps.init_uv(nu, nv);
58 
59  // set the axis of rotation
60  switch(axis)
61  {
62  case(0):
63  {
64  normal << 1, 0, 0;
65  break;
66  }
67  case(1):
68  {
69  normal << 0, 1, 0;
70  break;
71  }
72  case(2):
73  {
74  normal << 0, 0, 1;
75  break;
76  }
77  default:
78  {
79  assert(false);
80  return false;
81  }
82  }
83  if (outward_normal)
84  {
85  normal*=-1;
86  }
87 
88  // cycle through each curve segment
89  circle_creator_type circle_creator;
90  for (pp=0; pp<nu; ++pp)
91  {
92  // resize the surface patch
93  udim=c.dimension();
94  vdim=3;
95  pc.get(c, du, pp);
96  s[0].resize(udim, vdim);
97  s[1].resize(udim, vdim);
98  s[2].resize(udim, vdim);
99  s[3].resize(udim, vdim);
100 
101  // cycle through each control point in current curve and create patch control points
102  for (i=0; i<=udim; ++i)
103  {
104  // set up the vectors for this circle
105  start=c.get_control_point(i);
106  origin=normal.dot(start)*normal;
107 
108  // get the circle
109  circle_creator.set(start, origin, normal);
110  if (!circle_creator.create(pc_circle))
111  {
112  assert(false);
113  return false;
114  }
115 
116  // for each segment of circle set the control points
117  for (qq=0; qq<4; ++qq)
118  {
119  pc_circle.get(arc, dv, qq);
120  for (j=0; j<4; ++j)
121  {
122  s[qq].set_control_point(arc.get_control_point(j), i, j);
123  }
124  }
125  }
126 
127  // set the surface patches
128  for (qq=0; qq<4; ++qq)
129  {
130  ps.set(s[qq], pp, qq);
131  }
132  }
133 
134  return true;
135  }
136  }
137  }
138 }
139 #endif
Definition: math.hpp:20
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
index_type number_segments() const
Definition: piecewise.hpp:419
Definition: piecewise.hpp:37
Definition: piecewise_circle_creator.hpp:244
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
error_code get(curve_type &curve, const index_type &index) const
Definition: piecewise.hpp:729
error_code set(const surface_type &surf, const index_type &ui, const index_type &vi)
Definition: piecewise.hpp:509