MC_grid_3d_scalar_slicer.cpp

Go to the documentation of this file.
00001 
00002 #include <MC_grid_3d_scalar_slicer.hpp>
00003 
00004 #include <MC_grid_3d_scalar.hpp>
00005 #include <MC_mesh_index_vector.hpp>
00006 
00007 #include <cmath>
00008 
00009 namespace mesh_conv
00010 {
00011     MC_double_vector MC_grid_3d_scalar_slicer::slice(const MC_grid_3d_scalar& potential,const MC_mesh_index_vector& mesh)
00012     {
00013         MC_double_vector v=MC_double_vector::zeros(mesh.vertex_number());
00014         for(unsigned int k=0,N=mesh.vertex_number();k<N;++k)
00015             v[k]=potential(mesh.point_set()(k));
00016         return v;
00017     }
00018 
00019     void MC_grid_3d_scalar_slicer::export_square_ppm_file(const std::string& filename,const MC_double_vector& value,const unsigned int& N0,const unsigned int& N1)
00020     {
00021         if(N0*N1 != value.size())
00022         {exception::MC_exception("Error in MC_grid_3d_scalar_slicer::export_square_ppm_file size does not match ");}
00023 
00024         std::ofstream stream(filename.c_str());
00025         if(stream.good()!=true)
00026         {exception::MC_exception("Cannot open file "+filename+" in MC_grid_3d_scalar_slicer::export_square_ppm_file");}
00027         export_square_ppm(stream,value,N0,N1);
00028         stream.close();
00029     }
00030 
00031     void MC_grid_3d_scalar_slicer::export_square_ppm(std::ofstream& stream,const MC_double_vector& value,const unsigned int& N0,const unsigned int& N1)
00032     {
00033         if(N0*N1 != value.size())
00034         {exception::MC_exception("Error in MC_grid_3d_scalar_slicer::export_square_ppm size does not match ");}
00035 
00036         stream<<"P3"<<std::endl; // magic number
00037         stream<<N0<<" "<<N1<<std::endl;
00038         stream<<"255"<<std::endl;
00039         for(unsigned int k0=0;k0<N0;k0++)
00040         {
00041             for(unsigned int k1=0;k1<N1;k1++)
00042             {
00043                 int v = static_cast<int>(std::min(std::max(static_cast<double>(value[k0+k1*N0]),static_cast<double>(0)),static_cast<double>(255)));
00044                 stream<<v<<" "<<v<<" "<<v<<std::endl;
00045             }
00046         }
00047     }
00048 
00049 }

Generated on Sun Apr 18 20:24:47 2010 by  doxygen 1.6.1