From: Jonathan S. <jjs...@us...> - 2005-07-24 04:35:45
|
Update of /cvsroot/octaviz/octaviz/Scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24715 Modified Files: vtk_meshc.m vtk_surfc.m Added Files: vtk_contour.m vtk_contourf.m Removed Files: vtk_contour3.m Log Message: contour function improvements --- NEW FILE: vtk_contour.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_contour(@var{x},@var{y},@var{z},[@var{prop},@var{val}]) ## Displays a contour plot defined by @var{x},@var{y},@var{z} matrices, ## where @var{x} and @var{y} are typically formed by meshgrid. ## ## Optional @var{prop},@var{val} arguments can be used to change ## properties of the plot. Currently, valid properties are ## ";NConts;". ## ## @end deftypefn ## @seealso{vtk_contourf, vtk_surf} ## Author: Dragan Tubic function vtk_contour( varargin ) valid_props = ";NConts;"; [no_numerical_params, first_prop_index, line_spec_index] = vtk_parse_params(valid_props, all_va_args); if ( first_prop_index > 0 ) properties = struct(varargin{first_prop_index:length(varargin)}); ncts = properties.NConts; # number of contours; else properties.empty = 1; ncts=10; end if ( no_numerical_params < 1 | no_numerical_params > 3 ) error("Syntax is vtk_contour( x, (y), (z))"); end if ( no_numerical_params == 1 ) z = nth (varargin,1); [nr nc] = size(z); [x y] = meshgrid(1:nr,1:nc); c = z; elseif ( no_numerical_params == 2 ) z = nth (varargin,1); [nr nc] = size(z); [x y] = meshgrid(1:nr,1:nc); c = nth (varargin,1); elseif ( no_numerical_params == 3 ) x = nth (varargin,1); y = nth (varargin,2); z = nth (varargin,3); c = z; end ## form the array that specifies connecting points [nr nc] = size(x); m=nc; n=nr; i=0:m-2; j=0:n-2; [i,j]=meshgrid(i,j); i=i(:); j=j(:); t=[i*n+j,(i+1)*n+j,(i+1)*n+(j+1) ; (i+1)*n+(j+1),i*n+(j+1),i*n+j]; x = x(:); y = y(:); z = z(:); c = c(:); vtk_init; if ( length(x) != length(y) | length(x) != length(z) | length(x) != length(c) ) error("Lengths of all three coordinates have to be the same."); end %% We'll create the building blocks of polydata including data attributes. surface = vtkPolyData(); points = vtkPoints(); polys = vtkCellArray(); scalars = vtkFloatArray(); %% Load the point, cell, and data attributes. %% for (i=0; i<8; i++) points->InsertPoint(i,x[i]); coords = vtkFloatArray; coords.SetNumberOfTuples( length(x) ); coords.SetNumberOfComponents(3); pts = [x y z]'; pts(3,:) = min(z) - max( [max(x)-min(x) max(y)-min(y) max(z)-min(z) ] )/4; #puts the contour lines in one plane coords.SetArray( pts(:), 3*length(x), 0 ); points.SetData(coords); no_tris = length(t); t = [ones(no_tris,1)*3 t]'; ptids = vtkIdTypeArray; ptids.SetArray( t(:), no_tris*4, 0 ); polys.SetCells( no_tris, ptids ); ## manually create color map table instead; a must if later add a scalar bar lut = vtkLookupTable(); lut.SetHueRange(0.66667, 0.0); lut.SetNumberOfColors(256); lut.SetRampToLinear(); lut.Build(); scalars.SetArray( c, length(c) , 0 ); %% We now assign the pieces to the vtkPolyData. surface.SetPoints(points); surface.SetPolys(polys); surface.GetPointData().SetScalars(scalars); contours = vtkContourFilter(); contours.SetInput(surface) contours.GenerateValues(ncts, min(c), max(c)) %% The contour lines are mapped to the graphics library. contMapper = vtkPolyDataMapper(); contMapper.SetInput(contours.GetOutput()) contMapper.SetLookupTable(lut); % use manually created color map table contMapper.SetScalarRange(min(c),max(c)); % relative scaling contActor = vtkActor(); contActor.SetMapper(contMapper) f = vtk_figure(0); f.renderer.AddActor(contActor); %f.axes.YAxisVisibilityOff(); # turn off the "Z" axes (but use YAxis command!?) - must be a bug, JJS 7/23/05 vtk_update(f); endfunction Index: vtk_surfc.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_surfc.m,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- vtk_surfc.m 25 Oct 2004 05:37:10 -0000 1.3 +++ vtk_surfc.m 24 Jul 2005 04:35:31 -0000 1.4 @@ -26,7 +26,7 @@ ## ";Opacity;Color;NConts;". ## ## @end deftypefn -## @seealso{vtk_surf, vtk_contour3, vtk_meshc} +## @seealso{vtk_surf, vtk_contour, vtk_meshc} ## Author: Jonathan Stickel @@ -68,14 +68,14 @@ error("input has to be at least 2xN or Nx2 matrix"); end - ## complicated assessment of passed properties in order to call vtk_surf and vtk_contour3 correctly... + ## complicated assessment of passed properties in order to call vtk_surf and vtk_contour correctly... if ( first_prop_index > 0 ) properties = struct(varargin{first_prop_index:length(varargin)}); if isfield(properties,"NConts") - vtk_contour3(x,y,z,c,"NConts",properties.NConts) + vtk_contour(x,y,z,"NConts",properties.NConts) properties = rmfield(properties,"NConts"); else - vtk_contour3(x,y,z,c); + vtk_contour(x,y,z); endif if size(fieldnames(properties),1) # returns 0 if no fieldnames @@ -94,11 +94,11 @@ endif else - vtk_contour3(x,y,z,c); + vtk_contour(x,y,z); vtk_surf(x,y,z,c); endif f = vtk_figure(0); - f.axes.YAxisVisibilityOn(); # turn back on the "Z" axes (vtk_contour3 call turns it off) + f.axes.YAxisVisibilityOn(); # turn back on the "Z" axes (vtk_contour call turns it off) endfunction --- vtk_contour3.m DELETED --- --- NEW FILE: vtk_contourf.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_contourf(@var{x},@var{y},@var{z},[@var{prop},@var{val}]) ## Displays a filled contour plot defined by @var{x},@var{y},@var{z} matrices, ## where @var{x} and @var{y} are typically formed by meshgrid. ## ## Optional @var{prop},@var{val} arguments can be used to change ## properties of the plot. Currently, valid properties are ## ";NConts;". ## ## @end deftypefn ## @seealso{vtk_contour, vtk_surf} ## Author: Dragan Tubic, Jonathan Stickel ## TBD: allow options for the contour lines through the line spec interface function vtk_contourf( varargin ) valid_props = ";NConts;"; [no_numerical_params, first_prop_index, line_spec_index] = vtk_parse_params(valid_props, all_va_args); if ( first_prop_index > 0 ) properties = struct(varargin{first_prop_index:length(varargin)}); ncts = properties.NConts; # number of contours; else properties.empty = 1; ncts=10; end if ( no_numerical_params < 1 | no_numerical_params > 3 ) error("Syntax is vtk_contourf( x, (y), (z))"); end if ( no_numerical_params == 1 ) z = nth (varargin,1); [nr nc] = size(z); [x y] = meshgrid(1:nr,1:nc); c = z; elseif ( no_numerical_params == 2 ) z = nth (varargin,1); [nr nc] = size(z); [x y] = meshgrid(1:nr,1:nc); c = nth (varargin,1); elseif ( no_numerical_params == 3 ) x = nth (varargin,1); y = nth (varargin,2); z = nth (varargin,3); c = z; end [nr nc] = size(x); if ( nr < 2 | nc < 2 ) error("input has to be at least 2xN or Nx2 matrix"); end ## make a contour plot with black contour lines if ( first_prop_index > 0 ) properties = struct(varargin{first_prop_index:length(varargin)}); vtk_contour(x,y,z,"NConts",properties.NConts) else vtk_contour(x,y,z); endif f = vtk_figure(0); ctractor = f.renderer.GetActors.GetLastActor; ctractor.GetMapper.ScalarVisibilityOff ctractor.GetProperty().SetColor( 0, 0, 0 ) ## now make a surface plot with z axis the same level as the contour render plane ctrbnds = ctractor.GetMapper.GetInput.GetBounds; z = (ctrbnds(end)+0.01*ctrbnds(end))*ones(size(z)); m = nc; n=nr; i = 0:m-2; j = 0:n-2; [i,j] = meshgrid(i,j); i = i(:); j = j(:); ## t = [i*n+j,i*n+(j+1),(i+1)*n+(j+1) ; (i+1)*n+(j+1),(i+1)*n+j,i*n+j]; %1; one way to construct the triangles t = [i*n+j,(i+1)*n+j,(i+1)*n+(j+1) ; (i+1)*n+(j+1),i*n+(j+1),i*n+j]; %2; another way, seems a bit better ## could pass some properties to surf, e.g. opacity; this tbd, JJS 7/23/05 ##if ( first_prop_index > 0 ) ## f = vtk_trisurf(t+1,x(:),y(:),z(:),c(:),varargin{first_prop_index:length(varargin)}); ##else f = vtk_trisurf(t+1,x(:),y(:),z(:),c(:)); ##end endfunction Index: vtk_meshc.m =================================================================== RCS file: /cvsroot/octaviz/octaviz/Scripts/vtk_meshc.m,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- vtk_meshc.m 25 Oct 2004 05:37:10 -0000 1.1 +++ vtk_meshc.m 24 Jul 2005 04:35:31 -0000 1.2 @@ -26,7 +26,7 @@ ## ";BallRadius;LineRadius;Fancy;NConts;". ## ## @end deftypefn -## @seealso{vtk_mesh, vtk_contour3, vtk_surfc} +## @seealso{vtk_mesh, vtk_contour, vtk_surfc} ## Author: Jonathan Stickel @@ -68,14 +68,14 @@ error("input has to be at least 2xN or Nx2 matrix"); end - ## complicated assessment of passed properties in order to call vtk_mesh and vtk_contour3 correctly... + ## complicated assessment of passed properties in order to call vtk_mesh and vtk_contour correctly... if ( first_prop_index > 0 ) properties = struct(varargin{first_prop_index:length(varargin)}); if isfield(properties,"NConts") - vtk_contour3(x,y,z,c,"NConts",properties.NConts) + vtk_contour(x,y,z,"NConts",properties.NConts) properties = rmfield(properties,"NConts"); else - vtk_contour3(x,y,z,c); + vtk_contour(x,y,z); endif if size(fieldnames(properties),1) # returns 0 if no fieldnames @@ -98,11 +98,11 @@ endif else - vtk_contour3(x,y,z,c); + vtk_contour(x,y,z); vtk_mesh(x,y,z,c); endif f = vtk_figure(0); - f.axes.YAxisVisibilityOn(); # turn back on the "Z" axes (vtk_contour3 call turns it off) + f.axes.YAxisVisibilityOn(); # turn back on the "Z" axes (vtk_contour call turns it off) endfunction |