-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainForm.cs
More file actions
1745 lines (1466 loc) · 85.8 KB
/
Copy pathMainForm.cs
File metadata and controls
1745 lines (1466 loc) · 85.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Gigasoft.ProEssentials;
using Gigasoft.ProEssentials.Enums;
using Gigasoft.ProEssentials.EventArg;
namespace GigaPrime3D
{
/// <summary>
/// GigaPrime3D - WinForms .NET 8 port of the WPF ProEssentials 3D surface demo.
///
/// Three synchronized charts:
/// Chart3DSurface (Pe3do) - GPU compute-shader 3D surface (center, fills)
/// Chart2DContour (Pesgo) - linked 2D top-down contour (bottom-left overlay)
/// Chart2DLine (Pesgo) - live cross-section at the X plane (right column)
///
/// Per the port rules: the ProEssentials chart-logic blocks below are copied
/// VERBATIM from the WPF code-behind - only the host shell (layout, control
/// creation, event signatures) is rewritten. Cross-framework conversions:
/// * WPF Pe3doWpf/PesgoWpf -> WinForms Pe3do/Pesgo
/// * System.Windows.Media.Color.FromRgb(r,g,b) -> FromRgb helper (opaque ARGB)
/// * System.Windows.Media.Colors.White -> System.Drawing.Color.White
/// * Slider RoutedPropertyChangedEventArgs<double> -> EventArgs + slider.Value
/// * CheckBox Checked/Unchecked pair -> one CheckedChanged reading .Checked
/// * ComboBox SelectionChanged -> SelectedIndexChanged
/// * Window.Closing -> FormClosing, Main.SizeChanged -> Resize
/// * Cursor.LastMouseMove System.Windows.Point(double) -> System.Drawing.Point(int)
/// * GCHandle pins freed in Dispose(bool), not a finalizer
/// * control Loaded events -> Form.Load / Initialize* calls
/// </summary>
public partial class MainForm : Form
{
// ===== ProEssentials chart controls (WPF Pe3doWpf/PesgoWpf -> Pe3do/Pesgo) =====
private Pe3do Chart3DSurface;
private Pesgo Chart2DContour;
private Pesgo Chart2DLine;
// ===== Sidebar host controls (replace the named WPF XAML elements) =====
private ComboBox HeightMaps;
private FlatCheckBox ShowLegend;
private FlatCheckBox BottomContour;
private FlatCheckBox ShowPlane;
private FlatCheckBox HotSpots;
private ComboBox ReduceDataAmount;
private Button HelpButton;
private FlatSlider SliderHorizontalMove;
private FlatSlider SliderVerticalMove;
private FlatSlider SliderHorizontalLightRotation;
private FlatSlider SliderVerticalLightRotation;
// ===== Center overlay sliders (overlay the 3D surface, top-left) =====
private FlatSlider SliderVerticalRotation;
private FlatSlider SliderHorizontalRotation;
private FlatSlider SliderZoom;
private FlatSlider SliderZExaggeration;
// ===== Right column (WPF Chart2DContainer grid) and its X-plane slider =====
private Panel Chart2DContainer;
private FlatSlider SliderXPlane;
// #002B35 dark scientific background used throughout (WPF "#002B35")
private static readonly Color BackTeal = Color.FromArgb(255, 0x00, 0x2B, 0x35);
// Startup cover - hides the white first-paint while the heavy load blocks the
// UI thread; lifted by a one-shot timer once the real UI has actually painted.
private Form _startupCover;
private System.Windows.Forms.Timer _coverLiftTimer;
// ================== state fields (verbatim from WPF) ==================
public HeightMap CurrentHeightMap { get; set; }
public HeightMap HeightMapA { get; set; }
private bool _bShowingPlane = false;
private int _nDataStep = 2; // Reduce Data default as user may have a slow PC without dedicated GPU
private int _nAppliedStep = 2; // if less than 1000x1000 we avoid reduction.
private int _rows;
private int _cols;
private bool _bZoomed = false;
private float _maxx = 0f;
private float _miny = 0f;
private float _maxy = 0f;
private float _minz = 0f;
private float _maxz = 0f;
private float _VertLightDegree = 0f;
private float _HorzLightDegree = 0f;
private int CursorTrackingMenu3d = 0;
private int UndoZoomMenu3d = 1;
private bool _updatingUi;
// 36M points x 4 bytes ~150M
// Passing shared app memory to both Pe3do and Pesgo saves 150M
// Set up static shared memory resources
private static float[] sMyXData = new float[6000]; // cols max
private static float[] sMyZData = new float[6000]; // rows max
private static float[] sMyYData = new float[36000000]; // rows x cols max
private GCHandle _pinXHandle; // data less than 85K bytes, best to pin
private GCHandle _pinZHandle; // no need to pin YData > 85K
public MainForm()
{
// being safe, pin the smaller data arrays x and z
_pinXHandle = GCHandle.Alloc(sMyXData, GCHandleType.Pinned);
_pinZHandle = GCHandle.Alloc(sMyZData, GCHandleType.Pinned);
// ===== Window properties (WPF Window attrs -> Form properties) =====
Text = "GigaPrime3D - 3D Surface + 2D Contour (WinForms)";
BackColor = BackTeal;
MinimumSize = new Size(400, 400); // WPF MinWidth/MinHeight
StartPosition = FormStartPosition.CenterScreen;
var wa = Screen.PrimaryScreen.WorkingArea; // WPF CenterWindowOnScreen: 80% of screen, centered
Size = new Size((int)(wa.Width * 0.8), (int)(wa.Height * 0.8));
BuildLayout();
// Wire chart events (WPF wired these in the ctor + via XAML attributes).
Chart3DSurface.MouseMove += Chart_MouseMove;
Chart3DSurface.PeCustomMenu += new Pe3do.CustomMenuEventHandler(Chart_PeCustomMenu);
Chart3DSurface.PeHorzScroll += Chart_OnPeHorzScroll; // XAML PeHorzScroll="..."
Chart3DSurface.PeVertScroll += Chart_OnPeVertScroll; // XAML PeVertScroll="..."
Chart3DSurface.PeZoomIn += Chart_OnPeZoomIn; // XAML PeZoomIn="..."
Chart2DContour.MouseEnter += Chart2DContour_MouseEnter;
Chart2DContour.PeZoomIn += Chart2DContour_OnPeZoomIn;
Chart2DContour.PeZoomOut += Chart2DContour_OnPeZoomOut;
Chart2DContour.PeHorzScroll += Chart2DContour_PeHorzScroll;
Chart2DContour.PeVertScroll += Chart2DContour_PeVertScroll;
// WinForms: initialize charts in Form.Load (the WPF per-control Loaded
// events are not needed - by Form.Load all handles exist).
this.Load += MainForm_Load;
this.FormClosing += Window_Closing; // WPF Window.Closing
this.Resize += Main_SizeChanged; // WPF Main.SizeChanged
}
// WPF finalizer ~MainWindow freed the pins; WinForms uses Dispose(bool).
protected override void Dispose(bool disposing)
{
if (disposing)
{
if (_pinXHandle.IsAllocated) { _pinXHandle.Free(); }
if (_pinZHandle.IsAllocated) { _pinZHandle.Free(); }
}
base.Dispose(disposing);
}
// =====================================================================
// BuildLayout - replaces MainWindow.xaml.
//
// WPF 3-column Grid (275 sidebar | star chart | 220 right) becomes:
// centerPanel Dock=Fill - holds the 3D surface + rotation overlay
// Chart2DContainer Dock=Right W=220 - holds the 2D line + X-plane slider
// sidebar Dock=Left W=275 - the controls column
// Chart2DContour - a floating 360x360 overlay pinned bottom-left
//
// Docking rule (per the WinForms template): add the Fill control FIRST so
// it sits at the back of the z-order; docked edges added afterward claim
// their strips and Fill takes the remainder. Floating overlays are added
// last and brought to front.
// =====================================================================
private void BuildLayout()
{
// ----- Center: 3D surface fills, rotation sliders overlay top-left -----
var centerPanel = new Panel { Dock = DockStyle.Fill, BackColor = BackTeal };
Chart3DSurface = new Pe3do { Dock = DockStyle.Fill };
centerPanel.Controls.Add(Chart3DSurface); // Fill added first
var rotationOverlay = new FlowLayoutPanel
{
FlowDirection = FlowDirection.TopDown,
WrapContents = false,
AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink,
BackColor = BackTeal, // blends with the chart's dark corner
Location = new Point(6, 30),
};
SliderVerticalRotation = MakeSlider(-90, 90, 0);
SliderHorizontalRotation = MakeSlider(0, 360, 0);
SliderZoom = MakeSlider(-50, -5, -24);
SliderZExaggeration = MakeSlider(1, 50, 10);
SliderVerticalRotation.ValueChanged += SliderVerticalRotation_OnValueChanged;
SliderHorizontalRotation.ValueChanged += SliderHorizontalRotation_OnValueChanged;
SliderZoom.ValueChanged += SliderZoom_OnValueChanged;
SliderZExaggeration.ValueChanged += SliderZExaggeration_OnValueChanged;
rotationOverlay.Controls.Add(MakeLabel("Vertical rotation"));
rotationOverlay.Controls.Add(SliderVerticalRotation);
rotationOverlay.Controls.Add(MakeLabel("Horizontal rotation"));
rotationOverlay.Controls.Add(SliderHorizontalRotation);
rotationOverlay.Controls.Add(MakeLabel("Magnification / Distance"));
rotationOverlay.Controls.Add(SliderZoom);
rotationOverlay.Controls.Add(MakeLabel("Explode Z Axis"));
rotationOverlay.Controls.Add(SliderZExaggeration);
centerPanel.Controls.Add(rotationOverlay);
rotationOverlay.BringToFront();
// ----- Right column: 2D line cross-section + X-plane slider -----
Chart2DContainer = new Panel { Dock = DockStyle.Right, Width = 220, BackColor = BackTeal };
Chart2DLine = new Pesgo { Dock = DockStyle.Fill };
Chart2DContainer.Controls.Add(Chart2DLine); // Fill added first
var xplanePanel = new Panel { Dock = DockStyle.Top, Height = 34, BackColor = BackTeal };
SliderXPlane = MakeSlider(0, 100, 0);
SliderXPlane.Width = 150;
SliderXPlane.Anchor = AnchorStyles.Top | AnchorStyles.Right;
SliderXPlane.Location = new Point(xplanePanel.Width - 150 - 8, 7);
SliderXPlane.ValueChanged += SliderXPlane_OnValueChanged;
xplanePanel.Controls.Add(SliderXPlane);
Chart2DContainer.Controls.Add(xplanePanel); // docked Top, above the line chart
// ----- Left sidebar: the controls column -----
var sidebar = new Panel { Dock = DockStyle.Left, Width = 275, BackColor = BackTeal };
var sideFlow = new FlowLayoutPanel
{
Dock = DockStyle.Fill,
FlowDirection = FlowDirection.TopDown,
WrapContents = false,
AutoScroll = true,
BackColor = BackTeal,
Padding = new Padding(6, 6, 6, 6),
};
HeightMaps = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
FlatStyle = FlatStyle.Flat,
Width = 258,
Font = new Font("Segoe UI", 11f),
BackColor = BackTeal,
ForeColor = Color.White,
Margin = new Padding(1, 6, 0, 15),
};
HeightMaps.SelectedIndexChanged += HeightMaps_SelectionChanged;
ShowLegend = MakeCheck("Legend");
BottomContour = MakeCheck("Bottom Contour");
ShowPlane = MakeCheck("X Plane");
HotSpots = MakeCheck("Cursor Tracking");
ShowLegend.CheckedChanged += ShowLegend_CheckedChanged;
BottomContour.CheckedChanged += ShowContour_CheckedChanged;
ShowPlane.CheckedChanged += ShowPlane_CheckedChanged;
HotSpots.CheckedChanged += HotSpots_CheckedChanged;
ShowPlane.Margin = new Padding(3, 3, 3, 18);
HotSpots.Margin = new Padding(3, 3, 3, 18);
var reduceRow = new FlowLayoutPanel
{
FlowDirection = FlowDirection.LeftToRight,
WrapContents = false,
AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink,
BackColor = BackTeal,
Margin = new Padding(0, 0, 0, 18),
};
var reduceLabel = MakeLabel("Reduce Data");
reduceLabel.Margin = new Padding(3, 8, 6, 0);
ReduceDataAmount = new ComboBox
{
DropDownStyle = ComboBoxStyle.DropDownList,
FlatStyle = FlatStyle.Flat,
Width = 64,
Font = new Font("Segoe UI", 10f),
BackColor = BackTeal,
ForeColor = Color.White,
// Bottom margin so the FlowLayoutPanel's auto-height clears the
// combo's bottom border (a DropDownList forces its own height).
Margin = new Padding(0, 5, 0, 4),
};
ReduceDataAmount.SelectedIndexChanged += ReduceDataAmount_SelectionChanged;
reduceRow.Controls.Add(reduceLabel);
reduceRow.Controls.Add(ReduceDataAmount);
HelpButton = new Button
{
Text = "Help ?",
AutoSize = false,
Width = 80,
Height = 30,
FlatStyle = FlatStyle.Flat,
BackColor = Color.Black,
ForeColor = Color.White,
Margin = new Padding(3, 0, 3, 18),
};
HelpButton.FlatAppearance.BorderColor = Color.FromArgb(255, 0x5A, 0xAA, 0xEB);
HelpButton.Click += HelpButton_Click;
SliderHorizontalMove = MakeSlider(-10, 10, 0);
SliderVerticalMove = MakeSlider(-10, 10, 0);
SliderHorizontalLightRotation = MakeSlider(0, 360, 0);
SliderVerticalLightRotation = MakeSlider(0, 360, 0);
SliderHorizontalMove.ValueChanged += SliderHorizontalMove_OnValueChanged;
SliderVerticalMove.ValueChanged += SliderVerticalMove_OnValueChanged;
SliderHorizontalLightRotation.ValueChanged += SliderHorizontalLightRotation_OnValueChanged;
SliderVerticalLightRotation.ValueChanged += SliderVerticalLightRotation_OnValueChanged;
sideFlow.Controls.Add(HeightMaps);
sideFlow.Controls.Add(ShowLegend);
sideFlow.Controls.Add(BottomContour);
sideFlow.Controls.Add(ShowPlane);
sideFlow.Controls.Add(HotSpots);
sideFlow.Controls.Add(reduceRow);
sideFlow.Controls.Add(HelpButton);
sideFlow.Controls.Add(MakeLabel("Move Horizontally"));
sideFlow.Controls.Add(SliderHorizontalMove);
sideFlow.Controls.Add(MakeLabel("Move Vertically"));
sideFlow.Controls.Add(SliderVerticalMove);
sideFlow.Controls.Add(MakeLabel("Rotate Light Horizontally"));
sideFlow.Controls.Add(SliderHorizontalLightRotation);
sideFlow.Controls.Add(MakeLabel("Rotate Light Vertically"));
sideFlow.Controls.Add(SliderVerticalLightRotation);
sidebar.Controls.Add(sideFlow);
// ----- Assemble on the form: Fill first, then edges, then floating -----
Controls.Add(centerPanel); // Dock=Fill (back of z-order)
Controls.Add(Chart2DContainer); // Dock=Right
Controls.Add(sidebar); // Dock=Left
// 2D contour floats over the bottom-left corner (WPF: 360x360, ZIndex 1)
Chart2DContour = new Pesgo { Size = new Size(360, 360) };
Controls.Add(Chart2DContour);
Chart2DContour.BringToFront();
PositionContour();
}
private FlatSlider MakeSlider(int min, int max, int value)
{
var s = new FlatSlider { Width = 250, Height = 24, Margin = new Padding(5) };
s.Minimum = min;
s.Maximum = max;
s.Value = value;
return s;
}
private Label MakeLabel(string text)
{
return new Label
{
Text = text,
ForeColor = Color.White,
AutoSize = true,
Font = new Font("Segoe UI", 10.5f),
Margin = new Padding(3, 3, 3, 0),
};
}
private FlatCheckBox MakeCheck(string text)
{
return new FlatCheckBox { Text = text, Width = 180, Height = 26, Margin = new Padding(3, 3, 3, 0) };
}
// Pin the 2D contour to the bottom-left corner (WPF margin 0,450 in a tall
// maximized window placed it at the lower-left; we anchor it there).
private void PositionContour()
{
if (Chart2DContour == null) { return; }
int y = ClientSize.Height - Chart2DContour.Height - 8;
if (y < 8) { y = 8; }
Chart2DContour.Location = new Point(8, y);
}
// =====================================================================
// MainForm_Load - replaces WPF Main_Loaded + the three chart Loaded events.
// =====================================================================
private void MainForm_Load(object sender, EventArgs e)
{
// Startup cover: a SEPARATE top-level teal form (see CreateStartupCover)
// sized over our client area, force-painted now so it stays composited on
// screen while the heavy bring-up below blocks the UI thread - hiding the
// white first-paint. A child panel can't do this (it's painted by the same
// blocked message loop); a top-level window has its own backing store and
// Refresh() paints it synchronously. Lifted in the finally, once the real
// UI is fully rendered, so the cover never reveals a half-painted app.
_startupCover = CreateStartupCover();
_startupCover.Show(this);
_startupCover.Refresh(); // synchronous paint - survives the blocking load that follows
try
{
_nDataStep = _nAppliedStep; // you can change for better performance (e.g. 3)
_updatingUi = true;
Chart2DContainer.Visible = false; // WPF Chart2DContainer.Visibility = Collapsed
HeightMaps.Items.Add("MaterialSurfaceScan1-2464x2056.bhm");
HeightMaps.Items.Add("MaterialSurfaceScan2-5024x2736.bhm");
HeightMaps.Items.Add("MaterialSurfaceScan3-5024x2736.bhm");
HeightMaps.Items.Add("GrandCanyon-4033x4033.bhm");
HeightMaps.Items.Add("NoisyTerrain-4352x4352.bhm");
HeightMaps.Items.Add("GrandCanyon-grayscale-rawpng-512x512.png");
HeightMaps.Items.Add("Terrain-rgb-rawpng-1000x1000.png");
HeightMaps.Items.Add("Cat-grayscale-rawpng-2047x1531.png");
HeightMaps.Items.Add("leaf-grayscale-rawpng-1096x2048.png");
ReduceDataAmount.Items.Add("None");
ReduceDataAmount.Items.Add("2X");
ReduceDataAmount.Items.Add("3X");
ReduceDataAmount.Items.Add("4X");
ReduceDataAmount.SelectedIndex = 1;
_updatingUi = false;
// ----- (WPF Chart_Loaded / Chart2DContour_Loaded / Chart2D_Loaded) -----
Initialize3D();
Initialize2D();
Initialize2DContour();
HeightMaps.SelectedIndex = 0; // Set default chart example file; invokes initial RefreshUi(hm)
SliderHorizontalRotation.Value = (int)Chart3DSurface.PeUserInterface.Scrollbar.DegreeOfRotation;
SliderVerticalRotation.Value = (int)Chart3DSurface.PeUserInterface.Scrollbar.ViewingHeight;
SliderZoom.Value = (int)Chart3DSurface.PePlot.Option.DxZoom;
_updatingUi = true;
SliderVerticalLightRotation.Value = 300;
SliderHorizontalLightRotation.Value = 180;
SliderHorizontalMove.Value = 0;
SliderVerticalMove.Value = 2; // WPF 2.5f (DxViewportY already 2.5 from Initialize3D)
_updatingUi = false;
PositionContour();
}
finally
{
// Kick the now-complete UI to repaint, then lift the cover from a
// one-shot timer rather than closing it here. Closing synchronously
// races the first paint: this.Refresh() does NOT force the child
// windows (sidebar + native charts) to paint - their WM_PAINTs are
// still queued - so the reveal would show them paint white->themed.
// WM_PAINT outranks WM_TIMER, so by the time the timer ticks the loop
// has flushed every queued paint; the delay also covers the GPU present.
this.Refresh();
Chart3DSurface.Refresh();
Chart2DContour.Refresh();
Chart2DLine.Refresh();
_coverLiftTimer = new System.Windows.Forms.Timer { Interval = 700 };
_coverLiftTimer.Tick += LiftStartupCover;
_coverLiftTimer.Start();
}
}
private void LiftStartupCover(object sender, EventArgs e)
{
if (_coverLiftTimer != null)
{
_coverLiftTimer.Stop();
_coverLiftTimer.Dispose();
_coverLiftTimer = null;
}
if (_startupCover != null)
{
_startupCover.Close();
_startupCover.Dispose();
_startupCover = null;
}
}
// Builds the startup cover form. Text is drawn in the Paint handler (not a
// child Label) so a single synchronous cover.Refresh() paints both the teal
// background and the "Loading..." text in one WM_PAINT.
private Form CreateStartupCover()
{
var cover = new Form
{
FormBorderStyle = FormBorderStyle.None,
StartPosition = FormStartPosition.Manual,
Bounds = RectangleToScreen(ClientRectangle),
BackColor = BackTeal,
ShowInTaskbar = false,
ControlBox = false,
};
cover.Paint += (s, pe) =>
{
pe.Graphics.Clear(BackTeal);
using (var f = new Font("Segoe UI", 18f))
TextRenderer.DrawText(pe.Graphics, "Loading...", f, cover.ClientRectangle,
Color.White, TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter);
};
return cover;
}
private void Initialize3D()
{
try
{
// always start a 3D new initialization with a call to Reset
Chart3DSurface.PeFunction.Reset();
Chart3DSurface.PeSpecial.AutoImageReset = false; // important for final optimization
Chart3DSurface.PeString.MainTitle = string.Empty;
Chart3DSurface.PeString.SubTitle = string.Empty;
Chart3DSurface.PeString.MultiSubTitles[0] = string.Empty;
Chart3DSurface.PeString.XAxisLabel = "X";
Chart3DSurface.PeString.YAxisLabel = "Z";
Chart3DSurface.PeString.ZAxisLabel = "Y";
Chart3DSurface.PeUserInterface.Dialog.ModelessAutoClose = true;
Chart3DSurface.PeUserInterface.Dialog.PlotCustomization = true;
Chart3DSurface.PePlot.PolyMode = PolyMode.SurfacePolygons;
Chart3DSurface.PePlot.Method = ThreeDGraphPlottingMethod.Four;
Chart3DSurface.PeColor.DxTransparencyMode = TransparencyMode.None;
Chart3DSurface.PeGrid.Configure.DxPsManualCullXZ = true;
Chart3DSurface.PePlot.Option.DxFitControlShape = false;
Chart3DSurface.PePlot.Option.DxViewportX = 0;
Chart3DSurface.PePlot.Option.DxViewportY = 2.5F;
Chart3DSurface.PePlot.Option.DxFOV = 1;
Chart3DSurface.PePlot.Option.DxZoom = -24.0f;
Chart3DSurface.PeUserInterface.Scrollbar.ViewingHeight = 28;
Chart3DSurface.PeUserInterface.Scrollbar.DegreeOfRotation = 145;
Chart3DSurface.PePlot.Option.DegreePrompting = true;
Chart3DSurface.PePlot.LinesOrTubes = LinesOrTubes.AllLines;
Chart3DSurface.PePlot.SubsetLineTypes[0] = LineType.MediumThinSolid;
Chart3DSurface.PePlot.Allow.WireFrame = false;
Chart3DSurface.PePlot.Option.SurfacePolygonBorders = true;
Chart3DSurface.PePlot.Option.ShowContour = ShowContour.None;
Chart3DSurface.PeFont.SizeGlobalCntl = 1.1f;
Chart3DSurface.PeFont.Fixed = true;
Chart3DSurface.PeFont.FontSize = Gigasoft.ProEssentials.Enums.FontSize.Large;
Chart3DSurface.PeAnnotation.Show = true;
Chart3DSurface.PeGrid.Configure.AutoPadBeyondZeroX = true;
Chart3DSurface.PeGrid.Configure.AutoPadBeyondZeroY = true;
Chart3DSurface.PeGrid.Configure.AutoPadBeyondZeroZ = true;
Chart3DSurface.PeGrid.Configure.AutoMinMaxPaddingX = 1;
Chart3DSurface.PeGrid.Configure.AutoMinMaxPaddingY = 1;
Chart3DSurface.PeGrid.Configure.AutoMinMaxPaddingZ = 1;
Chart3DSurface.PeGrid.Configure.ManualScaleControlX = ManualScaleControl.None;
Chart3DSurface.PeGrid.Configure.ManualScaleControlY = ManualScaleControl.None;
Chart3DSurface.PeGrid.Configure.ManualScaleControlZ = ManualScaleControl.None;
Chart3DSurface.PeGrid.Option.ShowXAxis = ShowAxis.All;
Chart3DSurface.PeGrid.Option.ShowYAxis = ShowAxis.All;
Chart3DSurface.PeGrid.Option.ShowZAxis = ShowAxis.All;
Chart3DSurface.PeUserInterface.RotationDetail = RotationDetail.WireFrame;
Chart3DSurface.PeUserInterface.Allow.FocalRect = false;
Chart3DSurface.PeUserInterface.Menu.LegendLocation = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Scrollbar.ScrollSmoothness = 0;
Chart3DSurface.PeUserInterface.Scrollbar.MouseWheelZoomSmoothness = 2;
Chart3DSurface.PeUserInterface.Scrollbar.MouseWheelZoomFactor = 25.0f;
Chart3DSurface.PeUserInterface.Scrollbar.PinchZoomSmoothness = 2;
Chart3DSurface.PeUserInterface.Scrollbar.PinchZoomFactor = 20.0f;
Chart3DSurface.PePlot.Option.DxViewportPanFactor = 10.0F;
Chart3DSurface.PePlot.Option.DxZoomMin = -40;
Chart3DSurface.PePlot.Option.DxZoomMax = -3;
Chart3DSurface.PeUserInterface.Scrollbar.HorzScrollBar = false;
Chart3DSurface.PeUserInterface.Scrollbar.VertScrollBar = false;
Chart3DSurface.PeUserInterface.Scrollbar.MouseDraggingX = true;
Chart3DSurface.PeUserInterface.Scrollbar.MouseDraggingY = true;
Chart3DSurface.PeUserInterface.Scrollbar.MouseWheelFunction = MouseWheelFunction.HorizontalVerticalZoom;
Chart3DSurface.PeUserInterface.Scrollbar.MouseWheelZoomEvents = true;
Chart3DSurface.PeData.DuplicateDataX = DuplicateData.PointIncrement;
Chart3DSurface.PeData.DuplicateDataZ = DuplicateData.SubsetIncrement;
// Controls color of Surface //
Chart3DSurface.PeColor.SubsetColors.Clear();
Chart3DSurface.PeColor.SubsetShades.Clear();
for (var colx = 0; colx < 256; ++colx)
{
var index = (byte)(colx / 256.0 * (MyColors.Length - 1));
var color = MyColors[index];
Chart3DSurface.PeColor.SubsetColors[colx] = color;
Chart3DSurface.PeColor.SubsetShades[colx] = Color.FromArgb(255, (byte)(100 + colx), (byte)(100 + colx), (byte)(100 + colx));
}
Chart3DSurface.PeColor.SubsetColors[(int)Gigasoft.ProEssentials.Enums.SurfaceColors.SolidSurface] = Color.FromArgb(255, 170, 170, 255);
// non data Color settings //
Chart3DSurface.PeColor.BitmapGradientMode = false;
Chart3DSurface.PeColor.QuickStyle = QuickStyle.DarkNoBorder;
Chart3DSurface.PeConfigure.BorderTypes = TABorder.NoBorder;
Chart3DSurface.PeColor.GraphBmpStyle = BitmapStyle.NoBmp;
Chart3DSurface.PeColor.GraphBackground = FromRgb(0x00, 0x2B, 0x35);
Chart3DSurface.PeColor.Desk = FromRgb(0x35, 0x2B, 0x00); // RGB is BGR for DeskColor, don't want to break code so leaving it
Chart3DSurface.PeColor.GraphForeground = Color.White;
Chart3DSurface.PeColor.ZAxis = Color.White;
Chart3DSurface.PeColor.YAxis = Color.White;
Chart3DSurface.PeColor.XAxis = Color.White;
Chart3DSurface.PeColor.Text = Color.White;
Chart3DSurface.PeLegend.ContourStyle = true;
Chart3DSurface.PeLegend.Show = false; // there will be a UI CheckBox that controls this
Chart3DSurface.PeLegend.Location = LegendLocation.Right;
Chart3DSurface.PeData.NullDataValue = -9999;
Chart3DSurface.PeData.NullDataValueX = -9999;
Chart3DSurface.PeData.NullDataValueZ = -9999;
Chart3DSurface.PeUserInterface.Cursor.PromptLocation = CursorPromptLocation.ToolTip;
Chart3DSurface.PeLegend.ContourLegendPrecision = ContourLegendPrecision.TwoDecimals;
Chart3DSurface.PeFont.SizeGlobalCntl = 1.35F;
Chart3DSurface.PeUserInterface.Allow.Customization = false;
Chart3DSurface.PeUserInterface.Allow.Maximization = false;
Chart3DSurface.PeUserInterface.Menu.Contour = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.BorderType = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.BitmapGradient = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.ShowLegend = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.CustomizeDialog = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.QuickStyle = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.DataPrecision = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.Rotation = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Menu.LegendLocation = MenuControl.Hide;
Chart3DSurface.PeUserInterface.Dialog.AllowEmfExport = false;
Chart3DSurface.PeUserInterface.Dialog.AllowSvgExport = false;
Chart3DSurface.PeUserInterface.Dialog.AllowWmfExport = false;
Chart3DSurface.PeUserInterface.Allow.TextExport = false;
Chart3DSurface.PeUserInterface.Dialog.HideExportImageDpi = true;
Chart3DSurface.PeUserInterface.Dialog.HidePrintDpi = true;
Chart3DSurface.PeUserInterface.Allow.FocalRect = false;
Chart3DSurface.PeUserInterface.Menu.CustomMenuText[CursorTrackingMenu3d] = "Cursor Tracking";
Chart3DSurface.PeUserInterface.Menu.CustomMenuState[CursorTrackingMenu3d, 0] = CustomMenuState.UnChecked;
Chart3DSurface.PeUserInterface.Menu.CustomMenuLocation[CursorTrackingMenu3d] = CustomMenuLocation.Bottom;
Chart3DSurface.PeUserInterface.Menu.CustomMenuText[UndoZoomMenu3d] = "Undo Zoom";
Chart3DSurface.PeUserInterface.Menu.CustomMenuLocation[UndoZoomMenu3d] = CustomMenuLocation.Bottom;
Chart3DSurface.PeUserInterface.Menu.CustomMenu[UndoZoomMenu3d, 0] = CustomMenu.Grayed;
Chart3DSurface.PeConfigure.RenderEngine = RenderEngine.Direct3D;
Chart3DSurface.PeConfigure.PrepareImages = true;
Chart3DSurface.PeConfigure.CacheBmp = true;
Chart3DSurface.PeConfigure.AntiAliasGraphics = false;
Chart3DSurface.PeConfigure.AntiAliasText = false;
Chart3DSurface.PeFunction.SetViewingAt(0.0f, 0.0f, 0.0f);
// Final settings to control how scene is asked to render / refresh
Chart3DSurface.PeFunction.Force3dxNewColors = true;
Chart3DSurface.PeFunction.Force3dxAnnotVerticeRebuild = true;
Chart3DSurface.PeFunction.Force3dxVerticeRebuild = true;
Chart3DSurface.PeFunction.ReinitializeResetImage();
Chart3DSurface.Invalidate();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
}
}
private void Initialize2DContour() // Left side Pesgo 2d contour
{
Chart2DContour.PeConfigure.RenderEngine = RenderEngine.Direct3D;
Chart2DContour.PeConfigure.Composite2D3D = Composite2D3D.Foreground;
Chart2DContour.PeUserInterface.Allow.Zooming = AllowZooming.HorzAndVert;
Chart2DContour.PeUserInterface.Allow.ZoomStyle = ZoomStyle.Ro2Not;
Chart2DContour.PePlot.Allow.ContourColors = true;
Chart2DContour.PePlot.Allow.ContourColorsShadows = true;
Chart2DContour.PePlot.Allow.ContourLines = false;
Chart2DContour.PeConfigure.PrepareImages = true;
Chart2DContour.PeConfigure.CacheBmp = true;
Chart2DContour.PeConfigure.AntiAliasGraphics = true;
Chart2DContour.PePlot.SubsetLineTypes[0] = LineType.MediumSolid;
Chart2DContour.PeUserInterface.Allow.FocalRect = false;
Chart2DContour.PeColor.Desk = FromRgb(0x00, 0x2B, 0x35);
Chart2DContour.PeColor.Text = FromRgb(255, 255, 255);
Chart2DContour.PeColor.GraphBackground = FromRgb(0x00, 0x2B, 0x35);
Chart2DContour.PeConfigure.BorderTypes = TABorder.NoBorder;
Chart2DContour.PeString.MainTitle = "";
Chart2DContour.PeString.SubTitle = "";
Chart2DContour.PeString.YAxisLabel = "";
Chart2DContour.PeString.XAxisLabel = "";
Chart2DContour.PeGrid.Configure.AutoMinMaxPadding = 0;
Chart2DContour.PeLegend.ContourLegendPrecision = ContourLegendPrecision.TwoDecimals;
Chart2DContour.PeLegend.ContourStyle = true;
Chart2DContour.PeLegend.Location = LegendLocation.Left;
Chart2DContour.PeLegend.Show = false;
Chart2DContour.PeColor.SubsetColors.Clear();
Chart2DContour.PeColor.SubsetShades.Clear();
for (var colx = 0; colx < 256; ++colx)
{
var index = (byte)(colx / 256.0 * (MyColors.Length - 1));
var color = MyColors[index];
Chart2DContour.PeColor.SubsetColors[colx] = color;
Chart2DContour.PeColor.SubsetShades[colx] = Color.FromArgb(255, (byte)(100 + colx), (byte)(100 + colx), (byte)(100 + colx));
}
Chart2DContour.PeConfigure.ImageAdjustLeft = -100; // shrink-tweak the borders
Chart2DContour.PeConfigure.ImageAdjustRight = -100;
Chart2DContour.PeConfigure.ImageAdjustTop = 50;
Chart2DContour.PeConfigure.ImageAdjustBottom = 0;
Chart2DContour.PeUserInterface.Scrollbar.ScrollingHorzZoom = true;
Chart2DContour.PeUserInterface.Scrollbar.ScrollingVertZoom = true;
Chart2DContour.PeConfigure.Composite2D3D = Composite2D3D.Foreground;
Chart2DContour.PeConfigure.RenderEngine = RenderEngine.Direct3D;
Chart2DContour.PeUserInterface.Allow.Customization = false;
Chart2DContour.PeUserInterface.Allow.Maximization = false;
Chart2DContour.PeUserInterface.Menu.BorderType = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.BitmapGradient = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.ShowLegend = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.PlotMethod = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.CustomizeDialog = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.QuickStyle = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.DataPrecision = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.LegendLocation = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.MarkDataPoints = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.ViewingStyle = MenuControl.Hide;
Chart2DContour.PeUserInterface.Menu.GridLine = MenuControl.Hide;
Chart2DContour.PeUserInterface.Dialog.AllowEmfExport = false;
Chart2DContour.PeUserInterface.Dialog.AllowSvgExport = false;
Chart2DContour.PeUserInterface.Dialog.AllowWmfExport = false;
Chart2DContour.PeUserInterface.Allow.TextExport = false;
Chart2DContour.PeUserInterface.Dialog.HideExportImageDpi = true;
Chart2DContour.PeUserInterface.Dialog.HidePrintDpi = true;
Chart2DContour.PeColor.Desk = FromRgb(0x35, 0x2B, 0x00); // there's a bug in the control! Ya, R B reversed.
}
private void Initialize2D() // Right side Pesgo 2d crosssection plane
{
Chart2DLine.PeConfigure.RenderEngine = RenderEngine.Direct2D; // its also the default
Chart2DLine.PeString.MainTitle = "";
Chart2DLine.PeString.SubTitle = "";
Chart2DLine.PeString.XAxisLabel = "Z";
Chart2DLine.PeString.YAxisLabel = "Y";
Chart2DLine.PeGrid.Option.XAxisVertNumbering = true;
Chart2DLine.PeFont.SizeGlobalCntl = .90F;
Chart2DLine.PeConfigure.PrepareImages = true;
Chart2DLine.PeConfigure.CacheBmp = true;
Chart2DLine.PeConfigure.AntiAliasGraphics = true;
Chart2DLine.PePlot.SubsetLineTypes[0] = LineType.MediumSolid;
Chart2DLine.PeUserInterface.Allow.FocalRect = false;
Chart2DLine.PeColor.Desk = FromRgb(0x00, 0x2B, 0x35);
Chart2DLine.PeColor.Text = FromRgb(255, 255, 255);
Chart2DLine.PeColor.GraphBackground = FromRgb(0x00, 0x2B, 0x35);
Chart2DLine.PeColor.GraphForeground = Color.White;
Chart2DLine.PeConfigure.BorderTypes = TABorder.NoBorder;
Chart2DLine.PeGrid.GridBands = false;
Chart2DLine.PeUserInterface.Allow.Customization = false;
Chart2DLine.PeUserInterface.Allow.Maximization = false;
Chart2DLine.PeUserInterface.Menu.BorderType = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.BitmapGradient = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.ShowLegend = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.PlotMethod = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.CustomizeDialog = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.DataShadow = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.QuickStyle = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.DataPrecision = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.LegendLocation = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.MarkDataPoints = MenuControl.Hide;
Chart2DLine.PeUserInterface.Menu.ViewingStyle = MenuControl.Hide;
Chart2DLine.PeUserInterface.Dialog.AllowEmfExport = false;
Chart2DLine.PeUserInterface.Dialog.AllowSvgExport = false;
Chart2DLine.PeUserInterface.Dialog.AllowWmfExport = false;
Chart2DLine.PeUserInterface.Allow.TextExport = false;
Chart2DLine.PeUserInterface.Dialog.HideExportImageDpi = true;
Chart2DLine.PeUserInterface.Dialog.HidePrintDpi = true;
}
private void Chart2DContour_MouseEnter(object sender, EventArgs e)
{
// Disable Chart Pe3do hot spots (cursor tracking)
CustomMenuState n = Chart3DSurface.PeUserInterface.Menu.CustomMenuState[CursorTrackingMenu3d, 0];
if (n == CustomMenuState.Checked || HotSpots.Checked == true)
{
Chart2DContour.PeAnnotation.Graph.Show = false; // remove the dot if there happens to be one
Chart2DContour.PeAnnotation.Show = false;
Chart2DContour.PeFunction.ResetImage(0, 0);
Chart2DContour.Invalidate();
n = CustomMenuState.UnChecked;
Chart3DSurface.Freeze = true;
Chart3DSurface.PeUserInterface.Cursor.HighlightColor = Color.FromArgb(0, 0, 0, 0);
HotSpots.Checked = false;
Chart3DSurface.PeUserInterface.HotSpot.Data = false;
Chart3DSurface.PeUserInterface.Cursor.PromptTracking = false;
Chart3DSurface.PeUserInterface.Menu.CustomMenuState[CursorTrackingMenu3d, 0] = n;
Chart3DSurface.PeFunction.Force3dxVerticeRebuild = true;
Chart3DSurface.PeFunction.ReinitializeResetImage();
Chart3DSurface.Invalidate();
Chart3DSurface.Freeze = false;
}
}
private void Chart_PeCustomMenu(object sender, Gigasoft.ProEssentials.EventArg.CustomMenuEventArgs e)
{
CustomMenuState n = CustomMenuState.UnChecked;
// Custom Menu was clicked //
if (e.MenuIndex == CursorTrackingMenu3d) // Cursor Tracking State
{
// Reverse option //
n = Chart3DSurface.PeUserInterface.Menu.CustomMenuState[CursorTrackingMenu3d, 0];
if (n == CustomMenuState.UnChecked)
{
n = CustomMenuState.Checked;
HotSpots.Checked = true;
Chart3DSurface.PeUserInterface.HotSpot.Data = true;
Chart3DSurface.PeUserInterface.Cursor.PromptTracking = true;
Chart3DSurface.PeUserInterface.Cursor.HighlightColor = Color.FromArgb(255, 255, 0, 0);
}
else
{
n = CustomMenuState.UnChecked;
HotSpots.Checked = false;
Chart3DSurface.PeUserInterface.HotSpot.Data = false;
Chart3DSurface.PeUserInterface.Cursor.PromptTracking = false;
Chart3DSurface.PeUserInterface.Cursor.HighlightColor = Color.FromArgb(0, 0, 0, 0);
}
Chart3DSurface.PeUserInterface.Menu.CustomMenuState[CursorTrackingMenu3d, 0] = n;
Chart3DSurface.PeFunction.Force3dxVerticeRebuild = true;
Chart3DSurface.PeFunction.ReinitializeResetImage();
Chart3DSurface.Invalidate();
return;
}
if (e.MenuIndex == UndoZoomMenu3d) // Undo Zoom
{
if (_bZoomed)
{
Chart2DContour.PeGrid.Zoom.Mode = false;
_bZoomed = false;
Chart2DContour.Invalidate();
Chart3DSurface.PeUserInterface.Menu.CustomMenu[UndoZoomMenu3d, 0] = CustomMenu.Grayed;
Chart3DSurface.PeGrid.Configure.ManualScaleControlX = ManualScaleControl.None;
Chart3DSurface.PeGrid.Configure.ManualScaleControlZ = ManualScaleControl.None;
Chart3DSurface.PeFunction.Force3dxVerticeRebuild = true;
Chart3DSurface.PeFunction.Force3dxAnnotVerticeRebuild = true;
Chart3DSurface.PeData.SkipRanging = true;
Chart3DSurface.PeFunction.Reinitialize();
Chart3DSurface.Invalidate();
float fRange = (float)(Chart3DSurface.PeGrid.Configure.ManualMaxX - Chart3DSurface.PeGrid.Configure.ManualMinX);
double dPos = Chart3DSurface.PeGrid.Configure.ManualMinX + (fRange * SliderXPlane.Value / 100.0F);
MoveXPlane(dPos);
}
}
}
private void RefreshUi(HeightMap hm)
{
// Changing the data of the chart, mostly maintaining all existing settings and states.
CurrentHeightMap = hm;
_nAppliedStep = 1;
if (hm.HeightPx > 1001 || hm.WidthPx > 1001) { _nAppliedStep = _nDataStep; }
_rows = hm.HeightPx / _nAppliedStep;
_cols = hm.WidthPx / _nAppliedStep;
var size = _rows * _cols;
float fResolution = (float)hm.Resolution;
var idx = 0;
for (var row = 0; row < hm.HeightPx - (_nAppliedStep - 1); row += _nAppliedStep)
sMyZData[idx++] = row * fResolution;
idx = 0;
for (var col = 0; col < hm.WidthPx - (_nAppliedStep - 1); col += _nAppliedStep)
sMyXData[idx++] = col * fResolution;
Chart3DSurface.PeData.ScaleForYData = 0;
if (_nAppliedStep > 1)
{
idx = 0;
for (var row = 0; row < hm.HeightPx - (_nAppliedStep - 1); row += _nAppliedStep)
{
for (var col = 0; col < hm.WidthPx - (_nAppliedStep - 1); col += _nAppliedStep)
{
sMyYData[idx++] = (hm.GetPel(row, col));
}
}
}
else
{
Array.Copy(hm.ImageData, sMyYData, _rows * _cols);
}
_maxx = (float)hm.WidthMm;
_miny = (float)hm.MinZMm;
_maxy = (float)hm.MaxZMm;
_minz = 0.0F;
_maxz = (float)hm.HeightMm;
Chart3DSurface.PeData.Subsets = _rows;
Chart3DSurface.PeData.Points = _cols;
Chart3DSurface.PeData.DuplicateDataX = DuplicateData.PointIncrement;
Chart3DSurface.PeData.DuplicateDataZ = DuplicateData.SubsetIncrement;
// v10 new feature - build the scene on the GPU vs the CPU.
Chart3DSurface.PeData.ComputeShader = true;
// GPU staging buffers keep the X/Y/Z data resident video-side so later
// forced rebuilds that DON'T change data (dragging Explode-Z) can reuse
// them. ReuseData* are false here because the data IS changing on load -
// the Explode-Z handler flips them true around its rebuild.
Chart3DSurface.PeData.StagingBufferX = true;
Chart3DSurface.PeData.StagingBufferY = true;
Chart3DSurface.PeData.StagingBufferZ = true;
Chart3DSurface.PeData.ReuseDataX = false;
Chart3DSurface.PeData.ReuseDataY = false;
Chart3DSurface.PeData.ReuseDataZ = false;
// No transfer of data, set chart uses the app memory, same memory used for Pesgo below //
Chart3DSurface.PeData.X.UseDataAtLocation(sMyXData, _cols);
Chart3DSurface.PeData.Y.UseDataAtLocation(sMyYData, size);
Chart3DSurface.PeData.Z.UseDataAtLocation(sMyZData, _rows);
var width = (float)hm.WidthMm;
var height = (float)hm.HeightMm;
var diag = (float)Math.Sqrt(width * width + height * height);
Chart3DSurface.PeGrid.Option.GridAspectX = width;
Chart3DSurface.PeGrid.Option.GridAspectZ = height;
Chart3DSurface.PeGrid.Option.GridAspectY = diag * 0.1f; // Z Axis Expansion
Chart3DSurface.PeString.MainTitle = hm.Path;
Chart3DSurface.PeFunction.SetLight(0, -2.0F, -7.0F, -7.0F); // reset the light location
_updatingUi = true;
SliderHorizontalRotation.Value = (int)Chart3DSurface.PeUserInterface.Scrollbar.SBPos;
SliderVerticalRotation.Value = (int)Chart3DSurface.PeUserInterface.Scrollbar.ViewingHeight;
SliderZExaggeration.Value = 10;
_updatingUi = false;
Chart3DSurface.PeFunction.Force3dxVerticeRebuild = true;
Chart3DSurface.PeFunction.ReinitializeResetImage();
Chart3DSurface.Invalidate();
///////////////////////////////
// Set data for 2D Contour //
///////////////////////////////
Initialize2DContour();
Chart2DContour.PeConfigure.RenderEngine = RenderEngine.Direct3D;
Chart2DContour.PeData.Subsets = _rows;
Chart2DContour.PeData.Points = _cols;
Chart2DContour.PeData.ComputeShader = true;
Chart2DContour.PeData.DuplicateDataX = DuplicateData.PointIncrement;
Chart2DContour.PeData.DuplicateDataY = DuplicateData.SubsetIncrement;
// No transfer of data, set chart uses the app memory, same memory used for Pe3do above //
Chart2DContour.PeData.X.UseDataAtLocation(sMyXData, _cols);
Chart2DContour.PeData.Z.UseDataAtLocation(sMyYData, size);
Chart2DContour.PeData.Y.UseDataAtLocation(sMyZData, _rows);
Chart2DContour.PeGrid.Option.GridAspect = (float)_rows / (float)_cols;