0001 function drawLine(node1,node2,map,edgeColor,edgeArrowColor,edgeWeight,nodeWeight,rxnDir,rxnDirMultiplier)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 if nargin < 9
0020 rxnDirMultipler = 2;
0021 end
0022
0023 if nargin < 8
0024 rxnDir = 0;
0025 end
0026
0027 if (nargin < 7)
0028 rad = 20;
0029 else
0030 index1 = find(map.molIndex(:) == node1);
0031 index2 = find(map.molIndex(:) == node2);
0032 if length(index1) == 1
0033 rad = nodeWeight(index1);
0034 elseif length(index2) == 1
0035 rad = nodeWeight(index2);
0036 else
0037 rad = 20;
0038 end
0039 end
0040
0041 if isnan(node1) || isnan(node2)
0042 return;
0043 end
0044
0045 [type1, nodePos(:,1)] = getType(node1, map);
0046 [type2, nodePos(:,2)] = getType(node2, map);
0047 p1 = nodePos(:,1);
0048 p2 = nodePos(:,2);
0049
0050 if type1 == 1 && type2 == 1
0051 drawVector(nodePos(:,1),nodePos(:,2),edgeColor,edgeWeight);
0052
0053 elseif type1 == 1 && type2 == 2
0054
0055 index1 = find(map.connection(:,1) == node2);
0056 index2 = find(map.connection(:,2) == node2);
0057 isend = 0;
0058 if map.connectionReversible(index1) == 1
0059 isend = 1;
0060 end
0061 if length(index1) == 1 && length(index2) == 1
0062 [point1,dir] = c2p(nodePos(:,1),nodePos(:,2),rad);
0063 drawVector(point1, nodePos(:,2),edgeColor,edgeWeight);
0064 if isend
0065 if rxnDir < 0, rad = rad*rxnDirMultiplier; end
0066 drawArrowhead(point1,dir,rad,edgeArrowColor);
0067 end
0068 elseif length(index1) > 1 && length(index2) == 1
0069 display('blah');
0070 elseif length(index1) == 1 && length(index2) > 1
0071 othernode = map.connection(index1,2);
0072 [t3,p3] = getType(othernode, map);
0073
0074 direction = p2-p3;
0075
0076 if any(direction~=0)
0077 dirnorm = direction/(norm(direction));
0078 else
0079 dirnorm = zeros(size(direction));
0080 end
0081 multiplier = dirnorm' * (p1-p2);
0082 multiplier = max([.3*norm(p2-p1), multiplier]);
0083 ptemp = p2 + multiplier*dirnorm;
0084 distance = norm(ptemp-p1);
0085 if distance < multiplier
0086 multiplier = mean([multiplier, distance]);
0087 end
0088 ptemp = p2 + multiplier*dirnorm;
0089
0090
0091 [p1,dir] = c2p(p1,ptemp,rad);
0092 drawBezier([p2,ptemp,p1],edgeColor,edgeWeight);
0093 if isend
0094 if rxnDir < 0, rad = rad*rxnDirMultiplier; end
0095 drawArrowhead(p1,dir,rad,edgeArrowColor)
0096 end
0097 else
0098 display('oops');
0099 end
0100
0101 elseif type1 == 2 && type2 == 1
0102
0103 index1 = find(map.connection(:,1) == node1);
0104 index2 = find(map.connection(:,2) == node1);
0105
0106
0107
0108
0109
0110 othernode = map.connection(index2,1);
0111 [t3,p3] = getType(othernode, map);
0112
0113 direction = p1-p3;
0114 if any(direction~=0)
0115 dirnorm = direction/(norm(direction));
0116 else
0117 dirnorm = zeros(size(direction));
0118 end
0119 multiplier = dirnorm' * (p2-p1);
0120 multiplier = max([ .3*norm(p2-p1), multiplier]);
0121 ptemp = p1 + multiplier*dirnorm;
0122 distance = norm(ptemp-p2);
0123 if distance < multiplier
0124 multiplier = mean([multiplier, distance]);
0125 end
0126 ptemp = p1 + multiplier*dirnorm;
0127
0128
0129 [p2,dir] = c2p(p2,ptemp,rad);
0130 drawBezier([p1,ptemp,p2],edgeColor,edgeWeight);
0131 if rxnDir > 0, rad = rad*rxnDirMultiplier; end
0132 drawArrowhead(p2,dir,rad,edgeArrowColor);
0133
0134
0135
0136
0137
0138
0139 elseif type1 ==2 && type2 == 2
0140 drawVector(nodePos(:,1),nodePos(:,2),edgeColor,edgeWeight);
0141 else
0142 display('oops');
0143 pause;
0144 end
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161
0162
0163 end
0164
0165
0166 function [type, position] = getType(node, map)
0167 molIndex = find(map.molIndex == node);
0168 rxnIndex = find(map.rxnIndex == node);
0169 if ~isempty(molIndex)
0170 type = 1;
0171 position = map.molPosition(:,molIndex);
0172 elseif ~isempty(rxnIndex)
0173 type = 2;
0174 position = map.rxnPosition(:,rxnIndex);
0175
0176 else
0177 display('errorXYZ in drawLine.m');
0178
0179 end
0180 if numel(molIndex) > 1 || numel(rxnIndex) > 1
0181 display('error2');
0182
0183 end
0184 end
0185
0186
0187 function [point,dir] = c2p(p1,p2,rad)
0188 dir = p2-p1;
0189 point = p1+rad*(dir/sqrt(dir(1)^2+dir(2)^2));
0190
0191 end
0192