📄 xgpaint3d.c
字号:
XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x2 - k1 - 1, y2 + theFontAscent + 2, theString[5].buffer, k); theWindow->c1 = c1 = (x2 - x1) / (xprojmax - xprojmin + DBL_MIN); theWindow->d1 = d1 = (xprojmax * x1 - xprojmin * x2) / (xprojmax - xprojmin + DBL_MIN) + 0.5; if (Is_Scatter(data_Ptr)) { XSetForeground(theDisplay, theWindow->xwingc, theBKGDColor); XFillRectangle(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x1, y1, x2 - x1, y2 - y1 + 1); XSetForeground(theDisplay, theWindow->xwingc, theWhitePixel); XDrawRectangle(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x1, y1, x2 - x1, y2 - y1); } } else { i = strlen(theString[0].buffer); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x1, (int) (c2 * theString[0].y + d2 + theFontAscent), theString[0].buffer, i); x1 += XTextWidth(theFontStruct, theString[0].buffer, i) + 2; i = strlen(theString[5].buffer); i1 = XTextWidth(theFontStruct, theString[5].buffer, i); j = strlen(theString[6].buffer); j1 = XTextWidth(theFontStruct, theString[6].buffer, j); k = strlen(theString[7].buffer); k1 = XTextWidth(theFontStruct, theString[7].buffer, k); maxlen = (i1 > j1) ? i1 : j1; maxlen = (k1 > maxlen) ? k1 : maxlen; x2 -= maxlen; XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x2, (int) (c2 * theString[5].y + d2 + theFontAscent + 5), theString[5].buffer, i); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x2 + maxlen - j1, (int) (c2 * theString[6].y + d2 - theFontDescent - 2), theString[6].buffer, j); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, x2 + maxlen - k1, (int) (c2 * theString[7].y + d2 + theFontAscent), theString[7].buffer, k); x2 -= 2; theWindow->c1 = c1 = (x2 - x1) / (xprojmax - xprojmin + DBL_MIN); theWindow->d1 = d1 = (xprojmax * x1 - xprojmin * x2) / (xprojmax - xprojmin + DBL_MIN) + 0.5; i = strlen(theString[2].buffer); i1 = XTextWidth(theFontStruct, theString[2].buffer, i); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, (int) (c1 * theString[2].x + d1 - i1 - 5), y2 + theFontAscent + 2, theString[2].buffer, i); j = strlen(theString[3].buffer); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, (int) (c1 * theString[3].x + d1 + 5), y2 + theFontAscent + 2, theString[3].buffer, j); i = strlen(theString[1].buffer); i1 = XTextWidth(theFontStruct, theString[1].buffer, i); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, (int) (c1 * theString[1].x + d1 - i1 - 5), (int) (c2 * theString[1].y + d2 + theFontAscent), theString[1].buffer, i); j = strlen(theString[4].buffer); XDrawString(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, (int) (c1 * theString[4].x + d1 + 5), (int) (c2 * theString[4].y + d2 + theFontAscent + 5), theString[4].buffer, j); } theClientArea.x = x1; theClientArea.y = y1; theClientArea.width = x2 - x1 + 1; theClientArea.height = y2 - y1 + 1; XSetClipRectangles(theDisplay, theWindow->xwingc, 0, 0, &theClientArea, 1, Unsorted); /***********************/ /* Draw the back walls */ if (theta_flag != ABOVE) { switch (phi_flag) { case FIRST_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, BACK); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 1, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 4, BACK); break; case SECOND_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, BACK); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 1, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 2, BACK); break; case THIRD_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, BACK); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 2, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 3, BACK); break; case FOURTH_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, BACK); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 3, BACK); DrawWall(theWindow, theBox, c1, d1, c2, d2, 4, BACK); break; } } /***********************************************/ /* Used for scaling the arrays before rotating */ if (Is_X_Log(theWindow)) { a1 = 1.0 / log10(max(label_Ptr->X_Max / (label_Ptr->X_Min + DBL_MIN), DBL_MIN)); b1 = log10(max(label_Ptr->X_Min / (label_Ptr->X_Scale+DBL_MIN),DBL_MIN))/ log10(max(label_Ptr->X_Max / (label_Ptr->X_Min+DBL_MIN), DBL_MIN)); } else { a1 = label_Ptr->X_Scale / (label_Ptr->X_Max - label_Ptr->X_Min +DBL_MIN); b1 = label_Ptr->X_Min / (label_Ptr->X_Max - label_Ptr->X_Min + DBL_MIN); } if (Is_Y_Log(theWindow)) { a2 = 1.0 / log10(max(label_Ptr->Y_Max / (label_Ptr->Y_Min+DBL_MIN), DBL_MIN)); b2 = log10(max(label_Ptr->Y_Min/(label_Ptr->Y_Scale+DBL_MIN),DBL_MIN)) / log10(max(label_Ptr->Y_Max / (label_Ptr->Y_Min+DBL_MIN),DBL_MIN)); } else { a2 = label_Ptr->Y_Scale / (label_Ptr->Y_Max - label_Ptr->Y_Min +DBL_MIN); b2 = label_Ptr->Y_Min / (label_Ptr->Y_Max - label_Ptr->Y_Min + DBL_MIN); } if (Is_Z_Log(theWindow)) { a3 = 1.0 / log10(max(label_Ptr->Z_Max / (label_Ptr->Z_Min+DBL_MIN), DBL_MIN)); b3 = log10(max(label_Ptr->Z_Min/(label_Ptr->Z_Scale+DBL_MIN),DBL_MIN)) / log10(max(label_Ptr->Z_Max / (label_Ptr->Z_Min+DBL_MIN),DBL_MIN)); } else { a3 = label_Ptr->Z_Scale / (label_Ptr->Z_Max - label_Ptr->Z_Min+DBL_MIN); b3 = label_Ptr->Z_Min / (label_Ptr->Z_Max - label_Ptr->Z_Min + DBL_MIN); } /********************************************/ /* do the actual 3d drawing onto the pixmap */ if (Is_Scatter(data_Ptr)) { XSetForeground(theDisplay, theWindow->xwingc, data_Ptr->color); for (i = 0; i < n; i++) { if (Is_X_Log(theWindow)) xtemp = max(a1 * log10(fabs(ScatterX(data_Ptr,i)) + DBL_MIN) - b1,DBL_MIN); else xtemp = a1 * ScatterX(data_Ptr,i) - b1; if (Is_Y_Log(theWindow)) ytemp = max(a2 * log10(fabs(ScatterY(data_Ptr,i)) + DBL_MIN) - b2,DBL_MIN); else ytemp = a2 * ScatterY(data_Ptr,i) - b2; if (Is_Z_Log(theWindow)) ztemp = max(a3 * log10(fabs(ScatterZ(data_Ptr,i)) + DBL_MIN) - b3,DBL_MIN); else ztemp = a3 * ScatterZ(data_Ptr,i) - b3; if (0.0 < xtemp && xtemp < 1.0 && 0.0 < ytemp && ytemp < 1.0 && 0.0 < ztemp && ztemp < 1.0) { if (Is_ColorCode_On(theWindow)) { if (Is_Z_Log(theWindow)) colornumber = MAXTHREEDCOLORS * (a3 * log10(fabs(ScatterZ(data_Ptr,i)) + DBL_MIN) - b3); else colornumber = MAXTHREEDCOLORS * (a3 * (ScatterZ(data_Ptr,i)) - b3); if (colornumber >= MAXTHREEDCOLORS) colornumber = MAXTHREEDCOLORS - 1; else if (colornumber < 0) colornumber = 0; XSetForeground(theDisplay, theWindow->xwingc, ThreeDColor[colornumber]); } XDrawPoint(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, (int) (c1 * (u1 * xtemp + u2 * ytemp + u3 * ztemp) + d1), (int) (c2 * (v1 * xtemp + v2 * ytemp + v3 * ztemp) + d2)); } } } else { for (i=0; i<m; i++) { if (Is_Irr_Surf(data_Ptr)) { for (j = 0; j < n; j++) { if (Is_X_Log(theWindow)) xtemp = max(a1 * log10(fabs(IrregularX(data_Ptr,i,j))+ DBL_MIN) - b1,DBL_MIN); else xtemp = a1 * IrregularX(data_Ptr,i,j) - b1; if (Is_Y_Log(theWindow)) ytemp = max(a2 * log10(fabs(IrregularY(data_Ptr,i,j))+ DBL_MIN) - b2,DBL_MIN); else ytemp = a2 * IrregularY(data_Ptr,i,j) - b2; if (Is_Z_Log(theWindow)) ztemp = max(a3 * log10(fabs(IrregularZ(data_Ptr,i,j))+ DBL_MIN) - b3,DBL_MIN); else ztemp = a3 * IrregularZ(data_Ptr,i,j) - b3; if (ztemp > 1.0) ztemp = 1.0; else if (ztemp < 0.0) ztemp = 0.0; theMeshPoint[i][j].x = u1 * xtemp + u2 * ytemp + u3 * ztemp; theMeshPoint[i][j].y = v1 * xtemp + v2 * ytemp + v3 * ztemp; } } else { for (j = 0; j < n; j++) { if (Is_X_Log(theWindow)) xtemp = max(a1 * log10(fabs(SurfaceX(data_Ptr,i)+DBL_MIN)) - b1,DBL_MIN); else xtemp = a1 * SurfaceX(data_Ptr,i) - b1; if (Is_Y_Log(theWindow)) ytemp = max(a2 * log10(fabs(SurfaceY(data_Ptr,j)+DBL_MIN)) - b2,DBL_MIN); else ytemp = a2 * SurfaceY(data_Ptr,j) - b2; if (Is_Z_Log(theWindow)) ztemp = max(a3 * log10(fabs(SurfaceZ(data_Ptr,i,j)+DBL_MIN)) - b3,DBL_MIN); else ztemp = a3 * SurfaceZ(data_Ptr,i,j) - b3; if (ztemp > 1.0) ztemp = 1.0; else if (ztemp < 0.0) ztemp = 0.0; theMeshPoint[i][j].x = u1 * xtemp + u2 * ytemp + u3 * ztemp; theMeshPoint[i][j].y = v1 * xtemp + v2 * ytemp + v3 * ztemp; } } } /*********************************/ switch (phi_flag) { case FIRST_QUAD: xstart = mstart; xend = mend - 1; xstep = 1; ystart = nstart; yend = nend - 1; ystep = 1; break; case SECOND_QUAD: xstart = mend - 2; xend = mstart - 1; xstep = -1; ystart = nstart; yend = nend - 1; ystep = 1; break; case THIRD_QUAD: xstart = mend - 2; xend = mstart - 1; xstep = -1; ystart = nend - 2; yend = nstart - 1; ystep = -1; break; case FOURTH_QUAD: xstart = mstart; xend = mend - 1; xstep = 1; ystart = nend - 2; yend = nstart - 1; ystep = -1; break; } if (Is_Crosshair_On(theWindow)) { theWindow->mstart = mstart; theWindow->mend = mend; theWindow->nstart = nstart; theWindow->nend = nend; if (theWindow->data->xCoord < mstart) theWindow->data->xCoord = mstart; else if (theWindow->data->xCoord > mend-1) theWindow->data->xCoord = mend-1; if(theWindow->data->yCoord < nstart) theWindow->data->yCoord = nstart; else if (theWindow->data->yCoord > nend-1) theWindow->data->yCoord = nend; sprintf(TclCommand,"Set3dCross \"%s\" %d %d %d %d\n",theWindow->plot_title,mstart,mend,nstart,nend); Tcl_Eval(interp,TclCommand); Open_Before(theWindow); } for (i = xstart; i != xend; i += xstep) for (j = ystart; j != yend; j += ystep) { thePolygon[0].x = ToShort(thePolygon[4].x = c1 * theMeshPoint[i][j].x + d1); thePolygon[0].y = thePolygon[4].y = ToShort(c2 * theMeshPoint[i][j].y + d2); thePolygon[1].x = ToShort(c1 * theMeshPoint[i + 1][j].x + d1); thePolygon[1].y = ToShort(c2 * theMeshPoint[i + 1][j].y + d2); thePolygon[2].x = ToShort(c1 * theMeshPoint[i + 1][j + 1].x + d1); thePolygon[2].y = ToShort(c2 * theMeshPoint[i + 1][j + 1].y + d2); thePolygon[3].x = ToShort(c1 * theMeshPoint[i][j + 1].x + d1); thePolygon[3].y = ToShort(c2 * theMeshPoint[i][j + 1].y + d2); if (Is_Shading_On(theWindow)) { if (Is_ColorCode_On(theWindow)) { if (Is_Z_Log(theWindow)) colornumber = MAXTHREEDCOLORS * (.25 * a3 * log10(fabs(SurfaceZ(data_Ptr,i,j) * SurfaceZ(data_Ptr,i+1,j) * SurfaceZ(data_Ptr,i+1,j+1) * SurfaceZ(data_Ptr,i,j+1)) + DBL_MIN) - b3); else colornumber = MAXTHREEDCOLORS * (.25 * a3 * (SurfaceZ(data_Ptr,i,j) + SurfaceZ(data_Ptr,i+1,j) + SurfaceZ(data_Ptr,i+1,j+1) + SurfaceZ(data_Ptr,i,j+1)) - b3); if (colornumber >= MAXTHREEDCOLORS) colornumber = MAXTHREEDCOLORS - 1; else if (colornumber < 0) colornumber = 0; XSetForeground(theDisplay, theWindow->xwingc, ThreeDColor[colornumber]); } else XSetForeground(theDisplay, theWindow->xwingc, data_Ptr->color); } else XSetForeground(theDisplay, theWindow->xwingc, theBlackPixel); XFillPolygon(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, thePolygon, 5, Complex, CoordModeOrigin); if (Is_Shading_On(theWindow)) XSetForeground(theDisplay, theWindow->xwingc, theBlackPixel); else { if (Is_ColorCode_On(theWindow)) { if (Is_Z_Log(theWindow)) colornumber = MAXTHREEDCOLORS * (.25 * a3 * log10(fabs(SurfaceZ(data_Ptr,i,j) * SurfaceZ(data_Ptr,i+1,j) * SurfaceZ(data_Ptr,i+1,j+1) * SurfaceZ(data_Ptr,i,j+1)) + DBL_MIN) - b3); else colornumber = MAXTHREEDCOLORS * (.25 * a3 * (SurfaceZ(data_Ptr,i,j) + SurfaceZ(data_Ptr,i+1,j) + SurfaceZ(data_Ptr,i+1,j+1) + SurfaceZ(data_Ptr,i,j+1)) - b3); if (colornumber >= MAXTHREEDCOLORS) colornumber = MAXTHREEDCOLORS - 1; else if (colornumber < 0) colornumber = 0; XSetForeground(theDisplay, theWindow->xwingc, ThreeDColor[colornumber]); } else XSetForeground(theDisplay, theWindow->xwingc, data_Ptr->color); } if (Is_Grid_On(theWindow)) XDrawLines(theDisplay, theWindow->pixmap_buffer, theWindow->xwingc, thePolygon, 5, CoordModeOrigin); } } /***********************/ /* Draw the front walls */ if (theta_flag != ABOVE) { switch (phi_flag) { case FIRST_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, FRONT); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 2, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 3, FRONT); break; case SECOND_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, FRONT); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 3, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 4, FRONT); break; case THIRD_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, FRONT); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 1, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 4, FRONT); break; case FOURTH_QUAD: if (theta_flag == UPPER) DrawWall(theWindow, theBox, c1, d1, c2, d2, 5, FRONT); else DrawWall(theWindow, theBox, c1, d1, c2, d2, 0, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 1, FRONT); DrawWall(theWindow, theBox, c1, d1, c2, d2, 2, FRONT); break; } } XSetClipMask(theDisplay, theWindow->xwingc, None);} /****************************************************************/ /****************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -