📄 oglsim.c
字号:
int x; int y; // Loop through both dimensions and fill the 2D array for (x=0; x<20; x++) { // Generate one white noise array for each X value if (WhiteNoise (20, noiseLevel, -1, noiseArray) != 0) return -1; for (y=0; y<20; y++) { // Determine the correct function and calculate a data point switch (function) { case FUNC_1: dataArray[y][x] = A*sin(PI*(x-10)/10) + B*cos(PI*(y-10)/10) + noiseArray[y]; break; case FUNC_2: dataArray[y][x] = A*sin(B*((PI*(x-10)/10)*(PI*(x-10)/10) +(PI*(y-10)/10)*(PI*(y-10)/10))) + noiseArray[y]; break; case FUNC_3: dataArray[y][x] = A*exp(-((2*PI*x/20)+(2*PI*y/20))) * sin(B*((2*PI*x/20)*(2*PI*x/20) +(2*PI*y/20)*(2*PI*y/20))) + noiseArray[y]; break; case FUNC_4: dataArray[y][x] = A*sinh(PI*(x-10)/10)*cos(B*2*PI*y/20) + noiseArray[y]; break; } } } return 0;}/*---------------------------------------------------------------------------*//* ChangePlotStateCB *//*---------------------------------------------------------------------------*/int CVICALLBACK ChangePlotStateCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int timerEnabled; switch (event) { case EVENT_COMMIT: // Is the timer enabled (are we plotting)? Adjust it accordingly GetCtrlVal (mainPanel, MAINPNL_STARTPLOT, &timerEnabled); SetCtrlAttribute (mainPanel, MAINPNL_PLOTTIMER, ATTR_ENABLED, timerEnabled); break; } return 0;}//-----------------------------------------------------------------------------// NoiseLevelCB: Responds to the Noise Level control and adjusts the noiseLevel// element of the myNumerics struct passed into callbackData upper-right X close control//-----------------------------------------------------------------------------int CVICALLBACK NoiseLevelCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_VAL_CHANGED: GetCtrlVal (mainPanel, MAINPNL_NOISELEVEL, &(myNumerics.noiseLevel)); break; } return 0;}//-----------------------------------------------------------------------------// ChangeFuncCB: Responds to the function-select control; adjusts appropriate// plot attributes for scaling and updates elements of myNumerics// to reflect default values for A and B for each function//-----------------------------------------------------------------------------int CVICALLBACK ChangeFuncCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ int function; switch (event) { case EVENT_VAL_CHANGED: GetCtrlVal (mainPanel, MAINPNL_FUNCRING, &function); myNumerics.function = function; switch (myNumerics.function) { case FUNC_1: OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_OFFSET, -PI); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_GAIN, 2.0*PI/19.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_OFFSET, -PI); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_GAIN, 2.0*PI/19.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MAX_VALUE, 5.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MIN_VALUE, -5.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MAX_VALUE, 5.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MIN_VALUE, -5.0); myNumerics.A = -5.0; myNumerics.B = 5.0; SetCtrlVal (mainPanel, MAINPNL_A, myNumerics.A); SetCtrlVal (mainPanel, MAINPNL_B, myNumerics.B); break; case FUNC_2: OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_OFFSET, -PI); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_GAIN, 2.0*PI/19.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_OFFSET, -PI); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_GAIN, 2.0*PI/19.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MAX_VALUE, 10.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MIN_VALUE, -10.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MAX_VALUE, 2.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MIN_VALUE, -2.0); myNumerics.A = 5.0; myNumerics.B = 0.25; SetCtrlVal (mainPanel, MAINPNL_A, myNumerics.A); SetCtrlVal (mainPanel, MAINPNL_B, myNumerics.B); break; case FUNC_3: OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_OFFSET, 0.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_GAIN, 2.0*PI/19.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_OFFSET, 0.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_GAIN, 2.0*PI/19.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MAX_VALUE, 35.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MIN_VALUE, -35.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MAX_VALUE, 10.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MIN_VALUE, 1.0); myNumerics.A = 33.0; myNumerics.B = 1.0; SetCtrlVal (mainPanel, MAINPNL_A, myNumerics.A); SetCtrlVal (mainPanel, MAINPNL_B, myNumerics.B); break; case FUNC_4: OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_OFFSET, 0.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YAXIS_GAIN, 2.0*PI/19.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_OFFSET, -PI); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XAXIS_GAIN, 2.0*PI/19.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MAX_VALUE, 30.0); SetCtrlAttribute (mainPanel, MAINPNL_A, ATTR_MIN_VALUE, 1.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MAX_VALUE, 5.0); SetCtrlAttribute (mainPanel, MAINPNL_B, ATTR_MIN_VALUE, 1.0); myNumerics.A = 1.0; myNumerics.B = 1.61; SetCtrlVal (mainPanel, MAINPNL_A, myNumerics.A); SetCtrlVal (mainPanel, MAINPNL_B, myNumerics.B); break; } break; } return 0;}//-----------------------------------------------------------------------------// ChangeABCB: Responds to the A and B slider controls; adjusts the appropriate// elements of the myNumerics struct pointer passed in as callbackData upper-right X close control//-----------------------------------------------------------------------------int CVICALLBACK ChangeABCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ double A,B; switch (event) { case EVENT_VAL_CHANGED: if (control == MAINPNL_A) { GetCtrlVal (mainPanel, MAINPNL_A, &A); myNumerics.A = A; } if (control == MAINPNL_B) { GetCtrlVal (mainPanel, MAINPNL_B, &B); myNumerics.B = B; } break; } return 0;}//-----------------------------------------------------------------------------// PlotTimerCB: Responds to a tick of the PLOTTIMER timer; passes the correct// parameters to MakeDataArray by de-referencing the callbackData // pointer to myNumerics; refreshes the OGL plot by calling// OGLRefreshGraph//-----------------------------------------------------------------------------int CVICALLBACK PlotTimerCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_TIMER_TICK: // Update the plot with this new data MakeDataArray (myNumerics.function, myNumerics.dataArray, myNumerics.A, myNumerics.B, myNumerics.noiseLevel); OGLRefreshGraph (mainPanel, OGLControlID); break; } return 0;}//-----------------------------------------------------------------------------// QuitAppCB: Responds to the Quit button (hidden on panel but accessible through// upper-right X close control//-----------------------------------------------------------------------------int CVICALLBACK QuitAppCB (int panel, int control, int event, void *callbackData, int eventData1, int eventData2){ switch (event) { case EVENT_COMMIT: QuitUserInterface (0); break; } return 0;}//-----------------------------------------------------------------------------// PanelCallback: To responde to resize events//-----------------------------------------------------------------------------int CVICALLBACK PanelCallback (int panel, int event, void *callbackData, int eventData1, int eventData2){ int top, height, left, width; switch (event) { case EVENT_PANEL_SIZE: GetCtrlAttribute(panel, MAINPNL_OGLPORT, ATTR_TOP, &top); GetCtrlAttribute(panel, MAINPNL_OGLPORT, ATTR_LEFT, &left); GetCtrlAttribute(panel, MAINPNL_OGLPORT, ATTR_WIDTH, &width); GetCtrlAttribute(panel, MAINPNL_OGLPORT, ATTR_HEIGHT, &height); OGLSetCtrlAttribute (panel, MAINPNL_OGLPORT, OGLATTR_TOP, top); OGLSetCtrlAttribute (panel, MAINPNL_OGLPORT, OGLATTR_LEFT, left); OGLSetCtrlAttribute (panel, MAINPNL_OGLPORT, OGLATTR_WIDTH, width); OGLSetCtrlAttribute (panel, MAINPNL_OGLPORT, OGLATTR_HEIGHT, height); OGLRefreshGraph(panel,MAINPNL_OGLPORT); break; } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -