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

📄 glrgraph.hpp

📁 FreeFem++可以生成高质量的有限元网格。可以用于流体力学
💻 HPP
📖 第 1 页 / 共 3 页
字号:
    short int fNum;    // cout <<" GetFNum \n";    unsigned char buf10[10];    GetFNum(c2p("Geneva",buf10), &fNum);									// build font	fontList = BuildFontGL (ctx, fNum, normal, 9); #endif#ifdef XGL {    XVisualInfo* vi;    Colormap cmap;    XSetWindowAttributes swa;    static int attrib[] = { GLX_RGBA,			    GLX_DOUBLEBUFFER,			    GLX_RED_SIZE, 1,			    GLX_GREEN_SIZE, 1,			    GLX_BLUE_SIZE, 1,			    GLX_DEPTH_SIZE, 16,			    GLX_STENCIL_SIZE, 4,			    None };    /* get a connection */      dpy = XOpenDisplay(0);  if (!dpy)     {      cerr << " Error openning  dpy " << endl;      exit(2);    }    /* get an appropriate visual */    vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrib);    if (vi == NULL) {	fprintf(stderr, "Can't find a satisfactory visual.  Abort.\n");	exit(1);    }    glXGetConfig(dpy, vi, GLX_STENCIL_SIZE, &stensize);    /* create a GLX context */    cx = glXCreateContext(dpy, vi, 0, GL_TRUE);    /* create a color map */    cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen),                           vi->visual, AllocNone);    /* create a window */    swa.colormap = cmap;    swa.border_pixel = 0;    swa.event_mask = StructureNotifyMask;    height = 512;    width = 512;	aspx = width;	aspy =height;    win = XCreateWindow(dpy, RootWindow(dpy, vi->screen), 0, 0, width, height,                        0, vi->depth, InputOutput, vi->visual,                        CWBorderPixel|CWColormap|CWEventMask, &swa);    XMapWindow(dpy, win);	glXMakeCurrent(dpy, win, cx);     cursor_arrow = XCreateFontCursor(dpy,XC_arrow);    cursor_watch = XCreateFontCursor(dpy,XC_watch);    XDefineCursor(dpy,win,cursor_watch);    MyXSelectInput (dpy, win, (int) (ExposureMask				       | KeyPressMask				       | KeyReleaseMask				       | ButtonPressMask				       | ButtonReleaseMask				       /*                               | ResizeRedirectMask   */				       | StructureNotifyMask)		  );   font_info = XLoadQueryFont(dpy, "6x9");  //XSetFont(dpy, gc, font_info->fid);  {unsigned int first, last; 	     int id = font_info->fid;    first = font_info->min_char_or_byte2;    last = font_info->max_char_or_byte2;         fontList = glGenLists(last+1);    if (fontList == 0) {        printf ("out of display lists\n");    exit (1);    }    glXUseXFont(id, first, last-first+1, fontList+first);         }}        #endif#ifdef WGL    a faire #endif	carre = aspx == aspy;	lacouleur = getcolor();	nbcolor= 256; 	ncolortable =0;	LastColor=2;// En couleur pas defaul	colortable=0;	SetColorTable(2+6);	INITGRAPH = 1;    gluOrtho2D(0.0, height,0,width);    glLineWidth(1);	    // cout <<" End Initgraphique\n";}static RGBColor DefColorGL( int k,int nb, bool hsv,bool grey,int nbcolors,float *colors){ RGBColor 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.red= (short unsigned int) (65535*r); C.green=(short unsigned int)(65535*g); C.blue= (short unsigned int) (65535*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 (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]=DefColorGL(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){  if(!INITGRAPH) return;   if (ncolortable == nb) return;// optim   if (nbcolor && nb>2)      {        if(colortable) delete [] colortable;       colortable = new RGBColor[nb];       ncolortable = nb;       if(LastColor>1) LastColor=nb-1;       int k=0;       colortable[k].red=65534;       colortable[k].green=65534;       colortable[k].blue=65534;       k++;       colortable[k].red=0;       colortable[k].green=0;       colortable[k].blue=0;       k++;       nb = nb -2;       for (long i0=0;i0<nb;i0++,k++)         {        //     long  i1 = nb - i0;           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;           //cout << "\t\t" << i0 << " " << j0 << " " << j1 << " " << k0 << " " << k1  << " "<<kk<<endl;         	if(kk<=0) kk=1;         // throwassert(kk);                   if (! grey)           {           colortable[k].red   = (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk;           colortable[k].green = (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk;           colortable[k].blue  = (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk;           }          else            {           kk=nb-1;           k1 =  i0;           k0 = nb - i0 -1;           colortable[k].red   = (grey6[0][0]*k0+grey6[1][0]*k1)/kk;           colortable[k].green = (grey6[0][1]*k0+grey6[1][1]*k1)/kk;           colortable[k].blue  = (grey6[0][2]*k0+grey6[1][2]*k1)/kk;           }                /*    colortable[k].red   = (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk;           colortable[k].green = (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk;           colortable[k].blue  = (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk;*/            throwassert(k<ncolortable);                     }  /*    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 closegraphique(void){  if(INITGRAPH)     {     	DeleteFontGL (fontList);#ifdef AGL 		aglSetCurrentContext (NULL);	aglSetDrawable (ctx, NULL);	aglDestroyContext (ctx);    DisposeWindow(grafWindow0);#endif#ifdef XGL      XUnloadFont(dpy, font_info->fid);//      XFreeGC(dpy, gc);      XCloseDisplay(dpy);#endif#ifdef WGL  a faire #endif      closePS();         delete [] colortable;colortable=0;    }  INITGRAPH=0;}void showgraphic(){#ifdef AGL  if (grafWindow0 != FrontWindow())   { 	ShowWindow(grafWindow0);	BringToFront(grafWindow0);	SelectWindow(grafWindow0);	SetPortWindowPort(grafWindow0); }	GetPort(&grafPort0);#endif	}void reffecran(void){  if(!INITGRAPH) return;  		glClearColor(1.f, 1.f, 1.f, 1.0f);		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); /* Clear buffer */ }int getcolor(void){ return lacouleur;}void putpixel(int ix,int iy, int couleur){//  if (ncolortable>3 && couleur < ncolortable && couleur >=0 ) //    SetCPixel(ix,iy,colortable+couleur);//  DrawCStringGL ((char*) glGetString (GL_VENDOR), fontList);  glBegin(GL_POINTS);  glVertex2i(ix, height-iy);  glEnd();} void plotstring(const char *s){ // cout << "plotstring" << s << endl;int lx=0,l = strlen(s); DrawCStringGL(s,fontList);#ifdef XGL  lx = XTextWidth( font_info,s,l);#endif if(psfile) fprintf(psfile,"(%s) S\n",s); currx += lx;} 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;    float r=1,g=1,b=1;      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; 	glColor4f (r,g,b,1.);    if (psfile)     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);  glLineWidth(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){  float 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);  } // cout << "cadreortho\n";}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);  currx = newx; curry = newy;  }void rlineto(float x, float y){  int newx = scalx(x), newy = scaly(y);  glBegin(GL_LINES);  glVertex2i(currx, height-curry);  glVertex2i(newx, height-newy);  glEnd();   if (psfile)     fprintf(psfile,"%d %d L\n", newx,height-newy);  currx = newx; curry = newy;  }void fillpoly(int n, float *poly){  glBegin(GL_POLYGON);  for (int i=0;i<n;i++)    glVertex2i(scalx(poly[2*i]),height-scaly( poly[2*i+1]));  glEnd();    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");    }}int execute(const char* what){  system(what);  return 1; // error}#ifdef AGLint DoMouseDown (int windowPart, WindowPtr whichWindow, EventRecord *myEvent){  int wasactive;	switch (windowPart) {		case inGoAway:			if (ours(whichWindow))				if (TrackGoAway(whichWindow, myEvent->where))					{ 					   closegraphique();					   cout << "The end (closing the graphic window) " <<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, &dragRect);				}			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) {  //  cout << "HandleEvent\n";	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: 			{

⌨️ 快捷键说明

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