changeset 17506:1ccff59592f0

tetramesh.m: Overhaul function. * scripts/plot/tetramesh.m: Call newplot() before adding patches. Set FaceAlpha property to 0.9 (for gnuplot which supports transparency). Set 3-D viewpoint and turn plot box off. Rename variable colmap to cmap.
author Rik <rik@octave.org>
date Fri, 27 Sep 2013 11:24:52 -0700
parents 3dcd7fb9945d
children 87a4abf72726
files scripts/plot/tetramesh.m
diffstat 1 files changed, 25 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/plot/tetramesh.m	Fri Sep 27 09:57:18 2013 -0700
+++ b/scripts/plot/tetramesh.m	Fri Sep 27 11:24:52 2013 -0700
@@ -60,21 +60,20 @@
   X = reg{2};
 
   if (! ismatrix (T) || columns (T) != 4)
-    error ("tetramesh: T must be a n-by-4 matrix");
-  endif
-  if (! ismatrix (X) || columns (X) != 3)
-    error ("tetramesh: X must be a n-by-3 matrix");
+    error ("tetramesh: T must be an n-by-4 matrix");
+  elseif (! ismatrix (X) || columns (X) != 3)
+    error ("tetramesh: X must be an n-by-3 matrix");
   endif
 
   size_T = rows (T);
-  colmap = colormap ();
+  cmap = colormap ();
   
   if (length (reg) < 3)
-    size_colmap = rows (colmap);
-    C = mod ((1:size_T)' - 1, size_colmap) + 1;
-    if (size_T < size_colmap && size_T > 1) 
+    size_cmap = rows (cmap);
+    C = mod ((1:size_T)' - 1, size_cmap) + 1;
+    if (size_T < size_cmap && size_T > 1) 
       ## expand to the available range of colors
-      C = floor ((C - 1) * (size_colmap - 1) / (size_T - 1)) + 1;
+      C = floor ((C - 1) * (size_cmap - 1) / (size_T - 1)) + 1;
     endif
   else
     C = reg{3};
@@ -83,23 +82,32 @@
     endif
   endif
 
-  h = zeros (1, size_T);
+  hax = newplot ();
+
+  hvec = zeros (size_T, 1);
   if (strcmp (graphics_toolkit (), "gnuplot"))
-    ## tiny reduction of the tetrahedron size to help gnuplot by
+    ## Tiny reduction of the tetrahedron size to help gnuplot by
     ## avoiding identical faces with different colors
     for i = 1:size_T
       [th, p] = __shrink__ ([1 2 3 4], X(T(i, :), :), 1 - 1e-7);
       hvec(i) = patch ("Faces", th, "Vertices", p, 
-                       "FaceColor", colmap(C(i), :), prop{:});
+                       "FaceColor", cmap(C(i), :), "FaceAlpha", 0.9,
+                       prop{:});
     endfor
   else
+    ## FLTK does not support FaceAlpha.
     for i = 1:size_T
       th = [1 2 3; 2 3 4; 3 4 1; 4 1 2];
       hvec(i) = patch ("Faces", th, "Vertices", X(T(i, :), :), 
-                       "FaceColor", colmap(C(i), :), prop{:});
+                       "FaceColor", cmap(C(i), :), "FaceAlpha", 1.0,
+                       prop{:});
     endfor
   endif
 
+  if (! ishold ())
+    set (hax, "view", [-37.5, 30], "box", "off");
+  endif
+
   if (nargout > 0)
     h = hvec;
   endif
@@ -129,7 +137,8 @@
 %! set (h(1:2:end), 'Visible', 'off');
 %! axis equal;
 %! view (30, 20);
-%! title ('Using jet (64), every other tetrahedron invisible');
+%! title ({'tetramesh() plot', ...
+%!         'colormap = jet (64), every other tetrahedron invisible'});
 
 %!demo
 %! clf;
@@ -144,5 +153,6 @@
 %! tetramesh (tetra, X, 21:20:241, 'EdgeColor', 'w');
 %! axis equal;
 %! view (30, 20);
-%! title ('Using gray (256) and white edges');
+%! title ({'tetramesh() plot', ...
+%!         'colormap = gray (256) with white edges'});