Skip to content

Commit 61008e2

Browse files
1 parent 006c5fa commit 61008e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+458
-60
lines changed

HELP_patch2Im.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
patch('Faces',F,'Vertices',V,'FaceColor','flat','CData',C,'EdgeColor','none','FaceAlpha',faceAlpha2);
172172
camlight('headlight'); lighting flat;
173173
axis equal; view(3); axis tight; grid on; set(gca,'FontSize',fontSize);
174-
colormap gjet; colorbar;
174+
colormap gjet; colorbar; caxis([0 max(C(:))]);
175175

176176
subplot(1,2,2);
177177
title('Patch data derived image data (3 slices)','FontSize',fontSize);
@@ -189,7 +189,7 @@
189189
Vm=Vm+imOrigin(ones(size(Vm,1),1),:);
190190
patch('Faces',Fm,'Vertices',Vm,'FaceColor','flat','CData',Cm,'EdgeColor','k','FaceAlpha',faceAlpha1);
191191

192-
colormap gjet; colorbar;
192+
colormap gjet; colorbar; caxis([0 max(C(:))]);
193193
camlight('headlight'); lighting flat;
194194
axis equal; view(3); axis tight; grid on; set(gca,'FontSize',fontSize);
195195
drawnow;

html/helpsearch-v2/_0.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v2/_0.cfs

-634 KB
Binary file not shown.

html/helpsearch-v2/_0.si

-255 Bytes
Binary file not shown.

html/helpsearch-v2/segments.gen

-20 Bytes
Binary file not shown.

html/helpsearch-v2/segments_1

-81 Bytes
Binary file not shown.

html/helpsearch-v3/_5.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_5.cfs

-1.23 MB
Binary file not shown.

html/helpsearch-v3/_5.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_6.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_6.cfs

-1.71 MB
Binary file not shown.

html/helpsearch-v3/_6.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_7.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_7.cfs

-1.72 MB
Binary file not shown.

html/helpsearch-v3/_7.si

-264 Bytes
Binary file not shown.

html/helpsearch-v3/_8.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_8.cfs

-1.76 MB
Binary file not shown.

html/helpsearch-v3/_8.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_9.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_9.cfs

-1.77 MB
Binary file not shown.

html/helpsearch-v3/_9.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_a.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_a.cfs

-1.78 MB
Binary file not shown.

html/helpsearch-v3/_a.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_e.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_e.cfs

-1.97 MB
Binary file not shown.

html/helpsearch-v3/_e.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_f.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_f.cfs

-1.7 MB
Binary file not shown.

html/helpsearch-v3/_f.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/_k.cfe

-268 Bytes
Binary file not shown.

html/helpsearch-v3/_k.cfs

-1.71 MB
Binary file not shown.

html/helpsearch-v3/_k.si

-255 Bytes
Binary file not shown.

html/helpsearch-v3/segments.gen

-20 Bytes
Binary file not shown.

html/helpsearch-v3/segments_6

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_7

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_8

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_9

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_a

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_b

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_f

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_g

-81 Bytes
Binary file not shown.

html/helpsearch-v3/segments_l

-81 Bytes
Binary file not shown.

lib/anim8.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@
165165
hf.UserData.ButtonHandles.Play=hPlay;
166166
hf.UserData.ButtonHandles.hCycle=hCycle;
167167
hf.UserData.ButtonHandles.hTextTime=hTextTime;
168-
hf.UserData.pauseTime=2/numel(animStruct.Time);
169-
hf.UserData.shiftMag=1;
168+
hf.UserData.pauseTime=mean(diff(animStruct.Time));
169+
hf.UserData.shiftMag=ceil(numel(animStruct.Time)/20);
170170
hf.UserData.icons.play=iconPlay;
171171
hf.UserData.icons.stop=iconStop;
172172

lib/gcontour.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,16 @@
8383
for q=1:1:numContours
8484

8585
Vg=[Q(1,IND1(q):IND2(q))' Q(2,IND1(q):IND2(q))']; %Get coordinates
86-
cLevel(q)=Q(1,IND1(q)-1); %Get level
86+
cLevel(q)=Q(1,IND1(q)-1); %Get level
87+
88+
%Check for non-unique points
89+
[~,indUni,~]=unique(pround(Vg,5),'rows');
90+
logicKeep=false(size(Vg,1),1);
91+
logicKeep(indUni)=1;
92+
Vg=Vg(logicKeep,:);
8793

8894
if size(Vg,1)>1
95+
8996
%Check if contour is closed loop or not
9097
d=sqrt(sum((Vg(1,:)-Vg(end,:)).^2)); %Distance between first and last point
9198
if d<(min(v)/10) %Smaller than 1/10th of a pixel dimension

lib/getInnerPoint.m

+74-31
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,70 @@
1-
function [V_inner]=getInnerPoint(F_input,V_input,searchRadius,voxelSize,plotOn)
1+
function [varargout]=getInnerPoint(varargin)
22

33
%%
44

5-
if isa(F_input,'cell')
6-
[F_input,V_input,C_input]=joinElementSets(F_input,V_input);
5+
switch nargin
6+
case 2
7+
F=varargin{1};
8+
V=varargin{2};
9+
searchRadius=[];
10+
voxelSize=[];
11+
plotOn=0;
12+
case 3
13+
F=varargin{1};
14+
V=varargin{2};
15+
searchRadius=varargin{3};
16+
voxelSize=[];
17+
plotOn=0;
18+
case 4
19+
F=varargin{1};
20+
V=varargin{2};
21+
searchRadius=varargin{3};
22+
voxelSize=varargin{4};
23+
plotOn=0;
24+
case 5
25+
F=varargin{1};
26+
V=varargin{2};
27+
searchRadius=varargin{3};
28+
voxelSize=varargin{4};
29+
plotOn=varargin{5};
30+
otherwise
31+
error('Wrong number of input arguments');
32+
end
33+
34+
if isempty(voxelSize)
35+
D=patchEdgeLengths(F,V);
36+
voxelSize=mean(D)/2;
37+
end
38+
39+
if isempty(searchRadius)
40+
searchRadius=voxelSize*3;
41+
end
42+
43+
%%
44+
45+
if isa(F,'cell')
46+
[F,V,C]=joinElementSets(F,V);
747
else
8-
C_input=ones(size(F_input,1),1);
48+
C=ones(size(F,1),1);
949
end
1050

1151
%% Get an inner point
1252

1353
%Convert patch data to image
14-
[M,G,~]=patch2Im(F_input,V_input,C_input,voxelSize);
54+
[M,G,~]=patch2Im(F,V,C,voxelSize);
1555
L_test=(M==1); %Logic for interior voxels of surface mesh
16-
M=double(L_test);
1756
imOrigin=G.origin; %Image origin can be used to allign image with surface
1857

19-
2058
%Construct search blurring kernel
21-
[x,y,z]=ndgrid(-searchRadius:1:searchRadius); %kernel coordinates
59+
[x,y,z]=ndgrid(-searchRadius:voxelSize:searchRadius); %kernel coordinates
2260
d=sqrt(x.^2+y.^2+z.^2); %distance metric
2361
k=(d<=searchRadius); %Define kernel based on radius
2462
k=k./sum(k(:)); %Normalize kernel
2563

2664
%Convolve interior image with kernel
2765
ML=convn(double(L_test),k,'same');
28-
[~,indInternal]=max(ML(:)); %Kernel should yield max at "deep" (related to search radius) point
66+
ML(M~=1)=NaN; %Set other sites to NaN
67+
[~,indInternal]=nanmax(ML(:)); %Kernel should yield max at "deep" (related to search radius) point
2968
[I_in,J_in,K_in]=ind2sub(size(M),indInternal); %Convert to subscript coordinates
3069

3170
%Derive point coordinates
@@ -35,47 +74,51 @@
3574

3675
%% Plotting image, mesh and inner point
3776
if plotOn==1
38-
figColor='w'; figColorDef='white';
77+
3978
fontSize=20;
4079
markerSize1=50;%round(voxelSize*25);
41-
faceAlpha1=0.7;
42-
faceAlpha2=0.2;
80+
faceAlpha1=1;
81+
faceAlpha2=0.5;
4382

44-
hf=figuremax(figColor,figColorDef);
45-
xlabel('X','FontSize',fontSize); ylabel('Y','FontSize',fontSize); zlabel('Z','FontSize',fontSize);
83+
cFigure;
4684
hold on;
4785

48-
hp= patch('Faces',F_input,'Vertices',V_input,'FaceColor','flat','CData',C_input,'EdgeColor','none','FaceAlpha',faceAlpha2);
86+
gpatch(F,V,0.5*ones(1,3),'none',faceAlpha2);
4987
plotV(V_inner,'k.','MarkerSize',markerSize1);
5088

51-
L_plot=false(size(M));
89+
L_plot=false(size(ML));
5290
L_plot(:,:,K_in)=1;
53-
L_plot=L_plot&M>0;
54-
[Fm,Vm,Cm]=ind2patch(L_plot,double(M),'sk');
91+
L_plot=L_plot & ~isnan(ML);
92+
[Fm,Vm,Cm]=ind2patch(L_plot,double(ML),'sk');
5593
[Vm(:,1),Vm(:,2),Vm(:,3)]=im2cart(Vm(:,2),Vm(:,1),Vm(:,3),voxelSize*ones(1,3));
5694
Vm=Vm+imOrigin(ones(size(Vm,1),1),:);
57-
patch('Faces',Fm,'Vertices',Vm,'FaceColor',0.5*ones(1,3),'EdgeColor','k','FaceAlpha',faceAlpha1);
5895

59-
L_plot=false(size(M));
96+
gpatch(Fm,Vm,Cm,'k',faceAlpha1);
97+
98+
L_plot=false(size(ML));
6099
L_plot(I_in,:,:)=1;
61-
L_plot=L_plot&M>0;
62-
[Fm,Vm,Cm]=ind2patch(L_plot,M,'si');
100+
L_plot=L_plot & ~isnan(ML);
101+
[Fm,Vm,Cm]=ind2patch(L_plot,ML,'si');
63102
[Vm(:,1),Vm(:,2),Vm(:,3)]=im2cart(Vm(:,2),Vm(:,1),Vm(:,3),voxelSize*ones(1,3));
64103
Vm=Vm+imOrigin(ones(size(Vm,1),1),:);
65-
patch('Faces',Fm,'Vertices',Vm,'FaceColor',0.5*ones(1,3),'EdgeColor','k','FaceAlpha',faceAlpha1);
104+
gpatch(Fm,Vm,Cm,'k',faceAlpha1);
66105

67-
L_plot=false(size(M));
106+
L_plot=false(size(ML));
68107
L_plot(:,J_in,:)=1;
69-
L_plot=L_plot&M>0;
70-
[Fm,Vm,Cm]=ind2patch(L_plot,M,'sj');
108+
L_plot=L_plot & ~isnan(ML);
109+
[Fm,Vm,Cm]=ind2patch(L_plot,ML,'sj');
71110
[Vm(:,1),Vm(:,2),Vm(:,3)]=im2cart(Vm(:,2),Vm(:,1),Vm(:,3),voxelSize*ones(1,3));
72111
Vm=Vm+imOrigin(ones(size(Vm,1),1),:);
73-
patch('Faces',Fm,'Vertices',Vm,'FaceColor',0.5*ones(1,3),'EdgeColor','k','FaceAlpha',faceAlpha1);
112+
gpatch(Fm,Vm,Cm,'k',faceAlpha1);
74113

75-
colormap(gjet(numel(unique(C_input(:))))); colorbar;
76-
77-
axis equal; view(3); axis tight; grid on; set(gca,'FontSize',fontSize);
78-
set(gca,'FontSize',fontSize);
114+
colormap(gjet(250)); colorbar;
115+
axisGeom(gca,fontSize);
79116
drawnow;
80117
end
81118

119+
varargout{1}=V_inner;
120+
varargout{2}=M;
121+
varargout{3}=G;
122+
varargout{4}=ML;
123+
124+

lib/getInnerVoxel.m

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
voxelSize=[1 1 1];
2020
[I_in,J_in,K_in]=ind2sub(size(L),indInternal); %Convert to subscript coordinates
2121
[X_in,Y_in,Z_in]=im2cart(I_in,J_in,K_in,voxelSize);
22+
V_in=[X_in Y_in Z_in];
2223

2324
%Plot settings
2425
figColor='w'; figColorDef='white';
@@ -31,7 +32,7 @@
3132
hold on;
3233

3334
%Found voxel location
34-
plot3(X_in,Y_in,Z_in,'r.','MarkerSize',markerSize1);
35+
plotV(V_in,'r.','MarkerSize',markerSize1);
3536

3637
%Local slices
3738
L_plot=false(size(L));

lib/imx.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@
514514
hf.UserData.sliceIndices=[sliceIndexI sliceIndexJ sliceIndexK];
515515
hf.UserData.contourSlice=sliceIndexK;
516516
hf.UserData.fontColor=fontColor;
517-
hf.UserData.faceAlpha=0.8;
517+
hf.UserData.faceAlpha=1;
518518
hf.UserData.lineColors=gjet(4);
519519
hf.UserData.logicThreshold=true(size(M));
520520
hf.UserData.ButtonHandles.Sample=hSample;

lib/patchMarchCountPointSeed.m

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
indSeed=nan(n,1);
88
indSeed(1:numStarts)=indStart;
99

10-
for q=2:1:n
11-
[marchCount,~]=patchMarchCount(F,V,indSeed(~isnan(indSeed)),optStruct);
10+
for q=numStarts:1:n
11+
[marchCount,seedIndex]=patchMarchCount(F,V,indSeed(~isnan(indSeed)),optStruct);
1212
[~,indAdd]=max(marchCount);
13-
indSeed(q)=indAdd;
13+
if q<n
14+
indSeed(q)=indAdd;
15+
end
1416
end
15-
[marchCount,seedIndex]=patchMarchCount(F,V,indSeed(~isnan(indSeed)),optStruct);

lib/patchMarchDistMapIterative.m

+146
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
function [varargout]=patchMarchDistMapIterative(varargin)
2+
3+
4+
%%
5+
6+
switch nargin
7+
case 2
8+
F=varargin{1};
9+
V=varargin{2};
10+
indStart=1;
11+
W=ones(size(V,1),1);
12+
optStruct.waitBarOn=0;
13+
optStruct.numIterationsMax=200;
14+
optStruct.toleranceLevel=1e-3;
15+
case 3
16+
F=varargin{1};
17+
V=varargin{2};
18+
indStart=varargin{3};
19+
W=ones(size(V,1),1);
20+
optStruct.waitBarOn=0;
21+
optStruct.numIterationsMax=200;
22+
optStruct.toleranceLevel=1e-3;
23+
case 4
24+
F=varargin{1};
25+
V=varargin{2};
26+
indStart=varargin{3};
27+
W=varargin{4};
28+
optStruct.waitBarOn=0;
29+
optStruct.numIterationsMax=200;
30+
optStruct.toleranceLevel=1e-3;
31+
case 5
32+
F=varargin{1};
33+
V=varargin{2};
34+
indStart=varargin{3};
35+
W=varargin{4};
36+
optStruct=varargin{5};
37+
end
38+
39+
if isempty(W)
40+
W=ones(size(V,1),1);
41+
end
42+
43+
if isempty(indStart)
44+
indStart=1;
45+
end
46+
47+
if isfield(optStruct,'numIterationsMax')
48+
numIterationsMax=optStruct.numIterationsMax;
49+
else
50+
numIterationsMax=200;
51+
end
52+
53+
if isfield(optStruct,'toleranceLevel')
54+
toleranceLevel=optStruct.toleranceLevel;
55+
else
56+
toleranceLevel=1e-3;
57+
end
58+
59+
%%
60+
61+
i = F(:);
62+
j = [F(:,2); F(:,3); F(:,1)];
63+
k = [F(:,3); F(:,1); F(:,2)];
64+
numPoints = size(V,1);
65+
x = V(i,:);
66+
x1 = V(j,:) - x;
67+
x2 = V(k,:) - x;
68+
69+
Inv1 = @(M,d)[M(:,4)./d -M(:,3)./d -M(:,2)./d M(:,1)./d];
70+
Inv = @(M)Inv1(M, M(:,1).*M(:,4) - M(:,3).*M(:,2));
71+
Mult = @(M,u)[M(:,1).*u(:,1) + M(:,3).*u(:,2) M(:,2).*u(:,1) + M(:,4).*u(:,2)];
72+
73+
U = getoptions(optStruct, 'U', []);
74+
if isempty(U)
75+
U = zeros(numPoints,1);
76+
end
77+
78+
% inner product matrix
79+
C = [dot(x1,x1,2) dot(x1,x2,2) dot(x2,x1,2) dot(x2,x2,2)];
80+
81+
S = Inv(C);
82+
83+
% a = <S*1,1>
84+
a = sum(S,2);
85+
86+
w = W(i);
87+
88+
% edge length
89+
L1 = sqrt(dot(x1,x1,2));
90+
L1 = L1(:).*w(:);
91+
L2 = sqrt(dot(x2,x2,2));
92+
L2 = L2(:).*w(:);
93+
94+
E=nan(numPoints,1);
95+
96+
ii=1:1:numel(i);
97+
98+
for q=1:numIterationsMax
99+
uj = U(j);
100+
uk = U(k);
101+
u = [uj uk];
102+
b = sum([S(:,1)+S(:,3) S(:,2)+S(:,4)].*u,2);
103+
c = sum(Mult(S,u).*u,2)-w.^2;
104+
delta = max( b.^2 - a.*c, 0);
105+
d = (b + sqrt(delta) )./a; % solution
106+
107+
alpha = Mult(S,u-repmat(d, 1,2)); % direction of the update
108+
109+
logic_d =alpha(:,1)>0 | alpha(:,2)>0;
110+
111+
% update along edges
112+
d1 = L1 + uj(:);
113+
d2 = L2 + uk(:);
114+
d = d(:);
115+
d(logic_d) = min(d1(logic_d), d2(logic_d));
116+
117+
%Create U1 using sparse array to get minima
118+
maxd=max(d(:));
119+
df=abs(maxd-d);
120+
U1 = sparse(i,ii,df,numPoints,max(ii),numel(d));
121+
U1 =maxd-full(max(U1,[],2));
122+
U1(U1==0) = Inf;
123+
U1(indStart) = 0; % boundary condition
124+
125+
% enforce monotony
126+
if min(U1-U)<-1e-5
127+
warning('Monotony problem');
128+
end
129+
130+
% Store error
131+
if q==1
132+
e1=norm(U-U1,'fro');
133+
end
134+
135+
E(q) = norm(U-U1,'fro')/e1;
136+
if E(q)<toleranceLevel
137+
break;
138+
end
139+
140+
% Update
141+
U = U1;
142+
end
143+
144+
%Output
145+
varargout{1}=U;
146+
varargout{2}=E;

0 commit comments

Comments
 (0)