-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #207 from CHLNDDEV/precise_knn_map
Precise nearest neighbor mapping for extremely close points (e.g., weirs/levess)
- Loading branch information
Showing
4 changed files
with
47 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
function ind = nearest_neighbor_map(m_old, m_new) | ||
function ind = nearest_neighbor_map(m_old, m_new, type) | ||
% ind = nearest_neighbor_map(m_old, m_new, type) | ||
% | ||
% Determine the indices of the nearest neighbors from m_old.p to m_new.p | ||
% to do for example a trivial transfer of nodal attributes or bathymetry. | ||
% | ||
% Inputs | ||
% m_old: the old mesh object | ||
% m_new: the new mesh object | ||
% type (optional): 'approx' to use ourKNNsearch ANN wrapper | ||
% 'precise' to use built in MATLAB knnsearch | ||
% | ||
% Output | ||
% The indices of points from m_old to m_new | ||
% | ||
% Example | ||
% Transfer bathymetry data from one grid to a new one. | ||
% m_new.b = m_old.b(ind) | ||
ind = ourKNNsearch(m_old.p',m_new.p',1); | ||
|
||
% checking type input | ||
if nargin < 3 || isempty(type) | ||
type = 'approx'; | ||
end | ||
% check that knnsearch built-in exists if precise selection, | ||
% otherwise use approx | ||
if strcmp(type,'precise') && ~exist('knnsearch') | ||
type = 'approx'; | ||
end | ||
|
||
if strcmp(type,'approx') | ||
ind = ourKNNsearch(m_old.p',m_new.p',1); | ||
elseif strcmp(type,'precise') | ||
ind = knnsearch(m_old.p,m_new.p); | ||
else | ||
error(['Unknown selection for type: ' type]) | ||
end | ||
|
||
end |