% plotLightpath
%
%>> Usage: plotLightpath (nodesPlaceMatrix,edgeTable, lightpathID, lightpathRoutingMatrix, lightpathTitle)
%
%>> Abstract: This function draws a light-path over a physical topology of nodes and edges when it is done
% the positions of nodes, the matrix of edges information, the set of physical links which pertain
% to the light-path and the wavelenght used in every link of the light-path.
%
%>> Arguments:
% o In:
% nodesPlaceMatrix(Nx2): XY coordinates of nodes, where N is the number of nodes.
% They are contained in the first and second column respectively.
%
% . edgeTable(M,2): M-by-2 integer matrix. Each row is a physical link 'm',
% where the first and second columns of each row are the origin node 'x' and
% destination node 'y' of this physical link 'm' respectively and M is the
% number of physical links in the physical topology
%
% . lightpathID: Identifier of the lightpath to plot
%
% . lightpathRoutingMatrix (L,M): L-by-M integer matrix where L is the number of
% lightpaths and M is the number of physical fibre links. Each row is a
% lightpath 'l' and each column is a physical link 'm'. If a lightpath 'l'
% uses a physical link 'm' with a certain wavelength 'w', the entry (l,m) is
% equal to 'w'. If no physical link is used by the lightpath 'l', the entry
% is equal to '0'.
%
% . lightpathTitle: Title of the plot.
%
function plotLightpath (nodesPlaceMatrix, edgeTable, lightpathID, lightpathRoutingMatrix, lightpathTitle)
if (nargin==0), help plotLightpath ;return, end %help calling
if (nargin~=5), error('1: Incorrect number of arguments.'),end %Number of input arguments different of 5
if(size(nodesPlaceMatrix,2)~=2), error('2: Argument "nodePlaceMatrix" must have two columns'), end
backgroundScaleX = abs(max(nodesPlaceMatrix(:,1)) - min(nodesPlaceMatrix(:,1)));
backgroundScaleY = abs(max(nodesPlaceMatrix(:,2)) - min(nodesPlaceMatrix(:,2)));
textOffset = 0.07;
%All nodes are drawn
plot(nodesPlaceMatrix(:,1),nodesPlaceMatrix(:,2),'bo','MarkerSize',10,'Color',[1 0.4 0],'LineWidth',2.0,'MarkerFaceColor',[1 0.4 0]);
%The axis are fixed in both dimensions according to minimum and maximum values of nodesPlaceMatrix
axis([min(min(nodesPlaceMatrix(:,1)))-backgroundScaleX*0.01 max(max(nodesPlaceMatrix(:,1)))+backgroundScaleX*0.01 min(min(nodesPlaceMatrix(:,2)))-backgroundScaleY*0.01 max(max(nodesPlaceMatrix(:,2)))+backgroundScaleY*0.1],'manual','off');
%We plot the physical topology
hold off
for m=1:size(edgeTable,1),
line([nodesPlaceMatrix(edgeTable(m,1),1) nodesPlaceMatrix(edgeTable(m,2),1)],[nodesPlaceMatrix(edgeTable(m,1),2) nodesPlaceMatrix(edgeTable(m,2),2)],'color',[1 0.4 0],'lineWidth',1);
end
hold off
H=title(lightpathTitle,'FontSize',8,'Fontweight','light','FontName','Verdana');
aux=get(H,'Position');
%We plot the demanded lightpath over the physical topology
lightpathLinks=find(lightpathRoutingMatrix(lightpathID, :)>0);
for i=1:length(lightpathLinks),
arrow(line([nodesPlaceMatrix(edgeTable(lightpathLinks(i),1),1) nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),1)],[nodesPlaceMatrix(edgeTable(lightpathLinks(i),1),2) nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),2)],'color',[0 0.2 0.4],'lineWidth',2),'Length',15,'BaseAngle',90,'TipAngle',5,'Width',0,'FaceColor',[0 0.2 0.4]);
%The distances between source and destination node pair in
%both dimensions are necessary to set the label of the established
%wavelength over the edge.
distanceX=nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),1) - nodesPlaceMatrix(edgeTable(lightpathLinks(i),1),1);
distanceY=nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),2) - nodesPlaceMatrix(edgeTable(lightpathLinks(i),1),2);
colour=[0 0.2 0.4];
%The text labels are the the wavelength used in the edge.
%Text labels are set according to the relative node pairs position
textLabel=['w',num2str(lightpathRoutingMatrix(lightpathID, lightpathLinks(i)))];
distanceVector = [distanceX distanceY 0];
normalVectorToDistanceVector = cross(distanceVector/norm(distanceVector) , [0 0 1]);
text(nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),1) - distanceX/3 + textOffset*backgroundScaleX*normalVectorToDistanceVector(1) , nodesPlaceMatrix(edgeTable(lightpathLinks(i),2),2) - distanceY/3 + textOffset*backgroundScaleY*normalVectorToDistanceVector(2) , textLabel,'color',colour,'FontSize',8);
end
%At the end, text label of each node is set
for i=1:length(nodesPlaceMatrix)
text(nodesPlaceMatrix(i,1),nodesPlaceMatrix(i,2),{int2str(i)},'FontSize',6,'Color',[1 1 1],'HorizontalAlignment','Center');
end
hold off