1 #ifndef VTESTBED_GEOMETRY_SPLINE_SURFACE_HH 2 #define VTESTBED_GEOMETRY_SPLINE_SURFACE_HH 4 #include <vtestbed/geometry/polyhedron.hh> 10 template <
class T,
class Curve>
14 using curve_type = Curve;
15 using value_type =
typename curve_type::value_type;
16 using reference = value_type&;
17 using const_reference =
const value_type&;
19 using size_type = size_t;
20 using pointer = curve_type*;
21 using const_pointer =
const curve_type*;
34 operator()(T u)
const {
36 points.reserve(this->_curves.size());
37 for (
const auto& curve : this->_curves) {
38 points.emplace_back(curve(u));
40 return curve_type(points);
44 operator()(T u, T v)
const {
45 return this->operator()(u)(v);
49 operator()(
const Vertex<T,2>& v)
const {
50 return this->operator()(v(0), v(1));
55 return this->_curves.size();
61 for (
const auto& s : this->_curves) {
62 size_type new_s = s.size();
63 if (new_s > max_s) { max_s = new_s; }
68 inline const curve_type& operator[](size_type i)
const {
return this->_curves[i]; }
69 inline curve_type& operator[](size_type i) {
return this->_curves[i]; }
70 inline size_type size()
const {
return this->_curves.size(); }
71 inline const_pointer begin()
const {
return this->_curves.data(); }
72 inline pointer begin() {
return this->_curves.data(); }
73 inline const_pointer end()
const {
return this->_curves.data() + size(); }
74 inline pointer end() {
return this->_curves.data() + size(); }
77 polyhedron(size_type resolution_u, size_type resolution_v)
const {
80 using index_type =
typename vtb::geometry::Face<3>::value_type;
81 index_type nrows = this->_curves.size()*resolution_u;
82 index_type ncols = this->_curves.front().size()*resolution_v;
84 vertex_array vertices;
85 vertices.reserve(ncols*nrows);
86 faces.reserve(ncols*nrows);
87 T du = T{1}/(nrows-1);
88 T dv = T{1}/(ncols-1);
89 for (index_type i=0; i<nrows; ++i) {
90 const auto& curve = (*this)(i*du);
91 for (index_type j=0; j<ncols; ++j) {
92 const auto& v2 = curve(j*dv);
93 vertices.emplace_back();
94 auto& v1 = vertices.back();
95 for (
int i=0; i<3; ++i) {
100 for (index_type i=1; i<nrows; ++i) {
101 for (index_type j=1; j<ncols; ++j) {
102 auto i1 = ncols*(i-1) + (j-1);
103 auto i2 = ncols*(i-1) + j;
104 auto i3 = ncols*i + j;
105 auto i4 = ncols*i + (j-1);
106 faces.emplace_back(i1, i2, i3);
107 faces.emplace_back(i1, i3, i4);
122 #endif // vim:filetype=cpp
void unique()
Remove duplicate vertices and faces.
void normalise()
Compute face and vertex normals in one loop.