\subsection{Junctions}

The last step to complete is to mesh the junctions.
A junction is a point of a skeleton where more than 2 branches join. The process for meshing this portion of the skeleton is complex. In fact it needs to be applicable on multiple cases, for instance 3 or 4 branches (see Figure \ref{junction}, and to take into account the fact that the perfect case will not always be there.

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.5]{img/Junctions9}
   \caption{\label{junction}Three splines junction}
   \end{center}
\end{figure}

In the figure \ref{junction1}  you can see what we should theoretically obtain with a perfect skeleton. You can see the sphere shared between three splines joining in this junction, and the three characteristic circles associated. Those circles are tangent in one point.

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.5]{img/JunctionTheory}
   \caption{\label{junction1}Theoretical case with perfect characteristic circles}
   \end{center}
\end{figure}

But in most of practical cases it is not like this. This is due to number's approximation on computers. The idea is then to look for the closest points of two consecutive circles and to join them. Then we join every point of the circles in one point upside and one downside.

We begin by identifying the last circles of each spline of the junction (see figure \ref{junction3}).

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.5]{img/Junctions3}
   \caption{\label{junction3}3-splines junction}
   \end{center}
\end{figure}

To be able to do it the first step is to cut the circles in two parts to find the upside and downside of each of them. This can be done by computing the best fitting plane for the set of circles' center points (figure \ref{junction2}).

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.35]{img/Junctions1}
   \includegraphics[scale=0.35]{img/Junctions2}
   \caption{\label{junction2}Best fitting plane for the set of circles' center points}
   \end{center}
\end{figure}

Then when points are sorted we connect the up-points of each circle with the up-projection of the sphere's center on itself, and idem for the down-points with the down-projection of the sphere's center.
The result of this process is presented in figure \ref{junction4}.

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.5]{img/Junctions4}
   \includegraphics[scale=0.5]{img/Junctions5}
   \caption{\label{junction4}Edges added and mesh result}
   \end{center}
\end{figure}

To easily see the result of the mesh on a junction, we have made some tests with only the extreme circles that we use. On real skeletons the junction are not easy to watch.
Here \ref{junction5} are two examples of a junction's mesh for 3 and 4-branches junctions.

\begin{figure}[H]
   \begin{center}
   \includegraphics[scale=0.5]{img/Junctions10}
   \includegraphics[scale=0.4]{img/Junctions11}
   \caption{\label{junction5}Mesh result on 3 and 4-branches junctions}
   \end{center}
\end{figure}
