Commit e2438272 authored by Jean-Yves TINEVEZ's avatar Jean-Yves TINEVEZ
Browse files

Greatly improve the performance of plotting and responsiveness of plots.

We now plot the cell many contours as a single patch object relying
on the special low-level syntax of patch.
parent 74d27a59
......@@ -31,6 +31,9 @@ classdef deproj
% Returns the faces and vertices of a deproj collection.
[ V, F ] = to_vertices_and_faces( obj )
% Returns the cells boundary polygons as 3 matrices padded by NaNs.
[ X, Y, Z ] = to_matrices( obj )
%% Generate figures.
% Figure with the local tissue orientation for a collection of epicells.
......
......@@ -5,22 +5,24 @@ function hts = plot_values_contour( obj, values, ax )
% obj: a deproj object, with N epicells.
% values - a N x 1 array with values to use for coloring.
% ax - the axes to plot in.
%
%
% OUTPUT:
% a N x 1 array of handles to the cell polygon objects.
% the handle to the cells patch object.
epicells = obj.epicells;
boundaries = { epicells.boundary };
n_objects = numel( boundaries );
hts = NaN( n_objects, 1 );
n_objects = numel( boundaries );
if n_objects > 1000, lw = 1; else, lw = 2; end
for i = 1 : n_objects
p = boundaries{ i };
val = values( i );
hts(i ) = patch( ax, p(:,1), p(:,2), p(:,3), val, ...
'LineWidth', lw );
end
[ X, Y, Z ] = obj.to_matrices();
hts = patch( ...
'XData', X, ...
'YData', Y, ...
'ZData', Z, ...
'FaceVertexCData', values, ...
'FaceColor', 'flat', ...
'LineWidth', lw, ...
'Parent', ax );
end
function [ X, Y, Z ] = to_matrices( obj )
%TO_MATRICES Returns the cells boundary polygons as 3 matrices padded by NaNs.
n_obj = numel( obj.epicells );
boundaries = { obj.epicells.boundary }';
n_points = cellfun( @(c) size(c,1), boundaries );
max_n_poins = max( n_points );
% 1 column per polygon.
X = zeros( max_n_poins + 1, n_obj );
Y = zeros( max_n_poins + 1, n_obj );
Z = zeros( max_n_poins + 1, n_obj );
for i = 1 : n_obj
P = boundaries{ i };
np = n_points(i);
X( 1 : np, i ) = P( : , 1 );
Y( 1 : np, i ) = P( : , 2 );
Z( 1 : np, i ) = P( : , 3 );
X( np + 1 : end, i ) = P( 1 , 1 );
Y( np + 1 : end, i ) = P( 1 , 2 );
Z( np + 1 : end, i ) = P( 1 , 3 );
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment