image.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 IMAGE_HPP
22 #define IMAGE_HPP
23 
24 #include <iostream>
25 #include <vector>
26 #include <exception_cpe.hpp>
27 #include <color.hpp>
28 
29 
30 
31 namespace cpe
32 {
33 
34 class pos2;
35 
37 class image
38 {
39  public:
40 
41  // ********************************************* //
42  // ********************************************* //
43  // CONSTRUCTORS
44  // ********************************************* //
45  // ********************************************* //
46 
48  image();
52  image(int N);
57  image(int Nx,int Ny);
61  image(const std::string& filename);
62 
63 
64  // ********************************************* //
65  // ********************************************* //
66  // Picture Size
67  // ********************************************* //
68  // ********************************************* //
69 
71  int Nx() const;
73  int Ny() const;
74 
79  void reshape(int Nx2);
80 
81 
86  bool check_position(const pos2& u) const;
87 
88 
89  // ********************************************* //
90  // ********************************************* //
91  // Pixel access
92  // ********************************************* //
93  // ********************************************* //
94 
96  const color& operator()(const pos2& index) const;
98  color& operator()(const pos2& index);
99 
100 
101  // ********************************************* //
102  // ********************************************* //
103  // Special pixel filling
104  // ********************************************* //
105  // ********************************************* //
106 
110  void fill(const color& c);
116  void fill_rectangle(const pos2& u1,const pos2& u2,const color& c);
117 
118 
119  // ********************************************* //
120  // ********************************************* //
121  // I/O
122  // ********************************************* //
123  // ********************************************* //
124 
126  void export_file(const std::string& filename);
127 
128 
129 
130  protected:
131 
134  void assert_position(const pos2& u) const;
135 
136 
138  int coordinate_to_index(const pos2& u) const;
139 
140  private:
141 
142 
143  // ********************************************* //
144  // ********************************************* //
145  // Internal data
146  // ********************************************* //
147  // ********************************************* //
148 
153  std::vector<color> internal_data;
158 
159 
160 };
161 
162 
165 {
166  public:
167 
171  exception_image(const std::string& msg_param,const std::string& file_param,const std::string& caller_param,const int& line_param):exception_cpe(msg_param,file_param,caller_param,line_param){}
172 };
173 }
174 
175 #endif