# Difference between revisions of "Automatic DBS lead topology correction"

Coming up soon.

### What this code does

This codes takes as input a wireframe model of a DBS lead and returns in output the wireframe model that is the closest to the initial path (in the L2 sense) but for which:

• The distance between any two segments of the path is greater than Dmin, where Dmin is a distance defined by the user.
• At every point of the path, the curvature is smaller than Kmax, where Kmax is the maximum curvature defined by the user.

By wireframe path, I mean a piecewise linear curve in 3D space that represents the centerline path of the DBS lead. Every segment is linear and the wireframe path model is therefore simply defined by a set of ordered points in 3D space.

I refer to this process of enforcing (i) a minimum distance between any two segments of the path and (ii) a maximum curvature at every point of the path as "topology correction". This is because if the two segments are too close to each other (distance constraint violation) or if the path bends too quickly (curvature constraint violation), once the path is thickened to the actual lead diameter this will result in self-intersections of the cable model. This topology correction process is formulated as a constrained optimization problem solved using an active-set approach. The technique is accelerated using a GPU, but even then computation is relatively slow: Count a few minutes for a lead with ~300 points.

### Instructions

#### Running an example

The subfolder EXAMPLE/ contains an example of how to run the code. The master script is RUN_OPT.m. All the options used in this script are commented and should be easy to understand. There are several things to note in this script:

• Both the left and right DBS leads are loaded in Matlab and are connected in a single wireframe dataset. The topology correction process is run on this "super-lead" in order to remove gamma distance violations not only between the segments of a given lead, but also between segments belonging to different leads. Once the topology correction has been performed, the left and right leads can be separated again.
• The topology correction process itself is performed by the Matlab function deform_path_LINEAR.m.