Example 148: Scientific Graph 2D Contour RealTime ComputeShader plus CircularBuffer

PesgoScientific Graph Objectadvanced

2D Contour RealTime ComputeShader plus CircularBuffer

Preview

ProEssentials Pesgo Scientific Graph Object - Scientific Graph 2D Contour RealTime ComputeShader plus CircularBuffer
Click to enlarge

Source Code

Form3.cs
1//! Right button click to show popup menu. //
2//! Double Click to show customization dialog. //
3//! MouseWheel Zoom. //
4
5// Code to get partial data from a binary file //
6int Row, Col, o, nQ, nStartRow, nStartCol;
7int nEndRow, nEndCol, nTargetRows, nTargetCols;
8
9nStartRow = 0;
10nEndRow = 999;
11nTargetRows = nEndRow - nStartRow + 1;
12nStartCol = 0;
13nEndCol = 999;
14nTargetCols = nEndCol - nStartCol + 1;
15nQ = nTargetRows * nTargetCols;
16
17String filepath = null;
18filepath = System.AppDomain.CurrentDomain.BaseDirectory + "\\terrain2.bin";
19System.IO.FileStream fs = null;
20try
21{
22 fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
23}
24catch
25{
26 System.Windows.Forms.MessageBox.Show("Demo File Not Found?", "Error", System.Windows.Forms.MessageBoxButtons.OK);
27 System.Windows.Forms.Application.Exit();
28}
29
30System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
31for (o = 0; o < 2250000; o++)
32MainWindow.pGlobalElevData[o] = r.ReadInt32();
33fs.Close();
34
35float[] pMyXData = new float[nTargetCols];
36float[] pMyYData = new float[nTargetRows];
37float[] pMyZData = new float[nQ]; // Pesgo 2D contours, the elevation/3rd dimension is zdata
38
39int rowcounter, colcounter;
40Boolean foundtargetindex = false;
41int s;
42rowcounter = 0;
43colcounter = 0;
44
45for (Row = 0; Row < 1500; Row++)
46{
47 for (Col = 0; Col < 1500; Col++)
48 {
49 foundtargetindex = false;
50 if (Row >= nStartRow && Row <= nEndRow)
51 {
52 if (Col >= nStartCol && Col <= nEndCol)
53 {
54 foundtargetindex = true;
55 if (Row == nStartRow) // v9.5
56 pMyXData[Col - nStartCol] = Col + 1;
57 if (Col == nStartCol) // v9.5
58 pMyYData[Row - nStartRow] = Row + 1;
59 // See our help, topic SubsetByPoint to understand the below formula // v9.5
60 o = (rowcounter * nTargetRows) + colcounter;
61 pMyZData[o] = (float)(MainWindow.pGlobalElevData[(Row * 1500) + Col] * 0.1);
62 }
63 }
64 if (foundtargetindex)
65 colcounter = colcounter + 1;
66}
67if (foundtargetindex)
68rowcounter = rowcounter + 1;
69}
70
71Pesgo1.PeData.Subsets = nTargetRows;
72Pesgo1.PeData.Points = nTargetCols;
73
74Pesgo1.PeData.DuplicateDataX = DuplicateData.PointIncrement; // set duplicatedatax type properties early before calling FastCopy
75Pesgo1.PeData.DuplicateDataY = DuplicateData.SubsetIncrement;
76
77// Perform the transfer of data //
78Pesgo1.PeData.X.FastCopyFrom(pMyXData, nTargetCols);
79Pesgo1.PeData.Y.FastCopyFrom(pMyYData, nTargetRows);
80Pesgo1.PeData.Z.FastCopyFrom(pMyZData, nQ);
81
82// Real-Time with large amounts of data, it's best to manually scale axes
83// so the chart does not need to spend time determining ranges of data.
84
85Pesgo1.PeGrid.Configure.ManualScaleControlX = ManualScaleControl.MinMax;
86Pesgo1.PeGrid.Configure.ManualMinX = 1;
87Pesgo1.PeGrid.Configure.ManualMaxX = 1000;
88
89Pesgo1.PeGrid.Configure.ManualScaleControlY = ManualScaleControl.MinMax;
90Pesgo1.PeGrid.Configure.ManualMinY = 1;
91Pesgo1.PeGrid.Configure.ManualMaxY = 1000;
92
93Pesgo1.PeGrid.Configure.ManualScaleControlZ = ManualScaleControl.MinMax;
94Pesgo1.PeGrid.Configure.ManualMinZ = 600;
95Pesgo1.PeGrid.Configure.ManualMaxZ = 1900;
96
97
98// Set Contour Color regions //
99Pesgo1.PeColor.SubsetColors.Clear();
100for (s = 0; s <= 10; s++)
101{
102 Pesgo1.PeColor.SubsetColors[s] = Color.FromArgb(255, 0, (byte)(31 + (s * 21)), (byte)(95 + (s * 15)));
103 Pesgo1.PeColor.SubsetColors[s + 11] = Color.FromArgb(255, 0, (byte)(95 + (s * 15)), 0);
104}
105for (s = 0; s <= 14; s++)
106 Pesgo1.PeColor.SubsetColors[s + 22] = Color.FromArgb(255, (byte)(128 + (s * 9)), (byte)(128 + (s * 9)), (byte)(128 + (s * 9)));
107
108Pesgo1.PeColor.SubsetShades.Clear(); // v9.5
109for (s = 0; s <= 36; s++)
110 Pesgo1.PeColor.SubsetShades[s] = Color.FromArgb(255, (byte)(75 + (s * 5)), (byte)(75 + (s * 5)), (byte)(75 + (s * 5)));
111
112Pesgo1.PeLegend.ContourLegendPrecision = ContourLegendPrecision.ZeroDecimals;
113Pesgo1.PeLegend.ContourStyle = true;
114
115// Set Various Other Properties ///
116Pesgo1.PeColor.BitmapGradientMode = true;
117Pesgo1.PeColor.QuickStyle = QuickStyle.DarkShadow;
118Pesgo1.PeConfigure.BorderTypes = TABorder.NoBorder;
119Pesgo1.PeColor.GridBold = true;
120
121// Set the plotting method ///
122Pesgo1.PePlot.Allow.ContourColors = true;
123Pesgo1.PePlot.Allow.ContourColorsShadows = true;
124
126Pesgo1.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
127
128Pesgo1.PeLegend.Location = LegendLocation.Left;
129Pesgo1.PeGrid.InFront = true;
130Pesgo1.PeGrid.LineControl = GridLineControl.Both;
131Pesgo1.PeGrid.Style = GridStyle.Dot;
132Pesgo1.PeConfigure.PrepareImages = true;
133Pesgo1.PeConfigure.CacheBmp = true;
134
135Pesgo1.PeUserInterface.Allow.ZoomStyle = ZoomStyle.Ro2Not;
136Pesgo1.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVert;
137Pesgo1.PeUserInterface.Scrollbar.MouseWheelFunction = MouseWheelFunction.HorizontalVerticalZoom;
138Pesgo1.PeUserInterface.Scrollbar.MouseWheelZoomSmoothness = 2;
139Pesgo1.PeUserInterface.Scrollbar.MouseWheelZoomFactor = 1.1F;
140Pesgo1.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVertMb; // enables left click drag
141Pesgo1.PeGrid.GridBands = false;
142
143Pesgo1.PeUserInterface.Menu.MarkDataPoints = MenuControl.Hide;
144Pesgo1.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
145
146// Disable other non contour plotting method //
147Pesgo1.PePlot.Allow.Line = false;
148Pesgo1.PePlot.Allow.Point = false;
149Pesgo1.PePlot.Allow.Bar = false;
150Pesgo1.PePlot.Allow.Area = false;
151Pesgo1.PePlot.Allow.Spline = false;
152Pesgo1.PePlot.Allow.SplineArea = false;
153Pesgo1.PePlot.Allow.PointsPlusLine = false;
154Pesgo1.PePlot.Allow.PointsPlusSpline = false;
155Pesgo1.PePlot.Allow.BestFitCurve = false;
156Pesgo1.PePlot.Allow.BestFitLine = false;
157Pesgo1.PePlot.Allow.Stick = false;
158
159// Set Titles //
160Pesgo1.PeString.MainTitle = "1 Million vertices redrawn per update";
161Pesgo1.PeString.SubTitle = "";
162
163// So contour goes to edge of grid //
164Pesgo1.PeGrid.Configure.AutoMinMaxPadding = 0;
165
166// Set small font size //
167Pesgo1.PeFont.FontSize = FontSize.Medium;
168Pesgo1.PeFont.Fixed = true;
169
170// Disable appropriate tabs //
171Pesgo1.PeUserInterface.Dialog.Axis = false;
172Pesgo1.PeUserInterface.Dialog.Style = false;
173Pesgo1.PeUserInterface.Dialog.Subsets = false;
174
175Pesgo1.PeConfigure.TextShadows = TextShadows.BoldText;
176Pesgo1.PeFont.MainTitle.Bold = true;
177Pesgo1.PeFont.SubTitle.Bold = true;
178Pesgo1.PeFont.Label.Bold = true;
179
180Pesgo1.PeUserInterface.Scrollbar.ScrollingVertZoom = true;
181Pesgo1.PeUserInterface.Scrollbar.ScrollingHorzZoom = true;
182Pesgo1.PeUserInterface.Scrollbar.MouseDraggingX = true;
183Pesgo1.PeUserInterface.Scrollbar.MouseDraggingY = true;
184
185Pesgo1.PeUserInterface.Menu.AnnotationControl = true;
186Pesgo1.PeUserInterface.Menu.ShowAnnotationText = MenuControl.Show;
187
188Pesgo1.PeConfigure.AntiAliasGraphics = true;
189Pesgo1.PeConfigure.AntiAliasText = true;
190
191// Set various export defaults //
192Pesgo1.PeSpecial.DpiX = 600;
193Pesgo1.PeSpecial.DpiY = 600;
194
195// default export setting //
196Pesgo1.PeUserInterface.Dialog.ExportSizeDef = ExportSizeDef.NoSizeOrPixel;
197Pesgo1.PeUserInterface.Dialog.ExportTypeDef = ExportTypeDef.Png;
198Pesgo1.PeUserInterface.Dialog.ExportDestDef = ExportDestDef.Clipboard;
199Pesgo1.PeUserInterface.Dialog.ExportUnitXDef = "1280";
200Pesgo1.PeUserInterface.Dialog.ExportUnitYDef = "768";
201Pesgo1.PeUserInterface.Dialog.ExportImageDpi = 300;
202Pesgo1.PeUserInterface.Dialog.AllowEmfExport = false; // v9.5
203Pesgo1.PeUserInterface.Dialog.AllowWmfExport = false;
204
205Pesgo1.PeConfigure.Composite2D3D = Composite2D3D.Foreground;
206Pesgo1.PeConfigure.RenderEngine = RenderEngine.Direct3D;
207
208// v10 Enable ComputeShader for fastest possible rendering
209Pesgo1.PeData.ComputeShader = true;
210Pesgo1.PeData.StagingBufferX = true;
211Pesgo1.PeData.StagingBufferY = true;
212Pesgo1.PeData.StagingBufferZ = true;
213Pesgo1.PeData.CircularBuffers = true;
214// comment these above v10 lines to experience v9 building Direct3D content cpu side and using non-circular buffers
215
216Pesgo1.PeFunction.Force3dxNewColors = true;
217Pesgo1.PeFunction.Force3dxVerticeRebuild = true;
218
219// Generally call ReinitializeResetImage at end **'
220Pesgo1.PeFunction.ReinitializeResetImage();
221Pesgo1.Invalidate();
222
223MainWindow.m_nRealTimeCounter = 1001; // Keeps track of current row
224MainWindow.m_nOverallCounter = 1001;
225
226MainWindow.Timer1.Interval = 15;
227MainWindow.Timer1.Start();
228
229/*
230/////////////////////////
231// Example Timer Event //
232/////////////////////////
233private void Timer1_Tick(object sender, System.EventArgs e)
234{
235 int nNewPointsPerSubset = 5;
236 float[] pNewZData = new float[5000];
237
238 int l, s;
239 // prepare new data, 5 new points per subset, s0p0 s0p1 s1p0 s1p1
240
241 for (s = 0; s < 1000; s++)
242 {
243 for (int pcnt = 0; pcnt < nNewPointsPerSubset; pcnt++)
244 {
245 l = (pcnt) + (s * 1500) + m_nRealTimeCounter;
246 pNewZData[(s * nNewPointsPerSubset) + pcnt] = pGlobalElevData[l] * 0.1F;
247 }
248 }
249
250 float[] pNewXData = new float[5];
251 for (int scnt = 0; scnt < nNewPointsPerSubset; scnt++)
252 {
253 pNewXData[scnt] = m_nOverallCounter + scnt;
254 }
255
256 m_nRealTimeCounter = m_nRealTimeCounter + nNewPointsPerSubset;
257 if (m_nRealTimeCounter > 1499) { m_nRealTimeCounter = 0; } // end of terrain file
258 m_nOverallCounter = m_nOverallCounter + nNewPointsPerSubset;
259
260 Pesgo1.PeGrid.Configure.ManualMinX = m_nOverallCounter - 1000;
261 Pesgo1.PeGrid.Configure.ManualMaxX = m_nOverallCounter;
262
263 if (Pesgo1.PeGrid.Zoom.Mode == true)
264 {
265 Pesgo1.PeGrid.Zoom.MinX += nNewPointsPerSubset;
266 Pesgo1.PeGrid.Zoom.MaxX += nNewPointsPerSubset;
267 }
268
269 // transfer new Data //
270 Pesgo1.PeData.Z.AppendData(pNewZData, nNewPointsPerSubset);
271 Pesgo1.PeData.X.AppendData(pNewXData, nNewPointsPerSubset);
272
273 Pesgo1.PeData.ReuseDataY = true;
274
275 // causes 3D object to reconstruct polygon data //
276 Pesgo1.PeFunction.Force3dxVerticeRebuild = true;
277 Pesgo1.Invalidate();
278}
279
280*/
Tip: Uses property syntax like Pego1.PeData.Y[s, p]Click underlined properties to view documentation