Skip to content

Commit

Permalink
used signed distance
Browse files Browse the repository at this point in the history
  • Loading branch information
alecjacobson committed Jan 13, 2016
1 parent 1b95bb6 commit 0ad46f8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
36 changes: 33 additions & 3 deletions mesh/sample_interior.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
function C = sample_interior(V,F,n)
function [C,D] = sample_interior(V,F,n,varargin)
% SAMPLE_INTERIOR Sample the interior of a solid bounded by the triangle
% mesh (V,F)
%
% C = sample_interior(V,F,n)
% C = sample_interior(V,F,n,...)
%
% Inputs:
% V #V by 3 list of mesh vertex positions
% F #F by 3 list of triangle indices into V
% n number of samples
% Optional:
% 'MinDist' followed by minimum distance inside mesh, negative implies that
% it's OK to be outside by that much.
% Output:
% C n by 3 list of samples
%
%

% SAMPLE_BOUNDING_BOX Smample the interour of the bounding box of V
Expand All @@ -22,10 +29,33 @@
C = bsxfun(@plus, bsxfun(@times,rand(n,3),max(V)-min(V)),min(V));
end

% default values
% Map of parameter names to variable names
min_dist = 0;
params_to_variables = containers.Map( ...
{'MinDist'}, ...
{'min_dist'});
v = 1;
while v <= numel(varargin)
param_name = varargin{v};
if isKey(params_to_variables,param_name)
assert(v+1<=numel(varargin));
v = v+1;
% Trick: use feval on anonymous function to use assignin to this workspace
feval(@()assignin('caller',params_to_variables(param_name),varargin{v}));
else
error('Unsupported parameter: %s',varargin{v});
end
v=v+1;
end

out = 1:n;
while ~isempty(out)
C(out,:) = sample_bounding_box(V,numel(out));
w_out = winding_number(V,F,C(out,:));
out = out(abs(w_out)<0.5);
%w_out = winding_number(V,F,C(out,:));
%out = out(abs(w_out)<0.5);
% Negative is outside
D(out) = -signed_distance(C(out,:),V,F);
out = out(D(out)<min_dist);
end
end
2 changes: 1 addition & 1 deletion mex/signed_distance.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
% 'SignedDistanceType' followed by
% 'winding_number' use winding number (continuous sign value for
% non-watertight)
% 'pseudonormal' use pseudo-normal, binary scale (but not robust for
% {'pseudonormal'} use pseudo-normal, binary scale (but not robust for
% non-watertight meshes.
% Outputs:
% S #P list of smallest signed distances
Expand Down

0 comments on commit 0ad46f8

Please sign in to comment.