1 /** @file gsSurface.hpp
2 
3     @brief Provides implementation of Surface common operations.
4 
5     This file is part of the G+Smo library.
6 
7     This Source Code Form is subject to the terms of the Mozilla Public
8     License, v. 2.0. If a copy of the MPL was not distributed with this
9     file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 
11     Author(s): A. Mantzaflaris
12 */
13 
14 
15 #pragma once
16 
17 #include <gsTensor/gsGridIterator.h>
18 #include <gsUtils/gsMesh/gsMesh.h>
19 
20 
21 namespace gismo
22 {
23 
24 template<class T>
toMesh(gsMesh<T> & msh,int npoints) const25 void gsSurface<T>::toMesh(gsMesh<T> & msh, int npoints) const
26 {
27     const gsMatrix<T> param     = this->parameterRange();
28     gsMatrix<T> cp;
29     gsGridIterator<T,CUBE> pIter(param, npoints);
30     for(; pIter; ++pIter)
31     {
32         this->eval_into( *pIter, cp);
33         msh.addVertex( cp );
34     }
35 
36     const typename gsGridIterator<T,CUBE>::point_index np = pIter.numPointsCwise();
37     for(index_t j = 0; j + 1 != np[1]; j++)
38         for(index_t i= 0; i + 1 != np[0]; i++)
39         {
40             const index_t ind1 = j * np[0] + i;
41             const index_t ind2 = ind1 + np[0];
42             //msh.addFace(ind1, ind1+1, ind2+1, ind2);
43             msh.addFace(ind1  , ind1+1, ind2+1);
44             msh.addFace(ind2+1, ind2  , ind1  );
45         }
46 }
47 
48 /*
49    gsVector<unsigned> v;
50     v.setZero(2);
51     do
52     {
53         msh.addFace(v[0], v[0]+1, v[1]+1, v[1]);
54     }
55     while( nextLexicographic(v, np) );
56 */
57 
58 } // namespace gismo
59