00001
00002
00014
00015
00016 #ifndef polybori_groebner_draw_matrix_h_
00017 #define polybori_groebner_draw_matrix_h_
00018
00019
00020 #include "groebner_defs.h"
00021
00022 #ifdef PBORI_HAVE_GD
00023 #include <stdio.h>
00024 #include <gd.h>
00025 #endif
00026
00027 #ifdef PBORI_HAVE_M4RI_PNG
00028 #include <m4ri/io.h>
00029 #include <stdexcept>
00030 #endif
00031
00032 BEGIN_NAMESPACE_PBORIGB
00033
00034
00035 inline void
00036 draw_matrix(mzd_t* mat, const char* filename){
00037
00038 if ((mat->ncols == 0) || (mat->nrows == 0)) {
00039 std::cerr << "0-dimensional matrix cannot be drawed, skipping "<< filename<<"" <<std::endl;
00040 return;
00041 }
00042
00043 #ifdef PBORI_HAVE_M4RI_PNG
00044
00045 int err = mzd_to_png(mat, filename, 9, "Generated by PolyBoRi", 0);
00046 assert(err == 0);
00047
00048 if (err)
00049 throw std::runtime_error("Error writing png");
00050
00051 #elif defined(PBORI_HAVE_GD)
00052 int i,r,c,j;
00053 c=mat->ncols;
00054 r=mat->nrows;
00055 gdImagePtr im = gdImageCreate(c, r) ;
00056 FILE * out = fopen(filename, "wb") ;
00057 int black = gdImageColorAllocate(im, 0, 0, 0) ;
00058 int white = gdImageColorAllocate(im, 255, 255, 255);
00059 gdImageFilledRectangle(im, 0, 0, c-1, r-1, white) ;
00060
00061 for(i=0;i<r;i++){
00062 for(j=0;j<c;j++){
00063 if (mzd_read_bit(mat, i, j))
00064 gdImageSetPixel(im, j, i, black );
00065 }
00066 }
00067
00068 gdImagePng(im, out);
00069 gdImageDestroy(im);
00070 fclose(out);
00071
00072 #else
00073 std::cerr<<"warning: for drawing matrices compile with png support";
00074 #endif
00075
00076 }
00077
00078 END_NAMESPACE_PBORIGB
00079
00080 #endif