📄 output.cc
字号:
Output (initdisplay, initgc, initOutputicon, fontstruct, initx, inity, initwidth, initheight, text){ xindex = DEFAULTXINDEX; yindex = DEFAULTYINDEX; zindex = DEFAULTZINDEX; float_to_pixel = 1.0;}void Output2d_3d::Calculate_scale_2d (DVektorArray * inputData){ if (inputData->Lese_Dim () > 1) Calculate_scale_2d (MAX (inputData->Lese_Max (xindex), -inputData->Lese_Min (xindex)), MAX (inputData->Lese_Max (yindex), -inputData->Lese_Min (yindex))); else Calculate_scale_2d (MAX (inputData->Lese_Max (xindex), -inputData->Lese_Min (xindex)), MAX (inputData->Lese_Max (xindex), -inputData->Lese_Min (xindex)));}void Output2d_3d::Calculate_scale_2d (double xsize){ if (xsize == 0.0) xscale = 1.0; else xscale = 1.0 / xsize; yscale = 1.0;}void Output2d_3d::Calculate_scale_2d (double xsize, double ysize){ if (fitscaleicon->IsSelected ()) { if (xsize == 0.0) xscale = 1.0; else xscale = 1.0 / xsize; if (ysize == 0.0) yscale = 1.0; else yscale = 1.0 / ysize; } else { xsize = MAX (xsize, ysize); if (xsize == 0.0) xsize = 1.0; xscale = 1.0 / xsize; yscale = 1.0 / xsize; }}void Output2d_3d::Calculate_scale_3d (double xsize, double ysize){ if (fitscaleicon->IsSelected ()) { if (xsize == 0.0) xscale = 1.0; else xscale = 1.0 / xsize; if (ysize == 0.0) yscale = 1.0; else yscale = 1.0 / ysize; } else { xsize = MAX (xsize, ysize); if (xsize == 0.0) xsize = 1.0; xscale = 1.0 / xsize; yscale = 1.0 / xsize; } zscale = 1.0;}void Output2d_3d::Calculate_scale_3d (double xsize, double ysize, double zsize){ if (fitscaleicon->IsSelected ()) { if (xsize == 0.0) xscale = 1.0; else xscale = 1.0 / xsize; if (ysize == 0.0) yscale = 1.0; else yscale = 1.0 / ysize; if (zsize == 0.0) zscale = 1.0; else zscale = 1.0 / zsize; } else { xsize = MAX (xsize, ysize); xsize = MAX (xsize, zsize); if (xsize == 0.0) xscale = 1.0; xscale = 1.0 / xsize; yscale = 1.0 / xsize; zscale = 1.0 / xsize; }}void Output2d_3d::Calculate2dparameter (DVektorArray * inputData){ if (inputData->Lese_Dim () > 1) Calculate2dparameter (inputData->Lese_Min (xindex), inputData->Lese_Min (yindex), inputData->Lese_Max (xindex), inputData->Lese_Max (yindex)); else Calculate2dparameter (inputData->Lese_Min (xindex), inputData->Lese_Min (xindex), inputData->Lese_Max (xindex), inputData->Lese_Max (xindex));}void Output2d_3d::Calculate2dparameter (double xmin, double ymin, double xmax, double ymax){ double xdifference, ydifference; double float_to_pixelx, float_to_pixely; xmin = MIN (xmin, 0.0); ymin = MIN (ymin, 0.0);// *** NEW **** xdifference = (xmax - xmin) * xscale; ydifference = (ymax - ymin) * yscale; if (xdifference == 0.0) xdifference = 1.0; if (ydifference == 0.0) ydifference = 1.0; float_to_pixelx = (width - 2 * OUTPUTBORDERWIDTH) / xdifference; float_to_pixely = (height - 2 * OUTPUTBORDERWIDTH) / ydifference; float_to_pixel = MIN (float_to_pixelx, float_to_pixely); centerx = OUTPUTBORDERWIDTH - (short) (xmin * xscale * float_to_pixel); centery = height - OUTPUTBORDERWIDTH + (short) (ymin * yscale * float_to_pixel);}void Output2d_3d::Calculate3dparameter (char options){ if (options & RESET_AXES) {/* axisframe[0][0]=axisframe[1][1]=axisframe[2][2] = 1.0; axisframe[0][1]=axisframe[0][2] = 0.0; axisframe[1][0]=axisframe[1][2] = 0.0; axisframe[2][0]=axisframe[2][1] = 0.0; */ axisframe[0][1] = axisframe[1][2] = axisframe[2][0] = 1.0; axisframe[0][0] = axisframe[0][2] = 0.0; axisframe[1][0] = axisframe[1][1] = 0.0; axisframe[2][1] = axisframe[2][2] = 0.0; } if ((options & RESET_AXES) || (options & CENTER_AXES)) { axisframe[0][3] = -0.5; axisframe[1][3] = -0.5; axisframe[2][3] = -1.0; } scalefactor = (height - 2 * OUTPUTBORDERWIDTH); eyedistance = 2.0; xcenter = width / 2; ycenter = height / 2;}void Output2d_3d::Resized (int newwidth, int newheight){ ((Output *) this)->Resized (newwidth, newheight); if (Dataset != NULL) { Calculate2dparameter (&(Dataset->Lese_Daten ())); if (Dataset->Lese_Daten ().Lese_Dim () > 2) Calculate3dparameter (0); }}void Output2d_3d::DrawCoordinates (short xpos, short ypos){ double xoutput, youtput; int xnumber; char coord[30]; char box[30] = " "; short textheight = fontstruct->max_bounds.ascent + fontstruct->max_bounds.descent; if (Dataset->Lese_Daten ().Lese_Dim () > 1) { PixeltoWorld2d (xpos, ypos, &xoutput, &youtput); sprintf (coord, "%f %f", xoutput, youtput); } else { PixeltoWorld1d (xpos, ypos, &xnumber, &youtput); sprintf (coord, "%d %f", xnumber, youtput); } XSetForeground (display, gc, whitepix); XFillRectangle (display, window, gc, 1, height - textheight, XTextWidth (fontstruct, box, strlen (box)), textheight); XSetForeground (display, gc, blackpix); XDrawString (display, window, gc, 1, height - 1, coord, strlen (coord));}void Output2d_3d::PixeltoWorld1d (short xpos, short ypos, int *number, double *xis){ *number = (int) (Dataset->Lese_Daten ().Lese_Groesse () * (xpos - centerx) / float_to_pixel); *xis = (centery - ypos) / (xscale * float_to_pixel);}void Output2d_3d::WorldtoPixel1d (short number, double xpos, short *xis, short *yis){ *xis = centerx + (short) (number / (double) Dataset->Lese_Daten ().Lese_Groesse () * float_to_pixel); *yis = centery - (short) (xpos * float_to_pixel * xscale);}void Output2d_3d::PixeltoWorld2d (short xpos, short ypos, double *xis, double *yis){ *xis = (xpos - centerx) / (xscale * float_to_pixel); *yis = (centery - ypos) / (yscale * float_to_pixel);}void Output2d_3d::WorldtoPixel2d (double xpos, double ypos, short *xis, short *yis){ xpos *= xscale; ypos *= yscale; *xis = centerx + (short) (xpos * float_to_pixel); *yis = centery - (short) (ypos * float_to_pixel);}void Output2d_3d::WorldtoPixel3d (double xpos, double ypos, double zpos, short *xis, short *yis){ double viewx, viewy, viewz, x_2d, y_2d; xpos *= xscale; ypos *= yscale; zpos *= zscale; viewx = xpos * axisframe[0][0] + ypos * axisframe[0][1] + zpos * axisframe[0][2] + axisframe[0][3]; viewy = xpos * axisframe[1][0] + ypos * axisframe[1][1] + zpos * axisframe[1][2] + axisframe[1][3]; viewz = xpos * axisframe[2][0] + ypos * axisframe[2][1] + zpos * axisframe[2][2] + axisframe[2][3]; y_2d = (viewy * eyedistance) / (eyedistance - viewz); x_2d = (viewx * eyedistance) / (eyedistance - viewz); *xis = xcenter + (short) (x_2d * scalefactor); *yis = ycenter - (short) (y_2d * scalefactor);}void Output2d_3d::WorldtoPixel3d (double xpos, double ypos, double zpos, double zworld, short *xis, short *yis){ xpos *= xscale; ypos *= yscale; zpos *= zscale; double viewx, viewy, x_2d, y_2d; viewx = xpos * axisframe[0][0] + ypos * axisframe[0][1] + zpos * axisframe[0][2] + axisframe[0][3]; viewy = xpos * axisframe[1][0] + ypos * axisframe[1][1] + zpos * axisframe[1][2] + axisframe[1][3]; y_2d = (viewy * eyedistance) / (eyedistance - zworld); x_2d = (viewx * eyedistance) / (eyedistance - zworld); *xis = xcenter + (short) (x_2d * scalefactor); *yis = ycenter - (short) (y_2d * scalefactor);}void Output2d_3d::WorldtoZvalue (double xpos, double ypos, double zpos, double *zis){ xpos *= xscale; ypos *= yscale; zpos *= zscale; *zis = xpos * axisframe[2][0] + ypos * axisframe[2][1] + zpos * axisframe[2][2] + axisframe[2][3];}void Output2d_3d::AxisRotx (double angle){ double sinus = sin (angle), cosinus = cos (angle); double temp[4]; // temp. save the rowes of the matrix// first row temp[1] = axisframe[0][1] * cosinus + axisframe[0][2] * sinus; temp[2] = -axisframe[0][1] * sinus + axisframe[0][2] * cosinus; axisframe[0][1] = temp[1]; axisframe[0][2] = temp[2];// second row temp[1] = axisframe[1][1] * cosinus + axisframe[1][2] * sinus; temp[2] = -axisframe[1][1] * sinus + axisframe[1][2] * cosinus; axisframe[1][1] = temp[1]; axisframe[1][2] = temp[2];// third row temp[1] = axisframe[2][1] * cosinus + axisframe[2][2] * sinus; temp[2] = -axisframe[2][1] * sinus + axisframe[2][2] * cosinus; axisframe[2][1] = temp[1]; axisframe[2][2] = temp[2];}void Output2d_3d::AxisRoty (double angle){ double sinus = sin (angle), cosinus = cos (angle); double temp[4]; // temp. save the rowes of the matrix// first row temp[0] = axisframe[0][0] * cosinus - axisframe[0][2] * sinus; temp[2] = axisframe[0][0] * sinus + axisframe[0][2] * cosinus; axisframe[0][0] = temp[0]; axisframe[0][2] = temp[2];// second row temp[0] = axisframe[1][0] * cosinus - axisframe[1][2] * sinus; temp[2] = axisframe[1][0] * sinus + axisframe[1][2] * cosinus; axisframe[1][0] = temp[0]; axisframe[1][2] = temp[2];// third row temp[0] = axisframe[2][0] * cosinus - axisframe[2][2] * sinus; temp[2] = axisframe[2][0] * sinus + axisframe[2][2] * cosinus; axisframe[2][0] = temp[0]; axisframe[2][2] = temp[2];}void Output2d_3d::AxisRotz (double angle){ double sinus = sin (angle), cosinus = cos (angle); double temp[4]; // temp. save the rowes of the matrix// first row temp[0] = axisframe[0][0] * cosinus + axisframe[0][1] * sinus; temp[1] = -axisframe[0][0] * sinus + axisframe[0][1] * cosinus; axisframe[0][0] = temp[0]; axisframe[0][1] = temp[1];// second row temp[0] = axisframe[1][0] * cosinus + axisframe[1][1] * sinus; temp[1] = -axisframe[1][0] * sinus + axisframe[1][1] * cosinus; axisframe[1][0] = temp[0]; axisframe[1][1] = temp[1];// third row temp[0] = axisframe[2][0] * cosinus + axisframe[2][1] * sinus; temp[1] = -axisframe[2][0] * sinus + axisframe[2][1] * cosinus; axisframe[2][0] = temp[0]; axisframe[2][1] = temp[1];}DVektor *Output2d_3d::Getnearestpoint1d (short xpos, short ypos, int *index, short *xis, short *yis){ DVektorArray *inputData = &(Dataset->Lese_Daten ()); short tempx, tempy; int counter, nearestcounter = 0; int xoutput; double youtput; double distance, mindistance = MAXDOUBLE; // distance high 2 PixeltoWorld1d (xpos, ypos, &xoutput, &youtput); for (counter = 0; counter < inputData->Lese_Groesse (); counter++) { WorldtoPixel1d (counter, inputData->Lese_Vektor (counter, xindex), &tempx, &tempy); distance = ((xpos - tempx) * (xpos - tempx)) + ((ypos - tempy) * (ypos - tempy)); if (distance < mindistance) { mindistance = distance; nearestcounter = counter; } } *index = nearestcounter; WorldtoPixel1d (nearestcounter, inputData->Lese_Vektor (nearestcounter, xindex), xis, yis); return &(inputData->Lese_Vektor (nearestcounter));}DVektor *Output2d_3d::Getnearestpoint2d (short xpos, short ypos, int *index, short *xis, short *yis){ DVektorArray *inputData = &(Dataset->Lese_Daten ()); short tempx, tempy; int counter, nearestcounter = 0; double xoutput, youtput; double distance, mindistance = MAXDOUBLE; // distance high 2 PixeltoWorld2d (xpos, ypos, &xoutput, &youtput); for (counter = 0; counter < inputData->Lese_Groesse (); counter++) { WorldtoPixel2d (inputData->Lese_Vektor (counter, xindex),
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -