forked from jamesra/VikingPlot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildFacesForBifurcatedTriangle.m
153 lines (119 loc) · 4.58 KB
/
BuildFacesForBifurcatedTriangle.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function [ Faces ] = BuildFacesForBifurcatedTriangle( VO, VA, VB, iLineVerts, OverlappingVerts, InternalVerts )
%BuildFacesForBifurcatedTriangle VO, VA, VB defines a triangle which has
%had a line drawn through the vertex at VO
%iAddedVerts contains a sorted list of all indicies that lie on the line
%through the triangle. The first and last entry in iAddedVerts are on the edge of the triangle.
%iOverlappingVerts are verticies on the line which intersect the feature
%(Originally another intersecting triangle) which defined the line.
%InternalVerts is an optional 1x3 logical array indicating whether VO, VA, or VB are
%known to be internal to final mesh and should be removed.
%Returns an nx3 matrix of faces
%Determine which triangle verts are on the line...
Faces =[];
numLineVerts = length(iLineVerts);
NovelLineVert = setdiff(iLineVerts, [VO VA VB]);
numNewVerts = length(NovelLineVert);
iEdgeVert = 1;
iCenterVert = 2;
iLineOrder = [2:numLineVerts];
if(iLineVerts(iEdgeVert) == VO)
iEdgeVert = numLineVerts;
iLineOrder = [numLineVerts-1:-1:1];
iCenterVert = numLineVerts -1 ;
end
if(numNewVerts == 0)
Faces = [VO VA VB];
return;
elseif(numNewVerts == 1)
iLineVert = setdiff(iLineVerts, [VO VA VB]);
if(NovelLineVert == iLineVerts(iEdgeVert))
Faces = [VO VA iLineVert;
VO VB iLineVert];
elseif(NovelLineVert == iLineVerts(iCenterVert))
TriVerts = [VO VA VB];
NonLineVerts = setdiff(TriVerts, iLineVerts);
LineVerts = intersect(TriVerts, iLineVerts);
if(ismember(VO, LineVerts))
VO = NonLineVerts(1);
ind = setdiff(TriVerts, [VO]);
VA = ind(1);
VB = ind(2);
end
Faces = [VO VA iLineVert;
VO VB iLineVert;
];
end
return;
end
if(numLineVerts == 2)
%We know the two new verts must be overlapping.
%If VO is one of the verts on the line. We only have two triangles.
%If either VA or VB is internal we should not add them
if(~(InternalVerts(VA) && InternalVerts(VO) && OverlappingVerts(iLineVerts(iEdgeVert))))
Faces = [Faces; VO VA iLineVerts(iEdgeVert);];
end
if(~(InternalVerts(VB) && InternalVerts(VO) && OverlappingVerts(iLineVerts(iEdgeVert))))
Faces = [Faces; VO VB iLineVerts(iEdgeVert);];
end
%VA iLineVerts(iEdgeVert) VB];
return;
end
if(~(OverlappingVerts(iLineVerts(iEdgeVert)) && OverlappingVerts(iLineVerts(iCenterVert))))
%If they aren't overlapping use one triangle
Faces = [Faces; VA VB iLineVerts(iCenterVert)];
else
if(~InternalVerts(VA))
Faces = [Faces;
VA iLineVerts(iCenterVert) iLineVerts(iEdgeVert)];
end
if(~InternalVerts(VB))
Faces = [Faces;
VB iLineVerts(iCenterVert) iLineVerts(iEdgeVert);];
end
end
for(i = 1:length(iLineOrder)-1)
iLineVert = iLineOrder(i);
iNextLineVert = iLineOrder(i+1);
if(~(OverlappingVerts(iLineVerts(iLineVert)) && OverlappingVerts(iLineVerts(iNextLineVert))))
%If they aren't overlapping always create triangles
Faces = [Faces;
VA iLineVerts(iLineVert) iLineVerts(iNextLineVert);
VB iLineVerts(iLineVert) iLineVerts(iNextLineVert)];
else
%The are overlapping, check to see if triangle vertex is hidden
if(~InternalVerts(VA))
Faces = [Faces;
VA iLineVerts(iLineVert) iLineVerts(iNextLineVert);];
end
if(~InternalVerts(VB))
Faces = [Faces;
VB iLineVerts(iLineVert) iLineVerts(iNextLineVert);];
end
end
end
%
%
% if(iEdgeVert == 1)
% if(~InternalVerts(VA))
% Faces = [Faces; VA iLineVerts(2) iLineVerts(3);];
% end
%
% if(~InternalVerts(VB))
%
%
% VB iLineVerts(2) iLineVerts(3);];
% else
% Faces = [Faces;
% VA iLineVerts(2) iLineVerts(1);
% VB iLineVerts(2) iLineVerts(1);];
% end
%
%
%
%
%
%
%
% end
%
end