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

📄 macrgraf.cpp

📁 FreeFem++可以生成高质量的有限元网格。可以用于流体力学
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   greyo = grey;   colorso=colors;   if (nbcolor && nb>2)      {        if(colortable) delete [] colortable;       colortable = new RGBColor[nb];       ncolortable = nb;       if(LastColor>1) LastColor=nb-1;        for (int i0=0;i0<nb;i0++)         {             colortable[i0]=DefColorMacOs(i0,nb,hsv,grey,nbcolors,colors);                     }  /*    for (k=0;k<ncolortable;k++)           cout << " color"  << k                 <<" r = " << colortable[k].red                 <<" g = " << colortable[k].green                <<" b = " << colortable[k].blue << endl;  */                    }     else       ncolortable  =0;}void SetColorTable(int nb){  SetColorTable1(nb,false,0,0);}void closegraphique(void){  if(INITGRAPH)     {      DisposeWindow(grafWindow0);     delete [] colortable;colortable=0;    }  INITGRAPH=0;}void showgraphic(){    if (grafWindow0 != FrontWindow())   { 	ShowWindow(grafWindow0);	BringToFront(grafWindow0);	SelectWindow(grafWindow0);	SetPortWindowPort(grafWindow0); }	GetPort(&grafPort0);	}void reffecran(void){  if(!INITGRAPH) return;    Rect rect;    GetPortBounds(grafPort0,&rect);    EraseRect(&rect); }int getcolor(void){ return 0;}void putpixel(int ix,int iy, int couleur){  if (ncolortable>3 && couleur < ncolortable && couleur >=0 )     SetCPixel(ix,iy,colortable+couleur);} void plotstring(const char *s){  DrawText(s,0,strlen(s)); if(psfile) fprintf(psfile,"(%s) S\n",s);} int LaCouleur(){return lacouleur;}void couleur(int c){   if ( lacouleur == c) // small optim    return;  c= c > LastColor ? 1 : c; // c=Min(c,LastColor); pour noir et blanc  lacouleur =c;  if ( c == 0 )    ForeColor(30);  else if (ncolortable>3 && c < ncolortable && c >=0 )     RGBForeColor(colortable+c);  else    ForeColor(33); if (psfile)  {    float r=1,g=1,b=1;    if (colortable) {      if (c>0 && c < ncolortable)	{	  r =  (float) colortable[c].red /65535.F;	  g =  (float) colortable[c].green /65535.F;	  b =  (float) colortable[c].blue /65535.F;	}    }    else if (c!=0)      r=g=b=0;        fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b);  }   }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 penthickness(int pepais){  PenSize(pepais,pepais);  if (psfile) fprintf(psfile,"%d setlinewidth\n",pepais);}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){  int xasp,yasp, getmaxx, getmaxy;  	getmaxx = xasp =aspx;	getmaxy = yasp = aspy;	  if (getmaxx * (float)xasp > getmaxy * (float)yasp)  {    rymin = centrey - rayon;    rymax = centrey + rayon;    echy= getmaxy / (2 * rayon);    echx= (echy * xasp) / yasp;    rxmin= centrex - getmaxx / (2 * echx);    rxmax= centrex + getmaxx / (2 * echx);  }  else  {    rxmin = centrex - rayon;    rxmax = centrex + rayon;    echx = getmaxx / (2 * rayon);    echy = (echx * yasp) / xasp;    rymin = centrey - getmaxy / (2 * echy);    rymax = centrey + getmaxy / (2 * echy);  }}int scalx(float x){  return int((x - rxmin) * echx);}int scaly(float y){  return 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){  int newx = scalx(x), newy = scaly(y);  putpixel(newx, newy, lacouleur);  if (psfile)    fprintf(psfile,"%d %d P\n", newx, height-newy);  }void rmoveto(float x, float y){  int newx = scalx(x), newy = scaly(y);  MoveTo(newx,newy);  if (psfile)    fprintf(psfile,"%d %d M\n", newx, height-newy);  }void rlineto(float x, float y){  int newx = scalx(x), newy = scaly(y);  LineTo(newx,newy);   if (psfile)     fprintf(psfile,"%d %d L\n", newx,height-newy);  }void raffpoly(int n, float *poly){  PolyHandle thePoly;  int i;  thePoly =OpenPoly();   MoveTo(scalx(poly[0]),scaly( poly[1]));    for(i=1; i<n; i++)    LineTo(scalx(poly[2*i]),scaly( poly[2*i+1]));    ClosePoly();    FillPoly(thePoly,&white);    FramePoly(thePoly);    KillPoly(thePoly);}void fillpoly(int n, float *poly){  PolyHandle thePoly;  int i;  thePoly =OpenPoly();   MoveTo(scalx(poly[0]),scaly( poly[1]));    for(i=1; i<n; i++)    LineTo(scalx(poly[2*i]),scaly( poly[2*i+1]));    ClosePoly();    FillPoly(thePoly,&black);    FramePoly(thePoly);    KillPoly(thePoly);    if (psfile)     {     fprintf(psfile,"bF ");     for (i=0;i<n;i++)      fprintf(psfile,"%d %d ", scalx(poly[2*i]),height-scaly( poly[2*i+1]));     fprintf(psfile,"eF\n");    }}int pStrCopy (StringPtr p1, char * p2)/* copies a pascal string `p1 into a C string */{	int len,i;		len = (*p1++) %256;	for(i=1;i<=len;i++) *p2++=*p1++;	*p2 = 0;	return 0;}int execute(const char* what){  cout << " sorry no execute on MacOs we skip "<< what<<endl;  system(what);  return 1; // error}int DoMouseDown (int windowPart, WindowPtr whichWindow, EventRecord *myEvent){  int wasactive;	switch (windowPart) {		case inGoAway:			if (ours(whichWindow))				if (TrackGoAway(whichWindow, myEvent->where))					{ 					   closegraphique();					   cout << "Fin (fermeture fenetre graphique) " <<endl;					   exit(0);					   //HideWindow(whichWindow);  					} 			break;		case inZoomIn:			if (ours(whichWindow))				{					//SetCursor(&waitCursor);					 SetPortWindowPort(whichWindow);	                                 GetPort(&grafPort0);					 reffecran();					//EraseRect(&(whichWindow->portRect));					ZoomWindow(whichWindow, inZoomIn, true);					InitCursor();				}			break;		case inZoomOut:/*			if (ours(whichWindow))				{					SetCursor(&waitCursor); SetPort(whichWindow);					EraseRect(&(whichWindow->portRect));					ZoomWindow(whichWindow, inZoomOut, true);					if(whichWindow == editWindow) 						 MyZoomWindow(whichWindow);					InitCursor();				}*/			break;		case inMenuBar://			return(DoCommand(MenuSelect(myEvent->where)));            break;		case inSysWindow:			//SystemClick(myEvent, whichWindow);			break;		case inDrag:			if (ours(whichWindow))				{					SetPortWindowPort(whichWindow);				        GetPort(&grafPort0);					DragWindow(whichWindow, myEvent->where, 0);				}			break;		case inGrow:			//if (ours(whichWindow))			//	{MyGrowWindow(whichWindow, myEvent->where);}			break;		case inContent:			wasactive = (whichWindow == FrontWindow()); 	     if(!wasactive) { SelectWindow(whichWindow);	//	    if (ours(whichWindow) && MacReDraw ) (* MacReDraw)();		   }		  else if (ours(whichWindow))			{ SetPortWindowPort(whichWindow);	GetPort(&grafPort0);			   while (Button()) ;			   return 0;			}			break;	}return 1;}char HandleEvent(EventRecord	&	myEvent) {	WindowPtr		whichWindow=NULL;	short			windowPart;          char char1=0;	   switch (myEvent.what) {		case mouseDown:  		windowPart = FindWindow(myEvent.where, &whichWindow);	    if( DoMouseDown(windowPart, whichWindow, &myEvent) ==0) 	      char1=  251;	    break; //////		case keyDown:		case keyUp:		case autoKey: 			{			 windowPart = FindWindow(myEvent.where, &whichWindow);			if((whichWindow==grafWindow0) /* && (inContent == windowPart)*/)				{ if  (grafWindow0 !=  FrontWindow()) { 				     SelectWindow(whichWindow); 		             SetPortWindowPort(whichWindow);	GetPort(&grafPort0);		             }				   char1 = (myEvent.message & 127L);				  				}			break;}	   case updateEvt: 	     if (ours((WindowPtr) myEvent.message)) {	       	BeginUpdate((WindowPtr) myEvent.message);		    EndUpdate((WindowPtr) myEvent.message);	     }	    break;}  return char1;}void  viderbuff(){   QDFlushPortBuffer(grafPort0,0);}char Getijc(int & x,int & y){      char char1=0;   showgraphic();    EventRecord		myEvent;	int flag=1;	HLock( (Handle) WatchCurseur);	SetCursor(*CrossCurseur);	HUnlock( (Handle) WatchCurseur);	SelectWindow(grafWindow0);   while (char1==0) {	if (GetNextEvent(everyEvent, &myEvent) /* ,OxFFFFFFFF,h)*/) 	  char1=HandleEvent(myEvent);	 }   GlobalToLocal( & myEvent.where);   x = myEvent.where.h;   y = myEvent.where.v;	HLock( (Handle) WatchCurseur);	SetCursor(*WatchCurseur);	HUnlock( (Handle) WatchCurseur); //   printf("\t\t x = %d y = %d  c=%d\n", x,y,char1);  return char1;        }char Getxyc(float &x,float &y){   char c;  int i,j;  c = Getijc( i,j);  x = scali(i);  y = scalj(j);  return c;}void rattente(int waitm){ int i,j; char   c=0; if(waitm)  c = Getijc( i,j); if ( c == 3) {cout << "rattente: ^c => abort " << endl;closegraphique();exit(1);}// ^c  => exit/*    you may prefer to use carriage return to move to the next graph *//*	 getc(stdin);*/// if(waitm) while(!Button()){ };}void GetSizeScreen(int & ix,int &iy);void GetScreenSize(int & ix,int &iy){  	ix = width ;  	iy = height;}void openPS(const char *filename ){   char ffff[32];  int count=0;  if(psfile_save) closePS();  time_t t_loc;  float s=0.5;  const int shiftx=50,shifty=50; // char  username[10];  time(&t_loc);  bool notfound;  if( !filename)    do {      struct stat buf;      sprintf(ffff,"rgraph_%.3d.ps",count++);      volatile int r= stat(ffff,&buf) ;      notfound = r !=0;      if(count>1000) break;    } while ( !notfound );     psfile=fopen(filename?filename:ffff,"w");     if(psfile==0) {printf("Erreur %s errno %d\d",filename?filename:ffff,errno);exit(1);}  if(psfile) {  fprintf(psfile,"%%!PS-Adobe-2.0 EPSF-2.0\n%%%%Creator: %s\n%%%%Title: FreeFem++\n","user");  fprintf(psfile,"%%%%CreationDate: %s",ctime(&t_loc));  fprintf(psfile,"%%%%Pages: 1\n");  fprintf(psfile,"%%%%BoundingBox:       %d %d %d %d\n",shiftx,shifty,int(shiftx+width*s),int(shifty+height*s));  fprintf(psfile,"%%%%EndComments\n");  fprintf(psfile," /L {  lineto currentpoint stroke newpath moveto} def\n");  fprintf(psfile," /M {  moveto } def\n");  fprintf(psfile," /C {setrgbcolor} def\n");  fprintf(psfile," /rec {newpath 4 copy 8 1 roll moveto 3 -1 roll lineto 4 2 roll exch lineto lineto closepath} def\n");  fprintf(psfile," %d %d  translate \n",shiftx,shifty);  fprintf(psfile," %f %f  scale \n",s,s);  fprintf(psfile," 0 %d 0 %d rec clip newpath\n",int(width),int(height));  fprintf(psfile," /Helvetica findfont 10 scalefont setfont\n");  fprintf(psfile," /S { show} def\n");  fprintf(psfile," /bF  { mark} def \n");  fprintf(psfile," /eF {newpath moveto counttomark 2 idiv {lineto} repeat closepath fill cleartomark} def\n");  fprintf(psfile," /P { /yy exch def /xx exch def   xx xx 1 add yy yy 1 add  rec  fill } def\n");  fprintf(psfile," 1 setlinewidth\n");  psfile_save=psfile;  }}void closePS(void){  if(psfile_save)   {    fprintf(psfile_save,"showpage\n");    fclose(psfile_save);    }      psfile=0;  psfile_save=0;  }  void Commentaire(const char * c)    {  if(psfile)   {    fprintf(psfile,"%% %s\n",c);   }  };  void NoirEtBlanc(int NB)  {    if(NB) LastColor=1;    else LastColor=ncolortable?ncolortable:2;  }   void MettreDansPostScript(int in)   {     if(in)  psfile=psfile_save;          else    psfile=0;   }static void     FillRect(float x0,float y0, float x1, float y1) {     float r[8];     r[0]=x0;r[1]=y0;     r[2]=x1;r[3]=y0;     r[4]=x1;r[5]=y1;     r[6]=x0;r[7]=y1;     fillpoly(4,r); }float  GetHeigthFont(){   FontInfo 	MyFontInfo;  GetFontInfo(&MyFontInfo);   				 int interligne = MyFontInfo.ascent + MyFontInfo.descent + MyFontInfo.leading; return interligne*0.7/echy;}int PutLevel(int lineno, float xf, int col){  float xmin,xmax,ymin,ymax;  getcadre(xmin,xmax,ymin,ymax);  float xleft = xmax - (xmax-xmin)*0.1;  float ytop  = ymax;  float ydelta = (ymax-ymin)/40;  ydelta=GetHeigthFont();  xleft = xmax - 6*ydelta;    ytop -= ydelta*(col+2);  couleur(col);  FillRect(xleft+ydelta/8.,ytop+ydelta/8.,xleft+ydelta*7./8.,ytop+ydelta*7./8.);  rmoveto(xleft+ydelta*1.4,ytop+ydelta/4);  char buf[30];  sprintf(buf,"%g",xf);  couleur(1);  plotstring(buf);   return lineno;} void ShowHelp(const char * s,int k){  if(k) {    MettreDansPostScript(0);    couleur(1);    float xmin,xmax,ymin,ymax;    getcadre(xmin,xmax,ymin,ymax);    rmoveto(xmin+(xmax-xmin)/100,ymax-(k)*(ymax-ymin)/30);    plotstring(s);    MettreDansPostScript(1);       //  couleur(1);	  }}  void setgrey(bool gg ){grey=gg;}  int getgrey(){ return grey;}class Grid;void SaveMesh(Grid &t){}void SavePlot(int D, Grid& t, double *f){}void SavePlot(int D, Grid& t, float *f){}

⌨️ 快捷键说明

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