File size: 3,225 Bytes
c2ea21f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
function [newBox, order, rBoundary] = align_fp(boundary, rBox, rType, rEdge, fp, threshold, drawResult)
% align the neighboring rooms first and then align with the boundary

if nargin < 7
    drawResult =false;
end

% pre-processing: 
% move the edge relation w.r.t. living room to the end
livingIdx = find(rType==0);
idx = rEdge(:,1) == livingIdx-1 | rEdge(:,2) == livingIdx-1;
% a = rEdge(~idx, :);
% b = rEdge(idx, :);
% rEdge = [a; b];
rEdge = rEdge(~idx, :);
entranceBox = get_entrance_space(boundary(1:2, 1:2), boundary(1,3), threshold);

if drawResult
    clf
    subplot(2,2,1)
    plot_fp(rBox, boundary, rType, entranceBox);
    title('original');
end

%% option #1: use greedy method: align with boundary first and then neighbor
% 1. align with boundary after the neighbors have been aligned
[~, newBox, updated] = align_with_boundary(rBox, boundary, threshold, rType);

if drawResult
    subplot(2,2,2)
    plot_fp(newBox, boundary, rType, entranceBox);
    title('Align with boundary');
end


% 2. for each adjacent pair of room,
[~, newBox, ~] = align_neighbor(newBox, rEdge, updated, threshold+6);
if drawResult
    subplot(2,2,3)
    plot_fp(newBox, boundary, rType, entranceBox);
    title('Align with neighbors');
end

% 3. regularize fp, include crop using boundary, gap filling
[newBox, order] = regularize_fp(newBox, boundary, rType);

% 4. generate the room polygons
[newBox, rBoundary] = get_room_boundary(newBox, boundary, order);
    
if drawResult
    subplot(2,2,4)
    plot_fp(newBox(order,:), boundary, rType(order), entranceBox);
    title('Regularize fp');
end

% %% option #2: use optimization to align neighbors, and then align the boundary 
% % 1. get the constraint from the adjacent rooms, and optimize
% %[constraint1, ~, ~] = align_with_boundary(rBox, boundary, threshold, rNode);
% [constraint2, ~, ~] = align_neighbor(rBox, rEdge, [], threshold+2);
% newBox = optimize_fp(rBox, [], constraint2);
% if drawResult
%     subplot(3,4,6)
%     plot_fp(newBox, boundary, rNode, entranceBox);
%     title('Optimize the neighboring');
% end
% 
% % 2. align with boundary after the neighbors have been aligned
% [constraint1, newBox2, ~] = align_with_boundary(newBox, boundary, threshold, rNode);
% if drawResult
%     subplot(3,4,7)
%     plot_fp(newBox2, boundary, rNode, entranceBox);
%     title('Align with boundary w/o optimization');
% end
% 
% % 3. regularize fp, include crop using boundary, gap filling
% [newBox2, order] = regularize_fp(newBox2, boundary, rNode);
% if drawResult
%     subplot(3,4,8)
%     plot_fp(newBox2(order,:), boundary, rNode(order,:), entranceBox);
%     title('Regularize fp');
% end
% 
% 
% 
% newBox = optimize_fp(newBox, constraint1, constraint2);
% if drawResult
%     subplot(3,4,11)
%     plot_fp(newBox, boundary, rNode, entranceBox);
%     title('Align with boundary with optimization');
% end
% 
% % 3. regularize fp, include crop using boundary, gap filling
% [newBox, order] = regularize_fp(newBox, boundary, rNode);
% if drawResult
%     subplot(3,4,12)
%     plot_fp(newBox(order,:), boundary, rNode(order,:), entranceBox);
%     title('Regularize fp');
%     if ~isempty(figName)
%         saveas(gcf, figName);
%     end
% end
% 



%%
end