|
27 | 27 |
|
28 | 28 | pointSpacing=4; |
29 | 29 | cutHeight=810; |
| 30 | +cutHeight1=860; |
30 | 31 | saveOn=1; |
31 | 32 |
|
32 | 33 |
|
33 | | -Select_layer='outer_muscles_surface';%'outer_skin_surface';'outer_muscles_surface' |
34 | | -switch Select_layer |
| 34 | +Select_layer='outer_skin_surface';%'outer_skin_surface';'outer_muscles_surface' |
| 35 | +switch Select_layer |
35 | 36 | case 'outer_skin_surface' |
36 | 37 | %% Original |
37 | 38 | fileName_mat=fullfile(loadFolder,[fileName_FMA,'.mat']); |
|
54 | 55 | axisGeom; |
55 | 56 | camlight headlight; |
56 | 57 | drawnow; |
| 58 | + |
57 | 59 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
58 | 60 | %% Cut again preserving only right leg |
59 | 61 | optionStruct.outputType='label'; |
|
62 | 64 | logicKeep=G==indMax; |
63 | 65 | Fs=Fs(logicKeep,:); |
64 | 66 | [Fs,Vs]=patchCleanUnused(Fs,Vs); |
65 | | - |
| 67 | + |
66 | 68 | cFigure; hold on; |
67 | 69 | gpatch(Fs,Vs,'w','none',0.25); |
68 | 70 | axis off; |
69 | 71 | axisGeom; |
70 | 72 | camlight headlight; |
71 | 73 | drawnow; |
72 | | - |
| 74 | + |
73 | 75 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
74 | 76 | %% Slice the surface of the right leg at cutHeight |
75 | 77 | %% to detect all edges to form the list of curves within the slice |
|
100 | 102 | VTc=Vc(indCurveNow,:); |
101 | 103 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
102 | 104 | %% Forming the 2D convex hull around the curve |
103 | | - [V_slice_curve]=convexhull_curve(VTc,200); |
| 105 | + [VT0]=convexhull_curve(VTc,200); |
104 | 106 | [Fc,Vc]=patchCleanUnused(Fc(logicSide,:),Vc); |
105 | 107 |
|
| 108 | + VT0(:,3)=VT0(:,3)+25; |
106 | 109 | cFigure; hold on; |
107 | 110 | gpatch(Fc,Vc,'w','none',0.25); |
108 | | - plotV(V_slice_curve,'k-','LineWidth',4); |
| 111 | + plotV(VT0,'k-','LineWidth',4); |
109 | 112 | axis off; |
110 | 113 | axisGeom; |
111 | 114 | camlight headlight; |
|
116 | 119 | %Set-up orientation and location of cutting plane |
117 | 120 | snapTolerance=mean(patchEdgeLengths(Fc,Vc))/100; %Tolerance for surface slicing |
118 | 121 | n=vecnormalize([0 0 1]); %Normal direction to plane |
119 | | - Q1=euler2DCM([0.4*pi 0 0.8*pi]); |
120 | | - |
| 122 | + Q1=euler2DCM([0.38*pi 0 0.8*pi]); |
| 123 | + |
121 | 124 | n=n*Q1; |
122 | 125 | P_cut=[0 0 0]+n*306; %Point on plane |
123 | 126 | %Slicing surface |
124 | 127 | [Fd,Vd,Cd,logicSide,Ed]=triSurfSlice(Fc,Vc,[],P_cut,n); |
125 | 128 | %Compose isolated cut geometry and boundary curves |
126 | 129 | [Fe,Ve]=patchCleanUnused(Fd(logicSide==1,:),Vd); |
127 | 130 |
|
128 | | - |
| 131 | + Ebs=patchBoundary(Fe); |
| 132 | + groupStruct.outputType='label'; |
| 133 | + [G,~,groupSize]=tesgroup(Ebs,groupStruct); |
| 134 | + |
| 135 | + logicKeep=G==1; |
| 136 | + Eb_keep=Ebs(logicKeep,:); |
| 137 | + indCutLine=edgeListToCurve(Eb_keep); |
| 138 | + |
| 139 | + %Smoothen line |
| 140 | + logicRigid=true(size(Ve,1),1); |
| 141 | + logicRigid(indCutLine)=0; |
| 142 | + |
| 143 | + cPar.n=10; |
| 144 | + cPar.Method='LAP'; |
| 145 | + cPar.RigidConstraints=find(logicRigid); |
| 146 | + [Ve]=patchSmooth(Ebs,Ve,[],cPar); |
| 147 | + |
| 148 | + %Smoothen mesh |
| 149 | + logicTouch=any(ismember(Fe,indCutLine),2); |
| 150 | + indTouch=unique(Fe(logicTouch,:)); |
| 151 | + |
| 152 | + for q=1:1:2 |
| 153 | + logicTouch=any(ismember(Fe,indTouch),2); |
| 154 | + indTouch=unique(Fe(logicTouch,:)); |
| 155 | + end |
| 156 | + %Smoothen line |
| 157 | + logicRigid=true(size(Ve,1),1); |
| 158 | + logicRigid(indTouch)=0; |
| 159 | + logicRigid(indCutLine)=1; |
| 160 | + %Smoothen mesh |
| 161 | + clear cPar; |
| 162 | + cPar.n=100; |
| 163 | + cPar.Method='HC'; |
| 164 | + cPar.RigidConstraints=find(logicRigid); |
| 165 | + [Ve]=patchSmooth(Fe,Ve,[],cPar); |
| 166 | + |
| 167 | + VT=Ve(indCutLine,:); |
| 168 | + |
| 169 | + VT0=evenlySampleCurve(VT0,size(VT,1),'pchip',1); |
| 170 | + VT0=VT0(1:end-1,:); |
| 171 | + indCurve_S=(linspace(1,size(VT0,1),size(VT0,1))); |
| 172 | + indCurve_S=indCurve_S(1:end-1); |
| 173 | + indCurve_L=indCurve_S; |
| 174 | + %% Reorder curves |
| 175 | + [~,indMin]=minDist(VT(indCurve_L(1),:),VT0(indCurve_S,:)); |
| 176 | + |
| 177 | + if indMin>1 |
| 178 | + indCurve_S=[indCurve_S(indMin:end) indCurve_S(1:indMin-1)]; |
| 179 | + end |
| 180 | + |
| 181 | + D1=sum(sqrt(sum((VT(indCurve_L,:)-VT0(indCurve_S,:)).^2,2))); |
| 182 | + D2=sum(sqrt(sum((VT(indCurve_L,:)-VT0(flip(indCurve_S),:)).^2,2))); |
| 183 | + |
| 184 | + if D2<D1 |
| 185 | + indCurve_S=flip(indCurve_S); |
| 186 | + end |
| 187 | + |
| 188 | + cPar.closeLoopOpt=1; |
| 189 | + cPar.patchType='tri_slash'; |
| 190 | + [Fn1,Vn1]=polyLoftLinear(VT(indCurve_L,:),VT0(indCurve_S,:),cPar); |
| 191 | + |
| 192 | + %Smoothen mesh |
| 193 | + clear cPar; |
| 194 | + cPar.n=100; |
| 195 | + cPar.Method='HC'; |
| 196 | + [Vn1]=patchSmooth(Fn1,Vn1,[],cPar); |
| 197 | + |
| 198 | + [Fk,Vk]=regionTriMesh3D({VT0(indCurve_S,:)},pointSpacing,0,'natural'); |
| 199 | + |
129 | 200 | cFigure; hold on; |
130 | | - gpatch(F,V,'w','none',0.25); |
131 | | - gpatch(Fe,Ve,'rw','none',1); |
132 | | - plotV(V_slice_curve,'k-','LineWidth',4); |
| 201 | + |
| 202 | + plotV(VT,'g.-','MarkerSize',25,'LineWidth',3); |
| 203 | + plotV(VT0,'g.-','MarkerSize',25,'LineWidth',3); |
| 204 | + gpatch(Fe,Ve,'gw','none',1); |
| 205 | + gpatch(Fn1,Vn1,'w','none',1); |
| 206 | + gpatch(Fk,Vk,'w','none',1); |
133 | 207 | axis off; |
134 | 208 | axisGeom; |
135 | 209 | camlight headlight; |
136 | 210 | drawnow; |
137 | | - |
138 | | - %% Forming the point cloud out of the processed cut right leg a |
139 | | - %% and the edge of the skin (curve) formed at cutHeight |
140 | | - Ve=[Ve;V_slice_curve;]; |
141 | | - %% Construct alpha shape |
142 | | - % This deteriorates surface quality (bridges concave regions) but is a |
143 | | - % termporary "quick-and-dirty" work-around to obtain outer skin surface |
144 | | - % only. |
145 | | - shp = alphaShape(Ve,max(patchEdgeLengths(Fe,Ve)),'HoleThreshold',500,'RegionThreshold',100); |
| 211 | + |
| 212 | + |
| 213 | + V_total=[Ve;Vn1;Vk]; |
| 214 | + shp = alphaShape(V_total,max(patchEdgeLengths(Fe,Ve)));%,'HoleThreshold',500,'RegionThreshold',100); |
146 | 215 | [Fa,Va] = boundaryFacets(shp); %Get boundary faces of alpha shape |
147 | 216 | [Fa,Va] = patchCleanUnused(Fa,Va); %Remove unused vertices |
148 | 217 |
|
|
154 | 223 | %% Visualisation |
155 | 224 | cFigure; |
156 | 225 | hAxis(1)=subplot(1,2,1); hold on; |
157 | | - %gpatch(Fs,Vs,'w','none',0.25); |
158 | | - gpatch(Fe,Ve,'w','none',1); |
159 | | - plotV(V_slice_curve,'k-','LineWidth',4); |
| 226 | + gpatch(Fs,Vs,'w','none',0.25); |
| 227 | + %gpatch(Fe,Ve,'w','none',1); |
| 228 | + %plotV(VT0,'k-','LineWidth',4); |
160 | 229 |
|
161 | | - text(min(V(:,1))+50,min(V(:,2))+99,'A','FontSize',fontSize); |
| 230 | + %text(min(V(:,1))+50,min(V(:,2))+99,'A','FontSize',fontSize); |
162 | 231 | axis off; |
163 | 232 | axisGeom; |
164 | 233 | camlight headlight; |
165 | 234 |
|
166 | 235 | hAxis(2)=subplot(1,2,2); hold on; |
167 | 236 | gpatch(Fn,Vn,'w','k',1,lineWidth); |
168 | | - text(min(V(:,1))+40,min(V(:,2))+110,'B','FontSize',fontSize); |
| 237 | + %text(min(V(:,1))+40,min(V(:,2))+110,'B','FontSize',fontSize); |
169 | 238 | axis off; |
170 | 239 | axisGeom; |
171 | 240 | pos = get( hAxis(2), 'Position' ); |
172 | 241 | pos(1)=pos(1)-0.3; |
173 | 242 | set( hAxis(2), 'Position', pos ) ; |
174 | 243 | camlight headlight; |
175 | 244 | gdrawnow; |
176 | | - |
| 245 | + |
177 | 246 | %% Store model in structure |
178 | 247 | modelNew.source=fileName_FMA; |
179 | 248 | modelNew.faces=Fn; |
|
0 commit comments