Newer
Older
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software

Christophe Geuzaine
committed
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
#include "Gmsh.h"
#include "GmshUI.h"
#include "Mesh.h"
#include "Draw.h"
#include "Context.h"
#include "gl2ps.h"
#include "gl2gif.h"
#include "gl2jpeg.h"
#include "gl2ppm.h"
#include "gl2yuv.h"
InitOpengl();
ClearOpengl();
Draw3d();
Draw2d();
}
oldformat = CTX.print.format;
CTX.print.format = format;
width = viewport[2]-viewport[0];
height = viewport[3]-viewport[1];
for(len = strlen(name) - 1; len >= 0; len--) {
if(name[len] == '.') {
strcpy(ext, &name[len]);
if(!strcmp(ext, ".geo")) CreateOutputFile(name, FORMAT_GEO);
else if(!strcmp(ext, ".opt")) CreateOutputFile(name, FORMAT_OPT);
else if(!strcmp(ext, ".msh")) CreateOutputFile(name, FORMAT_MSH);
else if(!strcmp(ext, ".unv")) CreateOutputFile(name, FORMAT_UNV);
else if(!strcmp(ext, ".dmg")) CreateOutputFile(name, FORMAT_DMG);
else if(!strcmp(ext, ".pos")) CreateOutputFile(name, FORMAT_LC_SUR);
else if(!strcmp(ext, ".gif")) CreateOutputFile(name, FORMAT_GIF);
else if(!strcmp(ext, ".jpg")) CreateOutputFile(name, FORMAT_JPEG);
else if(!strcmp(ext, ".jpeg")) CreateOutputFile(name, FORMAT_JPEG);
else if(!strcmp(ext, ".png")) CreateOutputFile(name, FORMAT_PNG);
else if(!strcmp(ext, ".ps")) CreateOutputFile(name, FORMAT_PS);
else if(!strcmp(ext, ".eps")) CreateOutputFile(name, FORMAT_EPS);
else if(!strcmp(ext, ".pdf")) CreateOutputFile(name, FORMAT_PDF);
else if(!strcmp(ext, ".tex")) CreateOutputFile(name, FORMAT_TEX);
else if(!strcmp(ext, ".epstex")) CreateOutputFile(name, FORMAT_EPSTEX);
else if(!strcmp(ext, ".pdftex")) CreateOutputFile(name, FORMAT_PDFTEX);
else if(!strcmp(ext, ".jpegtex")) CreateOutputFile(name, FORMAT_JPEGTEX);
else if(!strcmp(ext, ".ppm")) CreateOutputFile(name, FORMAT_PPM);
else if(!strcmp(ext, ".yuv")) CreateOutputFile(name, FORMAT_YUV);
else if(!strcmp(ext, ".gref")) CreateOutputFile(name, FORMAT_GREF);
else if(!strcmp(ext, ".Gref")) CreateOutputFile(name, FORMAT_GREF);
else if(!strcmp(ext, ".wrl")) CreateOutputFile(name, FORMAT_VRML);
Msg(GERROR, "Unknown extension '%s' for automatic format detection", ext);
break;
case FORMAT_LC_SUR:
ExportLcFieldOnSurfaces(&M, name);
Msg(STATUS2N, "Wrote '%s'", name);
break;
case FORMAT_LC_VOL:
ExportLcFieldOnVolume(&M, name);
Msg(STATUS2N, "Wrote '%s'", name);
break;
if(!(fp = fopen(name, "wb"))) {
Msg(GERROR, "Unable to open file '%s'", name);
create_jpeg(fp, width, height,
CTX.print.jpeg_quality, CTX.print.jpeg_smoothing);
if(!(fp = fopen(name, "wb"))) {
Msg(GERROR, "Unable to open file '%s'", name);
CTX.print.gif_dither,
CTX.print.gif_sort,
CTX.print.gif_interlace,
CTX.print.gif_transparent,
UNPACK_RED(CTX.color.bg),
UNPACK_GREEN(CTX.color.bg), UNPACK_BLUE(CTX.color.bg));
if(!(fp = fopen(name, "wb"))) {
Msg(GERROR, "Unable to open file '%s'", name);
return;
}
break;
case FORMAT_PS:
psformat = GL2PS_PS;
break;
default:
psformat = GL2PS_EPS;
break;
if(CTX.print.eps_quality == 0){
if(format == FORMAT_EPSTEX || format == FORMAT_PDFTEX)
CTX.print.gl_fonts = 0;
FillBuffer();
CTX.print.gl_fonts = 1;
pixels = new float[width * height * 3];
glReadPixels(0, 0, width, height, GL_RGB, GL_FLOAT, pixels);
}
pssort = (CTX.print.eps_quality == 2) ? GL2PS_BSP_SORT : GL2PS_SIMPLE_SORT;
(CTX.print.eps_occlusion_culling ? GL2PS_OCCLUSION_CULL : 0) |
(CTX.print.eps_best_root ? GL2PS_BEST_ROOT : 0) |
(CTX.print.eps_background ? GL2PS_DRAW_BACKGROUND : 0) |
(CTX.print.eps_compress ? GL2PS_COMPRESS : 0) |
Msg(INFO, "Writing %s file '%s'", (psformat == GL2PS_PDF) ? "PDF" : "PS/EPS", name);
size3d = 0;
res = GL2PS_OVERFLOW;
while(res == GL2PS_OVERFLOW) {
size3d += 2048 * 2048;
gl2psBeginPage(CTX.base_filename, "Gmsh", viewport,
psformat, pssort, psoptions, GL_RGBA, 0, NULL,
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glPushMatrix();
gl2psDrawPixels(width, height, 0, 0, GL_RGB, GL_FLOAT, pixels);
glPopMatrix();
delete [] pixels;
}
else{
CTX.print.gl_fonts = 0;
FillBuffer();
CTX.print.gl_fonts = 1;
}
res = gl2psEndPage();
}
Msg(INFO, "Wrote %s file '%s'", (psformat == GL2PS_PDF) ? "PDF" : "PS/EPS", name);
Msg(STATUS2N, "Wrote '%s'", name);

Christophe Geuzaine
committed
fclose(fp);
case FORMAT_TEX:
if(!(fp = fopen(name, "w"))) {
Msg(GERROR, "Unable to open file '%s'", name);
GL2PS_TEX, GL2PS_NO_SORT, GL2PS_SILENT, GL_RGBA, 0, NULL,
0, 0, 0, 1000, fp, name);
CTX.print.gl_fonts = 0;
FillBuffer();
CTX.print.gl_fonts = 1;
res = gl2psEndPage();
Msg(INFO, "Wrote TEX file '%s'", name);
Msg(STATUS2N, "Wrote '%s'", name);
fclose(fp);
break;
CTX.print.format = oldformat;