Sample Program: |
The following short example creates an artificial region and calculates its polygonal shape along the edge of this region:
program ParticleEdgeVector;
const
PAGE = 1;
var
i, j : integer;
Region : TInt2Darray;
EdgePixels : TInt2Darray;
Anchorx : integer;
AnchorY : integer;
EdgePath : TPDblArray;
begin
ResizeIntMatrix (region, 30,30);
FillIntMatrix(region,0);
Region[1][9] := 1; // define the particle
Region[2][9] := 1;
Region[2][8] := 1;
Region[2][7] := 1;
Region[1][7] := 1;
Region[3][8] := 1;
Region[3][9] := 1;
Region[3][10] := 1;
Region[2][11] := 1;
Region[3][11] := 1;
Region[4][11] := 1;
Region[3][7] := 1;
Region[4][9] := 1;
Region[4][8] := 1;
Region[4][7] := 1;
Region[5][9] := 1;
Region[5][8] := 1;
Region[6][8] := 1;
Region[7][9] := 1;
Region[7][8] := 1;
Region[7][7] := 1;
Region[3][6] := 1;
Region[4][6] := 1;
Region[5][6] := 1;
Region[4][5] := 1;
Region[5][5] := 1;
Region[4][4] := 1;
Region[4][3] := 1;
// create the edge
CreateEdgeOfParticle (1,Region,EdgePixels, anchorx, anchory);
// calculate the edge polygon
CalcEdgePath (EdgePixels, AnchorX, AnchorY, EdgePath);
// display the results
ChartBook.Reset;
ChartBook.TabCaption[PAGE] := 'Edge';
ChartBook.Configure
(PAGE, // page 1
true, true, false, // only chart and table are visible
250, 250); // default width & height
ChartBook.TabCaption[PAGE] := 'Cross Section';
with ChartBook.Charts[PAGE] do
begin
Reset;
DataColor := clBlack; // indicate edge pixels
for i:=1 to length(Region) do
for j:=1 to length(Region[0]) do
if Region[i-1][j-1] = 0
then MarkAt (i-1, j-1, 0)
else MarkAt (i-1, j-1,26);
DataColor := clRed; // draw polygon
MoveTo (EdgePath[0].x,EdgePath[0].y);
for i:=1 to length(EdgePath) do
DrawTo (EdgePath[i-1].x,EdgePath[i-1].y);
AutoRange (1,4);
Update;
end;
with ChartBook.Tables[PAGE] do
begin // list the polygon
SuppressPaint := true;
Clear;
NrOfRows := length(EdgePath);
Header[1] := 'X';
Header[2] := 'Y';
for i:=1 to length(EdgePath) do
begin
Elem [1,i] := strff(EdgePath[i-1].x,1,2);
Elem [2,i] := strff(EdgePath[i-1].y,1,2);
end;
SuppressPaint := false;
end;
end.
|