MathgeomGLS
114 строк · 2.6 Кб
1unit fDelaunayPick;
2
3interface
4
5uses
6Winapi.Windows,
7Winapi.Messages,
8System.Types,
9System.SysUtils,
10System.Variants,
11System.Classes,
12Vcl.Graphics,
13Vcl.Controls,
14Vcl.Forms,
15Vcl.Dialogs,
16Vcl.StdCtrls,
17
18GLS.Triangulation,
19GLS.SceneViewer,
20
21GLS.BaseClasses,
22GLS.Scene;
23
24type
25TFormDelaunayPick = class(TForm)
26GLScene1: TGLScene;
27GLSceneViewer1: TGLSceneViewer;
28procedure FormCreate(Sender: TObject);
29procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
30Shift: TShiftState; X, Y: Integer);
31private
32Z, U, V : Single;
33MatIndex : Integer;
34TempBuffer: TBitmap;
35procedure ClearBackPage;
36procedure FlipBackPage;
37public
38TheMesh: TGLDelaunay2D;
39procedure Draw;
40end;
41
42var
43FormDelaunayPick: TFormDelaunayPick;
44
45implementation
46
47{$R *.dfm}
48
49procedure TFormDelaunayPick.FormCreate(Sender: TObject);
50begin
51TheMesh := TGLDelaunay2D.Create;
52TempBuffer := TBitmap.Create;
53FormDelaunayPick.Caption := 'Click on the form!';
54end;
55
56procedure TFormDelaunayPick.ClearBackPage;
57begin
58TempBuffer.Height := FormDelaunayPick.Height;
59TempBuffer.Width := FormDelaunayPick.Width;
60TempBuffer.Canvas.Brush.Color := clSilver;
61TempBuffer.Canvas.FillRect(Rect(0, 0,
62FormDelaunayPick.Width, FormDelaunayPick.Height));
63end;
64
65procedure TFormDelaunayPick.FlipBackPage;
66var
67ARect: TRect;
68begin
69ARect := Rect(0, 0, FormDelaunayPick.Width, FormDelaunayPick.Height);
70FormDelaunayPick.Canvas.CopyRect(ARect, TempBuffer.Canvas, ARect);
71end;
72
73procedure TFormDelaunayPick.Draw;
74var
75// variable to hold how many triangles are created by the triangulate function
76i: Integer;
77begin
78// Clear the form canvas
79ClearBackPage;
80
81TempBuffer.Canvas.Brush.Color := clTeal;
82// Draw the created triangles
83with TheMesh do
84begin
85if (TheMesh.HowMany > 0) then
86begin
87for i := 1 To TheMesh.HowMany do
88begin
89TempBuffer.Canvas.Polygon([Point(Trunc(Vertex[Triangle[i].vv0].x),
90Trunc(Vertex[Triangle[i].vv0].y)),
91Point(Trunc(Vertex[Triangle[i].vv1].x),
92Trunc(Vertex[Triangle[i].vv1].y)),
93Point(Trunc(Vertex[Triangle[i].vv2].x),
94Trunc(Vertex[Triangle[i].vv2].y))]);
95end;
96end;
97end;
98
99FlipBackPage;
100end;
101
102
103procedure TFormDelaunayPick.FormMouseDown(Sender: TObject; Button: TMouseButton;
104Shift: TShiftState; X, Y: Integer);
105begin
106TheMesh.AddPoint(X, Y, Z, U, V, MatIndex); // add a point to the mesh
107TheMesh.Mesh(True); // triangulate the mesh
108Draw; // draw the mesh on the forms canvas
109FormDelaunayPick.Caption := 'Points: ' + IntToStr(TheMesh.tPoints - 1) +
110' Triangles: ' + IntToStr(TheMesh.HowMany);
111end;
112
113
114end.
115