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 
21 #ifndef _GRID_HPP_
22 #define _GRID_HPP_
23 
24 #include <vec3.hpp>
25 #include <vector>
26 
27 namespace cpe
28 {
29 
30 class patch4;
31 
32 class grid
33 {
34  public:
35 
36  // ********************************************* //
37  // ********************************************* //
38  // CONSTRUCTORS
39  // ********************************************* //
40  // ********************************************* //
41 
43  grid();
45  grid(const unsigned int& Nu,const unsigned int& Nv);
46 
47  // ********************************************* //
48  // ********************************************* //
49  // Size
50  // ********************************************* //
51  // ********************************************* //
52 
54  void resize(const unsigned int& Nu,const unsigned int& Nv);
55 
57  const unsigned int& size_u() const;
59  const unsigned int& size_v() const;
60 
61 
62  // ********************************************* //
63  // ********************************************* //
64  // Data
65  // ********************************************* //
66  // ********************************************* //
67 
69  const vec3& operator()(const unsigned int& ku,const unsigned int& kv) const;
71  vec3& operator()(const unsigned int& ku,const unsigned int& kv);
72 
73 
74  // ********************************************* //
75  // ********************************************* //
76  // 4x4 patch
77  // ********************************************* //
78  // ********************************************* //
79 
81  patch4 get_patch(const unsigned int& k_patch_u,const unsigned int& k_patch_v) const;
82 
83 
84  // ********************************************* //
85  // ********************************************* //
86  // Special initialization
87  // ********************************************* //
88  // ********************************************* //
89 
91  void build_meshgrid();
93  void build_sphere();
94 
95 
96  // ********************************************* //
97  // ********************************************* //
98  // Grid transformation
99  // ********************************************* //
100  // ********************************************* //
101 
103  grid& operator*=(const double& s);
105  friend grid operator*(const double& s,const grid& g);
107  friend grid operator*(const grid& g,const double& s);
108 
110  grid& operator+=(const vec3& t);
112  grid& operator-=(const vec3& t);
114  friend grid operator+(const grid& g,const vec3& t);
116  friend grid operator+(const vec3& t,const grid& g);
118  friend grid operator-(const grid& g,const vec3& t);
120  friend grid operator-(const vec3& t,const grid& g);
121 
123  grid operator-() const;
124 
125 
126  // ********************************************* //
127  // ********************************************* //
128  // Topologie transform
129  // ********************************************* //
130  // ********************************************* //
131 
133  void add_back_u();
135  void add_front_u();
136 
138  void add_back_v();
140  void add_front_v();
141 
143  void suppress_back_u();
145  void suppress_front_u();
146 
148  void suppress_back_v();
150  void suppress_front_v();
151 
153  void duplicate_boundary();
154 
155 
156  // ********************************************* //
157  // ********************************************* //
158  // INPUT OUTPUT
159  // ********************************************* //
160  // ********************************************* //
161 
163  void write(const std::string& filename);
165  static grid read(const std::string& filename);
166 
167  private:
168 
170  void assert_size(const unsigned int& ku,const unsigned int& kv) const;
171 
173  unsigned int internal_size_u;
175  unsigned int internal_size_v;
176 
178  std::vector<vec3> internal_data;
179 };
180 }
181 
182 #endif