source: issm/oecreview/Archive/16133-16554/ISSM-16516-16517.diff@ 16556

Last change on this file since 16556 was 16556, checked in by Mathieu Morlighem, 11 years ago

NEW: added Archive/16133-16554

File size: 6.4 KB
RevLine 
[16556]1Index: ../trunk-jpl/src/m/exp/expcontourlevelzero.m
2===================================================================
3--- ../trunk-jpl/src/m/exp/expcontourlevelzero.m (revision 0)
4+++ ../trunk-jpl/src/m/exp/expcontourlevelzero.m (revision 16517)
5@@ -0,0 +1,13 @@
6+function expcontourlevelzero(md,mask,level,filename)
7+%EXPCONTOURLEVELZERO - write an Argus file from a structure recovered from running contourlevelzero
8+%
9+% Usage:
10+% expcontourlevelzero(md,mask,level,filename)
11+%
12+% Example:
13+% expcontourlevelzero(md,md.geometry.thickness,0, 'Level0.exp');
14+%
15+% See also CONTOURLEVELZERO, EXPWRITE
16+
17+contours=contourlevelzero(md,mask,level);
18+expwrite(contours,filename);
19Index: ../trunk-jpl/src/m/exp/contourlevelzero.m
20===================================================================
21--- ../trunk-jpl/src/m/exp/contourlevelzero.m (revision 0)
22+++ ../trunk-jpl/src/m/exp/contourlevelzero.m (revision 16517)
23@@ -0,0 +1,199 @@
24+function contours=contourlevelzero(md,mask,level)
25+%CONTOURLEVELZERO - figure out the zero level (or offset thereof, specified by the level value)
26+% of a vectorial mask, and vectorialize it into an exp or shp compatible
27+%structure.
28+%
29+% Usage:
30+% contours=contourlevelzero(md,mask,level)
31+%
32+% See also: PLOT_CONTOUR
33+
34+%process data
35+if md.mesh.dimension==3,
36+ error('contourlevelzero error message: routine not supported for 3d meshes, project on a layer');
37+end
38+
39+x=md.mesh.x;
40+y=md.mesh.y;
41+index=md.mesh.elements;
42+
43+if isempty(mask), error('mask provided is empty'); end
44+ if length(mask)~=md.mesh.numberofvertices, error('mask provided should be specified at the vertices of the mesh'); end
45+
46+%initialization of some variables
47+numberofelements=size(index,1);
48+elementslist=1:numberofelements;
49+c=[];
50+h=[];
51+
52+%get unique edges in mesh
53+%1: list of edges
54+edges=[index(:,[1,2]); index(:,[2,3]); index(:,[3,1])];
55+%2: find unique edges
56+[edges,I,J]=unique(sort(edges,2),'rows');
57+%3: unique edge numbers
58+vec=J;
59+%4: unique edges numbers in each triangle (2 triangles sharing the same edge will have
60+% the same edge number)
61+edges_tria=[vec(elementslist), vec(elementslist+numberofelements), vec(elementslist+2*numberofelements)];
62+
63+%segments [nodes1 nodes2]
64+Seg1=index(:,[1 2]);
65+Seg2=index(:,[2 3]);
66+Seg3=index(:,[3 1]);
67+
68+%segment numbers [1;4;6;...]
69+Seg1_num=edges_tria(:,1);
70+Seg2_num=edges_tria(:,2);
71+Seg3_num=edges_tria(:,3);
72+
73+%value of data on each tips of the segments
74+Data1=mask(Seg1);
75+Data2=mask(Seg2);
76+Data3=mask(Seg3);
77+
78+%get the ranges for each segment
79+Range1=sort(Data1,2);
80+Range2=sort(Data2,2);
81+Range3=sort(Data3,2);
82+
83+%find the segments that contain this value
84+pos1=(Range1(:,1)<level & Range1(:,2)>level);
85+pos2=(Range2(:,1)<level & Range2(:,2)>level);
86+pos3=(Range3(:,1)<level & Range3(:,2)>level);
87+
88+%get elements
89+poselem12=(pos1 & pos2);
90+poselem13=(pos1 & pos3);
91+poselem23=(pos2 & pos3);
92+poselem=find(poselem12 | poselem13 | poselem23);
93+numelems=length(poselem);
94+
95+%if no element has been flagged, skip to the next level
96+if numelems==0,
97+ warning('contourlevelzero warning message: no elements found with corresponding level value in mask');
98+ contours=struct([]);
99+ return;
100+end
101+
102+%go through the elements and build the coordinates for each segment (1 by element)
103+x1=zeros(numelems,1);
104+x2=zeros(numelems,1);
105+y1=zeros(numelems,1);
106+y2=zeros(numelems,1);
107+edge_l=zeros(numelems,2);
108+
109+for j=1:numelems,
110+
111+ weight1=(level-Data1(poselem(j),1))/(Data1(poselem(j),2)-Data1(poselem(j),1));
112+ weight2=(level-Data2(poselem(j),1))/(Data2(poselem(j),2)-Data2(poselem(j),1));
113+ weight3=(level-Data3(poselem(j),1))/(Data3(poselem(j),2)-Data3(poselem(j),1));
114+
115+ if poselem12(poselem(j));
116+
117+ x1(j)=x(Seg1(poselem(j),1))+weight1*(x(Seg1(poselem(j),2))-x(Seg1(poselem(j),1)));
118+ x2(j)=x(Seg2(poselem(j),1))+weight2*(x(Seg2(poselem(j),2))-x(Seg2(poselem(j),1)));
119+ y1(j)=y(Seg1(poselem(j),1))+weight1*(y(Seg1(poselem(j),2))-y(Seg1(poselem(j),1)));
120+ y2(j)=y(Seg2(poselem(j),1))+weight2*(y(Seg2(poselem(j),2))-y(Seg2(poselem(j),1)));
121+ edge_l(j,1)=Seg1_num(poselem(j));
122+ edge_l(j,2)=Seg2_num(poselem(j));
123+
124+ elseif poselem13(poselem(j)),
125+
126+ x1(j)=x(Seg1(poselem(j),1))+weight1*(x(Seg1(poselem(j),2))-x(Seg1(poselem(j),1)));
127+ x2(j)=x(Seg3(poselem(j),1))+weight3*(x(Seg3(poselem(j),2))-x(Seg3(poselem(j),1)));
128+ y1(j)=y(Seg1(poselem(j),1))+weight1*(y(Seg1(poselem(j),2))-y(Seg1(poselem(j),1)));
129+ y2(j)=y(Seg3(poselem(j),1))+weight3*(y(Seg3(poselem(j),2))-y(Seg3(poselem(j),1)));
130+ edge_l(j,1)=Seg1_num(poselem(j));
131+ edge_l(j,2)=Seg3_num(poselem(j));
132+
133+ elseif poselem23(poselem(j)),
134+
135+ x1(j)=x(Seg2(poselem(j),1))+weight2*(x(Seg2(poselem(j),2))-x(Seg2(poselem(j),1)));
136+ x2(j)=x(Seg3(poselem(j),1))+weight3*(x(Seg3(poselem(j),2))-x(Seg3(poselem(j),1)));
137+ y1(j)=y(Seg2(poselem(j),1))+weight2*(y(Seg2(poselem(j),2))-y(Seg2(poselem(j),1)));
138+ y2(j)=y(Seg3(poselem(j),1))+weight3*(y(Seg3(poselem(j),2))-y(Seg3(poselem(j),1)));
139+ edge_l(j,1)=Seg2_num(poselem(j));
140+ edge_l(j,2)=Seg3_num(poselem(j));
141+ else
142+ %it shoud not go here
143+ end
144+end
145+
146+%now that we have the segments, we must try to connect them...
147+
148+%loop over the subcontours
149+contours=struct([]);
150+
151+while ~isempty(edge_l),
152+
153+ %take the right edge of the second segment and connect it to the next segments if any
154+ e1=edge_l(1,1); e2=edge_l(1,2);
155+ xc=[x1(1);x2(1)]; yc=[y1(1);y2(1)];
156+
157+ %erase the lines corresponding to this edge
158+ edge_l(1,:)=[];
159+ x1(1)=[]; x2(1)=[];
160+ y1(1)=[]; y2(1)=[];
161+
162+ [ro1,co1]=find(edge_l==e1);
163+
164+ while ~isempty(ro1)
165+
166+ if co1==1,
167+ xc=[x2(ro1);xc]; yc=[y2(ro1);yc];
168+
169+ %next edge:
170+ e1=edge_l(ro1,2);
171+
172+ else
173+ xc=[x1(ro1);xc]; yc=[y1(ro1);yc];
174+
175+ %next edge:
176+ e1=edge_l(ro1,1);
177+ end
178+
179+ %erase the lines of this
180+ edge_l(ro1,:)=[];
181+ x1(ro1)=[]; x2(ro1)=[];
182+ y1(ro1)=[]; y2(ro1)=[];
183+
184+ %next connection
185+ [ro1,co1]=find(edge_l==e1);
186+ end
187+
188+ %same thing the other way (to the right)
189+ [ro2,co2]=find(edge_l==e2);
190+
191+ while ~isempty(ro2)
192+
193+ if co2==1,
194+ xc=[xc;x2(ro2)]; yc=[yc;y2(ro2)];
195+
196+ %next edge:
197+ e2=edge_l(ro2,2);
198+ else
199+ xc=[xc;x1(ro2)]; yc=[yc;y1(ro2)];
200+
201+ %next edge:
202+ e2=edge_l(ro2,1);
203+ end
204+
205+ %erase the lines of this
206+ edge_l(ro2,:)=[];
207+ x1(ro2)=[]; x2(ro2)=[];
208+ y1(ro2)=[]; y2(ro2)=[];
209+
210+ %next connection
211+ [ro2,co2]=find(edge_l==e2);
212+ end
213+
214+ %save xc,yc contour:
215+ contours(end+1).x=xc;
216+ contours(end).y=yc;
217+ contours(end).name='';
218+ contours(end).nods=length(xc);
219+ contours(end).density=1;
220+ contours(end).closed=0;
221+
222+end
Note: See TracBrowser for help on using the repository browser.