source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/3dRecon/utils/cropLineInBox.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 1.1 KB
Line 
1function  endPnts = cropLineInBox(n, c, cropBox)
2%  endPnts = cropLineInBox(n, c, cropBox)
3% For a line defined by n(1) x(1) + n(2) x(2) + c = 0, b
4% and a box determined by cropBox = [x(1) y(1) x(2) y(2)] with
5% x(1) <= x(2), y(1) <= y(2), return
6% endPts = [x1 y1 x2 y2] where the line from x1,y1 to x2,y2
7% is the segment of the original line cropped to be within
8% crop box.  If there is no such line, then x1 is nan.
9
10if (size(n,1) == 1) n = n'; end
11%
12% Check for sign change between successive vertices.
13pts = [cropBox(1:2); cropBox(3:-1:2); cropBox(3:4); cropBox(1:3:4)];
14err = pts * n + c;
15cntPnts = 1;
16endPnts = zeros(2,2);
17for j= 1:4
18 
19  k = mod(j,4) + 1;
20  if err(j) * err(k) < 0
21    % Sign change, find endpoint
22    r = err(k)/(err(k) - err(j));
23    endPnts(cntPnts, :) = pts(j,:) * r + (1-r) * pts(k,:);
24    cntPnts = cntPnts+1;
25  elseif err(k) == 0 % Be careful to find zeroes at corners just once.
26    endPnts(cntPnts, :) = pts(k,:);
27    cntPnts = cntPnts+1;
28  end
29  if cntPnts == 3
30    break;
31  end
32end
33
34if (cntPnts ~= 3)
35  endPnts = endPnts * NaN;
36end
37
38return;
39
Note: See TracBrowser for help on using the repository browser.