📄 sansrgraph.cpp
字号:
// -*- Mode : c++ -*-//// SUMMARY : // USAGE : // ORG : // AUTHOR : Frederic Hecht// 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 FF_GRAPH_SET_PTRusing namespace std;#include <ctime>#include <cstdlib>#include <cstdio>#include <cstring>#include <iostream>#include <cassert>#include "rgraph.hpp"#include "error.hpp"#ifdef macintoshxx#include <ConditionalMacros.h>#include <unix.h>#else#include <sys/stat.h>#endif#ifdef xTARGET_CARBON#include <Navigation.h>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 getprog(char* fn,int argc, char** argvptr){ OSErr anErr; NavDialogOptions dialogOptions; NavReplyRecord reply; anErr=NavGetDefaultDialogOptions(& dialogOptions); if( anErr != noErr) return -1; anErr =NavChooseFile(0,&reply,&dialogOptions,0,0,0,0,0) ; if (anErr == noErr && reply.validRecord) { // Deal with multiple file selection long count; anErr = AECountItems(&(reply.selection), &count); // Set up index for file list if (anErr == noErr) { long index; for (index = 1; index <= count; index++) { AEKeyword theKeyword; DescType actualType; Size actualSize; FSSpec documentFSSpec; // Get a pointer to selected file anErr = AEGetNthPtr(&(reply.selection), index, typeFSS, &theKeyword, &actualType,&documentFSSpec, sizeof(documentFSSpec), &actualSize); if (anErr == noErr) { anErr = HSetVol(0,documentFSSpec.vRefNum,documentFSSpec.parID); pStrCopy(documentFSSpec.name, fn); } } } // Dispose of NavReplyRecord, resources, descriptors anErr = NavDisposeReply(&reply); } return (2);}#else#include "getprog-unix.hpp"#endiftemplate<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;}static long cube6[7][3] ={ { 65535,32000,32000},{ 65535, 65535,0},{0, 65535,0},{0, 65535, 65535},{0,0, 65535} , { 65535,0, 65535},{ 32000,0,0} }; static long grey6[2][3] ={ {65534,65534,65534},{0,0,0} }; static bool grey=false;static FILE *psfile = 0;static FILE *psfile_save = 0;static int LastColor=2; // pour est en couleur par defautconst float fMinPixel = -32000;const float fMaxPixel = +32000;#define reel float typedef struct XColor { unsigned short red,green,blue;} XColor;static XColor *colortable;static int ncolortable,fcolor;static reel echx,echy,rxmin,rxmax,rymin,rymax;static int lacouleur=0, width, height, currx=0, curry=0;#define call(i) istatic int INITGRAPH=0;void myend(){ if (INITGRAPH) closegraphique(); cout << "the end" <<endl;// ExitToShell();}void myexit(int err) { cout << " The End err=" << err << endl; exit(err);}const char * edpfilenamearg=0; bool waitatend=true;#ifdef FREEFEM#include <fstream.h>#include <new.h>void out_of_memory ();void myexit(int );void compile(char *fname);int main (int argc, char **argv){ atexit(myend); int OPTION = 0; if (argc == 2) { printf ("PROGRAM FreeFem 1.0 %s \n",argv[1]); initgraphique(); compile (argv[1]); closegraphique(); } else printf ("To launch freefem you must type freefem and a file name\n"); return 0;}#elsevoid doatexitff(){#ifdef WIN32 bool err=true; if(edpfilenamearg) { cout << " try getConsole " << edpfilenamearg << endl; string fn = edpfilenamearg; err=GetConsoleBuff(fn); } if( waitatend && err) { char c; cout << "wait enter ? "; cin.get(); }#endif}extern int mymain(int argc,char **argv);int main (int argc, char **argv){ atexit(doatexitff); int ret=mymain(argc,argv); return ret;}#endifvoid message(char *s){ printf("%s \n",s);}void erreur(char *s){ message(s); exit(0);}void *safecalloc(size_t nb, size_t size){ void* p=NULL; p = calloc(nb, size); if (p == NULL) printf("Run out of Memory!\n"); return p;}void safefree(void** f){ if(*f){ free((char*) *f); *f=NULL;}}void rflush(){}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 (colortable) { if (c>0 && c < ncolortable) { r = (float) colortable[c].red /65535.; g = (float) colortable[c].green /65535.; b = (float) colortable[c].blue /65535.; } } else if (c!=0) r=g=b=0; if(psfile) fprintf(psfile,"%.3f %.3f %.3f C\n",r,g,b); }static XColor DefColorSansG( int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors){ XColor C; float r,g,b;extern void DefColor(float & r, float & g, float & b, int k,int nb, bool hsv,bool ggrey,int nbcolors,float *colors); DefColor(r,g,b, k,nb,hsv,ggrey,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 (nbcolors && nb>2) { if(colortable) delete [] colortable; colortable = new XColor[nb]; ncolortable = nb; if(LastColor>1) LastColor=nb-1; for (int i0=0;i0<nb;i0++) { colortable[i0]=DefColorSansG(i0,nb,hsv,grey,nbcolors,colors); } } else ncolortable =0;}void SetColorTable(int nb){ if (fcolor && nb>2 && nb < 256) { nb = Max(nb,8); if (ncolortable == nb) return;// optim if(colortable) delete [] colortable; colortable = new XColor[nb]; ncolortable = nb; if(LastColor>1) LastColor=nb-1; // cout << "SetColorTable "<< nb << endl; int k=0; colortable[k].red= 65535; colortable[k].green= 65535; colortable[k].blue= 65535; 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 <<k << " " << i0 << " " << j0 << " " << j1 << " " << k0 << " " << k1 << endl; if ( kk <= 0) { cerr << kk << " " << nb << " " << k0 << " " << k1 << " " << endl; assert(kk); } /* colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk); colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk); colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk);*/ if (! grey) { colortable[k].red = (unsigned short) ((long) (cube6[j1][0]*k0+cube6[j0][0]*k1)/kk); colortable[k].green = (unsigned short) ((long) (cube6[j1][1]*k0+cube6[j0][1]*k1)/kk); colortable[k].blue = (unsigned short) ((long) (cube6[j1][2]*k0+cube6[j0][2]*k1)/kk); } else { kk=nb-1; k1 = i0; k0 = nb - i0 -1; j0=1; j1=0; colortable[k].red = (unsigned short) ((long) (grey6[j1][0]*k0+grey6[j0][0]*k1)/kk); colortable[k].green = (unsigned short) ((long) (grey6[j1][1]*k0+grey6[j0][1]*k1)/kk); colortable[k].blue = (unsigned short) ((long) (grey6[j1][2]*k0+grey6[j0][2]*k1)/kk); } assert(k<ncolortable); // cout <<colortable[k].pixel // << " r=" << colortable[k].red // << " g=" << colortable[k].green // << " b=" <<colortable[k].blue <<endl; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -