📄 zbufinout.c
字号:
} tail->numsides = chgp->shape; /* allocate for corner coordinates */ CALLOC(tail->c, tail->numsides, double *, ON, AMSC); for(i = 0; i < tail->numsides; i++) CALLOC(tail->c[i], 3, double, ON, AMSC); /* xfer corner coordinates */ for(i = 0; i < tail->numsides; i++) { getAbsCoord(tail->c[i], chgp, i); } /* figure and store rhs and normal */ tail->rhs = getPlane(tail->normal, tail->c[0], tail->c[1], tail->c[2]); /* load grey level and line width */ tail->greylev = GREYLEV; tail->width = linewd; tail->index = *numfaces; (*numfaces)++; } /* extract an array of pointers to the faces */ CALLOC(faces, *numfaces, face *, ON, AMSC); for(tail = head, i = 0; tail != NULL; tail = tail->next, i++) faces[i] = tail; if(q != NULL) { figure_grey_levels(faces, q, chglist, use_density); } /* set up axes lines (always done - needed for alignment) */ setupLine(axes, 0, 0.0, 0.0, 0.0, axeslen, 0.0, 0.0); /* x axis */ setupLine(axes, 1, 0.0, 0.0, 0.0, 0.0, axeslen, 0.0); /* y axis */ setupLine(axes, 2, 0.0, 0.0, 0.0, 0.0, 0.0, axeslen); /* z axis */ setupLine(axes, 3, 0.85*axeslen, -0.15*axeslen, 0.0, 1.15*axeslen, 0.15*axeslen, 0.0); /* x marker */ setupLine(axes, 4, 1.15*axeslen, -0.15*axeslen, 0.0, 0.85*axeslen, 0.15*axeslen, 0.0); /* x marker */ setupLine(axes, 5, 0.0, axeslen, 0.0, -0.15*axeslen, 1.15*axeslen, 0.0); /* y marker */ setupLine(axes, 6, 0.0, axeslen, 0.0, 0.15*axeslen, 1.15*axeslen, 0.0); /* y marker */ return(faces);}/* allows recursive reads in a .fig file with line format read <filename> only lines (not faces or fills) may be read this way (ie encountering "FACES" or "fills" inside a recursive file read is an error, unless the ignore faces/fills option (f_) has been specified) **** above is only vaguely correct **** .fig file format for specifying lines, dots and arrows: # <comment> <fromx> <fromy> <fromz> (line from point) <tox> <toy> <toz> [<line width>] [<arrow size>] [<dot size>] ... r <file name> (hierarchical read) e (or \n) dot is always on from point; arrow is always on to point optional arguments are only partially so: if one arg is given, then all those to the left must also be given good sizes: width 0, 1 or 2 (goes straight to postscript) arrow size 3.0 dot size 2.0 to get just a dot, put in tiny length line and arrow size*/void readLines(fp, head, tail, numlines)line **head, **tail;int *numlines;FILE *fp;{ int flines = 0, falin = 0, fflag = 1, faflag = 1, getlines = 1, i, j; int f_; /* f_ == 1 => ignore face and fill info */ char linein[BUFSIZ], **chkp, *chk, *strtok(), *cp; char readfile[BUFSIZ], tempc[BUFSIZ]; double arrowsize, dotsize; int temp, linewd; FILE *fpin, *fopen(); f_ = 1; /* hardwire to take fill/face info as equivalent to end of file */ chkp = &chk; /* pointers for error checking */ /* input lines and add to linked list */ while(fgets(linein, sizeof(linein), fp) != NULL) { if(linein[0] == 'e' || linein[0] == '\0') return; if(linein[0] == 'r') { /* do a recursive read */ if(sscanf(linein, "%s %s", tempc, readfile) != 2) { fprintf(stderr, "readLines: bad recursive read line format:\n%s\n", linein); exit(1); } if((fpin = fopen(readfile, "r")) == NULL) { fprintf(stderr, "readLines: can't open recursive read file\n `%s'\nto read\n", readfile); exit(1); } readLines(fpin, head, tail, numlines); fclose(fpin); continue; } if(linein[0] == 'F') { if(f_ == 0) { fprintf(stderr, "readLines: attempt to input faces with a recursive read\n"); exit(1); } else { return; } } if(linein[0] == '#') continue; if(linein[0] == 'f') { if(f_ == 0) { fprintf(stderr, "readLines: attempt to input fills with a recursive read\n"); exit(1); } else { return; } } /* input lines of line information */ if(fflag == 1) { /* allocate a line struct; input a from line */ if(*numlines == 0) { CALLOC((*tail), 1, line, ON, AMSC); (*head) = (*tail); (*tail)->prev = NULL; } else { CALLOC((*tail)->next, 1, line, ON, AMSC); /* link forward */ ((*tail)->next)->prev = (*tail); /* link back */ (*tail) = (*tail)->next; } if(sscanf(linein,"%lf %lf %lf",&((*tail)->from[0]), &((*tail)->from[1]), &((*tail)->from[2])) != 3) { fprintf(stderr,"readLines: from line %d bad, '%s'\n",flines+1,linein); exit(1); } (*tail)->index = *numlines; fflag = 0; flines++; } else if(fflag == 0) { /* input a to line */ /* if arrow heads are used, line width must be specified */ if(sscanf(linein, "%lf %lf %lf %d %lf %lf", &((*tail)->to[0]), &((*tail)->to[1]), &((*tail)->to[2]), &linewd, &arrowsize, &dotsize) != 6) { if(sscanf(linein, "%lf %lf %lf %d %lf",&((*tail)->to[0]), &((*tail)->to[1]), &((*tail)->to[2]), &linewd, &arrowsize) != 5) { if(sscanf(linein, "%lf %lf %lf %d", &((*tail)->to[0]), &((*tail)->to[1]), &((*tail)->to[2]), &linewd) != 4) { if(sscanf(linein, "%lf %lf %lf", &((*tail)->to[0]), &((*tail)->to[1]), &((*tail)->to[2])) != 3) { fprintf(stderr, "readLines: to line %d bad, '%s'\n",flines+1, linein); exit(1); } linewd = LINE; } arrowsize = 0.0; } dotsize = 0.0; } (*tail)->width = linewd; (*tail)->arrow = arrowsize; (*tail)->dot = dotsize; fflag = 1; flines++; (*numlines)++; } } if(fflag == 0) { fprintf(stderr, "readLines: file ended with unmatched from line\n"); exit(1); }}/* opens a .fig file and reads only lines from it - closes if faces/fills found*/line **getLines(line_file, numlines)int *numlines;char *line_file;{ int i; FILE *fp; line *head, *tail, **linesout; *numlines = 0; if(line_file == NULL) return(NULL); if((fp = fopen(line_file, "r")) == NULL) { fprintf(stderr, "getLines: can't open .fig file\n `%s'\nto read\n", line_file); exit(1); } readLines(fp, &head, &tail, numlines); fclose(fp); /* extract array of pointers to line structs */ CALLOC(linesout, (*numlines), line *, ON, AMSC); for(i = 0; i < *numlines; i++) { linesout[i] = head; head = head->next; } return(linesout);}/* figure the bounding box and write ps file line*/void getBndingBox(faces, numfaces, lines, numlines, lowx, lowy, fp, axes)face **faces;line **lines;double ***axes;int numfaces, numlines, *lowx, *lowy;FILE *fp;{ int upx, upy; double xmax, ymax, minx, miny; int i, j; extern int x_; /* find the smallest and largest x and y coordinates (assumed pos) */ xmax = ymax = 0.0; for(i = 0; i < 7 && x_ == TRUE; i++) { /* check axes */ for(j = 0; j < 2; j++) { if(i == 0 && j == 0) { minx = axes[i][j][0]; miny = axes[i][j][1]; } else { minx = MIN(minx, axes[i][j][0]); miny = MIN(miny, axes[i][j][1]); } xmax = MAX(xmax, axes[i][j][0]); ymax = MAX(ymax, axes[i][j][1]); } } for(i = 0; i < numfaces; i++) { /* check faces */ for(j = 0; j < faces[i]->numsides; j++) { if(i == 0 && j == 0 && x_ == FALSE) { minx = faces[i]->c[j][0]; miny = faces[i]->c[j][1]; } else { minx = MIN(minx, faces[i]->c[j][0]); miny = MIN(miny, faces[i]->c[j][1]); } xmax = MAX(xmax, faces[i]->c[j][0]); ymax = MAX(ymax, faces[i]->c[j][1]); } } for(i = 0; i < numlines; i++) { /* check lines */ if(i == 0 && x_ == FALSE && numfaces == 0) { minx = MIN(lines[i]->from[0], lines[i]->to[0]); miny = MIN(lines[i]->from[1], lines[i]->to[1]); } else { minx = MIN(minx, lines[i]->from[0]); miny = MIN(miny, lines[i]->from[1]); minx = MIN(minx, lines[i]->to[0]); miny = MIN(miny, lines[i]->to[1]); } xmax = MAX(xmax, lines[i]->to[0]); xmax = MAX(xmax, lines[i]->from[0]); ymax = MAX(ymax, lines[i]->to[1]); ymax = MAX(ymax, lines[i]->from[1]); } *lowx = minx-2; /* note 2pnt offset and truncation */ *lowy = miny-2; upx = xmax+2; upy = ymax+2; fprintf(fp, "%%%%BoundingBox: %d %d %d %d\n", *lowx, *lowy, upx, upy);}/* dump axes to ps file*/void dumpAxes(axi, fp)double ***axi;FILE *fp;{ int i; for(i = 0; i < 7; i++) { /* loop on axes' lines (pointers too) */ fprintf(fp, "%g %g moveto\n", axi[i][0][0], axi[i][0][1]); fprintf(fp, "%g %g lineto\n", axi[i][1][0], axi[i][1][1]); fprintf(fp, "%g setlinewidth %d setlinecap %d setlinejoin ", AXEWID, LINCAP, LINJIN); fprintf(fp, " 0 setgray stroke\n"); } /*fprintf(stderr, "Axes inserted\n");*/}/* copy the body of the header to the output file*/void copyBody(fp)FILE *fp;{ static char str[] = "\%%%%DocumentProcSets: FreeHand_header 2 0 \n\%%%%DocumentSuppliedProcSets: FreeHand_header 2 0 \n\%%%%ColorUsage: Color \n\%%%%CMYKProcessColor: 0 0 0 0.1 (10%% gray) \n\%%%%+ 0 0 0 0.2 (20%% gray) \n\%%%%+ 0 0 0 0.4 (40%% gray) \n\%%%%+ 0 0 0 0.6 (60%% gray) \n\%%%%+ 0 0 0 0.8 (80%% gray) \n\%%%%EndComments \n\%%%%BeginProcSet: FreeHand_header 2 0 \n\/FreeHandDict 200 dict def \n\FreeHandDict begin \n\/currentpacking where{pop true setpacking}if \n\/bdf{bind def}bind def \n\/bdef{bind def}bdf \n\/xdf{exch def}bdf \n\/ndf{1 index where{pop pop pop}{dup xcheck{bind}if def}ifelse}bdf \n\/min{2 copy gt{exch}if pop}bdf \n\/max{2 copy lt{exch}if pop}bdf \n\/dr{transform .25 sub round .25 add \n\exch .25 sub round .25 add exch itransform}bdf \n\/curveto{dr curveto}bdf \n\/lineto{dr lineto}bdf \n\/moveto{dr moveto}bdf \n\/graystep 1 256 div def \n\/bottom -0 def \n\/delta -0 def \n\/frac -0 def \n\/left -0 def \n\/numsteps -0 def \n\/numsteps1 -0 def \n\/radius -0 def \n\/right -0 def \n\/top -0 def \n\/x -0 def \n\/y -0 def \n\/df currentflat def \n\/tempstr 1 string def \n\/clipflatness 3 def \n\/inverted? \n\0 currenttransfer exec .5 ge def \n\/concatprocs{ \n\/proc2 exch cvlit def/proc1 exch cvlit def \n\/newproc proc1 length proc2 length add array def \n\newproc 0 proc1 putinterval newproc proc1 length proc2 putinterval \n\newproc cvx}bdf \n\/storerect{/top xdf/right xdf/bottom xdf/left xdf}bdf \n\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -