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

Apply the same performance tweak to the ellipse plot.

We plot all ellipses as single patch, but this time we color the
vertices. A bit different, but still very instructive. It also turns
out it works very well. Also simplifies and shortens the code.
parent e2438272
......@@ -64,7 +64,7 @@ classdef deproj
hts = plot_values_contour( obj, values, ax )
% Plot the tissue with cells as ellipses, colored by the specified values.
hts = plot_values_ellipse( obj, values, cmap, ax, min_val_col, max_val_col )
hts = plot_values_ellipse( obj, values, ax )
end
......
......@@ -10,13 +10,13 @@ function [ hf, ax1, ax2 ] = figure_cell_elongation( obj, scale_bar_length )
%% Direction.
ax1 = subplot( 2, 1, 1 );
cmap1 = 'hsv';
colormap( cmap1 )
colormap( 'hsv' )
hold on
axis equal
values1 = rad2deg( [ obj.epicells.proj_direction ]' );
obj.plot_values_ellipse( values1, cmap1, ax1, -90, 90 );
obj.plot_values_ellipse( values1, ax1 );
set( ax1, 'CLim', [ -90 90 ] )
axis( ax1, 'off' )
colorbar( ax1 )
......@@ -31,8 +31,9 @@ function [ hf, ax1, ax2 ] = figure_cell_elongation( obj, scale_bar_length )
axis equal
values2 = [ obj.epicells.eccentricity ]';
cmap2 = 'parula';
obj.plot_values_ellipse( values2, cmap2, ax2, 0, 1 );
obj.plot_values_ellipse( values2, ax2 );
set( ax2, 'CLim', [ 0 1 ] )
colormap(ax2, 'parula' );
axis( ax2, 'off' )
colorbar( ax2 )
......@@ -42,8 +43,7 @@ function [ hf, ax1, ax2 ] = figure_cell_elongation( obj, scale_bar_length )
add_plot_scalebar( obj, scale_bar_length, ax2 );
linkaxes( [ ax1 ax2 ] )
end
function hts = plot_values_ellipse( obj, values, cmap, ax, min_val_col, max_val_col )
function hts = plot_values_ellipse( obj, values, ax )
%PLOT_VALUES_ELLIPSE Plot the tissue with cells as ellipses, colored by the specified values.
%
% INPUTS:
......@@ -7,64 +7,53 @@ function hts = plot_values_ellipse( obj, values, cmap, ax, min_val_col, max_val_
%
% values - a N x 1 array with values to use for coloring.
%
% cmap - the color-map to use for coloring. Optional, default value id
% the parula colormap.
%
% ax - the axes to plot in. Optional, default is current axes.
%
% min_val_col - min value to generate color. Optional, default is the
% minimal value of the specified values.
%
% max_val_col - max value to generate color. Optional, default is the
% maximal value of the specified values.
%
% OUTPUT:
%
% a 2N x 1 array of handles to the ellipse and major-axis line objects.
% the handle to the ellipse patch object.
%
epicells = obj.epicells;
n_objects = numel( epicells );
hts = NaN( 2 * n_objects, 1 );
minv = min( values );
maxv = max( values );
if nargin < 3
cmap = 'parula';
end
if nargin < 4
ax = gca;
end
if nargin < 5
min_val_col = minv;
end
if nargin < 6
max_val_col = maxv;
end
colors = colormap( ax, cmap );
n_points = 21;
X = zeros( n_points + 2, n_objects );
Y = zeros( n_points + 2, n_objects );
Z = zeros( n_points + 2, n_objects );
V = zeros( ( n_points + 2 ) * n_objects, 1 );
if n_objects > 1000, lw = 1; else, lw = 2; end
idx = @(v) 1 + round( (v - min_val_col)/(max_val_col - min_val_col) * ( size( colors, 1 ) - 1 ) );
index = 1;
mid = ceil( n_points / 2 );
for i = 1 : n_objects
o = epicells( i );
h1 = o.plot_ellipse_3d( 23, ax );
h2 = o.plot_ellipse_3d( 3, ax );
p = o.get_ellipse_points( n_points );
xp = p( :, 1 );
yp = p( :, 2 );
zp = p( :, 3 );
hts( 2 * i - 1 ) = h1;
hts( 2 * i ) = h2;
val = values( i );
j = idx( val );
j = max( [ 1 j ] );
j = min( [ size( colors, 1 ) j ] );
set( [ h1 h2 ], ...
'Color', colors( j, : ), ...
'LineWidth', lw )
end
X( 1 : n_points + 2, i ) = [ xp ; xp( mid ) ];
Y( 1 : n_points + 2, i ) = [ yp ; yp( mid ) ];
Z( 1 : n_points + 2, i ) = [ zp ; zp( mid ) ];
V( index : index + n_points + 1 ) = values( i );
index = index + n_points + 2;
set( ax, 'CLim', [ min_val_col max_val_col ] )
end
hts = patch( ...
'XData', X, ...
'YData', Y, ...
'ZData', Z, ...
'FaceVertexCData', V, ...
'EdgeColor', 'flat', ...
'FaceColor', 'none', ...
'LineWidth', lw, ...
'Parent', ax );
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