From: Jonathan S. <jjs...@us...> - 2005-05-11 05:11:58
|
Update of /cvsroot/octaviz/octaviz/Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv586 Modified Files: vtk_axis.m vtk_trisurf.m Log Message: clipping now works with vtk_axis(limits) Index: vtk_trisurf.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_trisurf.m,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- vtk_trisurf.m 7 Mar 2005 02:05:00 -0000 1.8 +++ vtk_trisurf.m 11 May 2005 05:11:49 -0000 1.9 @@ -151,7 +151,7 @@ ptids.SetArray( t(:), no_tris*4, 0 ); polys.SetCells( no_tris, ptids ); - ##in VTK, by default red = low values, blue - high values; we reverse that here + ##in VTK, by default red = low values, blue = high values; we reverse that here ##c=-c; ## manually create color map table instead; a must if later add a scalar bar lut = vtkLookupTable(); Index: vtk_axis.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_axis.m,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- vtk_axis.m 8 May 2005 00:47:32 -0000 1.8 +++ vtk_axis.m 11 May 2005 05:11:49 -0000 1.9 @@ -21,7 +21,15 @@ ## @end deftypefn ## @seealso{vtk_scalarbar} -## Author: Dragan Tubic +## Author: Jonathan Stickel, Dragan Tubic + +## almost there... clipping now works on multiple actors, even keeping coloring correct +## to do: +## - "equal"/"normal" and "square" to work on multiple actors (easy to do) +## - force axes wider when wider limits are specified (i.e. not "tight") +## - add "tight" option +## - update help + function vtk_axis(varargin) @@ -34,29 +42,6 @@ f.axes_on = 1; elseif ( strcmp(arg, "off") ) f.axes_on = 0; - - elseif ( strcmp(arg, "auto") ) ## reset axes bounds - ## (working with just one Prop for now) - ## remove any clipping... how to do this elegently? - clipping = 0; - for i = 2:f.renderer.GetActors.GetNumberOfItems - actor = f.renderer.GetActors.GetItemAsObject(i-1); - if (!actor.GetVisibility) - clipping = 1; # maybe add this as a structure to figure, so don't need to test here - 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) - for i = 2:f.renderer.GetActors.GetNumberOfItems - actor = f.renderer.GetActors.GetLastActor; - if (actor.GetVisibility) - f.renderer.RemoveViewProp(actor); - else - actor.VisibilityOn - endif - endfor - endif elseif ( strcmp(arg, "equal") || strcmp(arg, "normal") ) ## defaults in vtk ## (working with just one Prop for now) @@ -73,21 +58,52 @@ ## scale the plot so that it is square ## (working with just one Prop for now) f.renderer.GetProps.GetLastProp.SetScale(1/span(1),1/span(2),1/span(3)) + + 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 + clipping = 0; + for i = 1:f.renderer.GetActors.GetNumberOfItems-1 # vtk counting starts at 0 + actor = f.renderer.GetActors.GetItemAsObject(i); + if (!actor.GetVisibility) + clipping = 1; # maybe add this as a structure to vtk_figure, so don't need to test here + 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; + while i < f.renderer.GetActors().GetNumberOfItems(); + actor = f.renderer.GetActors.GetItemAsObject(i); + if (actor.GetVisibility) + f.renderer.RemoveViewProp(actor); + --i; + else + actor.VisibilityOn + endif + ++i; + endwhile + endif endif - + else ## clip everything to desired axes limits - ##disp("manual setting of axis bounds not implemented yet") - ## attempt at clipping (only one Actor for now) + ## how to do this elegently? + ## this seems to be a hack, but it works; however, it may lead to a memory leak limits = arg; - clippd = clipaxes(f.renderer.GetActors.GetLastActor.GetMapper.GetInput,limits); - ## this doesn't work because you can't recover original! - ##f.renderer.GetActors.GetLastActor.GetMapper.SetInput(clippoly.GetOutput); - clipmapper = vtkPolyDataMapper; - clipmapper.SetInput(clippd); - clipactor = vtkActor; - clipactor.SetMapper(clipmapper); - f.renderer.GetActors.GetLastActor.VisibilityOff; # turn unclipped actor off - f.renderer.AddActor(clipactor); + nactors = f.renderer.GetActors().GetNumberOfItems(); + for i = 1:nactors-1 # outline actor is i=0 + clipmapper{i} = vtkPolyDataMapper; + clipactor{i} = vtkActor; + unclipactor = f.renderer.GetActors.GetItemAsObject(i); + clipactor{i}.ShallowCopy(unclipactor); # copy actor properties (e.g. color) + clipmapper{i}.ShallowCopy(unclipactor.GetMapper); # copy mapper properties (e.g. lookup table) + unclipactor.VisibilityOff; # turn unclipped actor off + clippd{i} = clipaxes(clipactor{i}.GetMapper.GetInput, limits); + clipmapper{i}.SetInput(clippd{i}); + clipactor{i}.SetMapper(clipmapper{i}); + f.renderer.AddActor(clipactor{i}); + endfor endif endfor @@ -101,7 +117,6 @@ clippoly = vtkClipPolyData; clippoly.SetClipFunction(plane); clippd = vtkPolyData; - ##clippoly.GenerateClipScalarsOff(); clippoly.GenerateClippedOutputOn(); ## clip xlow @@ -150,8 +165,3 @@ ## to set arbitrary scaling ##f.renderer.GetProps.GetLastProp.SetScale(xscale,yscale,zscale) - -## to get at the polydata input of the last actor; hopefully I can then clip it -#f.renderer.GetActors.GetLastActor.GetMapper.GetInput - -## can add more inputs (i.e. from other actors) to vtkClipPolyData with AddInput command? \ No newline at end of file |