Mercurial > octave
comparison scripts/plot/draw/private/__unite_shared_vertices__.m @ 22232:a8fd02bc895b
Overhaul isosurface.m and associated functions.
* isosurface.m: Rewrite docstring and examples. Don't validate nargout.
Wrap long lines to < 80 characters. Use names from docstring in code.
Use "EdgeColor", "none" for Matlab compatibility, but preserve exception
for gnuplot. Use blank lines between case statements for readability.
Update demo #2 to properly show annotation textbox. Rewrite %!error
tests.
* __calc_isovalue_from_data__.m: Give private function a docstring.
Use '_' in numbers as thousands separator for readability. Wrap
long lines to < 80 characters.
* __unite_shared_vertices__.m: Reformat docstring. Use rows() rather
than size (XXX, 1). Wrap long lines to < 80 characters. Use space
after function name and before parenthesis.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 09 Aug 2016 11:09:38 -0700 |
parents | 7680225527ef |
children | 3a2b891d0b33 e9a0469dedd9 |
comparison
equal
deleted
inserted
replaced
22231:01ba6ebc52e4 | 22232:a8fd02bc895b |
---|---|
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {} {[@var{faces}, @var{vertices}, @var{J}] =} __unite_shared_vertices__ (@var{faces}, @var{vertices}) | 20 ## @deftypefn {} {[@var{faces}, @var{vertices}, @var{J}] =} __unite_shared_vertices__ (@var{faces}, @var{vertices}) |
21 ## | 21 ## |
22 ## Detect and unite shared vertices in patches | 22 ## Detect and unite shared vertices in patches. |
23 ## | 23 ## |
24 ## Vertices of neighboring faces are detected and united to shared vertices. For | 24 ## Vertices of neighboring faces are detected and united to shared vertices. |
25 ## this, the mutual squared distances between all vertices are calculated. If | 25 ## For this, the mutual squared distances between all vertices are |
26 ## all coordinates are closer than @command{2 * eps (max (abs (vertices(:))))}, | 26 ## calculated. If all coordinates are closer than |
27 ## the vertices are united to one. | 27 ## @code{2 * eps (max (abs (vertices(:))))}, the vertices are united to one. |
28 ## | 28 ## |
29 ## @var{J} holds the indices of the deleted vertices. | 29 ## @var{J} holds the indices of the deleted vertices. |
30 ## | 30 ## |
31 ## @seealso{isosurface, reducepatch} | 31 ## @seealso{isosurface, reducepatch} |
32 ## @end deftypefn | 32 ## @end deftypefn |
33 | 33 |
34 ## Author: mmuetzel | 34 ## Author: mmuetzel |
35 | 35 |
36 function [faces, vertices, J] = __unite_shared_vertices__ (faces, vertices) | 36 function [faces, vertices, J] = __unite_shared_vertices__ (faces, vertices) |
37 ### unite shared vertices | |
38 | 37 |
39 J = []; | 38 J = []; |
39 | |
40 ## Calculate the mutual differences of all vertex coordinates | 40 ## Calculate the mutual differences of all vertex coordinates |
41 close_points = zeros (0, 2); | 41 close_points = zeros (0, 2); |
42 num_vertices = size (vertices, 1); | 42 num_vertices = rows (vertices); |
43 skip_point = false (num_vertices, 1); | 43 skip_point = false (num_vertices, 1); |
44 ## FIXME: Can this be vectorized in some way to increase performance? | |
45 ## Regardless, should probably allocate close_points to be the | |
46 ## same size as the number of vertices and then truncate the | |
47 ## array at the end of the calculation. Extending an array | |
48 ## involves a copy operation every time. | |
44 for (i_point1 = 1:num_vertices - 1) | 49 for (i_point1 = 1:num_vertices - 1) |
45 if (skip_point(i_point1)) | 50 if (skip_point(i_point1)) |
46 ## points already detected as duplicates can be skipped | 51 ## points already detected as duplicates can be skipped |
47 continue | 52 continue; |
48 endif | 53 endif |
49 | 54 |
50 diff = vertices(i_point1,:) - vertices(i_point1 + 1:end,:); | 55 diff = vertices(i_point1,:) - vertices(i_point1 + 1:end,:); |
51 is_close_point = all (abs (diff) <= sqrt(3) * eps * ... | 56 is_close_point = all (abs (diff) <= sqrt (3) * eps * ... |
52 (max (abs (vertices(i_point1,:)), abs (vertices(i_point1 + 1:end,:)))), 2); | 57 (max (abs (vertices(i_point1,:)), abs (vertices(i_point1 + 1:end,:)))), 2); |
53 | 58 |
54 if (any (is_close_point)) | 59 if (any (is_close_point)) |
55 close_points_idx = find (is_close_point) + i_point1; | 60 close_points_idx = find (is_close_point) + i_point1; |
56 new_close_points_num = size (close_points_idx, 1); | 61 new_close_points_num = rows (close_points_idx); |
57 close_points(end + 1:end + new_close_points_num,1) = i_point1; | 62 close_points(end + 1:end + new_close_points_num,1) = i_point1; |
58 close_points(end - new_close_points_num + 1:end,2) = close_points_idx; | 63 close_points(end - new_close_points_num + 1:end,2) = close_points_idx; |
59 skip_point(close_points_idx) = true; | 64 skip_point(close_points_idx) = true; |
60 endif | 65 endif |
61 endfor | 66 endfor |
74 | 79 |
75 ## eliminate identical faces | 80 ## eliminate identical faces |
76 faces = sort (faces, 2); | 81 faces = sort (faces, 2); |
77 faces = unique (faces, "rows"); | 82 faces = unique (faces, "rows"); |
78 | 83 |
79 ## eliminate faces with zero area | 84 ## eliminate faces with zero area. Vertices in faces are sorted. |
80 is_zero_area = (faces(:,1) == faces(:,2)) | (faces(:,2) == faces(:,3)); # vertices in faces are sorted | 85 is_zero_area = (faces(:,1) == faces(:,2)) | (faces(:,2) == faces(:,3)); |
81 faces = faces(!is_zero_area,:); | 86 faces = faces(! is_zero_area, :); |
82 | 87 |
83 J = close_points(:,2); | 88 J = close_points(:,2); |
84 endif | 89 endif |
85 | 90 |
86 endfunction | 91 endfunction |
92 |