-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathvtkMapCellIds.m
executable file
·29 lines (25 loc) · 1.06 KB
/
vtkMapCellIds.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
% Maps cell ids from a source mesh onto a target mesh.
% Ids start from 1 (Matlab convention, not VTK/C++).
%
% Syntax:
% cellIds = vtkMapCellIds(struct sourceStruct, struct targetStruct, (bool mapUsingVtk))
%
% Written in 2019 by Steffen Schuler
% Institute of Biomedical Engineering, KIT
% www.ibt.kit.edu
function cellIds = vtkMapCellIds(sourceStruct, targetStruct, mapUsingVtk)
if nargin < 3
mapUsingVtk = false;
end
if mapUsingVtk
if size(sourceStruct.cells,1)
sourceStruct.cellData.MappedIds = int32(1:size(sourceStruct.cells,1))';
end
targetStruct = vtkArrayMapperNearestNeighbor(sourceStruct, targetStruct);
cellIds = targetStruct.cellData.MappedIds;
else
sourceCentroids = squeeze(mean(reshape(sourceStruct.points(sourceStruct.cells,:),[],size(sourceStruct.cells,2),size(sourceStruct.points,2)),2));
targetCentroids = squeeze(mean(reshape(targetStruct.points(targetStruct.cells,:),[],size(targetStruct.cells,2),size(targetStruct.points,2)),2));
cellIds = int32(knnsearch(sourceCentroids, targetCentroids, 'NSMethod','kdtree'));
end
end