grid.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2014 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 #pragma once
21 
22 #ifndef GRID_HPP
23 #define GRID_HPP
24 
25 #include "../lib3d/vec3.hpp"
26 #include <vector>
27 
28 namespace cpe
29 {
30 
31 class patch4;
32 
33 class grid
34 {
35  public:
36 
37  // ********************************************* //
38  // ********************************************* //
39  // CONSTRUCTORS
40  // ********************************************* //
41  // ********************************************* //
42 
44  grid();
46  grid(unsigned int Nu,unsigned int Nv);
47 
48  // ********************************************* //
49  // ********************************************* //
50  // Size
51  // ********************************************* //
52  // ********************************************* //
53 
55  void resize(unsigned int Nu,unsigned int Nv);
56 
58  unsigned int size_u() const;
60  unsigned int size_v() const;
61 
62 
63  // ********************************************* //
64  // ********************************************* //
65  // Data
66  // ********************************************* //
67  // ********************************************* //
68 
70  const vec3& operator()(unsigned int ku,unsigned int kv) const;
72  vec3& operator()(unsigned int ku,unsigned int kv);
73 
74 
75  // ********************************************* //
76  // ********************************************* //
77  // 4x4 patch
78  // ********************************************* //
79  // ********************************************* //
80 
82  patch4 get_patch(unsigned int k_patch_u,unsigned int k_patch_v) const;
83 
84 
85  // ********************************************* //
86  // ********************************************* //
87  // Special initialization
88  // ********************************************* //
89  // ********************************************* //
90 
92  void build_meshgrid();
94  void build_sphere();
95 
96 
97  // ********************************************* //
98  // ********************************************* //
99  // Grid transformation
100  // ********************************************* //
101  // ********************************************* //
102 
104  grid& operator*=(float s);
106  friend grid operator*(float s,const grid& g);
108  friend grid operator*(const grid& g,float s);
109 
111  grid& operator+=(const vec3& t);
113  grid& operator-=(const vec3& t);
115  friend grid operator+(const grid& g,const vec3& t);
117  friend grid operator+(const vec3& t,const grid& g);
119  friend grid operator-(const grid& g,const vec3& t);
121  friend grid operator-(const vec3& t,const grid& g);
122 
124  grid operator-() const;
125 
126 
127  // ********************************************* //
128  // ********************************************* //
129  // Topologie transform
130  // ********************************************* //
131  // ********************************************* //
132 
134  void add_back_u();
136  void add_front_u();
137 
139  void add_back_v();
141  void add_front_v();
142 
144  void suppress_back_u();
146  void suppress_front_u();
147 
149  void suppress_back_v();
151  void suppress_front_v();
152 
154  void duplicate_boundary();
155 
156 
157  // ********************************************* //
158  // ********************************************* //
159  // INPUT OUTPUT
160  // ********************************************* //
161  // ********************************************* //
162 
164  void write(const std::string& filename);
166  static grid read(const std::string& filename);
167 
168  private:
169 
171  void assert_size(unsigned int ku,unsigned int kv) const;
172 
174  unsigned int internal_size_u;
176  unsigned int internal_size_v;
177 
179  std::vector<vec3> internal_data;
180 };
181 }
182 
183 #endif
friend grid operator+(const grid &g, const vec3 &t)
translate the grid
Definition: grid.cpp:150
grid()
empty constructor
Definition: grid.cpp:31
void suppress_front_u()
suppress a line of grid in the u direction at the beginning
Definition: grid.cpp:327
grid operator-() const
negation positions of the grid
Definition: grid.cpp:176
void build_sphere()
build spherical distribution
Definition: grid.cpp:98
grid & operator-=(const vec3 &t)
translate the grid
Definition: grid.cpp:142
const vec3 & operator()(unsigned int ku, unsigned int kv) const
Accessor to the value (ku,kv)
Definition: grid.cpp:56
Definition: grid.hpp:33
unsigned int size_u() const
return the size in u direction
Definition: grid.cpp:48
Definition: patch4.hpp:30
unsigned int internal_size_u
internal size u
Definition: grid.hpp:174
void add_front_u()
add a line of grid in the u direction at the beginning
Definition: grid.cpp:206
unsigned int size_v() const
return the size in v direction
Definition: grid.cpp:52
void add_front_v()
add a line of grid in the v direction at the beginning
Definition: grid.cpp:251
void suppress_front_v()
suppress a line of grid in the v direction at the beginning
Definition: grid.cpp:363
grid & operator+=(const vec3 &t)
translate the grid
Definition: grid.cpp:134
patch4 get_patch(unsigned int k_patch_u, unsigned int k_patch_v) const
get a 4x4 patch
Definition: grid.cpp:73
void duplicate_boundary()
duplicate positions at the boundaries
Definition: grid.cpp:273
void resize(unsigned int Nu, unsigned int Nv)
resize the grid
Definition: grid.cpp:41
void suppress_back_u()
suppress a line of grid in the u direction at the end
Definition: grid.cpp:309
void add_back_v()
add a line of grid in the v direction at the end
Definition: grid.cpp:228
unsigned int internal_size_v
internal size v
Definition: grid.hpp:176
friend grid operator*(float s, const grid &g)
scale the grid homogeneously by a scalar
Definition: grid.cpp:122
void build_meshgrid()
build Matlab meshgrid style from 1 to size
Definition: grid.cpp:84
static grid read(const std::string &filename)
Read grid from a file.
Definition: grid.cpp:401
grid & operator*=(float s)
scale the grid homogeneously by a scalar
Definition: grid.cpp:114
Vectors/Points 3D.
Definition: vec3.hpp:36
void write(const std::string &filename)
Write grid into a file.
Definition: grid.cpp:381
std::vector< vec3 > internal_data
Internal storage under the form: ku+Nu*kv.
Definition: grid.hpp:179
void add_back_u()
add a line of grid in the u direction at the end
Definition: grid.cpp:183
void assert_size(unsigned int ku, unsigned int kv) const
ensure (ku,kv) is coherent with the size of the grid
Definition: grid.cpp:66
void suppress_back_v()
suppress a line of grid in the v direction at the end
Definition: grid.cpp:345