
\begin{algorithm}[H]
\caption{Build Mahalanobis Graph \& Prune Small Components (cf.\ \S\ref{sec:method:topo})}
\label{alg:build-graph}
\begin{algorithmic}[1]
\Require Gaussian set $\mathcal{S}$, $K$ (Euclidean pre-neighbors), $k$ (Mahalanobis neighbors), $S_{\min}$
\Ensure Undirected graph $A$, component labels $L(\cdot)$, prune set $\mathcal{R}$
\For{$i=1\ldots N$} \Comment{Euclidean pre-selection}
  \State $\mathcal{N}^{\text{Euc}}_{K}(i)\leftarrow \text{top-}K$ nearest by $\|\mathbf{x}_j-\mathbf{x}_i\|_2$
  \State $\mathcal{N}_k(i)\leftarrow \arg\min^{(k)}_{j\in \mathcal{N}^{\text{Euc}}_{K}(i)} d_M(i,j)$
\EndFor
\State $A \leftarrow$ symmetrize $\{\,(i,j)\mid j\in\mathcal{N}_k(i)\,\}$
\State $\{C_m\}_{m=1}^M \leftarrow \text{ConnectedComponents}(A)$, assign $L(i)\in\{1,\ldots,M\}$
\State $\mathcal{R}\leftarrow \{\, i \mid |C_{L(i)}|<S_{\min} \,\}$ \Comment{prune small components}
\State \Return $A, L(\cdot), \mathcal{R}$
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{Hole Detection \& Boundary Extraction (cf.\ Eq.~(2)–(3))}
\label{alg:holes}
\begin{algorithmic}[1]
\Require Candidate camera set $\mathcal{C}$ (interpolated), opacity threshold $\tau_\alpha$, dilation $\mathcal{D}$
\Ensure Best view $c^\star$, boundary index set $\mathcal{I}_\partial$
\For{each $c\in\mathcal{C}$}
  \State Render alpha map $\alpha_c(u)$, compute $s_c=\#\{u \mid \alpha_c(u)<\tau_\alpha\}$
\EndFor
\State $c^\star \leftarrow \arg\max_{c} s_c$
\State $\mathcal{M}\leftarrow \mathbf{1}[\alpha_{c^\star}<\tau_\alpha]$
\State $\mathcal{B}\leftarrow \mathcal{D}(\mathcal{M})\setminus \mathcal{M}$ \Comment{2D hole boundary}
\State $\mathcal{I}_\partial \leftarrow \{\mathrm{nn}(\mathbf{y}(u)) \,|\, u\in\mathcal{B}\}$ \Comment{$\mathbf{y}(u)$ is back-projected 3D point}
\State \Return $c^\star, \mathcal{I}_\partial$
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{Regularization Edits: Bridging and Filling (cf.\ Eq.~(4)–(6))}
\label{alg:plan-edits}
\begin{algorithmic}[1]
\Require $A$, labels $L(\cdot)$, boundary indices $\mathcal{I}_\partial$, bridge count $B$, neighbor count $k$
\Ensure Insert list ${Ins}$ (new centers/scales/rotations)
\State $\mathcal{L}_\partial \leftarrow \{L(i)\mid i\in \mathcal{I}_\partial\}$, ${Ins}\leftarrow \varnothing$
\If{$|\text{unique}(\mathcal{L}_\partial)|\ge 2$} \Comment{Inter-component bridging}
  \State $(\ell_1,\ell_2)\leftarrow$ two most frequent labels in $\mathcal{L}_\partial$
  \State $\mathcal{P}\!\leftarrow\!\{\mathbf{x}_i\mid i\in\mathcal{I}_\partial,\,L(i)=\ell_1\}$,\quad
         $\mathcal{Q}\!\leftarrow\!\{\mathbf{x}_j\mid j\in\mathcal{I}_\partial,\,L(j)=\ell_2\}$
  \State $(\mathbf{p}^\star,\mathbf{q}^\star)\!\leftarrow\!\arg\min_{\mathbf{p}\in\mathcal{P},\,\mathbf{q}\in\mathcal{Q}}\|\mathbf{p}-\mathbf{q}\|_2$
  \For{$b=1\ldots B$}
    \State $t_b\leftarrow b/(B+1)$, $\mathbf{x}^{(b)}_{\text{new}}\leftarrow (1-t_b)\mathbf{p}^\star+t_b\mathbf{q}^\star$
    \State ${Ins}\leftarrow {Ins}\cup\{\mathbf{x}^{(b)}_{\text{new}}\}$
  \EndFor
\Else \Comment{Intra-component filling via local tangent plane}
  \State $\mathcal{J}\leftarrow$ downsample of $\{i\in\mathcal{I}_\partial\}$
  \For{each $i\in \mathcal{J}$}
    \State $\mathcal{N}_k(i)\leftarrow$ Mahalanobis neighbors, $\boldsymbol{\mu}_i \leftarrow \frac{1}{k}\sum_{j\in\mathcal{N}_k(i)}\mathbf{x}_j$
    \State $C_i\leftarrow \frac{1}{k-1}\sum_{j\in\mathcal{N}_k(i)}(\mathbf{x}_j-\boldsymbol{\mu}_i)(\mathbf{x}_j-\boldsymbol{\mu}_i)^\top$
    \State $\mathbf{n}_i\leftarrow$ eigenvector of $C_i$ with the shortest eigenvalue
    \State $\bar d_i\leftarrow \frac{1}{k}\sum_{j\in\mathcal{N}_k(i)}\|\mathbf{x}_j-\boldsymbol{\mu}_i\|_2$
    \State Initialize candidate: center ${\boldsymbol{\mu}_i}$, scale $[0.5\bar d_i,0.5\bar d_i,0.1\bar d_i]$
    \State Set rotation aligning $\mathbf{n}_i$ to $\hat{\mathbf{z}}$, append to ${Ins}$
  \EndFor
\EndIf
\State \Return ${Ins}$
\end{algorithmic}
\end{algorithm}

\begin{algorithm}[H]
\caption{Atomic Execution \& Protection (one regularize cycle)}
\label{alg:execute}
\begin{algorithmic}[1]
\Require Prune set $\mathcal{R}$, insert list ${Ins}$, grace steps $t_{\text{grace}}$
\Ensure Updated $\mathcal{S}$ and protection flags $\pi(\cdot)$
\State Remove $\{\mathcal{G}_i\mid i\in\mathcal{R}\}$ from $\mathcal{S}$
\For{each proposed $\mathbf{x}^{\text{new}}$ in $\mathsf{Ins}$}
  \State $j\leftarrow \mathrm{nn}(\mathbf{x}^{\text{new}})$
  \State Inherit SH/scale/rotation from $\mathcal{G}_j$, set opacity to $\eta o_j$ with $\eta\in(0,1)$
  \State Add new Gaussian to $\mathcal{S}$ and set protection $\pi= t_{\text{grace}}$
\EndFor
\State \Return $\mathcal{S}, \pi(\cdot)$
\end{algorithmic}
\end{algorithm}

