Texture.cpp

Go to the documentation of this file.
00001 
00002 #include <fstream>
00003 #include <Texture.hpp>
00004 
00005 
00006 void Texture::export_ppm(const std::string& filename,const unsigned int& size_1,const int& size_2,const std::vector <float>& red_channel,const std::vector<float>& green_channel,const std::vector<float>& blue_channel)
00007 {
00008     std::ofstream stream(filename.c_str(),std::ofstream::out);
00009     if(!stream.good())
00010         throw std::string("Error in Texture::export_ppm("+filename+"...) : cannot open file \n");
00011 
00012     //magic number
00013     stream<<"P3 \n";
00014     //size
00015     stream<<size_2<<" "<<size_1<<" \n";
00016     //color number
00017     stream<<"255"<<std::endl;
00018 
00019                 for(int k2=0;k2<size_2;++k2)
00020     {
00021     for(unsigned int k1=0;k1<size_1;++k1)
00022         {
00023             int r=std::min(std::max(static_cast<int>(red_channel  [k1+size_1*k2]),0),255);
00024             int g=std::min(std::max(static_cast<int>(green_channel[k1+size_1*k2]),0),255);
00025             int b=std::min(std::max(static_cast<int>(blue_channel [k1+size_1*k2]),0),255);
00026 
00027             stream<<r<<" "<<g<<" "<<b<<std::endl;
00028         }
00029     }
00030     stream.close();
00031 
00032 }

Generated on Sun Jan 24 21:30:26 2010 by  doxygen 1.6.1