- 001
- 002
- 003
- 004
- 005
- 006
- 007
- 008
- 009
- 010
- 011
- 012
- 013
- 014
- 015
- 016
- 017
- 018
- 019
- 020
- 021
- 022
- 023
- 024
- 025
- 026
- 027
- 028
- 029
- 030
- 031
- 032
- 033
- 034
- 035
- 036
- 037
- 038
- 039
- 040
- 041
- 042
- 043
- 044
- 045
- 046
- 047
- 048
- 049
- 050
- 051
- 052
- 053
- 054
- 055
- 056
- 057
- 058
- 059
- 060
- 061
- 062
- 063
- 064
- 065
- 066
- 067
- 068
- 069
- 070
- 071
- 072
- 073
- 074
- 075
- 076
- 077
- 078
- 079
- 080
- 081
- 082
- 083
- 084
- 085
- 086
- 087
- 088
- 089
- 090
- 091
- 092
- 093
- 094
- 095
- 096
- 097
- 098
- 099
- 100
function TMFinder.FindDTMs(DTM: TMDTM; out Points: TPointArray; x1, y1, x2, y2, maxToFind: Integer): Boolean;
var
Len: integer;
DPoints: PMDTMPoint;
b: array of array of Integer;
ch: array of array of integer;
W, H: integer;
MA: TBox;
MaxX, MaxY: integer;
xx, yy: integer;
i, xxx, yyy: Integer;
StartX, StartY, EndX, EndY: integer;
cd: TPRGB32Array;
PtrData: TRetData;
pc: Integer = 0;
Found: boolean;
goodPoints: array of Boolean;
col_arr, tol_arr: array of Integer;
ctsinfoarray: TCTSInfoArray;
compare: TCTSCompareFunction;
label
theEnd;
begin
MA := ValidMainPointBox(DTM, x1, y1, x2, y2);
Len := dtm.Count;
DPoints := dtm.PPoints;
setlength(goodPoints, Len);
for i := 0 to Len - 1 do
goodPoints[i] := not DPoints[i].bp;
W := x2 - x1;
H := y2 - y1;
setlength(b, (W + 1));
setlength(ch, (W + 1));
for i := 0 to W do
begin
setlength(ch[i], (H + 1));
FillChar(ch[i][0], SizeOf(Integer) * (H + 1), 0);
setlength(b[i], (H + 1));
FillChar(b[i][0], SizeOf(Integer) * (H + 1), 0);
end;
PtrData := TClient(Client).IOManager.ReturnData(x1, y1, W + 1, H + 1);
SetLength(col_arr, Len);
SetLength(tol_arr, Len);
for i := 0 to Len - 1 do
begin
col_arr[i] := DPoints[i].c;
tol_arr[i] := DPoints[i].t;
end;
ctsinfoarray := Create_CTSInfoArray(col_arr, tol_arr);
compare := Get_CTSCompare(Self.CTS);
cd := CalculateRowPtrs(PtrData, h + 1);
MA.x1 := MA.x1 - x1;
MA.y1 := MA.y1 - y1;
MA.x2 := MA.x2 - x1;
MA.y2 := MA.y2 - y1;
MaxX := x2 - x1;
MaxY := y2 - y1;
for yy := MA.y1 to MA.y2 do
for xx := MA.x1 to MA.x2 do
begin
for i := 0 to Len - 1 do
begin
Found := false;
StartX := max(0, xx - DPoints[i].asz + DPoints[i].x);
StartY := max(0, yy - DPoints[i].asz + DPoints[i].y);
EndX := Min(MaxX, xx + DPoints[i].asz + DPoints[i].x);
EndY := Min(MaxY, yy + DPoints[i].asz + DPoints[i].y);
for xxx := StartX to EndX do
begin
for yyy := StartY to EndY do
begin
if ch[xxx][yyy] and (1 shl i) = 0 then
begin
ch[xxx][yyy] := ch[xxx][yyy] or (1 shl i);
if compare(ctsinfoarray[i], @ cd[yyy][xxx]) then
b[xxx][yyy] := b[xxx][yyy] or (1 shl i);
end;
if (b[xxx][yyy] and (1 shl i) <> 0) then
begin
if GoodPoints[i] then
begin
Found := true;
break;
end
else
goto AnotherLoopEnd;
end;
end;
if Found then
Break;
end;
if (not found) and (GoodPoints[i]) then
goto AnotherLoopEnd;
end;
ClientTPA[pc] := Point(xx + x1, yy + y1);
Inc(pc);
if (pc = maxToFind) then
goto theEnd;
end;
TheEnd: Free_CTSInfoArray(ctsinfoarray);