-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateSurfacePatches.m
99 lines (59 loc) · 2.56 KB
/
createSurfacePatches.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
clear,close all;clc
isDebug = true;
% sort out the torso as a triangulation object.
load('ThoraxAndHeartTriangulations.mat');
load('ThoraxRegions.mat')
% for debugging
if false
triHeart = trisphere(3);
end
% heartmodel
trisurf(triHeart);
axis equal
hold on
hTorso = trisurf(triTorso,(ElementID2RegionID-1)*127+1,'FaceAlpha',0.5);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% create torso pde model
torso_model = createpde();
% Geometry
geometryFromMesh(torso_model,triTorso.Points',triTorso.ConnectivityList');
generateMesh(torso_model); %clean up the mesh
%tetramesh(triTorsoMesh, 'FaceColor','none')
triTorsoMesh = triangulation(torso_model.Mesh.Elements(1:4,:)',torso_model.Mesh.Nodes');
skinFaces = freeBoundary(triTorsoMesh);
P = triTorsoMesh.Points;
% now use
% userdata = selectregionsonshell(hTorso, 'new',{'frontPatch','backPatch'})
% selectregionsonshell(hTorso, 'off')
% selectregionsonshell(hTorso, 'on')
% selectregionsonshell(hTorso, 'nextregion')
% userdata = selectregionsonshell(hTorso, 'getdata')
% then convert userdata into the regions
% ElementID2RegionID = zeros(1,size(skinFaces,1));
% ElementID2RegionID(userdata.faceRegions(:,1)) = 1;
% ElementID2RegionID(userdata.faceRegions(:,2)) = 2;
% ElementID2RegionID = 1+ElementID2RegionID;
% or load SkinFaceID2RegionID
load('SkinFaceID2RegionID_1.mat')
% for each face, find the attached tetrahedron in the original mesh
figure
hTorso = trisurf(skinFaces,P(:,1),P(:,2),P(:,3),(SkinFaceID2RegionID-1)*127+1,'FaceAlpha',0.5);
hold on; axis equal
trisurf(triHeart);
% now find the mesh elements with a patch surface
frontPatch = skinFaces(SkinFaceID2RegionID==2,:);
frontPatchID = triFaceAttachments(triTorsoMesh, frontPatch);
frontPatchID = cell2mat(frontPatchID);
frontPatchMesh = triangulation(triTorsoMesh.ConnectivityList(frontPatchID,:),triTorsoMesh.Points);
backPatch = skinFaces(SkinFaceID2RegionID==3,:);
backPatchID = triFaceAttachments(triTorsoMesh, backPatch);
backPatchID = cell2mat(backPatchID);
backPatchMesh = triangulation(triTorsoMesh.ConnectivityList(backPatchID,:),triTorsoMesh.Points);
figure
hTorso = trisurf(skinFaces,P(:,1),P(:,2),P(:,3),(SkinFaceID2RegionID-1)*127+1,'FaceAlpha',0.5);
hold on; axis equal
tetramesh(frontPatchMesh, 'FaceColor','b')
tetramesh(backPatchMesh, 'FaceColor','r')
ElementID2RegionID = ones(size(triTorsoMesh,1),1);
ElementID2RegionID(frontPatchID) = 2;
ElementID2RegionID(backPatchID) = 3;