📄 pscube.c
字号:
for (lcount=255;lcount>=0;lcount--,lll++) data_legend[lll]=(char) lcount; if (lendsup!=1) { for (;lll<ln;lll++) data_legend[lll]=(char) 0; /* black area */ } lf=lbeg;ld=(lend-lbeg)/(ln-1); if (!(getparfloat("ldnum",&ldnum))) ldnum=0.0; /* adjust lbeg and lend to fall on sampled values */ ilbeg = NINT((lbeg-lf)/ld); ilbeg = MAX(0,MIN(ln-1,ilbeg)); lbeg = lf+ilbeg*ld; ilend = NINT((lend-lf)/ld); ilend = MAX(0,MIN(ln-1,ilend)); lend = lf+ilend*ld; /* convert legend parameters to points */ lx *= 72.0; /* Schoenfelder */ ly *= 72.0; /* Schoenfelder */ lwidth *= 72.0; /* Schoenfelder */ lheight *= 72.0; /* Schoenfelder */ } /* convert axes parameters to points */ size1 *= 72; size2 *= 72; size3 *= 72; xbox *= 72; ybox *= 72; /* set bounding box */ psAxesBBox(xbox,ybox,size2+cos(angle)*size3,size1+sin(angle)*size3, labelfont,labelsize,titlefont,titlesize,style,bbox); if (legend) { psLegendBBox( /* Space for legend Schoenfelder */ lx,ly,lwidth,lheight, labelfont,labelsize, lstyle,lbbox); /* Include space for legend Schoenfelder */ bbox[0]=MIN(bbox[0],lbbox[0]); bbox[1]=MIN(bbox[1],lbbox[1]); bbox[2]=MAX(bbox[2],lbbox[2]); bbox[3]=MAX(bbox[3],lbbox[3]); } boundingbox(bbox[0],bbox[1],bbox[2],bbox[3]); /* begin PostScript */ begineps(); /* save graphics state */ gsave(); /* translate coordinate system by box offset */ translate(xbox,ybox); /* begin front */ gsave(); /* transform coordinates */ translate(0,0); scale(size2,size1); /* determine image matrix */ matrix[0] = 0; matrix[1] = n2s; matrix[2] = -n1s; matrix[3] = 0; matrix[4] = n1s; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n1s,n2s,bps,matrix,szfront); /* end front */ grestore(); /* begin side */ gsave(); /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = tan(angle); matrix[2] = 0; matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(size2,0); concat(matrix); scale(size3*cos(angle),size1); /* determine image matrix */ matrix[0] = 0; matrix[1] = n3s; matrix[2] = -n1s; matrix[3] = 0; matrix[4] = n1s; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n1s,n3s,bps,matrix,szside); /* end side */ grestore(); /* begin top */ gsave(); /* transform and skew coordinates */ matrix[0] = 1; matrix[1] = 0; matrix[2] = 1.0/tan(angle); matrix[3] = 1; matrix[4] = 0; matrix[5] = 0; translate(0,size1); concat(matrix); scale(size2,size3*sin(angle)); /* determine image matrix */ matrix[0] = n2s; matrix[1] = 0; matrix[2] = 0; matrix[3] = n3s; matrix[4] = 0; matrix[5] = 0; /* draw the image */ drawimage(hls,colors,n2s,n3s,bps,matrix,sztop); /* end top */ grestore(); if (legend) { gsave(); /* translate coordinate system by box offset */ translate(-xbox,-ybox); translate(lx,ly); scale(lwidth,lheight); if ((lstyle==VERTLEFT) || (lstyle==VERTRIGHT)) { labmatrix[0] = 1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); } else { labmatrix[0] = -1; labmatrix[1] = 0; labmatrix[2] = 0; labmatrix[3] = ln; labmatrix[4] = 0; labmatrix[5] = 0; rotate(-90); drawimage(hls,colors,1,ln,bps,labmatrix,data_legend); rotate(90); } grestore(); } /* restore graphics state */ grestore(); psCubeAxesBox(xbox,ybox,size1,size2,size3,angle, x1beg,x1end,p1beg,p1end, d1num,f1num,n1tic,grid1,label1, x2beg,x2end,p2beg,p2end, d2num,f2num,n2tic,grid2,label2, x3beg,x3end,p3beg,p3end, d3num,f3num,n3tic,grid3,label3, labelfont,labelsize, title,titlefont,titlesize, titlecolor,axescolor,gridcolor); /* draw axes and title for legend Schoenfelder*/ if (legend) { float lpbeg,lpend; int lntic=1; gsave(); lpbeg = 0.0; /*(lend>lbeg)?-fabs(d1s)/2:fabs(d1s)/2;*/ lpend = 0.0; /*(lend>lbeg)?fabs(d1s)/2:-fabs(d1s)/2;*/ psLegendBox( lx,ly,lwidth,lheight, lbeg,lend,lpbeg,lpend, ldnum,lf,lntic,ugrid,units, labelfont,labelsize, axescolor,gridcolor, lstyle); grestore(); } /* end PostScript */ showpage(); endeps(); return 0;}static void drawimage(int hls, float colors[3][2], int width, int height, int bps, float matrix[], unsigned char* z){ int row,col,rowbytes,hi,lo,zi,byte; unsigned char *rtab,*gtab,*btab,*rgb,*rgbp,*crgbp,*zp; /* handle gray scale as a special case */ if ( (hls && colors[L][0]==0.0 && colors[L][1]==1.0 && colors[S][0]==0.0 && colors[S][1]==0.0) || (colors[R][0]==0.0 && colors[R][1]==1.0 && colors[G][0]==0.0 && colors[G][1]==1.0 && colors[B][0]==0.0 && colors[B][1]==1.0) ) { image(width,height,8,matrix,z); return; } /* allocate space for rgb tables */ rtab = ealloc1(256,sizeof(unsigned char)); gtab = ealloc1(256,sizeof(unsigned char)); btab = ealloc1(256,sizeof(unsigned char)); /* if colors are hls values, map from hls to rgb tables */ if (hls) { float hscale,lscale,sscale,hbase,lbase,sbase,h,l,s,r,g,b; hbase = colors[H][0]; hscale = (colors[H][1]-colors[H][0])/255.0; lbase = colors[L][0]; lscale = (colors[L][1]-colors[L][0])/255.0; sbase = colors[S][0]; sscale = (colors[S][1]-colors[S][0])/255.0; for (zi=0; zi<256; ++zi) { h = hbase+zi*hscale; l = lbase+zi*lscale; s = sbase+zi*sscale; hlsrgb(h*360.0,l,s,&r,&g,&b); rtab[zi] = r*255.0; gtab[zi] = g*255.0; btab[zi] = b*255.0; } /* else colors are rgb values, map linearly to rgb tables */ } else { float rscale,gscale,bscale,rbase,gbase,bbase; rbase = colors[0][0]*255.0; rscale = colors[0][1]-colors[0][0]; gbase = colors[1][0]*255.0; gscale = colors[1][1]-colors[1][0]; bbase = colors[2][0]*255.0; bscale = colors[2][1]-colors[2][0]; for (zi=0; zi<256; ++zi) { rtab[zi] = rbase+zi*rscale; gtab[zi] = gbase+zi*gscale; btab[zi] = bbase+zi*bscale; } } /* convert unsigned char to rgb unsigned char */ rgb = ealloc1(width*height*3,sizeof(unsigned char)); for (row=0,rgbp=rgb,zp=z; row<height; ++row) { for (col=0; col<width; ++col) { zi = *zp++; *rgbp++ = (unsigned char)rtab[zi]; *rgbp++ = (unsigned char)gtab[zi]; *rgbp++ = (unsigned char)btab[zi]; } } /* free tables */ free1(rtab); free1(gtab); free1(btab); /* if necessary, compress 24 bit color to 12 bit color */ if (bps==12) { rowbytes = 1+(width*12-1)/8; crgbp = rgbp = rgb; for (row=0; row<height; ++row) { for (byte=0; byte<rowbytes-1; ++byte) { hi = (*rgbp++)>>4; lo = (*rgbp++)>>4; *crgbp++ = (hi<<4)|lo; } if (width%2) { hi = (*rgbp++)>>4; *crgbp++ = hi<<4; } else { hi = (*rgbp++)>>4; lo = (*rgbp++)>>4; *crgbp++ = (hi<<4)|lo; } } } /* draw color image */ rgbimage(width,height,bps/3,matrix,rgb); /* free workspace */ free1(rgb);}/* internal functions to convert HLS to RGB (adapted from Foley & Van Dam) */static float rgbvalue (float n1, float n2, float hue){ while (hue>360.0) hue -= 360.0; while (hue<0.0) hue += 360.0; if (hue<60.0) return n1+(n2-n1)*hue/60.0; else if (hue<180.0) return n2; else if (hue<240.0) return n1+(n2-n1)*(240.0-hue)/60.0; else return n1;}static void hlsrgb (float h, float l, float s, float *r, float *g, float *b){ float m1,m2; if (l<=0.5) m2 = l*(1.0+s); else m2 = l+s-l*s; m1 = 2*l-m2; if (s==0.0) { *r = *g = *b = l; } else { *r = rgbvalue(m1,m2,h+120.0); *g = rgbvalue(m1,m2,h); *b = rgbvalue(m1,m2,h-120.0); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -