A trajectory is defined as \(v = \lbrace T, E, R, G \rbrace \) where T is the target in the brain, E is the entry on the skull, R is the risk score, and G is the GM-WM ratio. For a set of N targets a plan is defined as \(V( N ) = \lbrace v_{1,a_{1}},\ldots , v_{N,a_{N}} \rbrace : a_{i} \in \lbrace 1,\ldots , M_{i} \rbrace , i \in \lbrace 1, \ldots , N \rbrace \) where \(M_{i}\) is the number of potential trajectories for the \(i^{\mathrm{th}}\) target. The plan V( N ) is defined such that each trajectory attains one of N targets. MTP finds a plan \(V_{\mathrm{min}}( N )\) that attains all targets, minimises R, maximises G, and avoids conflicts between electrodes.
Prior to trajectory planning, segmentation of the skull and critical structures is performed as described in the section “Critical structure extraction”. For each target \(T_{i}\), a risk score \(R_{i,a_{i}}\), that quantifies proximity to blood vessels, and a GM-WM ratio \(G_{i,a_{i}}\), that quantifies GM sampling, are calculated as described in the section “Single trajectory planning algorithm”. The MTP algorithm described in the section “Multiple trajectory planning algorithm” calculates \(V_{ \mathrm{min}}( N )\). The EpiNav\(^{\mathrm{TM}}\) software platform enables manual assessment of \(V_{\mathrm{min}}( N )\) as described in the section “Plan visualisation and assessment”.
Critical structure extraction
Automated trajectory planning is dependent on accurately segmenting critical structures (arteries, veins, and sulci), GM, and the skull surface. Algorithms chosen for these tasks are currently being used in the clinic to generate 3D models for manual trajectory planning and have been used in presurgical patient evaluation for over 4 years [19, 21]. Blood vessels are segmented with a customised vessel extraction tool [30] from CT angiography, 3D phase contrast MRI, or T1-weighted MRI with gadolinium enhancement. GM and the cortex were segmented using FreeSurfer [9]. Sulci were extracted from the cortex surface. Figure 1c illustrates an example segmentation for veins (cyan), arteries (red), and sulci (peach).
Skull segmentation with template registration constrains entry points to regions suitable for implantation. A patient-specific skull is segmented from a CT scan using thresholding and morphologic dilation to ensure a fully connected surface. The template skull is aligned to the patient skull using Iterative Closest Points (ICP) [28] to minimise the distance between the two surfaces. The template skull excludes regions inappropriate for implantation such as the face, ears, and regions inferior to the transverse sinus. Figure 1 shows an example patient (white) and template (yellow) skull.
Single trajectory planning algorithm
Previous work from our group [29] presented real-time automated single trajectory planning (STP) for a target \(T_i\). STP calculates potential entry points \(\hat{E}_{i,a_{i}} : a_{i} \in \lbrace 1, \ldots , M_{i} \rbrace \) by considering trajectory length and entry angle (described in the section “Entry point search”). Next trajectories, defined as \(\overline{\hat{E}_{i,a_{i}} T_{i}}\), that intersect critical structures (arteries, veins, or sulci) are removed from consideration. Then at evenly spaced points along each trajectory \(x \in \overline{E_{i,a_{i}} T_{i}}\) the distance to the nearest blood vessel \(f_{\mathrm{crit}}(x)\) is found (described the section “Bounding volume hierarchy (BVH) for trajectory evaluation”). Finally for \(\overline{E_{i,a_{i}} T_{i}}\) a risk score \(R_{i,a_{i}}\), computed from \(f_{\mathrm{crit}}(x)\), and a GM-WM ratio \(G_{i,a_{i}}\) are calculated (described in the section “Trajectory ranking”). A stratified ranking algorithm sorts trajectories by first minimising \(R_{i,a_{i}}\) and then maximising \(G_{i,a_{i}}\).
Entry point search
Potential entry points \(\hat{E}_{i,a_{i}} : a_{i} \in \lbrace 1, \ldots , M_{i} \rbrace \) are identified by considering all vertices in the template skull mesh. \(\hat{E}_{i,a_{i}}\) are removed from consideration based on the following criteria:
-
1.
Trajectory length The length of \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) must be shorter than \(d_{{\mathrm{length}}}\), the maximum electrode length.
-
2.
Entry angle The angle between \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) and the skull normal must be less than \(d_{{\mathrm{angle}}}\), the angle that can be accurately drilled.
Calculating these exclusion criteria for \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) is computationally inexpensive; hence, it is practical to remove \(\hat{E}_{i,a_{i}}\) that do not meet these criteria first.
Bounding volume hierarchy (BVH) for trajectory evaluation
Each trajectory \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) is tested for intersection with critical structures (arteries, veins, sulci) using a bounding volume hierarchy (BVH) to enable real-time calculation. Trajectories that intersect these structures are removed from consideration. All remaining trajectories are sampled at 128 evenly spaced points x such that \(x\in \overline{E_{i,a_{i}} T_{i}}\). For every x, the distance to the nearest blood vessel (arteries, veins) \(f_{\mathrm{crit}}(x)\) is calculated. BVH construction and traversal are described below.
Bounding volume hierarchy construction For each critical structure (arteries, veins, and sulci) a BVH is constructed as in [12]. Each triangle in the surface is assigned a 30-bit Morton code [15], calculated by combining the 10-bit Morton code of each triangle vertex coordinate. An efficient bit-wise sorting of the triangles is performed using the Morton codes. The BVH is created by iteratively splitting triangles according to the highest different bit between Morton codes. This is repeated until each leaf node contains one triangle. Finally, for every node a bounding box is calculated. For each leaf node the bounding box is calculated as the smallest rectangle that contains the triangle. The bounding box for all other nodes is the union of the bounding boxes of their children nodes.
Bounding volume hierarchy traversal BVH traversal detects collision of \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) with each critical structure. Initially the top BVH node is added to the queue. If \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) intersects the bounding box of the first node in the queue, its children nodes are added to the queue. Once a leaf node is reached \(\overline{\hat{E}_{i,a_{i}} T_{i}}\) is removed from consideration if it intersects the triangle of the leaf node.
For the remaining trajectories, the closest distance between each point \(x \in \overline{E_{i,a_{i}} T_{i}}\) and the \(j\hbox {th}\) critical structure \(f_{j}(x)\) is calculated. For this computation sulci are not included. Initially the top BVH node is added to the queue and \(f_{j}(x) = \infty \). The first node in the queue is removed, and the distance between each child node and its bounding box \(f_{bb}(x)\) is calculated. For a point inside the bounding box \(f_{bb}(x) = 0\). If \(f_{bb}(x) < f_{j}(x)\) the node is added to the queue so that the first node corresponds to the smallest value of \(f_{bb}(x)\). For a leaf node the distance between x and the triangle is computed, if \(f_{tri}(x) < f_{j}(x)\), then \(f_{j}(x) = f_{tri}(x)\). This is repeated until no nodes are in the queue. After all critical structures have been evaluated, the closest distance is calculated as \(\displaystyle f_{\mathrm{crit}}(x) = {{\mathrm{arg\,min}}}_{j} ( f_{j}(x))\).
Trajectory ranking
Entry points that meet all hard constraints, \(E_{i,a_{i}}: a_{i} \in \lbrace 1, \ldots , M_{i} \rbrace \), are ranked by risk score \(R_{i,a_{i}}\), a measure of cumulative distance from blood vessels, and GM-WM ratio \(G_{i,a_{i}}\), a measure of GM capture.
Risk score The risk score \(R_{i,a_{i}}\) measures cumulative distance to blood vessels. The trajectory \(\overline{E_{i,a_{i}} T_{i}}\) has a high risk if the nearest critical structure is less than a “Safety Margin”, determined by the user-defined value \(d_{\mathrm{safety}}\). If \(\overline{E_{i,a_{i}} T_{i}}\) has a distance to the nearest critical structure greater than a “Risk Zone”, determined by the user-defined value \(d_{\mathrm{risk}}\), it has no potential risk.
The cumulative distance of risk along \(\overline{E_{i,a_{i}} T_{i}}\) is calculated as,
$$\begin{aligned} S_{{\mathrm{crit}}} = \int _{E_{i,a_{i}}}^{T_{i}} d_{{\mathrm{risk}}} - ( f_{{\mathrm{crit}}}(x)-d_{{\mathrm{safety}}} ) dx, \end{aligned}$$
(1)
where \(f_{{\mathrm{crit}}}(x)\) is the distance between x and the nearest critical structure. For normalisation purposes if \(f_{{\mathrm{crit}}}(x) > d_{{\mathrm{risk}}}\), then \(f_{{\mathrm{crit}}}(x)= d_{{\mathrm{risk}}}\) so that the final value the x contributes to the risk score is zero. If \(f_{{\mathrm{crit}}}(x) < d_{{\mathrm{safety}}}\), then automatically \(R_{i,a_{i}} = 1\), representing the highest risk.
The final risk \(R_{i,a_{i}}\) is normalised to the range [0, 1], where 0 corresponds to no risk and 1 corresponds to the highest risk. \(R_{i,a_{i}}\) is calculated as,
$$\begin{aligned} R_{i,a_{i}} = \dfrac{S_{{\mathrm{crit}}}}{ (d_{{\mathrm{risk}}}-d_{{\mathrm{safety}}}) * { length}}, \end{aligned}$$
(2)
where \({ length}\) is the length of \(\overline{E_{i,a_{i}} T_{i}}\). Figure 2d displays \(R_{i,a_{i}}\) as a heat map from low (0-green) to high (1-red) risk.
Grey matter-white matter ratio GM-WM ratio measures the proportion of electrode contacts in GM. GM-WM ratio corresponds to the SEEG efficiency for each trajectory as GM generates seizures. For each trajectory \(\overline{E_{i,a_{i}} T_{i}}\) a set of J contact points, \(c_{j} : j \in \{1, \ldots , J \}\) each with a sampling radius \(c_r\) are defined. Each contact point is assessed if \(c_{j} \pm c_{r}\) is located in GM. GM-WM ratio is calculated as,
$$\begin{aligned}&G_{i,a_{i}} \nonumber \\&\quad = \dfrac{ \sum _{j = 1}^{J} (H[f_{gm}(c_j - c_r) ] + H[f_{gm}(c_j) ] +H[ f_{gm}(c_j + c_r) ] }{3 * J}, \nonumber \\ \end{aligned}$$
(3)
where \(f_{gm}(\cdot )\) is the signed distance at \(c_j\) from the GM surface, \(H[\cdot ]\) is the Heaviside function, and J is the number of contact points. \(H[\cdot ]\) is defined so negative values, locations inside GM, are 1 and positive values, locations outside GM, are 0. Similar to \(f_{{\mathrm{crit}}}(x)\) a BVH is used to calculate \(f_{gm}(\cdot )\).
Stratified ranking Trajectories are first ranked by \(R_{i,a_{i}}\) so that \(v_{i,1}\) has the lowest risk. Next trajectories are placed into K histogram bins so the \(k^{\mathrm{th}}\) bin contains \(v_{i,a_i}: (k-1)/K \le a_i < k/K\). Within each bin trajectories are ranked according to \(G_{i,a_{i}}\) so \(v_{i,1}\) has the highest GM-WM ratio.
Multiple trajectory planning algorithm
MTP aims to find the best plan \(V_{{\mathrm{min}}}( N ) = [ v_{1,a_{1}}, \ldots , v_{N,a_{N}}] : a_{i} \in \{1, \ldots , M_{i}\}, i \in \{1, \ldots , N \}\) with no electrode conflict. Electrode conflict occurs when two trajectories are closer than a user-defined value \(d_{{\mathrm{traj}}}\). \(V_{{\mathrm{min}}}( N )\) is defined as,
$$\begin{aligned} R_{{\mathrm{total}}}&= {{\mathrm{arg\,min}}}_{V_{{\mathrm{min}}}( N )} \bigg ( \dfrac{1}{N} \sum _{i=1}^{N} R_{i,a_{i}} \bigg ) \nonumber \\&\text { s.t. } D(\overline{E_{i,a_{i}} T_i}, \overline{E_{j,a_{j}} T_j} ) > d_{{\mathrm{traj}}}: \forall i,\nonumber \\ {}&\quad \ \forall j \in \{ 1, \ldots , N\}, i \ne j, \end{aligned}$$
(4)
where \(D( \cdot , \cdot )\) is the minimum Euclidean distance between two line segments. A depth-first search with dynamic programming to limit potential plans is used to calculate \(V_{{\mathrm{min}}}( N )\) as described in the sections “Depth-first search algorithm” and “Dynamic programming for determining potential combinations”.
Depth-first search algorithm
Algorithm 1 iteratively (1) calculates \(\hat{V}_{{\mathrm{min}}}(n)\), a suitable plan for n trajectories and (2) rejects \(\hat{V}_{{\mathrm{min}}}(n)\) if electrodes conflict. At each iteration of Algorithm 1 a set of low risk plans, defined as \({\mathbf {V}}_{p} (n) = [V_1(n), \ldots , V_q(n)]\), is calculated. For the lowest risk plan \(\hat{V}_{{\mathrm{min}}}(n) \in {\mathbf {V}}_{p} (n)\) the function \(D_{{\mathrm{all}}}( \cdot )\) detects conflict between electrodes by finding the minimum Euclidean distance between all pairs of trajectories in \(\hat{V}_{{\mathrm{min}}}(n)\) (i.e. \(\min (D(\overline{E_{i,a_{i}} T_i}, \overline{E_{j,a_{j}} T_j} ) : \forall i, \forall j \in \{ 1, \ldots , n\} , i \ne j)\)). When an electrode conflict is detected \({\mathbf {V}}_{p}(n)\) is updated as described in the section “Dynamic programming for determining potential combinations”. Once \(\hat{V}_{{\mathrm{min}}}(n)\) has no conflicts, \(n \longleftarrow n+1\) and the algorithm continues until \(V_{{\mathrm{min}}}(N)\) is found.
Dynamic programming for determining potential combinations
For each target \(T_i\), trajectories are ranked so \(v_{i,1}\) is the best trajectory (in the section “Trajectory ranking”). Initially, \({\mathbf {V}}_{p} (n) \longleftarrow [V_1]\) where \(V_1 = \lbrace v_{1,1} \rbrace \) which corresponds to adding a potential plan containing the best trajectory for the \(1{\mathrm{st}}\) electrode. At the next step, \(n=2\), \({\mathbf {V}}_{p}(n) \longleftarrow [ \lbrace V_{{\mathrm{min}}}(n-1), v_{n,1}\rbrace ]\), which corresponds to adding the best trajectory for the \(2{\mathrm{nd}}\) electrode. Algorithm 1 proceeds in this manner until electrode conflict is detected.
If \(\hat{V}_{{\mathrm{min}}}(n)= \lbrace v_{1,a_{1}}, \ldots , v_{n,a_{n}} \rbrace \) has an electrode conflict \({\mathbf {V}}_{p} (n)\) is updated by:
-
1.
Finding trajectories i and j that violate \(D(\overline{E_{i,a_{i}} T_i}, \overline{E_{j,a_{j}} T_j} ) < d_{{\mathrm{traj}}}\). Note that \(i \in \{1,\ldots , n-1\}\) and \(j=n\) otherwise an electrode conflict would have been detected earlier.
-
2.
Updating the \(i^{\mathrm{th}}\) trajectory \(\tilde{V}_{i} (n) = \min ({\mathbf {V}}_{p}(i))\).
-
3.
Updating the \(n^{\mathrm{th}}\) trajectory: \(\tilde{V}_{n} (n) = \lbrace v_{1,a_{1}},\ldots , v_{i,a_{i}}, \ldots , v_{n,a_{n}+1}\rbrace \).
-
4.
Adding \(\tilde{V}_{i}(n)\) and \(\tilde{V}_{n}(n)\) to \({\mathbf {V}}_{p}(n)\).
Algorithm 1 continues in this manner until \(V_{{\mathrm{min}}}(N)\) is found.
Plan visualisation and assessment
Clinicians must be able to visualise and assess trajectory feasibility. We have developed the EpiNav\(^{\mathrm{TM}}\) software platform to aid manual assessment with: (1) quantitative measures of trajectory suitability, (2) a trajectory profile, and (3) a probe eye view. Figure 3 displays an example layout of the EpiNav\(^{\mathrm{TM}}\) software platform.
Quantitative measures
Four measures of trajectory suitability, length, angle, risk score, and GM-WM ratio, are displayed in the EpiNav\(^{\mathrm{TM}}\) platform. Trajectory length is calculated as the length of \(\overline{E T}\), where E is the entry point and T is the target. Trajectory angle is calculated as the angle of \(\overline{E T}\) with respect to the skull normal. Trajectory risk score is calculated as in Equation 2, and GM-WM ratio is calculated as in Equation 3.
Trajectory profile
The trajectory profile provides a (a) risk profile and (b) GM profile. The risk profile displays \(f_{{\mathrm{crit}}}(x)\) (described in the section “Trajectory ranking”) for \(x \in \overline{E T}\). The colour of \(f_{{\mathrm{crit}}}(x)\) corresponds to the closest blood vessel at x. The GM profile displays the colour corresponding to the tissue type (GM or WM) each electrode contact is located in. Regions of the trajectory outside the cortex are shown in the electrode colour.
Figure 3 displays the risk profile in the upper right panel. Red corresponds to trajectory regions closest to an artery, cyan to trajectory regions closest to a vein. The red line indicates the “Safety Margin” \((d_{{\mathrm{safety}}})\). The black line indicates the position of the probe eye view (Fig. 3, bottom right panel), black text shows the distance between the probe eye view and T, and red text shows the distance to the nearest critical structure \((f_{{\mathrm{crit}}}(x))\).
Probe eye view
The probe eye view displays an image perpendicular to the trajectory. This allows the user to navigate along the trajectory and assess proximity to critical structures. The probe eye view is generated by finding the geometric plane perpendicular to \(x \in \overline{E T}\). Nearest neighbour interpolation calculates the intensity value for each pixel in this plane. Figure 3 displays a probe eye view in the bottom right panel.