-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsplitBoxEdges.m
56 lines (45 loc) · 1.27 KB
/
splitBoxEdges.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
function [ edges ] = splitBoxEdges( boxEdges,interSects )
%FUNCTIONS
% addEdgeBox: get box edges w.r.t intersction points
% duplicateEdgeRemove (center point based apporoach)
c=reshape(boxEdges,[size(boxEdges,1)*2,2]);
cc=unique(c,'rows');
edges=[];
newEdge=addEdgeBox(boxEdges,[interSects;cc]);
edges=[edges;newEdge];
edges=duplicateEdgeRemove(1, edges);
% visulization.drawEdgeSet(edges);
end
function edges=addEdgeBox(box,points)
% find the points for each BoxEdge
mat=isPointOnEdge(points, box);
edges=[];
for i=1:size(box,1)
col=mat(:,i);
inds=find(col==1);
% Edges:--> all combination indices
C=combnk(inds,2);
for iNe=C'
edges=[edges;[points(iNe(1),:),points(iNe(2),:)]];
end
end
end
function edgeSet=duplicateEdgeRemove(count, edgeSet)
% find the center of each edge
% get the matrix of isPointOnEdge
% If a point can be found more than one, remove it.
edge=edgeSet(count,:);
[p1,p2]=edge2point(edge);
n=size(edgeSet,1);
center=(p1+p2)./2;
mat=isPointOnEdge(center, edgeSet);
index=find(mat==1);
if(length(index)>1)
len = edgeLength(edgeSet(index,:));
[val,inc]=max(len);
edgeSet(index(inc),:)=[];
end
if(count<n-1)
edgeSet=duplicateEdgeRemove(count+1, edgeSet);
end
end