image.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _IMAGE_HPP_
00021 #define _IMAGE_HPP_
00022
00023 #include <iostream>
00024 #include <vector>
00025 #include <exception_cpe.hpp>
00026 #include <p2d.hpp>
00027
00028
00029
00030 namespace cpe
00031 {
00032
00033 class color;
00034
00036 class image
00037 {
00038 public:
00039
00040
00041
00042
00043
00044
00045
00047 image();
00051 image(const unsigned int& N);
00056 image(const unsigned int& Nx,const unsigned int& Ny);
00060 image(const std::string& filename);
00061
00062
00063
00064
00065
00066
00067
00068
00070 const unsigned int& get_Nx() const;
00072 const unsigned int& get_Ny() const;
00073
00077 void resize(const unsigned int& N);
00082 void resize(const unsigned int& Nx,const unsigned int& Ny);
00083
00088 void reshape(const unsigned int& Nx2);
00089
00094 bool check_position(const p2d& u) const
00095 { return (u.x()<0 || u.x()>=static_cast<int>(internal_Nx) || u.y()<0 || u.y()>=static_cast<int>(internal_Ny))?false:true; }
00096
00097
00098
00099
00100
00101
00102
00103
00108 void set_pixel(const p2d& u,const color& c);
00113 void get_pixel(const p2d& u,color *c) const;
00114
00118 const unsigned char& get_r(const p2d& u) const;
00122 const unsigned char& get_g(const p2d& u) const;
00126 const unsigned char& get_b(const p2d& u) const;
00127
00129 const std::vector<unsigned char>& get_data() const;
00131 std::vector<unsigned char>& get_data();
00132
00133
00134
00135
00136
00137
00138
00139
00143 void fill(const color& c);
00149 void fill_rectangle(const p2d& u1,const p2d& u2,const color& c);
00150
00151
00152
00153
00154
00155
00156
00157
00161 void export_ppm(const std::string& filename);
00162
00163
00164 protected:
00165
00167 int coordinate_to_index(const p2d& u) const;
00168
00169 private:
00170
00171
00172
00173
00174
00175
00176
00177
00182 std::vector<unsigned char> internal_data;
00184 unsigned int internal_Nx;
00186 unsigned int internal_Ny;
00187
00188
00189
00190
00191
00192
00193
00197 static image read_ppm(const std::string& filename);
00198 };
00199
00200
00202 class exception_image : public exception_cpe
00203 {
00204 public:
00205
00207 exception_image():exception_cpe(){}
00209 exception_image(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00210 };
00211 }
00212
00213 #endif