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