image.hpp
Go to the documentation of this file.
00001 /*
00002 **    TP 4ETI CPE Lyon
00003 **    Copyright (C) 2012 Damien Rohmer
00004 **
00005 **    This program is free software: you can redistribute it and/or modify
00006 **    it under the terms of the GNU General Public License as published by
00007 **    the Free Software Foundation, either version 3 of the License, or
00008 **    (at your option) any later version.
00009 **
00010 **   This program is distributed in the hope that it will be useful,
00011 **    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 **    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 **    GNU General Public License for more details.
00014 **
00015 **    You should have received a copy of the GNU General Public License
00016 **    along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 
00020 
00021 
00022 #ifndef IMAGE_HPP
00023 #define IMAGE_HPP
00024 
00025 #include <iostream>
00026 #include <vector>
00027 #include <exception_cpe.hpp>
00028 #include <color.hpp>
00029 
00030 
00031 
00032 namespace cpe
00033 {
00034 
00035 class p2d;
00036 
00038 class image
00039 {
00040     public:
00041 
00042         // ********************************************* //
00043         // ********************************************* //
00044         //  CONSTRUCTORS
00045         // ********************************************* //
00046         // ********************************************* //
00047 
00049         image();
00053         image(const unsigned int& N);
00058         image(const unsigned int& Nx,const unsigned int& Ny);
00062         image(const std::string& filename);
00063 
00064 
00065         // ********************************************* //
00066         // ********************************************* //
00067         //  Picture Size
00068         // ********************************************* //
00069         // ********************************************* //
00070 
00072         const unsigned int& get_Nx() const;
00074         const unsigned int& get_Ny() const;
00075 
00079         void resize(const unsigned int& N);
00084         void resize(const unsigned int& Nx,const unsigned int& Ny);
00085 
00090         void reshape(const unsigned int& Nx2);
00091 
00096         bool check_position(const p2d& u) const;
00097 
00098 
00099         // ********************************************* //
00100         // ********************************************* //
00101         //  Pixel access
00102         // ********************************************* //
00103         // ********************************************* //
00104 
00106         const color& operator()(const p2d& index) const;
00108         color& operator()(const p2d& index);
00109 
00111         void set(const p2d& index,const color& c);
00112 
00113 
00114         // ********************************************* //
00115         // ********************************************* //
00116         //  Special pixel filling
00117         // ********************************************* //
00118         // ********************************************* //
00119 
00123         void fill(const color& c);
00129         void fill_rectangle(const p2d& u1,const p2d& u2,const color& c);
00130 
00131 
00132         // ********************************************* //
00133         // ********************************************* //
00134         //  I/O
00135         // ********************************************* //
00136         // ********************************************* //
00137 
00139         void export_file(const std::string& filename);
00140 
00141 
00142 
00143     protected:
00144 
00146         int coordinate_to_index(const p2d& u) const;
00147 
00148     private:
00149 
00150 
00151         // ********************************************* //
00152         // ********************************************* //
00153         //  Internal data
00154         // ********************************************* //
00155         // ********************************************* //
00156 
00161         std::vector<color> internal_data;
00163         unsigned int internal_Nx;
00165         unsigned int internal_Ny;
00166 
00167 
00168 };
00169 
00170 
00172 class exception_image : public exception_cpe
00173 {
00174     public:
00175 
00177         exception_image():exception_cpe(){}
00179         exception_image(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
00180 };
00181 }
00182 
00183 #endif