Skip to content

Commit 574af4f

Browse files
authored
Add files via upload
1 parent cf2134d commit 574af4f

1 file changed

Lines changed: 96 additions & 27 deletions

File tree

mcode/C_BodyParts3D_isolate_LegOuterSkinSurface_LegMuscles_vs1.m

Lines changed: 96 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@
2727

2828
pointSpacing=4;
2929
cutHeight=810;
30+
cutHeight1=860;
3031
saveOn=1;
3132

3233

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
3536
case 'outer_skin_surface'
3637
%% Original
3738
fileName_mat=fullfile(loadFolder,[fileName_FMA,'.mat']);
@@ -54,6 +55,7 @@
5455
axisGeom;
5556
camlight headlight;
5657
drawnow;
58+
5759
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5860
%% Cut again preserving only right leg
5961
optionStruct.outputType='label';
@@ -62,14 +64,14 @@
6264
logicKeep=G==indMax;
6365
Fs=Fs(logicKeep,:);
6466
[Fs,Vs]=patchCleanUnused(Fs,Vs);
65-
67+
6668
cFigure; hold on;
6769
gpatch(Fs,Vs,'w','none',0.25);
6870
axis off;
6971
axisGeom;
7072
camlight headlight;
7173
drawnow;
72-
74+
7375
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7476
%% Slice the surface of the right leg at cutHeight
7577
%% to detect all edges to form the list of curves within the slice
@@ -100,12 +102,13 @@
100102
VTc=Vc(indCurveNow,:);
101103
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
102104
%% Forming the 2D convex hull around the curve
103-
[V_slice_curve]=convexhull_curve(VTc,200);
105+
[VT0]=convexhull_curve(VTc,200);
104106
[Fc,Vc]=patchCleanUnused(Fc(logicSide,:),Vc);
105107

108+
VT0(:,3)=VT0(:,3)+25;
106109
cFigure; hold on;
107110
gpatch(Fc,Vc,'w','none',0.25);
108-
plotV(V_slice_curve,'k-','LineWidth',4);
111+
plotV(VT0,'k-','LineWidth',4);
109112
axis off;
110113
axisGeom;
111114
camlight headlight;
@@ -116,33 +119,99 @@
116119
%Set-up orientation and location of cutting plane
117120
snapTolerance=mean(patchEdgeLengths(Fc,Vc))/100; %Tolerance for surface slicing
118121
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+
121124
n=n*Q1;
122125
P_cut=[0 0 0]+n*306; %Point on plane
123126
%Slicing surface
124127
[Fd,Vd,Cd,logicSide,Ed]=triSurfSlice(Fc,Vc,[],P_cut,n);
125128
%Compose isolated cut geometry and boundary curves
126129
[Fe,Ve]=patchCleanUnused(Fd(logicSide==1,:),Vd);
127130

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+
129200
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);
133207
axis off;
134208
axisGeom;
135209
camlight headlight;
136210
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);
146215
[Fa,Va] = boundaryFacets(shp); %Get boundary faces of alpha shape
147216
[Fa,Va] = patchCleanUnused(Fa,Va); %Remove unused vertices
148217

@@ -154,26 +223,26 @@
154223
%% Visualisation
155224
cFigure;
156225
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);
160229

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);
162231
axis off;
163232
axisGeom;
164233
camlight headlight;
165234

166235
hAxis(2)=subplot(1,2,2); hold on;
167236
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);
169238
axis off;
170239
axisGeom;
171240
pos = get( hAxis(2), 'Position' );
172241
pos(1)=pos(1)-0.3;
173242
set( hAxis(2), 'Position', pos ) ;
174243
camlight headlight;
175244
gdrawnow;
176-
245+
177246
%% Store model in structure
178247
modelNew.source=fileName_FMA;
179248
modelNew.faces=Fn;

0 commit comments

Comments
 (0)