One of the most useful mechanism in matlab are the handlers and the properties that can be accessed with get/set. I would be nice if octaviz could do something similar. I would like to share some thoughts about this could be implemented. Here follows an example that controls the position of the colorbar.
Cheers
Alex
function h = vtk_colorbar(string)
f=vtk_figure(0);
## clear existing bar, if it exists
nprops = f.renderer.GetProps.GetNumberOfItems;
for i = 0:nprops-1;
if ( f.renderer.GetProps.GetItemAsObject(i).IsA("vtkScalarBarActor") )
f.renderer.RemoveViewProp( f.renderer.GetProps.GetItemAsObject(i) );
break
endif
endfor
if ( !strcmp(string, "remove") )
scalarBar = vtkScalarBarActor;
for i = f.renderer.GetActors.GetNumberOfItems-1:-1:0;
mapper = f.renderer.GetActors.GetItemAsObject(i).GetMapper;
## a test to see if this actor is a real object (might be corner points generated in vtk_axis)
if ( mapper.GetInput.GetNumberOfPolys ) ## will be zero if an unintersting actor
scalarBar.SetLookupTable( mapper.GetLookupTable );
break
endif
endfor
scalarBar.SetTitle( string );
scalarBar.GetPositionCoordinate.SetCoordinateSystemToNormalizedViewport;
scalarBar.GetPositionCoordinate.SetValue(0.85, 0.05);
scalarBar.SetWidth(0.15);
scalarBar.SetHeight(0.9);
scalarBar.SetLabelFormat("%1.2g");
f.renderer.AddActor2D(scalarBar);
## shadow unnecessary, and doesn't export to vector format correctly
scalarBar.GetTitleTextProperty.ShadowOff
scalarBar.GetLabelTextProperty.ShadowOff
endif
vtk_update(f);
% if requested create a handler structure with the "type" of the object
% and the corresponding vtk object.
if (nargout = 1)
h.type = 'colorbar';
h.scalarBar = scalarBar;
end
endfunction
% maps matlab properties into vtk properties
function vtk_set(h,property,value)
if strcmp(h.type,'colorbar')
if (strcmpi(property,'position'))
h.scalarBar.GetPositionCoordinate.SetValue(value(1), value(2));
h.scalarBar.SetWidth(value(3));
h.scalarBar.SetHeight(value(4));
end
%
% here will come other types like :
% elseif strcmp(h.type,'plot')
% elseif strcmp(h.type,'xlabel')
% elseif strcmp(h.type,'ylabel')
% [...]
else
warning('not jet implemented');
end
% maps vtk properties into matlab properties
function value = vtk_get(h,property)
if strcmp(h.type,'colorbar')
if (strcmpi(property,'position'))
position = h.scalarBar.GetPositionCoordinate.GetValue();
width = h.scalarBar.GetWidth();
height = h.scalarBar.GetHeight();
value = [position(1) position(2) width height];
end
else
warning('not jet implemented');
end
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Jonathan, hi Dragan
One of the most useful mechanism in matlab are the handlers and the properties that can be accessed with get/set. I would be nice if octaviz could do something similar. I would like to share some thoughts about this could be implemented. Here follows an example that controls the position of the colorbar.
Cheers
Alex
function h = vtk_colorbar(string)
f=vtk_figure(0);
## clear existing bar, if it exists
nprops = f.renderer.GetProps.GetNumberOfItems;
for i = 0:nprops-1;
if ( f.renderer.GetProps.GetItemAsObject(i).IsA("vtkScalarBarActor") )
f.renderer.RemoveViewProp( f.renderer.GetProps.GetItemAsObject(i) );
break
endif
endfor
if ( !strcmp(string, "remove") )
scalarBar = vtkScalarBarActor;
for i = f.renderer.GetActors.GetNumberOfItems-1:-1:0;
mapper = f.renderer.GetActors.GetItemAsObject(i).GetMapper;
## a test to see if this actor is a real object (might be corner points generated in vtk_axis)
if ( mapper.GetInput.GetNumberOfPolys ) ## will be zero if an unintersting actor
scalarBar.SetLookupTable( mapper.GetLookupTable );
break
endif
endfor
scalarBar.SetTitle( string );
scalarBar.GetPositionCoordinate.SetCoordinateSystemToNormalizedViewport;
scalarBar.GetPositionCoordinate.SetValue(0.85, 0.05);
scalarBar.SetWidth(0.15);
scalarBar.SetHeight(0.9);
scalarBar.SetLabelFormat("%1.2g");
f.renderer.AddActor2D(scalarBar);
## shadow unnecessary, and doesn't export to vector format correctly
scalarBar.GetTitleTextProperty.ShadowOff
scalarBar.GetLabelTextProperty.ShadowOff
endif
vtk_update(f);
% if requested create a handler structure with the "type" of the object
% and the corresponding vtk object.
if (nargout = 1)
h.type = 'colorbar';
h.scalarBar = scalarBar;
end
endfunction
% maps matlab properties into vtk properties
function vtk_set(h,property,value)
if strcmp(h.type,'colorbar')
if (strcmpi(property,'position'))
h.scalarBar.GetPositionCoordinate.SetValue(value(1), value(2));
h.scalarBar.SetWidth(value(3));
h.scalarBar.SetHeight(value(4));
end
%
% here will come other types like :
% elseif strcmp(h.type,'plot')
% elseif strcmp(h.type,'xlabel')
% elseif strcmp(h.type,'ylabel')
% [...]
else
warning('not jet implemented');
end
% maps vtk properties into matlab properties
function value = vtk_get(h,property)
if strcmp(h.type,'colorbar')
if (strcmpi(property,'position'))
position = h.scalarBar.GetPositionCoordinate.GetValue();
width = h.scalarBar.GetWidth();
height = h.scalarBar.GetHeight();
value = [position(1) position(2) width height];
end
else
warning('not jet implemented');
end
Looks good to me! You are welcome to implement this (and other handle-graphics functions) and submit them.