Function FlagNeighborhood(,
,
,
,
):
= distTarget[
];
if withdrawn[i] AND AND
AND
then
touched[i] = true;
parent[i] = ;
distance[i] = ;
foreach in edgeNeighbors[
] do
if then
FlagNeighborhood(,
,
,
+ 1,
)
else
SetNeighbors(,
);
Function FlagTriangles(indices, ):
touched[] = false;
= 0;
numNewPatches = 0;
foreach in indices do
if !touched[i] and withdrawn[i] then
++numNewPatches;
active[i] = touched[i] = reflagged[i] = true;
parent[i] = i;
distance[i] = ;
foreach in edgeNeighbors[
] do
FlagNeighborhood(,
,
,
+ 1,
)
return numNewPatches
Function RefinePatch(,
):
count = Withdraw(,
)
if count == 0 then
return 0
else
UnSetAllNeighbors()
numNewPatches = FlagTriangles(patches[].patchIndices,
)
RebuildNeighbors()
UnWithdraw()
return numNewPatches
Algorithm 3: Recursive flagging and refinement of patches.
Function SetNeighbors(,
):
if parent[i] != and parent[i] !=
then
sparseNeighbors[parent[]].insert(
);
sparseNeighbors[].insert(parent[
]);
Function UnSetAllNeighbors():
foreach in sparseNeighbors[
].activeNeighbors do
sparseNeighbors[].erase(
);
sparseNeighbors[].erase(
);
Function RebuildNeighbors():
foreach in patches[
].patchIndices do
if then
foreach in edgeNeighbors[
] do
SetNeighbors(,
);
Algorithm 4: Helper functions for sparse neighbor handling.
Function Withdraw(,
):
count = 0;
foreach in patches[
].patchIndices do
if then
withdrawn[i] = true;
distance[i] = ;
parent[i] = -1;
++count;
return count
Function UnWithdraw():
foreach in patches[
].patchIndices do
withdrawn[i] = false;
Function RebuildPatches():
patches.clear();
for do
if parent[i] == -1 then
patches[parent[i]].insert(i);
Algorithm 5: Helper functions for withdrawal and building patch
information.