Coh3n
2011-07-15 18:53:59
Before you say anything, I know there's FilterPointsDist, this is slightly different. FilterPointsDist removes points in a TPA that are within a distance range of another point where as FilterTPADist removed any points in the TPA that are within a certain distance of each other.
I used it in MSI's object finding to get rid of some overlapping TPAs (would get multiple points on one tree). Also works well with FindDTMs since the same DTM is sometimes found several times, all within 5 points of each other.
I'm just wondering if it's worth sending a pull request for. If not, it'll stay in MSI. :)
I used it in MSI's object finding to get rid of some overlapping TPAs (would get multiple points on one tree). Also works well with FindDTMs since the same DTM is sometimes found several times, all within 5 points of each other.
I'm just wondering if it's worth sending a pull request for. If not, it'll stay in MSI. :)
procedure FilterTPADist(var TPA: TPointArray; maxDist: extended);
var
c, d, i, j, l, h: integer;
newTPA: TPointArray;
badElements: TIntegerArray;
begin
l := length(TPA);
h := high(TPA);
setLength(badElements, l);
setLength(newTPA, l);
c := 0;
for i := 0 to (h - 1) do
begin
if (i > 0) then // array elements are set to 0 by default
if (inIntArray(badElements, i)) then // increases speed significantly
continue;
for j := (i + 1) to h do
begin
d := distance(TPA[i].x, TPA[i].y, TPA[j].x, TPA[j].y);
if (d <= maxDist) then // if points are too close
if (not inIntArray(badElements, j)) then
begin
badElements[c] := j; // new array of bad elements (indexes)
inc(c);
end;
end;
end;
clearSameIntegers(badElements);
setLength(badElements, c);
c := 0;
// set the new TPA
for i := 0 to high(TPA) do
if (not inIntArray(badElements, i)) then
begin
newTPA[c] := TPA[i];
inc(c);
end;
setLength(newTPA, c);
TPA := newTPA;
end;
I'm also not sure if, because I call methods like clearSameIntegers and inIntArray, it would cause problems.