%plot the room from top in the figure
% code to set the axis whenever user loads a room
%get wall coordinates
wall_coor = room_stuff{2}/100;
wall_coor(:, 2) = wall_coor(:, 2)*-1;
wall_coor(size(wall_coor, 1)+1, :) = wall_coor(1, :);
wall_coor_x = wall_coor(1:size(wall_coor, 1), 1);
wall_coor_z = wall_coor(1:size(wall_coor, 1), 2)*-1;
ceil_coor = room_stuff{4}/100;
ceil_coor = ceil_coor(1);
floor_coor = room_stuff{5}/100;
floor_coor = floor_coor(1);
% set the axis - labels correctly for each of the three graphs
minx = min(wall_coor(:, 1));
maxx = max(wall_coor(:, 1));
minz = min(wall_coor(:, 2));
maxz = max(wall_coor(:, 2));
intx = 1;
while (maxx-minx)/intx>=10
intx=intx*2;
end
while (maxx-minx)/intx<5
intx=intx/2;
end
intz = 1;
while (maxz-minz)/intz>=10
intz=intz*2;
end
while (maxz-minz)/intz<5
intz=intz/2;
end
% get the source and mic coordinates and put the together
% x-y-z-type(0=src)-sel(0=not, 1=yes)-ord(for sources it shows the place in the src sorting, for mics its all 0)
src = room_stuff{6}/100;
mic = room_stuff{7}/100;
az = room_stuff{8};
el = room_stuff{9};
s = size(src, 1);
m = size(mic, 1);
list = zeros(s+m, 6);
selsrc = get(handles.src_list, 'value');
selmic = get(handles.mic_list, 'value');
list(1:s, 1:3) = src;
list(s+1:s+m, 1:3) = mic;
list(1:s, 4) = zeros(s, 1);
list(s+1:s+m, 4) = ones(m, 1);
list(selsrc, 5) = list(selsrc, 5)+1;
list(s+selmic, 5) = list(s+selmic, 5)+1;
list(1:s, 6) = [1:s];
% now first plot the room overview
axes(handles.main_axes)
fig_axis = axis(handles.main_axes);
xtck = get(handles.main_axes, 'xtick');
ytck = get(handles.main_axes, 'ytick');
ytcklbl = get(handles.main_axes, 'yticklabel');
selvert = get(handles.wallVertex, 'value');
for i=1:length(selvert)
if selvert(i)<size(wall_coor, 1)
plot(wall_coor(selvert(i), 1), wall_coor(selvert(i), 2), 'cs ', 'MarkerEdgeColor', 'c', 'MarkerFaceColor', 'c', 'Markersize', 15);
end
hold on
end
hold on
selwall = get(handles.wall_id_label, 'value');
plot(wall_coor(:, 1), wall_coor(:, 2), '--');
for i=1:length(selwall)
if selwall(i)<size(wall_coor, 1)
plot(wall_coor(selwall(i):selwall(i)+1, 1), wall_coor(selwall(i):selwall(i)+1, 2), 'b-', 'linewidth', 4');
end
end
% add the mics and the source
[dum, order] = sort(list(:, 2));
list = list(order, :);
b_type=1; b_sel=1;
src_ind = find(list(:, 4)==0);
sel = find(list(:, 5)==1);
plot_list = zeros(length(order), 1);
for i=1:length(order)
if length(find(src_ind==i))
if length(find(sel==i))==1
plot_list(i)=1;
else
plot_list(i)=2;
end
else
if length(find(sel==i))
plot_list(i)=3;
else
plot_list(i)=4;
end
end
end
b=1; e=1; i=0;
plot_type = zeros(1, 3);
while e<length(order)
e=e+1;
if plot_list(e)~=plot_list(b);
i=i+1;
plot_type(i, 1:3) = [b e-1 plot_list(b)];
b=e;
end
end
if size(plot_type, 1)<length(order)
next = plot_type(size(plot_type, 1), 2);
plot_type(size(plot_type, 1)+1, :) = [plot_type(size(plot_type, 1), 2)+1 length(order) plot_list(length(order))];
end
si = size(plot_type, 1)
for i=1:si
b = plot_type(i, 1);
e = plot_type(i, 2);
if plot_type(i, 3)==1
plot(list(b:e, 1), -list(b:e, 3), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',20)
for j=b:e
dumx(1) = list(j, 1);
dumx(2) = list(j, 1)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*cos(az{list(j, 6)}*pi/180);
dumz(1) = -list(j, 3);
dumz(2) = -list(j, 3)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*sin(az{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==2
plot(list(b:e, 1), -list(b:e, 3), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',10)
for j=b:e
dumx(1) = list(j, 1);
dumx(2) = list(j, 1)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*cos(az{list(j, 6)}*pi/180);
dumz(1) = -list(j, 3);
dumz(2) = -list(j, 3)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*sin(az{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==3
plot(list(b:e, 1), -list(b:e, 3), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10)
else
plot(list(b:e, 1), -list(b:e, 3), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5)
end
end
fig_axis = [minx-intx/5 maxx+intx/5 minz-intz/5 maxz+intz/5];
axis(fig_axis);
xtck = floor(minx-intx/5):intx:ceil(maxx+intx/5);
ytck = floor(minz-intz/5):intz:ceil(maxz+intz/5);
set(gca, 'xtick', xtck);
set(gca, 'ytick', ytck);
dum = floor(minz-intz/5):intz:ceil(maxz+intz/5);
for i=1:length(dum)
dummy{i} = num2str(-1*dum(i));
end
set(gca, 'yticklabel', dummy);
hold off
title('Room Overview from Top')
xlabel('x-axis - meters')
ylabel('z-axis - meters')
%plot the room at xy axis
axes(handles.xy_axes);
fig_axis = axis(handles.xy_axes);
xtck = get(handles.xy_axes, 'xtick');
ytck = get(handles.xy_axes, 'ytick');
mi = min(wall_coor_x);
ma = max(wall_coor_x);
plot([mi ma], [ceil_coor, ceil_coor], '--');
hold on
plot([mi ma], [floor_coor, floor_coor], '--');
for i=1:length(wall_coor_x)-1
plot([wall_coor_x(i) wall_coor_x(i)], [floor_coor ceil_coor], '--');
end
for i=1:length(selwall)
if selwall(i)<length(wall_coor_x)
plot([wall_coor_x(selwall(i)), wall_coor_x(selwall(i))], [floor_coor ceil_coor], 'b-', 'linewidth', 4');
plot([wall_coor_x(selwall(i)+1), wall_coor_x(selwall(i)+1)], [floor_coor ceil_coor], 'b-', 'linewidth', 4');
plot([wall_coor_x(selwall(i)), wall_coor_x(selwall(i)+1)], [floor_coor floor_coor], 'b-', 'linewidth', 4');
plot([wall_coor_x(selwall(i)), wall_coor_x(selwall(i)+1)], [ceil_coor ceil_coor], 'b-', 'linewidth', 4');
elseif selwall(i)==length(wall_coor_x) %means that ceiling is chosen
plot([mi ma], [ceil_coor, ceil_coor], 'b-', 'linewidth', 4');
else %the only alternative left is that floor is chosen
plot([mi ma], [floor_coor, floor_coor], 'b-', 'linewidth', 4');
end
end
% add the mics and the source
[dum, order] = sort(list(:, 3), 'descend');
list = list(order, :);
b_type=1; b_sel=1;
src_ind = find(list(:, 4)==0);
sel = find(list(:, 5)==1);
plot_list = zeros(length(order), 1);
for i=1:length(order)
if length(find(src_ind==i))
if length(find(sel==i))==1
plot_list(i)=1;
else
plot_list(i)=2;
end
else
if length(find(sel==i))
plot_list(i)=3;
else
plot_list(i)=4;
end
end
end
b=1; e=1; i=0;
plot_type = zeros(1, 3);
while e<length(order)
e=e+1;
if plot_list(e)~=plot_list(b);
i=i+1;
plot_type(i, 1:3) = [b e-1 plot_list(b)];
b=e;
end
end
if size(plot_type, 1)<length(order)
next = plot_type(size(plot_type, 1), 2);
plot_type(size(plot_type, 1)+1, :) = [plot_type(size(plot_type, 1), 2)+1 length(order) plot_list(length(order))];
end
si = size(plot_type, 1)
for i=1:si
b = plot_type(i, 1);
e = plot_type(i, 2);
if plot_type(i, 3)==1
plot(list(b:e, 1), list(b:e, 2), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',20)
for j=b:e
dumx(1) = list(j, 1);
dumx(2) = list(j, 1)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*cos(az{list(j, 6)}*pi/180);
dumz(1) = list(j, 2);
dumz(2) = list(j, 2)+min(intx, intz)*sin(el{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==2
plot(list(b:e, 1), list(b:e, 2), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',10)
for j=b:e
dumx(1) = list(j, 1);
dumx(2) = list(j, 1)+min(intx, intz)*cos(el{list(j, 6)}*pi/180)*cos(az{list(j, 6)}*pi/180);
dumz(1) = list(j, 2);
dumz(2) = list(j, 2)+min(intx, intz)*sin(el{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==3
plot(list(b:e, 1), list(b:e, 2), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10)
else
plot(list(b:e, 1), list(b:e, 2), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5)
end
end
fig_axis = [mi-intx/2 ma+intx/2 floor_coor-0.2 ceil_coor+0.2];
xtck = [mi:intx:ma];
ytck = [floor_coor ceil_coor];
axis(fig_axis);
set(gca, 'xtick', xtck);
set(gca, 'ytick', ytck);
hold off
title('Room Projected to xy plane')
xlabel('x-axis - meters')
ylabel('y-axis - meters')
%plot the room at zy axis
axes(handles.zy_axes);
fig_axis = axis(handles.zy_axes);
xtck = get(handles.zy_axes, 'xtick');
ytck = get(handles.zy_axes, 'ytick');
mi = min(wall_coor_z);
ma = max(wall_coor_z);
plot([mi ma], [ceil_coor, ceil_coor], '--');
hold on
plot([mi ma], [floor_coor, floor_coor], '--');
for i=1:length(wall_coor_z)-1
plot([wall_coor_z(i) wall_coor_z(i)], [floor_coor ceil_coor], '--');
end
for i=1:length(selwall)
if selwall(i)<length(wall_coor_z)
plot([wall_coor_z(selwall(i)), wall_coor_z(selwall(i))], [floor_coor ceil_coor], 'b-', 'linewidth', 4');
plot([wall_coor_z(selwall(i)+1), wall_coor_z(selwall(i)+1)], [floor_coor ceil_coor], 'b-', 'linewidth', 4');
plot([wall_coor_z(selwall(i)), wall_coor_z(selwall(i)+1)], [floor_coor floor_coor], 'b-', 'linewidth', 4');
plot([wall_coor_z(selwall(i)), wall_coor_z(selwall(i)+1)], [ceil_coor ceil_coor], 'b-', 'linewidth', 4');
elseif selwall(i)==length(wall_coor_z) %means that ceiling is chosen
plot([mi ma], [ceil_coor, ceil_coor], 'b-', 'linewidth', 4');
else %the only alternative left is that floor is chosen
plot([mi ma], [floor_coor, floor_coor], 'b-', 'linewidth', 4');
end
end
% add the mics and the source
[dum, order] = sort(list(:, 1), 'descend');
list = list(order, :);
b_type=1; b_sel=1;
src_ind = find(list(:, 4)==0);
sel = find(list(:, 5)==1);
plot_list = zeros(length(order), 1);
for i=1:length(order)
if length(find(src_ind==i))
if length(find(sel==i))==1
plot_list(i)=1;
else
plot_list(i)=2;
end
else
if length(find(sel==i))
plot_list(i)=3;
else
plot_list(i)=4;
end
end
end
b=1; e=1; i=0;
plot_type = zeros(1, 3);
while e<length(order)
e=e+1;
if plot_list(e)~=plot_list(b);
i=i+1;
plot_type(i, 1:3) = [b e-1 plot_list(b)];
b=e;
end
end
if size(plot_type, 1)<length(order)
next = plot_type(size(plot_type, 1), 2);
plot_type(size(plot_type, 1)+1, :) = [plot_type(size(plot_type, 1), 2)+1 length(order) plot_list(length(order))];
end
si = size(plot_type, 1)
for i=1:si
b = plot_type(i, 1);
e = plot_type(i, 2);
if plot_type(i, 3)==1
plot(list(b:e, 3), list(b:e, 2), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',20)
for j=b:e
dumx(1) = list(j, 3);
dumx(2) = list(j, 3)-min(intx, intz)*cos(el{list(j, 6)}*pi/180)*sin(az{list(j, 6)}*pi/180);
dumz(1) = list(j, 2);
dumz(2) = list(j, 2)+min(intx, intz)*sin(el{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==2
plot(list(b:e, 3), list(b:e, 2), 'rs ', 'MarkerEdgeColor','k','MarkerFaceColor','r','MarkerSize',10)
for j=b:e
dumx(1) = list(j, 3);
dumx(2) = list(j, 3)-min(intx, intz)*cos(el{list(j, 6)}*pi/180)*sin(az{list(j, 6)}*pi/180);
dumz(1) = list(j, 2);
dumz(2) = list(j, 2)+min(intx, intz)*sin(el{list(j, 6)}*pi/180);
plot(dumx, dumz, 'r');
end
elseif plot_type(i, 3)==3
plot(list(b:e, 3), list(b:e, 2), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','k','MarkerSize',10)
else
plot(list(b:e, 3), list(b:e, 2), 'gs ', 'MarkerEdgeColor','k','MarkerFaceColor','g','MarkerSize',5)
end
end
fig_axis = [mi-intz/2 ma+intz/2 floor_coor-0.2 ceil_coor+0.2];
xtck = [mi:intz:ma];
ytck = [floor_coor ceil_coor];
axis(fig_axis);
set(gca, 'xtick', xtck);
set(gca, 'ytick', ytck);
hold off
title('Room Projected to zy plane')
xlabel('z-axis - meters')
ylabel('y-axis - meters')