z_buffer.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 Z_BUFFER_HPP
22 #define Z_BUFFER_HPP
23 
24 #include <vector>
25 #include <string>
26 #include <pos2.hpp>
27 
28 namespace cpe
29 {
30 
32 class z_buffer
33 {
34  public:
35 
36  // ********************************************* //
37  // ********************************************* //
38  // CONSTRUCTORS
39  // ********************************************* //
40  // ********************************************* //
41 
43  z_buffer();
47  z_buffer(int size);
51  z_buffer(int size_x,int size_y);
52 
53 
54  // ********************************************* //
55  // ********************************************* //
56  // Manipulation
57  // ********************************************* //
58  // ********************************************* //
59 
61  void fill(double value);
62 
64  double operator()(const pos2& u) const;
66  double& operator()(const pos2& u);
67 
68  // ********************************************* //
69  // ********************************************* //
70  // Info
71  // ********************************************* //
72  // ********************************************* //
73 
75  double get_max() const;
77  double get_min() const;
78 
79  // ********************************************* //
80  // ********************************************* //
81  // Size
82  // ********************************************* //
83  // ********************************************* //
84 
86  int size_x() const;
88  int size_y() const;
89 
90  // ********************************************* //
91  // ********************************************* //
92  // I/O
93  // ********************************************* //
94  // ********************************************* //
95 
97  void export_file(const std::string& filename) const;
98 
99 
100  protected:
101 
103  int coordinate_to_index(const pos2& u) const;
104 
106  void assert_position(const pos2& u) const;
107 
108  private:
109 
110 
111 
113  std::vector<double> internal_data;
114 
119 
121  static const double depth_infinity=9e5;
122 };
123 }
124 
125 #endif