maigel
2012-01-24 22:50:55
Hi,
So recently I was working on a script that uses TPAs. I followed this tutorial to help my out a bit:
http://villavu.com/forum/showthread.php?t=49067
Now I needed a way to sort my ATPA array by the actual surface area the boxes had instead of the amount of matched pixels there were in the box. It turned out there wasn't any function to do this so I made one myself and I tought it might come in handy for others too ;)
So recently I was working on a script that uses TPAs. I followed this tutorial to help my out a bit:
http://villavu.com/forum/showthread.php?t=49067
Now I needed a way to sort my ATPA array by the actual surface area the boxes had instead of the amount of matched pixels there were in the box. It turned out there wasn't any function to do this so I made one myself and I tought it might come in handy for others too ;)
(*
Description: Sorts an ATPA array by its boundaries' surface area (sort by size sorts by the amount of dots)
*)
procedure SortATPAByBoundaries( atpa : T2DPointArray);
var
i, j, maxIndex : Integer;
box1, box2 : TBox;
temp : TPointArray;
begin
for i := 0 to High(atpa) do
begin
maxIndex := i;
for j := i + 1 to High(atpa) do
begin
box1 := GetTPABounds(atpa[j]);
box2 := GetTPABounds(atpa[maxIndex]);
if( (box1.X2 - box1.X1) * (box1.Y2 - box1.Y1) > (box2.X2 - box2.X1) * (box2.Y2 - box2.Y1) ) then
maxIndex := j;
end;
temp := atpa[i];
atpa[i] := atpa[maxIndex];
atpa[maxIndex] := temp;
end;
end;