Mercurial > hg > octave-nkf
annotate scripts/plot/draw/tetramesh.m @ 19946:b8e4104a8f55
Add the annotation function (bug #43282)
* NEWS: add annotation
* plot.txi: add annotation in same chapter as x/y/zlabel, title...
* __unimplemented__: remove annotation from the list
* scripts/plot/draw/annotation.m: new function file
* axes.m: restack figure children so that the annotation axes is always drawn on top
* axes.m: replace "parent" variable by "cf" for concistency
* clf.m: make "clf" delete the hidden annotation axes for matlab compatibility
* clf.m: avoid flashing a figure in the last test.
author | Pantxo Diribarne <pantxo.diribarne@gmail.com> |
---|---|
date | Sun, 08 Feb 2015 22:22:28 +0100 |
parents | 4197fc428c7d |
children | 777f26aa8e3e |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19793
diff
changeset
|
1 ## Copyright (C) 2012-2015 Martin Helm |
14514 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
14623
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
20 ## @deftypefn {Function File} {} tetramesh (@var{T}, @var{X}) |
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
21 ## @deftypefnx {Function File} {} tetramesh (@var{T}, @var{X}, @var{C}) |
fd3acd55dd42
tetramesh.m: Fix unbalanced parentheses in @deftypefn macro
Rik <octave@nomad.inbox5.com>
parents:
14541
diff
changeset
|
22 ## @deftypefnx {Function File} {} tetramesh (@dots{}, @var{property}, @var{val}, @dots{}) |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
23 ## @deftypefnx {Function File} {@var{h} =} tetramesh (@dots{}) |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
24 ## Display the tetrahedrons defined in the m-by-4 matrix @var{T} as 3-D patches. |
14514 | 25 ## |
17122
eaab03308c0b
doc: Rewrite docstrings for most plot functions.
Rik <rik@octave.org>
parents:
16828
diff
changeset
|
26 ## @var{T} is typically the output of a Delaunay triangulation |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
27 ## of a 3-D set of points. Every row of @var{T} contains four indices into |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
28 ## the n-by-3 matrix @var{X} of the vertices of a tetrahedron. Every row in |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
29 ## @var{X} represents one point in 3-D space. |
14514 | 30 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
31 ## The vector @var{C} specifies the color of each tetrahedron as an index |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
32 ## into the current colormap. The default value is 1:m where m is the number |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
33 ## of tetrahedrons; the indices are scaled to map to the full range of the |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
34 ## colormap. If there are more tetrahedrons than colors in the colormap then |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
35 ## the values in @var{C} are cyclically repeated. |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
36 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
37 ## Calling @code{tetramesh (@dots{}, "property", "value", @dots{})} passes all |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
38 ## property/value pairs directly to the patch function as additional arguments. |
14514 | 39 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
40 ## The optional return value @var{h} is a vector of patch handles where each |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
41 ## handle represents one tetrahedron in the order given by @var{T}. |
17281
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
42 ## A typical use case for @var{h} is to turn the respective patch |
bc924baa2c4e
doc: Add new @qcode macro for code samples which are quoted.
Rik <rik@octave.org>
parents:
17122
diff
changeset
|
43 ## @qcode{"visible"} property @qcode{"on"} or @qcode{"off"}. |
14514 | 44 ## |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
45 ## Type @code{demo tetramesh} to see examples on using @code{tetramesh}. |
19356
ba167badef9f
Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
46 ## @seealso{trimesh, delaunay, delaunayn, patch} |
14514 | 47 ## @end deftypefn |
48 | |
49 ## Author: Martin Helm <martin@mhelm.de> | |
50 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
51 function h = tetramesh (varargin) |
14514 | 52 |
53 [reg, prop] = parseparams (varargin); | |
54 | |
55 if (length (reg) < 2 || length (reg) > 3) | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
56 print_usage (); |
14514 | 57 endif |
58 | |
59 T = reg{1}; | |
60 X = reg{2}; | |
61 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
62 if (! ismatrix (T) || columns (T) != 4) |
17506 | 63 error ("tetramesh: T must be an n-by-4 matrix"); |
64 elseif (! ismatrix (X) || columns (X) != 3) | |
65 error ("tetramesh: X must be an n-by-3 matrix"); | |
14514 | 66 endif |
67 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
68 size_T = rows (T); |
17506 | 69 cmap = colormap (); |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
70 |
14514 | 71 if (length (reg) < 3) |
17506 | 72 size_cmap = rows (cmap); |
73 C = mod ((1:size_T)' - 1, size_cmap) + 1; | |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
74 if (size_T < size_cmap && size_T > 1) |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
75 ## expand to the available range of colors |
17506 | 76 C = floor ((C - 1) * (size_cmap - 1) / (size_T - 1)) + 1; |
14514 | 77 endif |
78 else | |
79 C = reg{3}; | |
80 if (! isvector (C) || size_T != length (C)) | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
81 error ("tetramesh: C must be a vector of the same length as T"); |
14514 | 82 endif |
83 endif | |
84 | |
17506 | 85 hax = newplot (); |
86 | |
87 hvec = zeros (size_T, 1); | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
88 if (strcmp (graphics_toolkit (), "gnuplot")) |
17506 | 89 ## Tiny reduction of the tetrahedron size to help gnuplot by |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
90 ## avoiding identical faces with different colors |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
91 for i = 1:size_T |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
92 [th, p] = __shrink__ ([1 2 3 4], X(T(i, :), :), 1 - 1e-7); |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
93 hvec(i) = patch ("Faces", th, "Vertices", p, |
17506 | 94 "FaceColor", cmap(C(i), :), "FaceAlpha", 0.9, |
95 prop{:}); | |
14514 | 96 endfor |
97 else | |
17506 | 98 ## FLTK does not support FaceAlpha. |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
99 for i = 1:size_T |
14514 | 100 th = [1 2 3; 2 3 4; 3 4 1; 4 1 2]; |
19790
446c46af4b42
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
17744
diff
changeset
|
101 hvec(i) = patch ("Faces", th, "Vertices", X(T(i, :), :), |
17506 | 102 "FaceColor", cmap(C(i), :), "FaceAlpha", 1.0, |
103 prop{:}); | |
14514 | 104 endfor |
105 endif | |
106 | |
17506 | 107 if (! ishold ()) |
108 set (hax, "view", [-37.5, 30], "box", "off"); | |
109 endif | |
110 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
111 if (nargout > 0) |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
112 h = hvec; |
14514 | 113 endif |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
114 |
14514 | 115 endfunction |
116 | |
117 ## shrink the tetrahedron relative to its center of gravity | |
118 function [tri, p] = __shrink__ (T, X, sf) | |
119 midpoint = repmat (sum (X(T, :), 1) / 4, 12, 1); | |
120 p = [X([1 2 3], :); X([2 3 4], :); X([3 4 1], :); X([4 1 2], :)]; | |
121 p = sf * (p - midpoint) + midpoint; | |
122 tri = reshape (1:12, 3, 4)'; | |
123 endfunction | |
124 | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
125 |
14514 | 126 %!demo |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
127 %! clf; |
14514 | 128 %! d = [-1 1]; |
129 %! [x,y,z] = meshgrid (d, d, d); | |
130 %! x = [x(:); 0]; | |
131 %! y = [y(:); 0]; | |
132 %! z = [z(:); 0]; | |
19356
ba167badef9f
Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
133 %! tetra = delaunay (x, y, z); |
14514 | 134 %! X = [x(:) y(:) z(:)]; |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
135 %! colormap (jet (64)); |
14514 | 136 %! h = tetramesh (tetra, X); |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
137 %! set (h(1:2:end), 'Visible', 'off'); |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
138 %! axis equal; |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
139 %! view (30, 20); |
17506 | 140 %! title ({'tetramesh() plot', ... |
141 %! 'colormap = jet (64), every other tetrahedron invisible'}); | |
14514 | 142 |
143 %!demo | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
144 %! clf; |
14514 | 145 %! d = [-1 1]; |
146 %! [x,y,z] = meshgrid (d, d, d); | |
147 %! x = [x(:); 0]; | |
148 %! y = [y(:); 0]; | |
149 %! z = [z(:); 0]; | |
19356
ba167badef9f
Deprecate delaunay3 and extend delaunay to 3-D inputs.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 %! tetra = delaunay (x, y, z); |
14514 | 151 %! X = [x(:) y(:) z(:)]; |
152 %! colormap (gray (256)); | |
16828
ddac88d32d6a
Make demos in plot m-files compatible with Matlab for running comparison script.
Rik <rik@octave.org>
parents:
14872
diff
changeset
|
153 %! tetramesh (tetra, X, 21:20:241, 'EdgeColor', 'w'); |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
154 %! axis equal; |
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
155 %! view (30, 20); |
17506 | 156 %! title ({'tetramesh() plot', ... |
157 %! 'colormap = gray (256) with white edges'}); | |
14541
759944521fd6
Improve tetramesh docstring and add function to manual.
Rik <octave@nomad.inbox5.com>
parents:
14514
diff
changeset
|
158 |