📄 oglsim.c
字号:
//-----------------------------------------------------------------------------// Demonstrates the CVIOGL plot attribute OGLATTR_COPY_ORIGINAL_DATA value // of FALSE to force the control to reference the users plot data when calling// OGLRefreshGraph.//-----------------------------------------------------------------------------//-----------------------------------------------------------------------------// Include necessary headers //-----------------------------------------------------------------------------#include <cvirte.h> #include <analysis.h>#include <ansi_c.h>#include <userint.h>#include "cviogl.h"#include "oglsim.h"//-----------------------------------------------------------------------------// Define useful constants//-----------------------------------------------------------------------------#define FUNC_1 2#define FUNC_2 3#define FUNC_3 4#define FUNC_4 5#define PI 3.14159//-----------------------------------------------------------------------------// Define numerics datatype to hold variables describing ploted waveform//-----------------------------------------------------------------------------typedef struct { double noiseLevel; int function; double A; double B; double dataArray[20][20];} numerics;static numerics myNumerics; //-----------------------------------------------------------------------------// Define module global variables//-----------------------------------------------------------------------------static int mainPanel;static int OGLControlID;static ColorMapEntry gColorMap[3];static int OGLPlotHandle = 0;//-----------------------------------------------------------------------------// Prototypes//-----------------------------------------------------------------------------int InitPlot (void);int InitOGLControl (void);int PlotColorScale (void);int MakeDataArray (int function, double dataArray[20][20], double A, double B, double noiseLevel);void MakeColorMap (int lowColor, int medColor, int highColor);//-----------------------------------------------------------------------------// Main//-----------------------------------------------------------------------------int main (int argc, char *argv[]){ int timerEnabled; // Initialize the RTE if necessary if (InitCVIRTE (0, argv, 0) == 0) return -1; // Load the main program panel if ((mainPanel = LoadPanel (0, "oglsim.uir", MAINPNL)) < 0) return -1; // Setup default timer value GetCtrlAttribute (mainPanel, MAINPNL_PLOTTIMER, ATTR_ENABLED, &timerEnabled); SetCtrlVal (mainPanel, MAINPNL_STARTPLOT, timerEnabled); // Initialize the OGL control if (InitOGLControl () != 0) return -1; // Initialize the main UIR if (InitPlot () != 0) return -1; // Display the program panel and run the user interface DisplayPanel (mainPanel); RunUserInterface (); return 0;}//-----------------------------------------------------------------------------// InitPlot: Initializes the color scale and sets the default plotting function;// returns 0 if successful//-----------------------------------------------------------------------------int InitPlot (){ // Make the color map with the default values MakeColorMap (VAL_BLACK, VAL_BLUE, VAL_RED); // Plot the color scale next to 3D plot to reflect this color map if (PlotColorScale() != 0) { MessagePopup ("Initialization Error", "Could not initialize color scale."); return -1; } // Set the plotting function to the default value ChangeFuncCB (mainPanel, 0, EVENT_VAL_CHANGED, 0, 0, 0); // Set the noise level to the default value NoiseLevelCB (mainPanel, 0, EVENT_VAL_CHANGED, 0, 0, 0); // Create the plotdata for the first time, we will use MakeDataArray (FUNC_1, myNumerics.dataArray, myNumerics.A, myNumerics.B, myNumerics.noiseLevel); OGLPlotHandle = OGLPlot3DUniform (mainPanel, OGLControlID, myNumerics.dataArray, 20, 20, OGLVAL_DOUBLE, 1.0, 0.0, 1.0, 0.0); // Set the plot attributes OGLSetPlotColorScheme (mainPanel, OGLControlID, OGLPlotHandle, OGLVAL_COLORMAP, gColorMap, 3, VAL_YELLOW, 1, NULL, 0, 0); OGLSetPlotAttribute(mainPanel, OGLControlID,OGLPlotHandle, OGLATTR_SURFACE_STYLE,OGLVAL_SMOOTH); OGLSetPlotAttribute(mainPanel, OGLControlID,OGLPlotHandle, OGLATTR_SURFACE_SPECULAR_FACTOR,1.0); OGLSetPlotAttribute(mainPanel, OGLControlID,OGLPlotHandle, OGLATTR_SURFACE_SHININESS,50); OGLSetPlotAttribute(mainPanel, OGLControlID,OGLPlotHandle, OGLATTR_WIRE_STYLE,OGLVAL_NONE); return 0;} //-----------------------------------------------------------------------------// InitOGLControl: Initializes the OGL control attributes;// returns 0 if successful//-----------------------------------------------------------------------------int InitOGLControl (void){ // Create the OGL Control from the picture control in the uir if ((OGLControlID = OGLConvertCtrl (mainPanel, MAINPNL_OGLPORT)) <= 0) return -1; // Set up the lighting attributes OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_LIGHTING_ENABLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_LIGHT_SELECT, 1); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_LIGHT_ENABLE, 1); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_LIGHT_DISTANCE, 3.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PROJECTION_TYPE,OGLVAL_PERSPECTIVE); // Set up the Z axis OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZNAME_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZNAME, "Z"); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZNAME_COLOR, OGLVAL_YELLOW); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZNAME_POINT_SIZE, 17); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZLABEL_VISIBLE, 1); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZLABEL_POINT_SIZE, 16); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZDIVISIONS, 5); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZAXIS_SCALING, OGLVAL_MANUAL); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZMIN, -10.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ZMAX, 10.0); // Set up the X axis OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XNAME, "X"); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XNAME_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XNAME_POINT_SIZE, 17); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XNAME_COLOR, OGLVAL_YELLOW); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XLABEL_POINT_SIZE, 16); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XLABEL_VISIBLE, OGLVAL_TRUE); // Set up the Y axis OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YNAME, "Y"); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YNAME_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YNAME_POINT_SIZE, 17); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YNAME_COLOR, OGLVAL_YELLOW); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YLABEL_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YLABEL_POINT_SIZE, 16); // Set up the grid planes OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YZ_GRID_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_YZ_GRID_COLOR, OGLVAL_LT_GRAY); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XY_GRID_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XY_GRID_COLOR, OGLVAL_LT_GRAY); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XZ_GRID_VISIBLE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_XZ_GRID_COLOR, OGLVAL_LT_GRAY); // Set up the plot area OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_ZSTART, -1.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_ZSIZE, 2.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_XSTART, -1.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_XSIZE, 2.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_YSTART, -1.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_PLOTAREA_YSIZE, 2.0); // Set up the default view position OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_VIEW_AUTO_DISTANCE, OGLVAL_FALSE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_VIEW_DISTANCE, 4.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_VIEW_LATITUDE, 66.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_VIEW_LONGITUDE, 64.0); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_VIEW_CENTERZ, -0.35); // Set up the control for Refresh operation (keeping a pointer only) OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_COPY_ORIGINAL_DATA, OGLVAL_FALSE); // Define user interaction OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ENABLE_PAN_ZOOM_ROTATE, OGLVAL_TRUE); OGLSetCtrlAttribute (mainPanel, OGLControlID, OGLATTR_ENABLE_PROPERTY_POPUP, OGLVAL_TRUE); return 0;}//-----------------------------------------------------------------------------// MakeColorMap: Builds the global three-color color map array gColorMap// with the passed-in colors//-----------------------------------------------------------------------------void MakeColorMap (int lowColor, int medColor, int highColor){ gColorMap[0].dataValue.valDouble = -10.0; gColorMap[0].color = lowColor; gColorMap[1].dataValue.valDouble = 0.0; gColorMap[1].color = medColor; gColorMap[2].dataValue.valDouble = 10.0; gColorMap[2].color = highColor;}//-----------------------------------------------------------------------------// PlotColorScale: Builds a temporary array spanning the range of Z values and // performs an interpolated intensity plot to display the scale; // returns 0 if successful //-----------------------------------------------------------------------------int PlotColorScale (void){ double scaleArray[3][2]; // Build an array that utilizes the full Z scale (-10<->10) scaleArray[0][0] = -10.0; scaleArray[0][1] = -10.0; scaleArray[1][0] = 0.0; scaleArray[1][1] = 0.0; scaleArray[2][0] = 10.0; scaleArray[2][1] = 10.0; // Plot this array on the color scale graph control and return the handle if (PlotIntensity (mainPanel, MAINPNL_COLORSCALE, scaleArray, 2, 3, VAL_DOUBLE, gColorMap, VAL_BLACK, 3, 1, 1) <= 0) return -1; return 0; }//-----------------------------------------------------------------------------// int MakeDataArray (int, double**, double, double, double): Updates the 2D array of data that// we will plot later;// returns 0 if successful//-----------------------------------------------------------------------------int MakeDataArray (int function, double dataArray[20][20], double A, double B, double noiseLevel){ double noiseArray[20];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -