⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcrgraph.cpp

📁 FreeFem++可以生成高质量的有限元网格。可以用于流体力学
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// -*- Mode : c++ -*-//// SUMMARY  :      // USAGE    :        // ORG      : // AUTHOR   : D. Bernardi, Y. Darmaillac F. Hecht,     *//*           O. Pironneau, K.Ohtsuka        */// E-MAIL   : hecht@ann.jussieu.fr///*  This file is part of Freefem++  Freefem++ is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.  Freefem++  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 Lesser General Public License for more details.  You should have received a copy of the GNU Lesser General Public License along with Freefem++; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA */#define PCRGRAPH_CPP#define FF_GRAPH_SET_PTR#include <config-wrapper.h>#define TOSTRING1(i) #i#define TOSTRING(i) TOSTRING1(i)#include <ext/stdio_filebuf.h>#include <cstdlib>///#include <unistd.h>#include <cmath>#include <string>#include <setjmp.h>#include <cctype>#include <new>#include <iostream>#include <fstream>using namespace std;//#include "vect.h"#include "error.hpp"#include "strversionnumber.hpp"//#include <memory.h>/*** Windows includes*/#include <windows.h>#include <commdlg.h>///#include <direct.h>#include <time.h>#include <stdio.h>#include <fcntl.h>#include <io.h>      //*OT  use for the console window///#include <stat.h>const char *  edpfilenamearg=0; bool  waitatend=true;#define fill thequikdrawfill#include "rgraph.hpp"//char *Version = "1.2.7";void out_of_memory ();void NEW_HANDLER (void);void myexit(int);void compile(char *fname);float scali(int i);float scalj(int j);//int pStrCopy (StringPtr p1, StringPtr p2);int execute(char* what);//int DoMouseDown (int windowPart, WindowPtr whichWindow, EventRecord *myEvent);char Getijc(int & x,int & y);void postexit();static int  cube6[7][3] ={ {255,0,0},{255,255,0},{0,255,0},      {0,255,255},{0,0,255}, {255,0,255},{255,0,0} }; static  int grey6[2][3] ={ {255,255,255},{0,0,0} }; static bool grey=false;      static int ncolortable=0;static int LastColor=2; // LastColor=1 => Noir et Blanc >2 =>couleurtypedef struct rgb {  BYTE r;    // red component of color  BYTE g;  // green component of color  BYTE b;    // blue component of color}	rgb;static rgb * colortable=0;static HPEN*  hpen=0;static HBRUSH*  hbr=0;static  HFONT  hFont=0;static int fontH = 0;	// The height of fontstatic int cstatic=1;int getcolor();void putpixel(int ix,int iy, int couleur);int scalx(float x);int scaly(float y);void compile (char *);void NEW_HANDLER (void){  set_new_handler (&out_of_memory);}#define ours(w)   (w==grafWindow0)template<class T> inline T Min (const T &a,const T &b){return a < b ? a : b;}template<class T> inline T Max (const T &a,const T & b){return a > b ? a : b;}char errbuf[255];static int INITGRAPH=0;float rayon;static int width,height;static FILE *psfile = 0;static FILE *psfile_save = 0;static float aspx, aspy, echx,echy,ech,rxmin,rxmax,rymin,rymax;static int currx, curry;static int carre;static HWND        hWnd;static WNDCLASS    rClass;static HDC hdc;static HANDLE hConOut=0;const float fMinPixel = -32000; // to avoid int overflot const float fMaxPixel = 32000;/* Function definitions */BOOL Init(HINSTANCE, HINSTANCE, LPSTR, int);int  DoMain(HINSTANCE hInstance);LONG WINAPI OpenWindowProc1(HWND, UINT, WPARAM, LPARAM);int getcolor();void putpixel(int ix,int iy, int couleur);int scalx(float x);int scaly(float y);void rattente (int);BOOL inittext(VOID);BOOL ShowOpenDialogBox(char *fileName);BOOL CreateProjetFile(char *fileName);char *ChangePdeToExt(char *fileName,char *ext);BOOL mainFreeFEM();int GetFileName(char *fullname, char  *shortname);DWORD GetOption(char lpszCmdLine[]);void SetConsole(HANDLE hConsole);FILE *GetConsoleHandle(DWORD Dev);BOOL GetConsoleBuff();BOOL EditLog();//void SaveMesh(Grid& t);//void SavePlot(int D,Grid& t, Real *f);BOOL FatalErr(char *s, int err);//BOOL CheckSameTrig(Grid& t);//*OT  flag for FreeFEM+/WinfFEM#define winf_VFFEM 1#define winf_NOWAIT 2#define winf_NOCOLOR 4#define winf_NOEDIT 8#define  winf_Usage   1024unsigned int winf_flg = 0;// endchar FreeFemCache[256]="\0",     shortName[256]="\0",     fullName[256]="\0";          void fillpoly(int n, float *poly){   POINT *pt;      pt = new POINT[n];   for (int i=0; i < n; i++) {      pt[i].x = scalx(poly[2*i]); pt[i].y = scaly(poly[2*i+1]);     }      if (cstatic <0  || cstatic > ncolortable)  cstatic =1;   SelectObject(hdc,hbr[cstatic]);   int ret = Polygon(hdc,pt,n);   delete []  pt;   SelectObject(hdc,hpen[n]);    if (psfile)     {     fprintf(psfile,"bF ");     for (int i=0;i<n;i++)      fprintf(psfile,"%d %d ", scalx(poly[2*i]),height-scaly( poly[2*i+1]));     fprintf(psfile,"eF\n");    }} void out_of_memory (){  cout << " error: operator new failed; not enough memory" << endl;  myexit (1);}void erreur(char *s){   ErrorExec(s,0); }void HandleWindowEvent(){  MSG msg;  //if ( PeekMessage(&msg,NULL,WM_PAINT,WM_PAINT,PM_NOREMOVE)) {if ( PeekMessage(&msg,NULL,0,0,PM_NOREMOVE)) {    	TranslateMessage(&msg);   		DispatchMessage(&msg);  	}  	}void SetColorTable(int n);void raffpoly(int n, float *poly){}#include "getprog-unix.hpp"    void penthickness(int pepais){  if (psfile) fprintf(psfile,"%d setlinewidth\n",pepais);}void showgraphic(){ShowWindow(hWnd, SW_SHOW ); } // UpdateWindow(hWnd);}void thisexit(){ myexit(0);}    void plotstring(const char *s){    static  HFONT  hOldFont;    if (s == 0) return;    hOldFont = (HFONT)::SelectObject(hdc,hFont);    //::GetTextMetrics(hdc, &tm);    ::TextOut(hdc, currx, curry-fontH, s, strlen(s));    ::DeleteObject(hOldFont);	  if(psfile) {	     fprintf(psfile,"%d %d M\n", currx,height-curry);	     fprintf(psfile,"(%s) S\n",s);	  }}void rmoveto(float x, float y){	currx = scalx(x);	curry = scaly(y);}         void rlineto(float x, float y){  HandleWindowEvent();  int newx = scalx(x), newy = scaly(y);  MoveToEx(hdc,currx,curry,NULL);  LineTo(hdc,newx,newy);  if (psfile) {    fprintf(psfile,"%d %d M\n", currx,height-curry);      fprintf(psfile,"%d %d L\n", newx,height-newy);  }  currx = newx; curry = newy;}void cadre(float xmin,float xmax,float ymin,float ymax){	rxmin = xmin;	rxmax = xmax;	rymin = ymin;	rymax = ymax;	echx=aspx/(xmax-xmin);	echy=aspy/(ymax-ymin); }void getcadre(float &xmin,float &xmax,float &ymin,float &ymax){  xmin = rxmin;  xmax = rxmax;  ymin = rymin;  ymax = rymax;}void cadreortho(float centrex, float centrey, float rayon){	RECT rc;	GetClientRect(hWnd, &rc);	width = rc.right - rc.left;	height = rc.bottom - rc.top;  if (height < width)  {    rymin = centrey - rayon;    rymax = centrey + rayon;    echx = echy= height / (2 * rayon);    rxmin= centrex - width / (2 * echx);    rxmax= centrex + width / (2 * echx);  }  else  {    rxmin = centrex - rayon;    rxmax = centrex + rayon;    echx = echy = width / (2 * rayon);    rymin = centrey - height / (2 * echy);    rymax = centrey + height / (2 * echy);  }}int scalx(float x){  return static_cast<int>((x - rxmin) * echx);}int scaly(float y){  return static_cast<int>((rymax - y) * echy);}float scali(int i){  return i/echx  + rxmin;}float scalj(int j){  return -j/echy  + rymax;}void pointe(float x, float y){//  putpixel(scalx(x), scaly(y), LastColor);}int InRecScreen(float x1, float y1,float x2, float y2){    float xi = Min(x1,x2),xa=Max(x1,x2);  float yi = Min(y1,y2),ya=Max(y1,y2);  return (xa >= rxmin) && (xi <= rxmax) && (ya >= rymin) && (yi <= rymax);}int InPtScreen( float x, float y){  return (x >= rxmin) && (x <= rxmax) && (y >= rymin) && (y <= rymax);}void SetRGBpen(int n){    SelectObject(hdc, hpen[n]);}static rgb DefColorWin32( int k,int nb, bool hsv,bool grey,int nbcolors,float *colors){ rgb C; float r,g,b;extern void DefColor(float & r, float & g, float & b,              int k,int nb, bool hsv,bool grey,int nbcolors,float *colors); DefColor(r,g,b,   k,nb,hsv,grey,nbcolors,colors); C.r=255*r; C.g=255*g; C.b=255*b; return C;}              void SetColorTable1(int nb,bool hsv,int nbcolors,float *colors){  static bool greyo = !grey;  static float * colorso =0;  if(!INITGRAPH) return;  if (ncolortable == nb && greyo == grey && colorso == colors ) return;// optim   greyo = grey;   colorso=colors;   {      if (hpen) for(int i=0; i<ncolortable;i++)       DeleteObject(hpen[i]);     delete [] hpen;     if (hbr) for(int i=0; i<ncolortable;i++)       DeleteObject(hbr[i]);     delete [] hbr;     if (hFont) DeleteObject(hFont);     hpen=0;     hbr=0;     hFont=0;          if(colortable)        delete [] colortable;     colortable = new rgb[nb+1];     ncolortable = nb;     if(LastColor>1) LastColor=nb-1;     for (int i0=0;i0<nb;i0++)       {  	 colortable[i0]=DefColorWin32(i0,nb,hsv,grey,nbcolors,colors);                  }        }      {          hpen = new HPEN[ncolortable];     hbr = new HBRUSH[ncolortable];          for(int i=0; i<ncolortable;i++)       {	 hpen[i] = CreatePen(PS_INSIDEFRAME, 1,RGB(colortable[i].r, 						   colortable[i].g,						   colortable[i].b));	 hbr[i] = CreateSolidBrush(RGB(colortable[i].r, 				       colortable[i].g,				       colortable[i].b));	 }   }   }void SetColorTable(int nb){  RECT rc;  GetClientRect(hWnd, &rc);  aspx = (float)(rc.right - rc.left);  aspy = (float)(rc.bottom - rc.top);    if (winf_flg & winf_NOCOLOR) return;  nb=Max(nb,23);  if(nb<2) nb = 2;  if (ncolortable == nb) return;  if(LastColor>1) LastColor=nb-1;    if (hpen) for(int i=0; i<ncolortable;i++)    DeleteObject(hpen[i]);  delete [] hpen;  if (hbr) for(int i=0; i<ncolortable;i++)    DeleteObject(hbr[i]);  delete [] hbr;  if (hFont) DeleteObject(hFont);  hpen=0;  hbr=0;  hFont=0;    if(colortable)     delete [] colortable;  colortable = new rgb[nb+1];  ncolortable = nb;  int k=0;  colortable[k].r = 255;  colortable[k].g = 255;  colortable[k++].b = 255;  colortable[k].r = 0;  colortable[k].g = 0;  colortable[k++].b = 0;  if (nb>2)     {       nb -= 2;      for (long i0=0;i0<nb;i0++,k++)        {  	  long  i6 = i0*6;	  long  j0 = i6/nb;// in 0..6	  long  j1 = j0+1;// in 1..6	  long  k0 = i0 - (nb*j0)/6L;	  long  k1 = (nb*j1)/6L-i0;	  long  kk = (k0+k1);	  	  if (! grey)	    {	      colortable[k].r  = ((cube6[j1][0]*k0+cube6[j0][0]*k1)/kk);	      colortable[k].g  = ((cube6[j1][1]*k0+cube6[j0][1]*k1)/kk);	      colortable[k].b  = ((cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);	    }          else 	    {	      kk=nb-1;	      k1 =  i0;	      k0 = nb - i0 -1;	      colortable[k].r   = ((grey6[0][0]*k0+grey6[1][0]*k1)/kk);	      colortable[k].g   = ((grey6[0][1]*k0+grey6[1][1]*k1)/kk);	      colortable[k].b   = ((grey6[0][2]*k0+grey6[1][2]*k1)/kk);	    }	  	  /*	    colortable[k].r = ((cube6[j1][0]*k0+cube6[j0][0]*k1)/kk)%256;	    colortable[k].g = ((cube6[j1][1]*k0+cube6[j0][1]*k1)/kk)%256;	    colortable[k].b = ((cube6[j1][2]*k0+cube6[j0][2]*k1)/kk)%256;	  */        }             }  else     {	ncolortable  =2;}    hpen = new HPEN[ncolortable];  hbr = new HBRUSH[ncolortable];    for(int i=0; i<ncolortable;i++)    {      hpen[i] = CreatePen(PS_INSIDEFRAME, 1,RGB(colortable[i].r, 						colortable[i].g,						colortable[i].b));      hbr[i] = CreateSolidBrush(RGB(colortable[i].r, 				    colortable[i].g, 				    colortable[i].b));    }}void couleur(int c){   if(c!=cstatic)   {     c= c > LastColor ? 1 : c; // c=Min(c,LastColor); pour noir et blanc    if (!(winf_flg&winf_NOCOLOR)) {    if (c>=0 && c < ncolortable)    	cstatic = c;    else cstatic = 1;  	SetRGBpen(cstatic);  	}  // else  SetRGBpen(1);  }  if (psfile)  {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -