Skip to content

Commit

Permalink
update docs, error handling in chunkerinterior
Browse files Browse the repository at this point in the history
  • Loading branch information
askhamwhat committed May 31, 2024
1 parent d1b8c8b commit 6d207a0
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 29 deletions.
10 changes: 6 additions & 4 deletions chunkie/chunkerinterior.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@
grid = true;
[xx,yy] = meshgrid(x,y);
pts = [xx(:).'; yy(:).'];
elseif isa(ptsobj, "chunker")
elseif isa(ptsobj, "chunker") || isa(ptsobj, "chunkgraph") || ...
(isstruct(ptsobj) && isfield(ptsobj,"r"))
pts = ptsobj.r(:,:);
elseif isa(ptsobj, "chunkgraph")
pts = ptsobj.r(:,:);
else
elseif isnumeric(ptsobj)
pts = ptsobj;
else
msg = "chunkerinterior: input 2 not a recognized type";
error(msg);
end


Expand Down
51 changes: 26 additions & 25 deletions chunkie/chunkgraphinregion.m
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
function [ids] = chunkgraphinregion(chnkobj,ptsobj,opts)
%CHUNKERINTERIOR returns an array indicating whether each point specified
% % by pts is inside the domain. Assumes the domain is closed.
function [ids] = chunkgraphinregion(cg,ptsobj,opts)
%CHUNKGRAPHINREGION returns an array indicating the region number for
% each point specified by pts.
%
% Syntax: in = chunkerinterior(chnkobj,pts,opts)
% in = chunkerinterior(chnkobj,{x,y},opts) % meshgrid version
% Syntax: ids = chunkerinterior(cg,pts,opts)
% ids = chunkerinterior(cg,{x,y},opts) % meshgrid version
%
% Input:
% chnkobj - chunker object or chunkgraph object describing geometry
% cg - chunkgraph object describing geometry
% ptsobj - object describing the target points, can be specified as
% * (chnkr.dim,:) array of points to test
% * (cg.echnks(1).dim,:) array of points to test
% * {x,y} - length 2 cell array. the points checked then have the
% coordinates of a mesh grid [xx,yy] = meshgrid(x,y)
% * chunker object, in which case it uses chunker.r(:,:)
% * chunkgraph object, in which case it uses chunkgraph.r(:,:)
% * chunker object, in which case it uses ptsobj.r(:,:)
% * chunkgraph object, in which case it uses ptsobj.r(:,:)
%
% Optional input:
% opts - options structure with entries:
Expand All @@ -24,14 +24,15 @@
% then unless explicitly set to false, it tries to use flam
%
% Output:
% in - logical array, if in(i) is true, then pts(:,i) is inside the
% domain or for a mesh grid [xx(i); yy(i)] is inside the domain.
% ids - integer array, pts(:,i) is in region ids(i)
%
% Examples:
% chnkr = chunkerfunc(@(t) starfish(t));
% verts = [1 0 -1 0; 0 1 0 -1]; edgesendverts = [1:3, 3, 4; 2:3, 1, 4, 1];
% cg = chunkgraph(verts,edgesendverts);
% pts = 2*randn(2,100);
% in = chunkerinterior(chnkr,pts);
% ids = chunkgraphinregion(cg,pts);
%
% see also CHUNKGRAPH, CHUNKERINTERIOR

% author: Travis Askham ([email protected])

Expand All @@ -41,7 +42,7 @@

% Assign appropriate object to chnkr
msg = "chunkgraphinregion: input 1 must be chunkgraph";
assert(class(chnkobj) == "chunkgraph",msg);
assert(class(cg) == "chunkgraph",msg);

% Figure out size of ids array based on ptsobj
if isa(ptsobj, "cell")
Expand All @@ -64,38 +65,38 @@
% loop over regions and use chunkerinterior to label
% TODO: make a more efficient version

nedge0 = numel(chnkobj.echnks);
nedge0 = numel(cg.echnks);
if nedge0 > 0
k = chnkobj.echnks(1).k;
t = chnkobj.echnks(1).tstor;
w = chnkobj.echnks(1).wstor;
k = cg.echnks(1).k;
t = cg.echnks(1).tstor;
w = cg.echnks(1).wstor;
p = struct("k",k);
else
ids = [];
return
end

nr = numel(chnkobj.regions);
nr = numel(cg.regions);
for ir = 1:nr
ncomp = numel(chnkobj.regions{ir});
ncomp = numel(cg.regions{ir});
intmp = zeros(npts,1);
for ic = 1:ncomp
edgelist = chnkobj.regions{ir}{ic};
edgelist = cg.regions{ir}{ic};
nedge = numel(edgelist);
chnkrs(nedge) = chunker(p,t,w);
for ie = 1:nedge
eid = edgelist(ie);
if eid > 0
if ir == 1
chnkrs(ie) = chnkobj.echnks(eid);
chnkrs(ie) = cg.echnks(eid);
else
chnkrs(ie) = reverse(chnkobj.echnks(eid));
chnkrs(ie) = reverse(cg.echnks(eid));
end
else
if ir == 1
chnkrs(ie) = reverse(chnkobj.echnks(-eid));
chnkrs(ie) = reverse(cg.echnks(-eid));
else
chnkrs(ie) = chnkobj.echnks(-eid);
chnkrs(ie) = cg.echnks(-eid);
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions devtools/test/chunkgraph_basicTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,12 @@
targs = [xx(:).'; yy(:).'];

ids = chunkgraphinregion(cg,targs);
ids2 = chunkgraphinregion(cg,{x1,x1});

idstrue = polygonids(cg,xx,yy);

assert(nnz(ids(:)-idstrue(:)) == 0)
assert(nnz(ids(:)-ids2(:)) == 0)

% nested triangles

Expand Down

0 comments on commit 6d207a0

Please sign in to comment.