SRL Archive - OSR Help

Filling Gaps in a TPA


purerange86

2015-02-02 22:13:30

So right now I'm trying to write a function that will look for objects on shaded tiles of a specific colour. What I'm thinking of doing is finding a TPA of the floor color, filling the gaps, and searching for the object within my filled TPA. How might I do this? Right now I have

//function FindGapsTPA(const TPA: TPointArray; MinPixels: Integer): T2DPointArray; (for reference)

function FindObjOnTPA: boolean;
var
TPA, TPA2, NewTPA: TPointArray;
ATPA, ATPA2: T2DPointArray;
begin
FindColorsTolerance(TPA,FloorColor,msx1,msy1,msx2,msy2,FloorTol);
ATPA := FindGapsTPA(TPA,5);
TPA2 := MergeATPA(ATPA);
NewTPA := CombineTPA(TPA,TPA2);
//I want to find a valid NewTPA to search in
end;

However I debugged writeln(ATPA) and it returned the same points as found in the original TPA. What is the proper way to use this function to find the GAPS in the TPA?
Any suggestions is appreciated, whether using this function or not

riwu

2015-02-02 22:32:18

Try FindGapsTPA()

purerange86

2015-02-02 23:03:39

From: riwu
Try FindGapsTPA()


That is what I'm trying but FindGapsTPA is simply returning an ATPA of everything in my original TPA, is there something wrong with code i posted?

Olly

2015-02-02 23:06:34

FindGapsTPA is *not* what you want, not even close don't mess with it.

purerange86

2015-02-02 23:48:24

From: Olly
FindGapsTPA is *not* what you want, not even close don't mess with it.


Hmm any ideas to shade in regions? And Also how do i find the source code for functions like this? WHen I double click it in the function finder it links me to a web page

riwu

2015-02-02 23:55:59


var
tpa: TPointArray;
ATPA: T2DPointArray;
i, k: Integer;
begin
tpa:= [Point(2, 2), Point(10, 2)];
if Length(tpa) <= 1 then
Exit;
for i:=0 to high(tpa) do
for k:=1 to high(tpa) do
if tpa[i].y = tpa[k].y then
begin
SetLength(ATPA, Length(ATPA) + 1);
ATPA[High(ATPA)]:= TPAFromBox(TBox([Min(tpa[i].x, tpa[k].x), tpa[i].y, Max(tpa[i].x, tpa[k].x), tpa[i].y]));
end;

tpa:= CombineTPA(MergeATPA(ATPA), tpa);
ClearDoubleTPA(tpa);
writeln(tpa);
end.
This would fill up the tpa row by row.
There's probably many more efficient ways to do this, like maybe sorting the tpa first etc but i'd leave that to u.

Although what most ppl do to find objects is to simply use SplitTPA()/TPAtoATPA() then MiddleTPA().

The Mayor

2015-02-03 00:34:55

So something like:


function findObjOnTPA(): Boolean;
var
TPA, newTPA: TPointArray;
begin
findColorsTolerance(TPA, 123456, mainScreen.getBounds(), 12);
newTPA := TPA.returnNotInTPA(TPA.getBounds());
end;


purerange86

2015-02-03 00:39:24

From: The Mayor
So something like:


function findObjOnTPA(): Boolean;
var
TPA, newTPA: TPointArray;
begin
findColorsTolerance(TPA, 123456, mainScreen.getBounds(), 12);
newTPA := TPA.returnNotInTPA(TPA.getBounds());
end;


Hey guys thanks for the very detailed responses! The reasons why i can't use colors is because there are similar size/shape objects in the area. Riwu that was very helpful and I will build on that