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

Change the input of functions.

Now we work more like a class with methods.
parent 49028dd1
......@@ -146,15 +146,15 @@ for i = 1 : n_objects
o = objects( i );
area = area3d( o.boundary );
perim = perimeter3d( o.boundary );
[ area, uncorr_area ] = area3d( o );
[ perim, uncorr_perim ] = perimeter3d( o );
objects( i ).area = area;
objects( i ).perimeter = perim;
uncorr = struct();
uncorr.area = polyarea( o.boundary(:,1), o.boundary(:,2) );
uncorr.perimeter = perimeter3d( o.boundary( :, 1:2 ) );
uncorr.area = uncorr_area;
uncorr.perimeter = uncorr_perim;
objects( i ).uncorr = uncorr;
end
......
function area = area3d( p )
%AREA3D Computes the area of a 3D closed polygon.
% p must be a Nx3 matrix.
function [ area, uncorr_area ] = area3d( o )
%AREA3D Computes the area of the object.
%% Deprojected 3D version.
p = o.boundary;
n_vertices = size( p, 1 );
......@@ -25,7 +28,14 @@ function area = area3d( p )
% Total positive area.
area = sum( area_triangle ) / 2;
%% 2D area.
uncorr_area = polyarea( o.boundary(:,1), o.boundary(:,2) );
%% Subfunction.
function n = euclidean_norm( v )
n = sqrt( sum( v .* v, ndims( v ) ) );
end
......
function perim = perimeter3d( p )
function [ perim, uncorr_perim ] = perimeter3d( o )
%PERIMETER3D Perimeter of a closed N-dimensional polygon.
% p can be a N x d matrix, with d being the dimensionality.
p2 = [ p ; p( 1, : ) ];
p_diff = diff( p2 );
perim = compute_perim( o.boundary );
uncorr_perim = compute_perim( o.boundary( : , 1:2 ) );
p_diff_2 = p_diff .* p_diff;
p_diff_2_sum = sum( p_diff_2, 2 );
sls = sqrt( p_diff_2_sum );
perim = sum( sls );
%% Subfunction
function l_perim = compute_perim( p )
% p can be a N x d matrix, with d being the dimensionality.
p2 = [ p ; p( 1, : ) ];
p_diff = diff( p2 );
p_diff_2 = p_diff .* p_diff;
p_diff_2_sum = sum( p_diff_2, 2 );
sls = sqrt( p_diff_2_sum );
l_perim = sum( sls );
end
end
Supports Markdown
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