simplepic.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 * VCGLib                                                            o o     *
00003 * Visual and Computer Graphics Library                            o     o   *
00004 *                                                                _   O  _   *
00005 * Copyright(C) 2004                                                \/)\/    *
00006 * Visual Computing Lab                                            /\/|      *
00007 * ISTI - Italian National Research Council                           |      *
00008 *                                                                    \      *
00009 * All rights reserved.                                                      *
00010 *                                                                           *
00011 * This program is free software; you can redistribute it and/or modify      *   
00012 * it under the terms of the GNU General Public License as published by      *
00013 * the Free Software Foundation; either version 2 of the License, or         *
00014 * (at your option) any later version.                                       *
00015 *                                                                           *
00016 * This program is distributed in the hope that it will be useful,           *
00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             *
00019 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)          *
00020 * for more details.                                                         *
00021 *                                                                           *
00022 ****************************************************************************/
00023 /****************************************************************************
00024   History
00025 
00026 $Log: not supported by cvs2svn $
00027 
00028 ****************************************************************************/
00029 
00030 #ifndef __VCG_SIMPLE_PIC
00031 #define __VCG_SIMPLE_PIC
00032 #include <vcg/math/matrix44.h>
00033 
00034 namespace vcg {
00035   template <class PixType> 
00036   class SimplePic
00037   {public:
00038     std::vector<PixType> img;
00039    int sx,sy;
00040    void Create(int tx,int ty)
00041    {
00042      sx=tx;sy=ty;
00043      img.resize(sx*sy);
00044    }
00045    PixType &Pix(int x, int y) {return img[sx*y+x];}
00046 
00047    void OpenGLSnap(GLenum format=0)
00048         {
00049                 int vp[4];
00050                 glGetIntegerv( GL_VIEWPORT,vp );                // Lettura viewport
00051                 glPixelStorei( GL_PACK_ROW_LENGTH, 0);
00052                 glPixelStorei( GL_PACK_ALIGNMENT, 1);
00053                 int tx = vp[2];
00054                 int ty = vp[3];
00055 
00056                 Create(tx,ty);
00057 
00058                 GLenum mtype  = 0;
00059 
00060                 if(format==0) {
00061                                 format = GL_RGBA;
00062         mtype = GL_UNSIGNED_BYTE;
00063                 }
00064                 if(format==GL_DEPTH_COMPONENT) {
00065                                 format = GL_DEPTH_COMPONENT;
00066         mtype = GL_FLOAT;
00067                 }
00068                 glReadPixels(vp[0],vp[1],vp[2],vp[3],format,mtype,(GLvoid *)&img[0]);
00069         }
00070         bool SavePPM( const char * filename )
00071         {
00072                 FILE * fp = fopen(filename,"wb");
00073                 if(fp==0) return false;
00074 
00075 
00076                         fprintf(fp,"P6\n%d %d\n255\n",sx,sy);
00077 
00078                         for(int i=0;i<sx*sy;++i)
00079                         {
00080                          fwrite(&(img[i]),3,1,fp);
00081                         }
00082         
00083                 fclose(fp);
00084                 return true;
00085         }
00086 
00087 };
00088 
00089 }
00090 #endif // __VCG_MESH_VISIBILITY


shape_reconstruction
Author(s): Roberto Martín-Martín
autogenerated on Sat Jun 8 2019 18:35:23