-
Notifications
You must be signed in to change notification settings - Fork 0
/
igraph_init.m
62 lines (50 loc) · 2.18 KB
/
igraph_init.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
52
53
54
55
56
57
58
59
60
61
62
function [igraph, ugraph] = igraph_init(ugraph, world)
%% Constructs a directed information graph from a visibility graph
%Robustness constant
epsilon = 0.00000000001;
%Snap distance (distance within which an observer location will be snapped to the
%boundary before the visibility polygon is computed)
snap_distance = 0.0001;
igraph = struct('x', [], 'b', [], 'gv', [], 'i', []);
igraph(1) = [];
%% first loop: initialize information graph
intPoints = findInteriorPoints(world);
for g = 1:numel(ugraph)
%Obtain the visibility polygon for current graph node
vp = visibility_polygon( [ugraph(g).x(1) ugraph(g).x(2)] , {world.vertices} , epsilon , snap_distance );
% h = patch( vp(:,1) , vp(:,2) , 0.1*ones( size(vp,1) , 1 ) , ...
% 'r' , 'linewidth' , 1.5, 'FaceColor' , [.65 1 .65], 'faceAlpha', .5);
%Get edges from visibility polygon
vpEdges = makeEdges(vp);
% vpEdges{:}
%Determine which edges are gap edges and count them
gapEdges = findGapEdges(vpEdges, ugraph(g).x, world);
nGaps = numel(gapEdges);
% gapEdges{:}
%Create a node in the information graph for every possible combination
%of gap edges, b vector
idx = numel(igraph)+1:numel(igraph)+2^nGaps;
[igraph(idx).x] = deal(ugraph(g).x);
ugraph(g).ii = idx;
%Put gap edges in graph
ugraph(g).gapEdges = gapEdges;
%Make cell array of all possble b vectors containing contamination of
%edge specified by igraph.gv
bCell = num2bin_vector(nGaps);
[igraph(idx).b] = deal(bCell{:});
%Assign the gap vertices that correspond to the gap edges. Each gap
%edge has one unique endpoint that is an interior corner of the
%environment. This is so the edges dont have to be parsed each time we
%check the transitions between conservative regions. gv is a matrix of
%points.
gv = findGapVertices(gapEdges, intPoints);
[igraph(idx).gv] = deal(gv);
ugraph(g).gv = gv;
%Attach the index of the visibility graph to each superimposed node of
%the information graph for reference
[igraph(idx).i] = deal(g);
%
% pause(1)
% delete(h)
end
end