PolyBoRi
draw_matrix.h
Go to the documentation of this file.
00001 // -*- c++ -*-
00002 //*****************************************************************************
00014 //*****************************************************************************
00015 
00016 #ifndef polybori_groebner_draw_matrix_h_
00017 #define polybori_groebner_draw_matrix_h_
00018 
00019 // include basic definitions
00020 #include "groebner_defs.h"
00021 
00022 #ifdef PBORI_HAVE_GD
00023 #define DRAW_MATRICES
00024 #endif
00025 #ifdef DRAW_MATRICES
00026 #include <stdio.h>
00027 #include <gd.h>
00028 #endif
00029 
00030 BEGIN_NAMESPACE_PBORIGB
00031 
00032 
00033 inline void
00034 draw_matrix(mzd_t* mat, const char* filename){
00035     #ifdef DRAW_MATRICES
00036     int i,r,c,j;
00037     c=mat->ncols;
00038     r=mat->nrows;
00039     gdImagePtr im = gdImageCreate(c, r) ;
00040      FILE * out = fopen(filename, "wb") ;
00041  int black = gdImageColorAllocate(im, 0, 0, 0) ;
00042  int white = gdImageColorAllocate(im, 255, 255, 255); 
00043  gdImageFilledRectangle(im, 0, 0, c-1, r-1, white) ;
00044  
00045  for(i=0;i<r;i++){
00046      for(j=0;j<c;j++){
00047          if (mzd_read_bit(mat, i, j))
00048              gdImageSetPixel(im, j, i, black );
00049      }
00050  }
00051   
00052 
00053  gdImagePng(im, out);
00054  gdImageDestroy(im);
00055  fclose(out);
00056  #else
00057  std::cerr<<"warning: for drawing matrices compile with GD";
00058  #endif
00059 }
00060 
00061 END_NAMESPACE_PBORIGB
00062 
00063 #endif /* polybori_groebner_draw_matrix_h_ */