-
Notifications
You must be signed in to change notification settings - Fork 326
/
plot_fast_marching_3d.m
150 lines (129 loc) · 3.47 KB
/
plot_fast_marching_3d.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
function plot_fast_marching_3d(W,S,path,start_points,end_points, options)
% plot_fast_marching_3d - plot the result of the fast marching.
%
% plot_fast_marching_3d(W,S,path [,start_points,end_points, options] );
%
% If you provide W, path is assumed to lie in [1,n]^3 where n=length(W).
% Path can be a cell array of 3D curves or a single 3D curve.
%
% Copyright (c) 2004 Gabriel Peyré
options.null = 0;
if isfield(options, 'plot_isosurface')
plot_isosurface = options.plot_isosurface;
else
plot_isosurface = 1;
end
if isfield(options, 'plot_planes')
plot_planes = options.plot_planes;
else
plot_planes = 1;
end
if isfield(options, 'path_width')
path_width = options.path_width;
else
path_width = 5;
end
if isfield(options, 'point_size')
point_size = options.point_size;
else
point_size = 16;
end
[n,p,q] = size(W);
hold on;
if ~isempty(W) && plot_planes
if 0
open_list = find( S==0 );
close_list = find( S==-1 );
W(open_list) = 0;
W(close_list) = W(close_list) - 0.2;
end
plot_volumetric_data(W);
end
if nargin>=4 && ~isempty(start_points)
if size(start_points,1)~=3
start_points = start_points';
end
if size(start_points,1)~=3
error('start_points must be of size 3xk');
end
% start_points = (start_points-1)/(n-1);
start_points = shift_array(start_points);
h = plot3(start_points(1), start_points(2), start_points(3), 'o', 'MarkerSize', point_size, ...
'MarkerEdgeColor','k', 'MarkerFaceColor','b');
end
if nargin>=5 && ~isempty(end_points)
if size(end_points,1)~=3
start_points = start_points';
end
if size(end_points,1)~=3
error('start_points must be of size 2xk');
end
end_points = shift_array(end_points);
% end_points = (end_points-1)/(n-1);
plot3(end_points(1), end_points(2), end_points(3), 'o', 'MarkerSize', point_size, ...
'MarkerEdgeColor','k', 'MarkerFaceColor','r');
end
if nargin>=3 && ~isempty(path)
if ~iscell(path)
path = {path};
end
for i=1:length(path)
path1 = path{i};
if size(path1,2)~=3
path1 = path1';
end
path1 = shift_array(path1);
plot3(path1(:,1), path1(:,2), path1(:,3), '-', 'LineWidth', path_width);
end
end
if plot_isosurface
S = smooth3(S,'gaussian',5,1);
F = isosurface( S,0.5 );
p = patch(F);
isonormals( S,p );
set(p, 'FaceColor', 'red', 'EdgeColor', 'none');
end
box on;
set(gca, 'XTick', []);
set(gca, 'YTick', []);
set(gca, 'ZTick', []);
lighting phong;
alpha(0.7);
camproj('perspective');
view(3);
axis equal;
axis([1 size(W,1) 1 size(W,2) 1 size(W,3)]);
daspect([1 1 1]);
% cameramenu;
camlight;
hold off;
function path1 = shift_array(path)
if( size(path, 2)==1 )
path1 = path( [2:-1:1 end] );
else
path1 = path( :, [2:-1:1 end] );
end
function plot_volumetric_data(W, nb_colors)
% plot_volumetric_data - plot a cube of data.
%
% plot_volumetric_data(W, nb_colors);
%
% Copyright (c) 2005 Gabriel Peyré
if nargin<2
nb_colors = 256;
end
[n,p,q] = size(W);
h = slice(W,p/2,n/2,q/2);
set(h,'FaceColor','interp','EdgeColor','none');
box on;
set(gca, 'XTick', []);
set(gca, 'YTick', []);
set(gca, 'ZTick', []);
colormap( jet(nb_colors) );
lighting phong;
camlight infinite;
camproj('perspective');
view(3);
axis tight;
axis equal;
% cameramenu;