MathgeomGLS

Форк
0
/
fDelaunayPick.pas 
114 строк · 2.6 Кб
1
unit fDelaunayPick;
2

3
interface
4

5
uses
6
  Winapi.Windows,
7
  Winapi.Messages,
8
  System.Types,
9
  System.SysUtils,
10
  System.Variants,
11
  System.Classes,
12
  Vcl.Graphics,
13
  Vcl.Controls,
14
  Vcl.Forms,
15
  Vcl.Dialogs,
16
  Vcl.StdCtrls,
17

18
  GLS.Triangulation,
19
  GLS.SceneViewer,
20
  
21
  GLS.BaseClasses,
22
  GLS.Scene;
23

24
type
25
  TFormDelaunayPick = class(TForm)
26
    GLScene1: TGLScene;
27
    GLSceneViewer1: TGLSceneViewer;
28
    procedure FormCreate(Sender: TObject);
29
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
30
      Shift: TShiftState; X, Y: Integer);
31
  private
32
    Z, U, V : Single;
33
    MatIndex : Integer;
34
    TempBuffer: TBitmap;
35
    procedure ClearBackPage;
36
    procedure FlipBackPage;
37
  public
38
    TheMesh: TGLDelaunay2D;
39
    procedure Draw;
40
  end;
41

42
var
43
  FormDelaunayPick: TFormDelaunayPick;
44

45
implementation
46

47
{$R *.dfm}
48

49
procedure TFormDelaunayPick.FormCreate(Sender: TObject);
50
begin
51
  TheMesh := TGLDelaunay2D.Create;
52
  TempBuffer := TBitmap.Create;
53
  FormDelaunayPick.Caption := 'Click on the form!';
54
end;
55

56
procedure TFormDelaunayPick.ClearBackPage;
57
begin
58
  TempBuffer.Height := FormDelaunayPick.Height;
59
  TempBuffer.Width := FormDelaunayPick.Width;
60
  TempBuffer.Canvas.Brush.Color := clSilver;
61
  TempBuffer.Canvas.FillRect(Rect(0, 0,
62
    FormDelaunayPick.Width, FormDelaunayPick.Height));
63
end;
64

65
procedure TFormDelaunayPick.FlipBackPage;
66
var
67
  ARect: TRect;
68
begin
69
  ARect := Rect(0, 0, FormDelaunayPick.Width, FormDelaunayPick.Height);
70
  FormDelaunayPick.Canvas.CopyRect(ARect, TempBuffer.Canvas, ARect);
71
end;
72

73
procedure TFormDelaunayPick.Draw;
74
var
75
  // variable to hold how many triangles are created by the triangulate function
76
  i: Integer;
77
begin
78
  // Clear the form canvas
79
  ClearBackPage;
80

81
  TempBuffer.Canvas.Brush.Color := clTeal;
82
  // Draw the created triangles
83
  with TheMesh do
84
  begin
85
    if (TheMesh.HowMany > 0) then
86
    begin
87
      for i := 1 To TheMesh.HowMany do
88
      begin
89
        TempBuffer.Canvas.Polygon([Point(Trunc(Vertex[Triangle[i].vv0].x),
90
          Trunc(Vertex[Triangle[i].vv0].y)),
91
          Point(Trunc(Vertex[Triangle[i].vv1].x),
92
          Trunc(Vertex[Triangle[i].vv1].y)),
93
          Point(Trunc(Vertex[Triangle[i].vv2].x),
94
          Trunc(Vertex[Triangle[i].vv2].y))]);
95
      end;
96
    end;
97
  end;
98

99
  FlipBackPage;
100
end;
101

102

103
procedure TFormDelaunayPick.FormMouseDown(Sender: TObject; Button: TMouseButton;
104
  Shift: TShiftState; X, Y: Integer);
105
begin
106
  TheMesh.AddPoint(X, Y, Z, U, V, MatIndex); // add a point to the mesh
107
  TheMesh.Mesh(True); // triangulate the mesh
108
  Draw; // draw the mesh on the forms canvas
109
  FormDelaunayPick.Caption := 'Points: ' + IntToStr(TheMesh.tPoints - 1) +
110
    '  Triangles: ' + IntToStr(TheMesh.HowMany);
111
end;
112

113

114
end.
115

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.