Example 122: Scientific Graph showing large 2D contour with more colors

PesgoScientific Graph Objectadvanced

Large 2D contour with more colors

Preview

ProEssentials Pesgo Scientific Graph Object - Scientific Graph showing large 2D contour with more colors
Click to enlarge

Source Code

Form3.cs
1//! Right button click to show popup menu. //
2//! Double Click to show customization dialog. //
3//! Middle-Button hold and drag to zoom, or MouseWheel Zoom. //
4//! Left-Click and drag to pan view.
5//! Use popup memu or 'z' to undo zoom. //
6
7Pesgo1.PeUserInterface.Scrollbar.MouseDraggingX = true;
8Pesgo1.PeUserInterface.Scrollbar.MouseDraggingY = true;
9
10// Code to get partial data from a binary file //
11int Row, Col, o, nQ, nStartRow, nStartCol;
12int nEndRow, nEndCol, nTargetRows, nTargetCols;
13
14nStartRow = 1;
15nEndRow = 1000;
16nTargetRows = nEndRow - nStartRow + 1;
17nStartCol = 1;
18nEndCol = 1000;
19nTargetCols = nEndCol - nStartCol + 1;
20nQ = nTargetRows * nTargetCols;
21
22Int32[] pElevData = new Int32[2250000];
23
24String filepath = null;
25filepath = System.AppDomain.CurrentDomain.BaseDirectory + "\\terrain2.bin";
26System.IO.FileStream fs = null;
27try
28{
29 fs = new System.IO.FileStream(filepath, System.IO.FileMode.Open);
30}
31catch
32{
33 System.Windows.Forms.MessageBox.Show("Demo File Not Found?", "Error", System.Windows.Forms.MessageBoxButtons.OK);
34 System.Windows.Forms.Application.Exit();
35}
36System.IO.BinaryReader r = new System.IO.BinaryReader(fs);
37
38for (o = 0; o < 2250000; o++)
39 pElevData[o] = r.ReadInt32();
40fs.Close();
41
42float[] pMyXData = new float[nTargetCols]; // v9.5
43float[] pMyYData = new float[nTargetRows];
44float[] pMyZData = new float[nQ]; // Pesgo 2D contours, the elevation/3rd dimension is zdata
45
46int rowcounter, colcounter;
47Boolean foundtargetindex = false;
48int s;
49rowcounter = 0;
50colcounter = 0;
51
52for (Row = 0; Row < 1500; Row++)
53{
54 for (Col = 0; Col < 1500; Col++)
55 {
56 foundtargetindex = false;
57 if (Row >= nStartRow && Row <= nEndRow)
58 {
59 if (Col >= nStartCol && Col <= nEndCol)
60 {
61 foundtargetindex = true;
62 if (Row == nStartRow) // v9.5
63 pMyXData[Col - nStartCol] = Col + 1;
64 if (Col == nStartCol) // v9.5
65 pMyYData[Row - nStartRow] = Row + 1;
66 // See our help, topic SubsetByPoint to understand the below formula // v9.5
67 o = (rowcounter * nTargetRows) + colcounter;
68 pMyZData[o] = (float)(pElevData[(Row * 1500) + Col] * 0.1);
69 }
70 }
71 if (foundtargetindex)
72 colcounter = colcounter + 1;
73 }
74 if (foundtargetindex)
75 rowcounter = rowcounter + 1;
76}
77
78Pesgo1.PeData.Subsets = nTargetRows; // Non-Jagged Data, PeData.JaggedData = False, set Subsets and Points first
79Pesgo1.PeData.Points = nTargetCols;
80
81Pesgo1.PeData.DuplicateDataX = DuplicateData.PointIncrement; // important to set Duplicate type properties before using FastCopyFrom
82Pesgo1.PeData.DuplicateDataY = DuplicateData.SubsetIncrement;
83
84// Perform the transfer of data //
85Pesgo1.PeData.X.FastCopyFrom(pMyXData, nTargetCols);
86Pesgo1.PeData.Y.FastCopyFrom(pMyYData, nTargetRows);
87Pesgo1.PeData.Z.FastCopyFrom(pMyZData, nQ);
88
89// Set Contour Color regions //
90Pesgo1.PeColor.SubsetColors.Clear();
91for (s = 0; s <= 10; s++)
92{
93 Pesgo1.PeColor.SubsetColors[s] = Color.FromArgb(255, 0, (byte)(31 + (s * 21)), (byte)(95 + (s * 15)));
94 Pesgo1.PeColor.SubsetColors[s + 11] = Color.FromArgb(255, 0, (byte)(95 + (s * 15)), 0);
95}
96for (s = 0; s <= 14; s++)
97 Pesgo1.PeColor.SubsetColors[s + 22] = Color.FromArgb(255, (byte)(128 + (s * 9)), (byte)(128 + (s * 9)), (byte)(128 + (s * 9)));
98
99Pesgo1.PeColor.SubsetShades.Clear(); // v9.5
100for (s = 0; s <= 36; s++)
101 Pesgo1.PeColor.SubsetShades[s] = Color.FromArgb(255, (byte)(75 + (s * 5)), (byte)(75 + (s * 5)), (byte)(75 + (s * 5)));
102
103Pesgo1.PeLegend.ContourLegendPrecision = ContourLegendPrecision.ZeroDecimals;
104Pesgo1.PeLegend.ContourStyle = true;
105
106// Set Various Other Properties ///
107Pesgo1.PeColor.BitmapGradientMode = true;
108Pesgo1.PeColor.QuickStyle = QuickStyle.DarkShadow;
109Pesgo1.PeConfigure.BorderTypes = TABorder.NoBorder;
110Pesgo1.PeColor.GridBold = true;
111
112// Set the plotting method ///
113Pesgo1.PePlot.Allow.ContourColors = true;
114Pesgo1.PePlot.Allow.ContourColorsShadows = true;
115Pesgo1.PePlot.Allow.RectHeatmap = true;
116
118Pesgo1.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
119
120Pesgo1.PeLegend.Location = LegendLocation.Left;
121Pesgo1.PeGrid.InFront = true;
122Pesgo1.PeGrid.LineControl = GridLineControl.Both;
123Pesgo1.PeGrid.Style = GridStyle.Dot;
124Pesgo1.PeConfigure.PrepareImages = true;
125Pesgo1.PeConfigure.CacheBmp = true;
126
127Pesgo1.PeUserInterface.Allow.ZoomStyle = ZoomStyle.Ro2Not;
128Pesgo1.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVert;
129Pesgo1.PeUserInterface.Scrollbar.MouseWheelFunction = MouseWheelFunction.HorizontalVerticalZoom;
130Pesgo1.PeUserInterface.Scrollbar.MouseWheelZoomSmoothness = 3;
131Pesgo1.PeUserInterface.Scrollbar.MouseWheelZoomFactor = 1.2F;
132Pesgo1.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVertMb; // enables left click drag
133Pesgo1.PeGrid.GridBands = false;
134
135// Disable other non contour plotting method //
136Pesgo1.PePlot.Allow.Line = false;
137Pesgo1.PePlot.Allow.Point = false;
138Pesgo1.PePlot.Allow.Bar = false;
139Pesgo1.PePlot.Allow.Area = false;
140Pesgo1.PePlot.Allow.Spline = false;
141Pesgo1.PePlot.Allow.SplineArea = false;
142Pesgo1.PePlot.Allow.PointsPlusLine = false;
143Pesgo1.PePlot.Allow.PointsPlusSpline = false;
144Pesgo1.PePlot.Allow.BestFitCurve = false;
145Pesgo1.PePlot.Allow.BestFitLine = false;
146Pesgo1.PePlot.Allow.Stick = false;
147
148// Set Titles //
149Pesgo1.PeString.MainTitle = "Elevation Example";
150Pesgo1.PeString.SubTitle = "";
151
152// So contour goes to edge of grid //
153Pesgo1.PeGrid.Configure.AutoMinMaxPadding = 0;
154
155// Set small font size //
156Pesgo1.PeFont.FontSize = FontSize.Medium;
157Pesgo1.PeFont.Fixed = true;
158
159// Disable appropriate tabs //
160Pesgo1.PeUserInterface.Dialog.Axis = false;
161Pesgo1.PeUserInterface.Dialog.Style = false;
162Pesgo1.PeUserInterface.Dialog.Subsets = false;
163
164Pesgo1.PeConfigure.TextShadows = TextShadows.BoldText;
165Pesgo1.PeFont.MainTitle.Bold = true;
166Pesgo1.PeFont.SubTitle.Bold = true;
167Pesgo1.PeFont.Label.Bold = true;
168
169Pesgo1.PeUserInterface.Scrollbar.ScrollingVertZoom = true;
170Pesgo1.PeUserInterface.Scrollbar.ScrollingHorzZoom = true;
171
172// v9.5
173Pesgo1.PeUserInterface.Menu.AnnotationControl = true;
174Pesgo1.PeUserInterface.Menu.ShowAnnotationText = MenuControl.Show;
175
176// Set some random annotations //
177int aCnt = 0;
178for (int i = 0; i <= 9; i++)
179{
180 Pesgo1.PeAnnotation.Graph.X[aCnt] = nStartCol + (Rand_Num.NextDouble() * 1000);
181 Pesgo1.PeAnnotation.Graph.Y[aCnt] = nStartRow + (Rand_Num.NextDouble() * 1000);
182 Pesgo1.PeAnnotation.Graph.Type[aCnt] = (int)GraphAnnotationType.SmallDotSolid;
183 Pesgo1.PeAnnotation.Graph.Color[aCnt] = Color.FromArgb(255, 200, 200, 200);
184 Pesgo1.PeAnnotation.Graph.Shadow[aCnt] = true;
185 aCnt++;
186}
187for (int i = 0; i <= 9; i++)
188{
189 Pesgo1.PeAnnotation.Graph.X[aCnt] = nStartCol + (Rand_Num.NextDouble() * 1000);
190 Pesgo1.PeAnnotation.Graph.Y[aCnt] = nStartRow + (Rand_Num.NextDouble() * 1000);
191 Pesgo1.PeAnnotation.Graph.Type[aCnt] = (int)GraphAnnotationType.SmallDownTriangleSolid;
192 Pesgo1.PeAnnotation.Graph.Color[aCnt] = Color.FromArgb(255, 255, 255, 255);
193 Pesgo1.PeAnnotation.Graph.Shadow[aCnt] = true;
194 aCnt++;
195 Pesgo1.PeAnnotation.Graph.X[aCnt] = Pesgo1.PeAnnotation.Graph.X[aCnt - 1];
196 Pesgo1.PeAnnotation.Graph.Y[aCnt] = Pesgo1.PeAnnotation.Graph.Y[aCnt - 1];
197 Pesgo1.PeAnnotation.Graph.Type[aCnt] = (int)Gigasoft.ProEssentials.Enums.GraphAnnotationType.Pointer;
198 Pesgo1.PeAnnotation.Graph.Text[aCnt] = "Annotation " + i.ToString();
199 Pesgo1.PeAnnotation.Graph.Color[aCnt] = Color.FromArgb(255, 255, 255, 255);
200 aCnt++;
201
202}
203Pesgo1.PeAnnotation.Show = true;
204Pesgo1.PeAnnotation.Graph.SizeCntl = .7F;
205Pesgo1.PeFont.GraphAnnotationTextSize = 100;
206Pesgo1.PeAnnotation.Graph.MinSymbolSize = MinimumPointSize.Large;
207Pesgo1.PeAnnotation.Graph.MaxSymbolSize = MinimumPointSize.Large;
208Pesgo1.PeConfigure.AntiAliasGraphics = true;
209
210// Set various export defaults //
211Pesgo1.PeSpecial.DpiX = 600;
212Pesgo1.PeSpecial.DpiY = 600;
213
214// default export setting //
215Pesgo1.PeUserInterface.Dialog.ExportSizeDef = ExportSizeDef.NoSizeOrPixel;
216Pesgo1.PeUserInterface.Dialog.ExportTypeDef = ExportTypeDef.Png;
217Pesgo1.PeUserInterface.Dialog.ExportDestDef = ExportDestDef.Clipboard;
218Pesgo1.PeUserInterface.Dialog.ExportUnitXDef = "1280";
219Pesgo1.PeUserInterface.Dialog.ExportUnitYDef = "768";
220Pesgo1.PeUserInterface.Dialog.ExportImageDpi = 300;
221Pesgo1.PeUserInterface.Dialog.AllowEmfExport = false; // v9.5
222Pesgo1.PeUserInterface.Dialog.AllowWmfExport = false;
223
224Pesgo1.PeConfigure.Composite2D3D = Composite2D3D.Foreground;
225Pesgo1.PeConfigure.RenderEngine = RenderEngine.Direct3D;
226
227Pesgo1.PeData.ComputeShader = true; // v10 Enable ComputeShader for fastest possible rendering
228
229Pesgo1.PeFunction.Force3dxNewColors = true;
230Pesgo1.PeFunction.Force3dxVerticeRebuild = true;
231
232// v9 features
233Pesgo1.PeUserInterface.Cursor.PromptTracking = true;
234Pesgo1.PeUserInterface.Cursor.PromptStyle = CursorPromptStyle.XYZValues;
235Pesgo1.PeUserInterface.Cursor.PromptLocation = CursorPromptLocation.Text;
236Pesgo1.PeUserInterface.Cursor.HourGlassThreshold = 9999999;
237
238// Generally call ReinitializeResetImage at end **'
239Pesgo1.PeFunction.ReinitializeResetImage();
240Pesgo1.Invalidate();
241// Optionally call Pesgo1.Refresh() if you are not seeing changes immediately
Tip: Uses property syntax like Pego1.PeData.Y[s, p]Click underlined properties to view documentation