Advertisement
Janilabo

sc

Dec 23rd, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 2.95 KB | None | 0 0
  1. {$loadlib pumbaa.dll}
  2.  
  3. procedure pp_TPAControlSegment(var TPA: TPointArray; kind: TControlKind; segment: TPointArray; accuracy: Extended);
  4. var
  5.   w, h, k, l, i, j, x, y, v, c, t, n: Integer;
  6.   o: TPoint;
  7.   b, s, g: TBox;
  8.   m, q: T2DBoolArray;
  9.   f, p: TPointArray;
  10.   z: TBoxArray;
  11.   a: Extended;
  12. begin
  13.   t := 0;
  14.   k := High(TPA);
  15.   l := High(segment);
  16.   if ((k > -1) and (l > -1) and (accuracy > 0) and not (accuracy > 100)) then
  17.   begin
  18.     s := pp_TPABounds(segment);
  19.     b := pp_TPABounds(TPA);
  20.     w := (b.X2 - b.X1);
  21.     h := (b.Y2 - b.Y1);
  22.     g := b;
  23.     pp_BoxStretch(g, (s.X2 - s.X1), smRight);
  24.     pp_BoxStretch(g, (s.Y2 - s.Y1), smDown);
  25.     z := pp_BoxPositions(s, g);
  26.     v := High(z);
  27.     if (v > -1) then
  28.     begin
  29.       n := Ceil(pp_Percentage((accuracy * 100), (l + 1)));
  30.       WriteLn('N: ' + IntToStr(n));
  31.       p := pp_Clone(segment);
  32.       o := pp_GetOffset(Point(s.X1, s.Y1), Point(0, 0));
  33.       pp_TPAOffset(p, o);
  34.       o := pp_GetOffset(Point(z[0].X1, z[0].Y1), Point(0, 0));
  35.       pp_TBAOffset(z, o);
  36.       m := pp_Create(False, ((b.X2 - b.X1) + 1), ((b.Y2 - b.Y1) + 1));
  37.       for i := 0 to k do
  38.         m[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] := True;
  39.       SetLength(f, (l + 1));
  40.       q := pp_Create(False, ((b.X2 - b.X1) + 1), ((b.Y2 - b.Y1) + 1));
  41.       for i := 0 to v do
  42.       begin
  43.         c := 0;
  44.         for j := 0 to l do
  45.         begin
  46.           x := (p[j].X + z[i].X1);
  47.           y := (p[j].Y + z[i].Y1);
  48.           if ((x < w) and (y < h)) then
  49.             if m[x][y] then
  50.             begin
  51.               f[c].X := x;
  52.               f[c].Y := y;
  53.               c := (c + 1);
  54.             end;
  55.         end;
  56.         if not (c < n) then
  57.         begin
  58.           c := (c - 1);
  59.           for j := 0 to c do
  60.             q[f[j].X][f[j].Y] := True;
  61.         end;
  62.       end;
  63.       case kind of
  64.         ckExtract:
  65.         for i := 0 to k do
  66.           if q[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] then
  67.           begin
  68.             TPA[t] := TPA[i];
  69.             t := (t + 1);
  70.           end;
  71.         ckFilter:
  72.         for i := 0 to k do
  73.           if not q[(TPA[i].X - b.X1)][(TPA[i].Y - b.Y1)] then
  74.           begin
  75.             TPA[t] := TPA[i];
  76.             t := (t + 1);
  77.           end;
  78.       end;
  79.     end;
  80.   end;
  81.   SetLength(TPA, t);
  82. end;
  83.  
  84. procedure DebugBitmap(bmp: Integer);
  85. var
  86.   w, h: Integer;
  87. begin
  88.   GetBitmapSize(bmp, w, h);
  89.   DisplayDebugImgWindow(w, h);
  90.   DrawBitmapDebugImg(bmp);
  91. end;
  92.  
  93. var
  94.   segment, TPA: TPointArray;
  95.   b: TBox;
  96.   o: TPoint;
  97.   bmp, w, h: Integer;
  98.  
  99. begin
  100.   segment := [Point(5, 2), Point(5, 2), Point(1, 6), Point(4, 3), Point(4, 1)];
  101.   TPA := pp_TPAFromBox(IntToBox(10, 10, 20, 20));
  102.   b := pp_TPABounds(TPA);
  103.   pp_TPADimensions(TPA, w, h);
  104.   pp_TPAControlSegment(TPA, ckExtract, segment, 0.9);
  105.   bmp := CreateBitmap((w + (b.X1 * 2)), (h + (b.Y1 * 2)));
  106.   DrawTPABitmap(bmp, TPA, 255);
  107.   DrawTPABitmap(bmp, segment, 16777215);
  108.   DebugBitmap(bmp);
  109.   FreeBitmap(bmp);
  110. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement