Mercurial > octave-nkf
comparison scripts/plot/draw/tetramesh.m @ 19630:0e1f5a750d00
maint: Periodic merge of gui-release to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 20 Jan 2015 10:24:46 -0500 |
parents | ba167badef9f 446c46af4b42 |
children | 4197fc428c7d |
comparison
equal
deleted
inserted
replaced
19626:37d37297acf8 | 19630:0e1f5a750d00 |
---|---|
24 ## Display the tetrahedrons defined in the m-by-4 matrix @var{T} as 3-D patches. | 24 ## Display the tetrahedrons defined in the m-by-4 matrix @var{T} as 3-D patches. |
25 ## | 25 ## |
26 ## @var{T} is typically the output of a Delaunay triangulation | 26 ## @var{T} is typically the output of a Delaunay triangulation |
27 ## of a 3-D set of points. Every row of @var{T} contains four indices into | 27 ## of a 3-D set of points. Every row of @var{T} contains four indices into |
28 ## the n-by-3 matrix @var{X} of the vertices of a tetrahedron. Every row in | 28 ## the n-by-3 matrix @var{X} of the vertices of a tetrahedron. Every row in |
29 ## @var{X} represents one point in 3-D space. | 29 ## @var{X} represents one point in 3-D space. |
30 ## | 30 ## |
31 ## The vector @var{C} specifies the color of each tetrahedron as an index | 31 ## The vector @var{C} specifies the color of each tetrahedron as an index |
32 ## into the current colormap. The default value is 1:m where m is the number | 32 ## into the current colormap. The default value is 1:m where m is the number |
33 ## of tetrahedrons; the indices are scaled to map to the full range of the | 33 ## of tetrahedrons; the indices are scaled to map to the full range of the |
34 ## colormap. If there are more tetrahedrons than colors in the colormap then | 34 ## colormap. If there are more tetrahedrons than colors in the colormap then |
35 ## the values in @var{C} are cyclically repeated. | 35 ## the values in @var{C} are cyclically repeated. |
36 ## | 36 ## |
37 ## Calling @code{tetramesh (@dots{}, "property", "value", @dots{})} passes all | 37 ## Calling @code{tetramesh (@dots{}, "property", "value", @dots{})} passes all |
38 ## property/value pairs directly to the patch function as additional arguments. | 38 ## property/value pairs directly to the patch function as additional arguments. |
39 ## | 39 ## |
40 ## The optional return value @var{h} is a vector of patch handles where each | 40 ## The optional return value @var{h} is a vector of patch handles where each |
41 ## handle represents one tetrahedron in the order given by @var{T}. | 41 ## handle represents one tetrahedron in the order given by @var{T}. |
42 ## A typical use case for @var{h} is to turn the respective patch | 42 ## A typical use case for @var{h} is to turn the respective patch |
43 ## @qcode{"visible"} property @qcode{"on"} or @qcode{"off"}. | 43 ## @qcode{"visible"} property @qcode{"on"} or @qcode{"off"}. |
44 ## | 44 ## |
45 ## Type @code{demo tetramesh} to see examples on using @code{tetramesh}. | 45 ## Type @code{demo tetramesh} to see examples on using @code{tetramesh}. |
46 ## @seealso{trimesh, delaunay, delaunayn, patch} | 46 ## @seealso{trimesh, delaunay, delaunayn, patch} |
65 error ("tetramesh: X must be an n-by-3 matrix"); | 65 error ("tetramesh: X must be an n-by-3 matrix"); |
66 endif | 66 endif |
67 | 67 |
68 size_T = rows (T); | 68 size_T = rows (T); |
69 cmap = colormap (); | 69 cmap = colormap (); |
70 | 70 |
71 if (length (reg) < 3) | 71 if (length (reg) < 3) |
72 size_cmap = rows (cmap); | 72 size_cmap = rows (cmap); |
73 C = mod ((1:size_T)' - 1, size_cmap) + 1; | 73 C = mod ((1:size_T)' - 1, size_cmap) + 1; |
74 if (size_T < size_cmap && size_T > 1) | 74 if (size_T < size_cmap && size_T > 1) |
75 ## expand to the available range of colors | 75 ## expand to the available range of colors |
76 C = floor ((C - 1) * (size_cmap - 1) / (size_T - 1)) + 1; | 76 C = floor ((C - 1) * (size_cmap - 1) / (size_T - 1)) + 1; |
77 endif | 77 endif |
78 else | 78 else |
79 C = reg{3}; | 79 C = reg{3}; |
88 if (strcmp (graphics_toolkit (), "gnuplot")) | 88 if (strcmp (graphics_toolkit (), "gnuplot")) |
89 ## Tiny reduction of the tetrahedron size to help gnuplot by | 89 ## Tiny reduction of the tetrahedron size to help gnuplot by |
90 ## avoiding identical faces with different colors | 90 ## avoiding identical faces with different colors |
91 for i = 1:size_T | 91 for i = 1:size_T |
92 [th, p] = __shrink__ ([1 2 3 4], X(T(i, :), :), 1 - 1e-7); | 92 [th, p] = __shrink__ ([1 2 3 4], X(T(i, :), :), 1 - 1e-7); |
93 hvec(i) = patch ("Faces", th, "Vertices", p, | 93 hvec(i) = patch ("Faces", th, "Vertices", p, |
94 "FaceColor", cmap(C(i), :), "FaceAlpha", 0.9, | 94 "FaceColor", cmap(C(i), :), "FaceAlpha", 0.9, |
95 prop{:}); | 95 prop{:}); |
96 endfor | 96 endfor |
97 else | 97 else |
98 ## FLTK does not support FaceAlpha. | 98 ## FLTK does not support FaceAlpha. |
99 for i = 1:size_T | 99 for i = 1:size_T |
100 th = [1 2 3; 2 3 4; 3 4 1; 4 1 2]; | 100 th = [1 2 3; 2 3 4; 3 4 1; 4 1 2]; |
101 hvec(i) = patch ("Faces", th, "Vertices", X(T(i, :), :), | 101 hvec(i) = patch ("Faces", th, "Vertices", X(T(i, :), :), |
102 "FaceColor", cmap(C(i), :), "FaceAlpha", 1.0, | 102 "FaceColor", cmap(C(i), :), "FaceAlpha", 1.0, |
103 prop{:}); | 103 prop{:}); |
104 endfor | 104 endfor |
105 endif | 105 endif |
106 | 106 |