grid.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2013 Damien Rohmer
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 #ifndef GRID_HPP_
21 #define GRID_HPP_
22 
23 #include <vec3.hpp>
24 #include <vector>
25 
26 namespace cpe
27 {
28 
29 class patch4;
30 
31 class grid
32 {
33  public:
34 
35  // ********************************************* //
36  // ********************************************* //
37  // CONSTRUCTORS
38  // ********************************************* //
39  // ********************************************* //
40 
42  grid();
44  grid(const unsigned int& Nu,const unsigned int& Nv);
45 
46  // ********************************************* //
47  // ********************************************* //
48  // Size
49  // ********************************************* //
50  // ********************************************* //
51 
53  void resize(const unsigned int& Nu,const unsigned int& Nv);
54 
56  const unsigned int& size_u() const;
58  const unsigned int& size_v() const;
59 
60 
61  // ********************************************* //
62  // ********************************************* //
63  // Data
64  // ********************************************* //
65  // ********************************************* //
66 
68  const vec3& operator()(const unsigned int& ku,const unsigned int& kv) const;
70  vec3& operator()(const unsigned int& ku,const unsigned int& kv);
71 
72 
73  // ********************************************* //
74  // ********************************************* //
75  // 4x4 patch
76  // ********************************************* //
77  // ********************************************* //
78 
80  patch4 get_patch(const unsigned int& k_patch_u,const unsigned int& k_patch_v) const;
81 
82 
83  // ********************************************* //
84  // ********************************************* //
85  // Special initialization
86  // ********************************************* //
87  // ********************************************* //
88 
90  void build_meshgrid();
92  void build_sphere();
93 
94 
95  // ********************************************* //
96  // ********************************************* //
97  // Grid transformation
98  // ********************************************* //
99  // ********************************************* //
100 
102  grid& operator*=(const double& s);
104  friend grid operator*(const double& s,const grid& g);
106  friend grid operator*(const grid& g,const double& s);
107 
109  grid& operator+=(const vec3& t);
111  grid& operator-=(const vec3& t);
113  friend grid operator+(const grid& g,const vec3& t);
115  friend grid operator+(const vec3& t,const grid& g);
117  friend grid operator-(const grid& g,const vec3& t);
119  friend grid operator-(const vec3& t,const grid& g);
120 
122  grid operator-() const;
123 
124 
125  // ********************************************* //
126  // ********************************************* //
127  // Topologie transform
128  // ********************************************* //
129  // ********************************************* //
130 
132  void add_back_u();
134  void add_front_u();
135 
137  void add_back_v();
139  void add_front_v();
140 
142  void suppress_back_u();
144  void suppress_front_u();
145 
147  void suppress_back_v();
149  void suppress_front_v();
150 
152  void duplicate_boundary();
153 
154 
155  // ********************************************* //
156  // ********************************************* //
157  // INPUT OUTPUT
158  // ********************************************* //
159  // ********************************************* //
160 
162  void write(const std::string& filename) const;
164  static grid read(const std::string& filename);
165 
166  private:
167 
169  void assert_size(const unsigned int& ku,const unsigned int& kv) const;
170 
172  unsigned int internal_size_u;
174  unsigned int internal_size_v;
175 
177  std::vector<vec3> internal_data;
178 };
179 }
180 
181 #endif