-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathunit2.pas
305 lines (284 loc) · 11.2 KB
/
unit2.pas
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
(******************************************************************************)
(* *)
(* Author : Uwe Schächterle (Corpsman) *)
(* *)
(* This file is part of FIR IIR *)
(* *)
(* See the file license.md, located under: *)
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
(* for details about the license. *)
(* *)
(* It is not allowed to change or remove this text from any *)
(* source file of the project. *)
(* *)
(******************************************************************************)
Unit Unit2;
{$MODE objfpc}{$H+}
Interface
Uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, Menus, usolver, math;
Type
{ TForm2 }
TForm2 = Class(TForm)
Button1: TButton;
MenuItem1: TMenuItem;
PaintBox1: TPaintBox;
PopupMenu1: TPopupMenu;
SaveDialog1: TSaveDialog;
Procedure Button1Click(Sender: TObject);
Procedure FormCreate(Sender: TObject);
Procedure FormDestroy(Sender: TObject);
Procedure MenuItem1Click(Sender: TObject);
Procedure PaintBox1Paint(Sender: TObject);
Procedure PaintBox1Resize(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
End;
Var
Form2: TForm2;
bitmap: Tbitmap = Nil;
renderproperties: Record
xmin: TDatatype;
xmax: TDatatype;
ymin: TDatatype;
ymax: TDatatype;
show_orig: Boolean;
orig_color: TColor;
dest_color: TColor;
show_x_achis: Boolean;
show_y_achis: Boolean;
mark_x_achis: Boolean;
mark_y_achis: Boolean;
mark_color: TColor;
mark_x_delta: TDatatype;
mark_y_delta: TDatatype;
enhance_mark_x_achis: Boolean;
enhance_mark_y_achis: Boolean;
enhance_mark_color: TColor;
enhance_mark_x_delta: TDatatype;
enhance_mark_y_delta: TDatatype;
End;
Need_2d_Output: Boolean;
Implementation
{$R *.lfm}
Uses unit1;
{ TForm2 }
Procedure TForm2.FormCreate(Sender: TObject);
Begin
caption := 'Graphic output';
bitmap := TBitmap.Create;
bitmap.Width := PaintBox1.Width;
bitmap.Height := PaintBox1.Height;
SaveDialog1.InitialDir := ExtractFilePath(paramstr(0));
End;
Procedure TForm2.FormDestroy(Sender: TObject);
Begin
bitmap.free;
bitmap := Nil;
End;
Procedure TForm2.MenuItem1Click(Sender: TObject);
Begin
If SaveDialog1.Execute Then Begin
bitmap.SaveToFile(SaveDialog1.FileName);
End;
End;
(*
* vmin / rmin vmax / rmax
* | |
* ---------------------------------------
* |
* v / result
*
* Berechnet den Wert von result so, dass er an der entsprechend
* gleichen Stelle in rmin / rmax liegt, wie v in vmin / vmax ist.
*)
Function convert_dimension(vmin, vmax, v: TDatatype; rmin, rmax: integer): integer;
Begin
If (vmax - vmin = 0) Then Begin
result := rmin;
exit;
End
Else Begin
result := round((((v - vmin) * (rmax - rmin)) / (vmax - vmin)) + rmin);
End;
End;
Procedure TForm2.PaintBox1Paint(Sender: TObject);
Var
x, y, i: integer;
fx, fy: TDatatype;
h, w: integer;
render_outside: Boolean;
Begin
If assigned(bitmap) Then Begin
If Need_2d_Output Then Begin
PaintBox1.Canvas.StretchDraw(rect(0, 0, PaintBox1.Width, PaintBox1.Height), form1.Daten_D2);
End
Else Begin
// Alles Löschen
bitmap.Canvas.Brush.Color := clwhite;
bitmap.Canvas.Brush.Style := bsSolid;
bitmap.Canvas.Rectangle(-1, -1, bitmap.Width + 1, bitmap.height + 1);
h := bitmap.Height;
w := bitmap.Width;
// -----------------Anzeigen des Grids und aller seiner Nuoncen ------------
// Anzeigen der enhanced Markierungen y - Achse
If renderproperties.enhance_mark_y_achis And (renderproperties.enhance_mark_y_delta > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.enhance_mark_color;
fy := 0;
// Anfahren des 1. delta Punktes >= xmin
While fy > min(renderproperties.ymin, renderproperties.ymax) Do
fy := fy - renderproperties.enhance_mark_y_delta;
While fy < min(renderproperties.ymin, renderproperties.ymax) Do
fy := fy + renderproperties.enhance_mark_y_delta;
While fy < max(renderproperties.ymin, renderproperties.ymax) Do Begin
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, fy, h, 0);
bitmap.Canvas.MoveTo(0, y);
bitmap.Canvas.lineTo(w, y);
fy := fy + renderproperties.enhance_mark_y_delta;
End;
End;
// Wenn die x-Achse Echt Positioniert werden kann
If (min(renderproperties.ymin, renderproperties.ymax) <= 0) And
(max(renderproperties.ymin, renderproperties.ymax) >= 0) Then Begin
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, 0, h, 0);
render_outside := false;
End
Else Begin
// Wenn die x- Achse eigentlich nicht sicht bar wäre
y := h - 10;
render_outside := true;
End;
// Anzeigen der enhanced Markierungen
If renderproperties.enhance_mark_x_achis And (renderproperties.enhance_mark_x_delta > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.enhance_mark_color;
fx := 0;
// Anfahren des 1. delta Punktes >= xmin
While fx > min(renderproperties.xmin, renderproperties.xmax) Do
fx := fx - renderproperties.enhance_mark_x_delta;
While fx < min(renderproperties.xmin, renderproperties.xmax) Do
fx := fx + renderproperties.enhance_mark_x_delta;
While fx < max(renderproperties.xmin, renderproperties.xmax) Do Begin
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, fx, 0, w);
bitmap.Canvas.MoveTo(x, 0);
bitmap.Canvas.lineTo(x, h);
fx := fx + renderproperties.enhance_mark_x_delta;
End;
End;
bitmap.Canvas.Pen.Color := clblack;
// Anzeigen der x-Achse
If renderproperties.show_x_achis Then Begin
// Malen der x- Achse
If render_outside Then Begin
bitmap.Canvas.Pen.Style := psDashDot;
End
Else Begin
bitmap.Canvas.Pen.Style := psSolid;
End;
bitmap.Canvas.MoveTo(0, y);
bitmap.Canvas.lineTo(w, y);
End;
bitmap.Canvas.Pen.Style := psSolid;
// Anzeigen der Markierungen
If renderproperties.mark_x_achis And (renderproperties.mark_x_delta > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.mark_color;
fx := 0;
// Anfahren des 1. delta Punktes >= xmin
While fx > min(renderproperties.xmin, renderproperties.xmax) Do
fx := fx - renderproperties.mark_x_delta;
While fx < min(renderproperties.xmin, renderproperties.xmax) Do
fx := fx + renderproperties.mark_x_delta;
While fx < max(renderproperties.xmin, renderproperties.xmax) Do Begin
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, fx, 0, w);
bitmap.Canvas.MoveTo(x, y - 4);
bitmap.Canvas.lineTo(x, y + 4);
fx := fx + renderproperties.mark_x_delta;
End;
End;
// Wenn die y-Achse Echt Positioniert werden kann
If (min(renderproperties.xmin, renderproperties.xmax) <= 0) And
(max(renderproperties.xmin, renderproperties.xmax) >= 0) Then Begin
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, 0, 0, w);
render_outside := false;
End
Else Begin
// Wenn die y- Achse eigentlich nicht sicht bar wäre
x := 10;
render_outside := true;
End;
bitmap.Canvas.Pen.Color := clblack;
If renderproperties.mark_y_achis And (renderproperties.mark_y_delta > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.mark_color;
fy := 0;
// Anfahren des 1. delta Punktes >= xmin
While fy > min(renderproperties.ymin, renderproperties.ymax) Do
fy := fy - renderproperties.mark_y_delta;
While fy < min(renderproperties.ymin, renderproperties.ymax) Do
fy := fy + renderproperties.mark_y_delta;
While fy < max(renderproperties.ymin, renderproperties.ymax) Do Begin
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, fy, h, 0);
bitmap.Canvas.MoveTo(x - 4, y);
bitmap.Canvas.lineTo(x + 4, y);
fy := fy + renderproperties.mark_y_delta;
End;
End;
// Anzeigen der y-Achse
If renderproperties.show_y_achis Then Begin
// Malen der y- Achse
If render_outside Then Begin
bitmap.Canvas.Pen.Style := psDashDot;
End
Else Begin
bitmap.Canvas.Pen.Style := psSolid;
End;
bitmap.Canvas.MoveTo(x, 0);
bitmap.Canvas.lineTo(x, h);
End;
bitmap.Canvas.Pen.Style := psSolid;
// Rendern der Original Funktion
If renderproperties.show_orig And assigned(form1.Samples) And (form1.sample_cnt > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.orig_color;
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, form1.Samples[0].x, 0, w);
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, form1.Samples[0].y, h, 0);
bitmap.Canvas.moveto(x, y);
For i := 1 To form1.sample_cnt - 1 Do Begin
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, form1.Samples[i].x, 0, w);
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, form1.Samples[i].y, h, 0);
bitmap.Canvas.lineto(x, y);
End;
End;
// Als Allerletztes die Gefilterte Funktion
If assigned(form1.results) And (form1.sample_cnt > 0) Then Begin
bitmap.Canvas.Pen.Color := renderproperties.dest_color;
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, form1.results[0].x, 0, w);
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, form1.results[0].y, h, 0);
bitmap.Canvas.moveto(x, y);
For i := 1 To form1.sample_cnt - 1 Do Begin
x := convert_dimension(renderproperties.xmin, renderproperties.xmax, form1.results[i].x, 0, w);
y := convert_dimension(renderproperties.ymin, renderproperties.ymax, form1.results[i].y, h, 0);
bitmap.Canvas.lineto(x, y);
End;
End;
// Ausgabe auf das Display
PaintBox1.Canvas.Draw(0, 0, bitmap);
End;
End
Else Begin
caption := 'Bitmap already freed';
End;
End;
Procedure TForm2.PaintBox1Resize(Sender: TObject);
Begin
If assigned(bitmap) Then Begin
bitmap.Width := PaintBox1.Width;
bitmap.Height := PaintBox1.Height;
PaintBox1.Invalidate;
End;
End;
Procedure TForm2.Button1Click(Sender: TObject);
Begin
visible := false;
End;
End.