Example 121: Scientific Graph showing 2D contour lines

PesgoScientific Graph Objectintermediate

2D contour lines

Preview

ProEssentials Pesgo Scientific Graph Object - Scientific Graph showing 2D contour lines
Click to enlarge

Source Code

Form3.cs
1//! Right button click to show popup menu. //
2//! Double Click to show customization dialog. //
3//! Left-Click and drag to draw zoom box. Use popup memu or 'z' to undo zoom. //
4
5//! This example shows square symbol annotations along with contour.
6
7// Enable middle mouse dragging //
8Pesgo1.PeUserInterface.Scrollbar.MouseDraggingX = true;
9Pesgo1.PeUserInterface.Scrollbar.MouseDraggingY = true;
10
11// Code to get partial data from a binary file //
12int Row, Col, o, nQ, nStartRow, nStartCol;
13int nEndRow, nEndCol, nTargetRows, nTargetCols;
14
15nStartRow = 300;
16nEndRow = 350;
17nTargetRows = nEndRow - nStartRow + 1;
18nStartCol = 50;
19nEndCol = 100;
20nTargetCols = nEndCol - nStartCol + 1;
21nQ = nTargetRows * nTargetCols;
22
23Int32[] pElevData = new Int32[2250000];
24
25String filepath = null;
26filepath = System.AppDomain.CurrentDomain.BaseDirectory + "\\terrain2.bin";
27System.IO.FileStream fs = null;
28try
29{
30 fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
31}
32catch
33{
34 System.Windows.Forms.MessageBox.Show("Demo File Not Found?", "Error", System.Windows.Forms.MessageBoxButtons.OK);
35 System.Windows.Forms.Application.Exit();
36}
37
38System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
39
40for (o = 0; o < 2250000; o++)
41 pElevData[o] = r.ReadInt32();
42fs.Close();
43
44float[] pMyXData = new float[nQ];
45float[] pMyYData = new float[nQ];
46float[] pMyZData = new float[nQ];
47
48int rowcounter, colcounter;
49Boolean foundtargetindex = false;
50int s;
51rowcounter = 0;
52colcounter = 0;
53
54for (Row = 0; Row < 1500; Row++)
55{
56 for (Col = 0; Col < 1500; Col++)
57 {
58 foundtargetindex = false;
59 if (Row >= nStartRow && Row <= nEndRow)
60 {
61 if (Col >= nStartCol && Col <= nEndCol)
62 {
63 foundtargetindex = true;
64 o = (rowcounter * nTargetRows) + colcounter;
65 pMyXData[o] = Col + 1;
66 pMyYData[o] = Row + 1;
67 pMyZData[o] = (float)(pElevData[(Row * 1500) + Col] * 0.1);
68 }
69 }
70 if (foundtargetindex)
71 colcounter = colcounter + 1;
72 }
73 if (foundtargetindex)
74 rowcounter = rowcounter + 1;
75}
76
77Pesgo1.PeData.Subsets = nTargetRows; // Non-Jagged Data, PeData.JaggedData = False, set Subsets and Points first
78Pesgo1.PeData.Points = nTargetCols;
79
80// Perform the transfer of data //
81Pesgo1.PeData.X.FastCopyFrom(pMyXData, nQ);
82Pesgo1.PeData.Y.FastCopyFrom(pMyYData, nQ);
83Pesgo1.PeData.Z.FastCopyFrom(pMyZData, nQ);
84
85Pesgo1.PeLegend.ContourLegendPrecision = ContourLegendPrecision.ZeroDecimals;
86
87// Set Contour Color regions //
88Pesgo1.PeColor.ContourColorBlends = 10;
89Pesgo1.PeColor.ContourColorSet = ContourColorSet.BlueCyanGreenYellowBrownWhite;
90
91for (s = 0; s <= 33; s++)
92 Pesgo1.PeColor.SubsetShades[s] = Color.FromArgb(255, (byte)(20 + (s * 7)), (byte)(20 + (s * 7)), (byte)(20 + (s * 7)));
93
94Pesgo1.PeLegend.ContourStyle = true;
95Pesgo1.PePlot.Option.GraphDataLabels = true;
96
97// v9.5
98Pesgo1.PeUserInterface.Menu.AnnotationControl = true;
99
100// Set some random annotations //
101for (s = 0; s <= 29; s++)
102{
103 Pesgo1.PeAnnotation.Graph.X[s] = nStartCol + (Rand_Num.NextDouble() * 50);
104 Pesgo1.PeAnnotation.Graph.Y[s] = nStartRow + (Rand_Num.NextDouble() * 50);
105 Pesgo1.PeAnnotation.Graph.Type[s] = (int)GraphAnnotationType.SmallDotSolid;
106 Pesgo1.PeAnnotation.Graph.Color[s] = Color.FromArgb(186, 198, 0, 0);
107 Pesgo1.PeAnnotation.Graph.GradientStyle[s] = (int)Gigasoft.ProEssentials.Enums.PlotGradientStyle.RadialTopLeft;
108 Pesgo1.PeAnnotation.Graph.Shadow[s] = true;
109}
110for (s = 30; s <= 59; s++)
111{
112 Pesgo1.PeAnnotation.Graph.X[s] = nStartCol + (Rand_Num.NextDouble() * 50);
113 Pesgo1.PeAnnotation.Graph.Y[s] = nStartRow + (Rand_Num.NextDouble() * 50);
114 Pesgo1.PeAnnotation.Graph.Type[s] = (int)GraphAnnotationType.SmallDotSolid;
115 Pesgo1.PeAnnotation.Graph.Color[s] = Color.FromArgb(186, 0, 198, 0);
116 Pesgo1.PeAnnotation.Graph.GradientStyle[s] = (int)Gigasoft.ProEssentials.Enums.PlotGradientStyle.RadialTopLeft;
117 Pesgo1.PeAnnotation.Graph.Shadow[s] = true;
118}
119Pesgo1.PeAnnotation.Show = true;
120Pesgo1.PeAnnotation.Graph.ShowShadows = true;
121
122// Set Various Other Properties //
123Pesgo1.PeColor.BitmapGradientMode = false;
124Pesgo1.PeColor.QuickStyle = QuickStyle.LightInset;
125
126// Set the plotting method //
127Pesgo1.PePlot.Allow.ContourColors = true;
128Pesgo1.PePlot.Allow.ContourLines = true;
129
130Pesgo1.PePlot.Method = SGraphPlottingMethod.ContourLines;
131Pesgo1.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
132Pesgo1.PeUserInterface.Menu.MarkDataPoints = MenuControl.Hide;
133
134Pesgo1.PeLegend.Location = LegendLocation.Left; ;
135Pesgo1.PeGrid.InFront = true;
136Pesgo1.PeGrid.LineControl = GridLineControl.Both;
137Pesgo1.PeGrid.Style = GridStyle.Dot;
138Pesgo1.PeConfigure.PrepareImages = true;
139Pesgo1.PeConfigure.CacheBmp = true;
140
141Pesgo1.PeUserInterface.Allow.ZoomStyle = ZoomStyle.Ro2Not;
142Pesgo1.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVert;
143Pesgo1.PeUserInterface.Scrollbar.MouseWheelFunction = MouseWheelFunction.HorizontalVerticalZoom;
144
145// Disable other non contour plotting method //
146Pesgo1.PePlot.Allow.Line = false;
147Pesgo1.PePlot.Allow.Point = false;
148Pesgo1.PePlot.Allow.Bar = false;
149Pesgo1.PePlot.Allow.Area = false;
150Pesgo1.PePlot.Allow.Spline = false;
151Pesgo1.PePlot.Allow.SplineArea = false;
152Pesgo1.PePlot.Allow.PointsPlusLine = false;
153Pesgo1.PePlot.Allow.PointsPlusSpline = false;
154Pesgo1.PePlot.Allow.BestFitCurve = false;
155Pesgo1.PePlot.Allow.BestFitLine = false;
156Pesgo1.PePlot.Allow.Stick = false;
157
158// Set Titles //
159Pesgo1.PeString.MainTitle = "Elevation Example";
160Pesgo1.PeString.SubTitle = "";
161Pesgo1.PeGrid.Option.ShowYAxis = ShowAxis.GridNumbers;
162Pesgo1.PeGrid.Option.ShowXAxis = ShowAxis.GridNumbers;
163
164// So contour goes to edge of grid //
165Pesgo1.PeGrid.Configure.AutoMinMaxPadding = 0;
166
167// Set small font size //
168Pesgo1.PeFont.FontSize = FontSize.Small;
169Pesgo1.PeFont.Fixed = true;
170
171// Disable appropriate tabs //
172Pesgo1.PeUserInterface.Dialog.Axis = false;
173Pesgo1.PeUserInterface.Dialog.Style = false;
174Pesgo1.PeUserInterface.Dialog.Subsets = false;
175
176Pesgo1.PeUserInterface.Scrollbar.ScrollingVertZoom = true;
177Pesgo1.PeUserInterface.Scrollbar.ScrollingHorzZoom = true;
178
179Pesgo1.PeConfigure.TextShadows = TextShadows.BoldText;
180Pesgo1.PeFont.MainTitle.Bold = true;
181Pesgo1.PeFont.SubTitle.Bold = true;
182Pesgo1.PeFont.Label.Bold = true;
183Pesgo1.PeFont.FontSize = FontSize.Medium;
184
185// Set various export defaults //
186Pesgo1.PeSpecial.DpiX = 600;
187Pesgo1.PeSpecial.DpiY = 600;
188
189// default export setting //
190Pesgo1.PeUserInterface.Dialog.ExportSizeDef = ExportSizeDef.NoSizeOrPixel;
191Pesgo1.PeUserInterface.Dialog.ExportTypeDef = ExportTypeDef.Png;
192Pesgo1.PeUserInterface.Dialog.ExportDestDef = ExportDestDef.Clipboard;
193Pesgo1.PeUserInterface.Dialog.ExportUnitXDef = "1280";
194Pesgo1.PeUserInterface.Dialog.ExportUnitYDef = "768";
195Pesgo1.PeUserInterface.Dialog.ExportImageDpi = 300;
196
197Pesgo1.PeConfigure.AntiAliasGraphics = true;
198Pesgo1.PeConfigure.AntiAliasText = true;
199
200Pesgo1.PeConfigure.RenderEngine = RenderEngine.GdiPlus;
201
202// Generally call ReinitializeResetImage at end **'
203Pesgo1.PeFunction.ReinitializeResetImage();
204Pesgo1.Invalidate();
205// Optionally call Pego1.Refresh() if you are not seeing changes immediately
Tip: Uses property syntax like Pego1.PeData.Y[s, p]Click underlined properties to view documentation