Overview
Comment:Initial revision
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: 9395f7dc2de4570b249562259a3406d99c8dc5526443bf8fcbe918ab6e42a9ac
User & Date: gawthrop@users.sourceforge.net on 1996-08-04 18:30:14
Other Links: branch diff | manifest | tags
Context
1996-08-04
18:37:57
Fixed no causal strokes bug. check-in: 00f3f1f154 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
18:30:14
Initial revision check-in: 9395f7dc2d user: gawthrop@users.sourceforge.net tags: origin/master, trunk
17:55:55
Initial revision check-in: 92c9933aa2 user: gawthrop@users.sourceforge.net tags: origin/master, trunk
Changes

Added mttroot/mtt/bin/trans/m/rbg2abg.m version [a9cedb476c].





















































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function [bonds,components] = rbg2abg(rbonds,rstrokes,rcomponents,rports,infofile)

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% Version control history
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% $Id$
% %% $Log$
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


if nargin<5
  infofile='stdout';
end;

% Xfig scaling factor
scale = 1200.0;

%Rotation matrix
rot = [0 -1; 1 0];

% Find number of strokes
[n_strokes,columns] = size(rstrokes);
if (columns ~= 4)&(n_strokes>0)
  error('Incorrect rstrokes matrix: must have 4 columns');
end;

% Find number of bonds
[n_bonds,columns] = size(rbonds);
if (columns ~= 6)&(n_bonds>0)
  error('Incorrect rbonds matrix: must have 6 columns');
end;

% Find number of components
[n_components,columns] = size(rcomponents);

% Find number of ports
[n_ports,columns] = size(rports);

% Determine coordinates of the arrow end of the bond and the other end
other_end_1 = rbonds(:,1:2);
arrow_end = rbonds(:,3:4);
other_end_2 = rbonds(:,5:6);

distance_1 = length2d(other_end_1 - arrow_end);
distance_2 = length2d(other_end_2 - arrow_end);
which_end = (distance_1>distance_2)*[1 1];
one = ones(size(which_end));
other_end = which_end.*other_end_1 + (one-which_end).*other_end_2;
arrow_vector = ( which_end.*other_end_2 + (one-which_end).*other_end_1 ) - ...
    arrow_end;
 
% Locate the bond end nearest to each port
for i = 1:n_ports
  near_bond = adjbond(rports(i,1:2),arrow_end,other_end);
  port_near_bond(i,:) = [near_bond, rports(i,3)];
end;

% Locate the components at the ends of each bond
for i = 1:n_bonds
  comp_near_bond(i,:) = adjcomp(arrow_end(i,:),other_end(i,:),rcomponents);
end;

% Produce a list of bonds on each component - sorted if explicit port numbers
for i = 1:n_components
  [index,n] = getindex(comp_near_bond,i);

  if index(1,1) ~= 0 % Then its a genuine component 
    one = ones(n,1);
    bond_list = index(:,1);
    
    % Default sort of bonds (ie no change)
    sort_index = [1:n]'; 
    
    if n_ports>0
      % Are the component ports numbered? (either they all are or none are)
      k=0;
      for j = 1:n
	[port_index,m] = getindex(port_near_bond(:,1),bond_list(j));
	if m==1 % exactly one number on this bond
	  if index(j,2)==port_near_bond(port_index,2) % same end
	    k=k+1;
	    port_number(k,1) = port_near_bond(port_index,3);
	  end;
	end;
      end;
      
      % Must have a lable for each port or non at all
      if k==n
	[junk,sort_index]=sort(port_number);
      elseif k~=0
	info = sprintf(... 
	    'Component at (%1.3f,%1.3f) has inconsistent port numbers', ...
	    rcomponents(i,1)/scale, rcomponents(i,2)/scale);
	mtt_info(info,infofile);
      end;
    end;
  end;

  % direction is 1 if arrow at component else -1
  direction = -sign(index(:,2)-1.5*one);
  signed_bond_list = bond_list.*direction;
  
  % Write out bond list sorted by port number (if any)
  for j = 1:length(sort_index)
    jj = sort_index(j);
    components(i,j) = signed_bond_list(jj);
  end;
end;

% Find out location of centre and ends of stroke.
if n_strokes>0
  causality = zeros(n_bonds,2);
  stroke_end_1 = [rstrokes(:,1) rstrokes(:,2)];
  stroke_end_2 = [rstrokes(:,3) rstrokes(:,4)];
  
  stroke_centre = (stroke_end_1 + stroke_end_2)/2;
  stroke_vector = (stroke_end_1 - stroke_end_2);
  stroke_length = length2d(stroke_vector);
end;

% Deduce bond causality from the strokes 
for i = 1:n_strokes
  stroke = [stroke_centre(i,:)
    stroke_end_1(i,:)
    stroke_end_2(i,:)];


  % Find the nearest bond end.
  [index,distance] = adjbond(stroke(1,:),arrow_end,other_end);
  if (distance>2*stroke_length(i))
    info = sprintf('Stroke at (%4.3f,%4.3f) is %4.3f away from the nearest bond\n', ...
	stroke(1,1)/scale, stroke(1,2)/scale, distance/scale);
  end;
  
  % Bond end coordinates
  j = index(1,1);
  which_end = index(1,2)==1;
  bond_end = arrow_end(j,:)*which_end + other_end(j,:)*(1-which_end);
  
  % Now decide which bit of the stroke is nearest
  stroke_index = adjbond(bond_end,stroke,zeros(size(stroke)));
  
  if stroke_index(1)==1 % uni-causal stroke
    causality(j,1:2) = (2*which_end-1)*[1 1];
  else % bicausal stroke
    % Find out whether stroke is on flow side of bond
    stroke_direction = stroke(1,:) - stroke(stroke_index(1),:);
    flow_side = stroke_direction*arrow_vector(j,:)'>0;
    causality(j,1+flow_side) = 2*which_end-1;
  end;
  
end;

bonds = causality;


MTT: Model Transformation Tools
GitHub | SourceHut | Sourceforge | Fossil RSS ]