From: Jonathan S. <jjs...@us...> - 2005-06-19 03:31:59
|
Update of /cvsroot/octaviz/octaviz/Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15853 Modified Files: vtk_axis.m vtk_scalarbar.m Added Files: vtk_xlabel.m vtk_xlim.m vtk_ylabel.m vtk_ylim.m vtk_zlabel.m vtk_zlim.m Log Message: new and improved axes functions --- NEW FILE: vtk_zlim.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_zlim([@var{zlimits}]) ## ## Set z-axis limits for plots. ## ## The argument @var{zlimits} should be a 2 element vector, [zmin, zmax]. ## ## @end deftypefn ## @seealso{vtk_axis,vtk_xlim,vtk_ylim,vtk_zlabel,vtk_scalarbar} ## Author: Jonathan Stickel function vtk_zlim(zlimits) f = vtk_figure(0); if (f.axes.GetUseRanges) limits = f.axes.GetRanges; else limits = f.outline.GetBounds; endif limits(5:6) = zlimits; vtk_axis(limits); endfunction Index: vtk_scalarbar.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_scalarbar.m,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- vtk_scalarbar.m 31 Mar 2005 17:40:21 -0000 1.5 +++ vtk_scalarbar.m 19 Jun 2005 03:31:50 -0000 1.6 @@ -25,6 +25,9 @@ ## Author: Jonathan Stickel +## bugs / todo: +## - doesn't seem to work after vtk_axis(LIMITS) has been used + function vtk_scalarbar(scalarname) --- NEW FILE: vtk_zlabel.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_xlabel (@var{string}) ## @deftypefnx {Function File} {} vtk_ylabel (@var{string}) ## @deftypefnx {Function File} {} vtk_zlabel (@var{string}) ## Specify x, y, and z axis labels for the plot. ## @end deftypefn ## ## @seealso{vtk_title,vtk_scalarbar,vtk_axis,vtk_xlim} ## Author: Jonathan Stickel function vtk_zlabel(string) f = vtk_figure(0); f.axes.SetZLabel(string) vtk_update(f); endfunction --- NEW FILE: vtk_ylabel.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_xlabel (@var{string}) ## @deftypefnx {Function File} {} vtk_ylabel (@var{string}) ## @deftypefnx {Function File} {} vtk_zlabel (@var{string}) ## Specify x, y, and z axis labels for the plot. ## @end deftypefn ## ## @seealso{vtk_title,vtk_scalarbar,vtk_axis,vtk_xlim} ## Author: Jonathan Stickel function vtk_ylabel(string) f = vtk_figure(0); f.axes.SetYLabel(string) vtk_update(f); endfunction --- NEW FILE: vtk_ylim.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_ylim([@var{ylimits}]) ## ## Set y-axis limits for plots. ## ## The argument @var{ylimits} should be a 2 element vector, [ymin, ymax]. ## ## @end deftypefn ## @seealso{vtk_axis,vtk_xlim,vtk_zlim,vtk_ylabel,vtk_scalarbar} ## Author: Jonathan Stickel function vtk_ylim(ylimits) f = vtk_figure(0); if (f.axes.GetUseRanges) limits = f.axes.GetRanges; else limits = f.outline.GetBounds; endif limits(3:4) = ylimits; vtk_axis(limits); endfunction --- NEW FILE: vtk_xlabel.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_xlabel (@var{string}) ## @deftypefnx {Function File} {} vtk_ylabel (@var{string}) ## @deftypefnx {Function File} {} vtk_zlabel (@var{string}) ## Specify x, y, and z axis labels for the plot. ## @end deftypefn ## ## @seealso{vtk_title,vtk_scalarbar,vtk_axis,vtk_xlim} ## Author: Jonathan Stickel function vtk_xlabel(string) f = vtk_figure(0); f.axes.SetXLabel(string) vtk_update(f); endfunction Index: vtk_axis.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_axis.m,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- vtk_axis.m 13 May 2005 05:14:31 -0000 1.10 +++ vtk_axis.m 19 Jun 2005 03:31:50 -0000 1.11 @@ -15,19 +15,38 @@ ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- -## @deftypefn {Function File} {} vtk_axis([@var{options}]) -## Right now, this can only be used to turn the axes on and off. -## Eventually this function should allow setting the scaling and limits of the axes. +## @deftypefn {Function File} {} vtk_axis([@var{limits}],[@var{options}]) +## +## Set or alter axis limits for plots. +## +## The argument @var{limits} should be a 6 element vector. The first +## and second elements specify the lower and upper limits for the x +## axis, the third and fourth specify the limits for the y axis, and the +## fifth and sixth specify the limits for the z axis. +## +## The following are valid options: +## +## @table @code +## @item "square" +## Set a square aspect ratio. +## @item "equal" +## Set x, y, and z scaling to be equal. +## @item "auto" +## Set limits so that all the data is visible. +## @item "tight" +## Take up any extra space so that the axes are "tight" around the plot. +## @item "default" +## Set axes limits and scales to vtk default ("auto" and "equal") +## @item "on" +## Turn tic marks and labels on for all axes. +## @item "off" +## Turn tic marks and labels off for all axes. +## @end table +## ## @end deftypefn -## @seealso{vtk_scalarbar} - -## Author: Jonathan Stickel, Dragan Tubic +## @seealso{vtk_xlim,vtk_xlabel,vtk_scalarbar} -## almost there... clipping now works on multiple actors, even keeping coloring correct -## to do: -## - fix inconsistency where vtk_axis(square), then vtk_axis(limits) ends up with wrong axes -## - add "tight" option? -## - update help +## Author: Jonathan Stickel function vtk_axis(varargin) @@ -36,20 +55,26 @@ for i=1:nargin arg = varargin{i}; + if isstr(arg) + if ( strcmp(arg, "on") ) f.axes_on = 1; + elseif ( strcmp(arg, "off") ) f.axes_on = 0; - elseif ( strcmp(arg, "normal") ) ## defaults in vtk - vtk_axis("auto") + + elseif ( strcmp(arg, "default") ) ## default of vtk vtk_axis("equal") + vtk_axis("auto") + elseif ( strcmp(arg, "equal") ) ## reset scaling for i = 1:f.renderer.GetActors.GetNumberOfItems-1 # outline actor is i=0 f.renderer.GetActors.GetItemAsObject(i).SetScale(1,1,1) endfor f.axes.UseRangesOff + elseif ( strcmp(arg, "square") ) vtk_axis("equal") # get to a known scale dlims = f.outline.GetBounds; @@ -61,9 +86,11 @@ for i = 1:f.renderer.GetActors.GetNumberOfItems-1 f.renderer.GetActors.GetItemAsObject(i).SetScale(1/span(1),1/span(2),1/span(3)) endfor - elseif ( strcmp(arg, "auto") ) ## reset axes bounds - ## remove any clipping... how to do this elegently? - ## this seems to be a hack, but it works; however, it may lead to a memory leak + + elseif ( strcmp(arg, "auto") ) ## reset axes bounds to limits of actors + ## first determine if square option has been used + rescale = f.axes.GetUseRanges; + ## check if there has been clipping (as determined by some actors not being visible), clipping = 0; for i = 1:f.renderer.GetActors.GetNumberOfItems-1 # vtk counting starts at 0 actor = f.renderer.GetActors.GetItemAsObject(i); @@ -72,7 +99,6 @@ break endif endfor - ## if there has been clipping (as determined by some actors not being visible), ## remove visible actors (the clipped ones) and make visible the others (unclipped) if (clipping) i = 1; @@ -87,15 +113,44 @@ ++i; endwhile endif + if (rescale) + vtk_axis("square") + endif + + elseif ( strcmp(arg, "tight") ) ## keep cuts, but otherwise bring axes tight + ## find current limits and limits for "auto" + if (f.axes.GetUseRanges) + limits1 = f.axes.GetRanges; + else + limits1 = f.outline.GetBounds; + endif + vtk_axis("auto") + if (f.axes.GetUseRanges) + limits2 = f.axes.GetRanges; + else + limits2 = f.outline.GetBounds; + endif + ## reduce, but do not expand, the limits from what they were + for i = 1:2:5 + limits(i) = max( limits1(i),limits2(i) ); + endfor + for i = 2:2:6 + limits(i) = min( limits1(i),limits2(i) ); + endfor + vtk_axis(limits) + else printf("Option '%s' is not implemented;\n", arg) disp("If you would like it to be, please contact the authors.") endif - else # force the specified axes limits - vtk_axis("auto") # return to original state + else # input is not a string; force the specified axes limits + ## first determine if square option has been used + rescale = f.axes.GetUseRanges; + ## return to original state + vtk_axis("default") ## clip everything to desired axes limits; how to do this elegently? - ## this seems to be a hack, but it works; however, it may lead to a memory leak + ## this works, but it is slow and may lead to a memory leak limits = arg; for i = 1:f.renderer.GetActors.GetNumberOfItems-1 clipmapper{i} = vtkPolyDataMapper; @@ -127,6 +182,9 @@ cornermapper.SetInput(cornerpoly); corneractor.SetMapper(cornermapper); f.renderer.AddActor(corneractor); + if (rescale) + vtk_axis("square") + endif endif endfor @@ -179,19 +237,3 @@ clippoly.Update; clippd.DeepCopy(clippoly.GetOutput); endfunction - - -## notes: -## to set arbitrary ranges on the axes -##f.axes.UseRangesOn -##f.axes.SetRanges(xl,xh,yl,yh,zl,zh) - -## to set arbitrary scaling -##f.renderer.GetProps.GetLastProp.SetScale(xscale,yscale,zscale) - - -## probably best option to implement "tight" is: -## - find current limits -## - vtk_axis("auto") -## - reduce, but do not expand, the limits from what they were (series of if statements) -## - vtk_axis(limits) --- NEW FILE: vtk_xlim.m --- ## Copyright (C) 2004 Dragan Tubic ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2, or (at your option) ## any later version. ## ## This program is distributed in the hope that it will be useful, but ## WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ## General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this file. If not, write to the Free Software Foundation, ## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ## -*- texinfo -*- ## @deftypefn {Function File} {} vtk_xlim([@var{xlimits}]) ## ## Set x-axis limits for plots. ## ## The argument @var{xlimits} should be a 2 element vector, [xmin, xmax]. ## ## @end deftypefn ## @seealso{vtk_axis,vtk_ylim,vtk_zlim,vtk_xlabel,vtk_scalarbar} ## Author: Jonathan Stickel function vtk_xlim(xlimits) f = vtk_figure(0); if (f.axes.GetUseRanges) limits = f.axes.GetRanges; else limits = f.outline.GetBounds; endif limits(1:2) = xlimits; vtk_axis(limits); endfunction |