# Equation for medial axis from SPHARM-PDM

**URL:** <https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311>\
**Category:** SlicerSALT\
**Tags:** spharm-pdm\
**Created:** [July 1, 2020, 1:57am UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311 "2020-07-01T01:57:32Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![christinah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/christinah/32/7306_2.png) [@christinah](https://discourse.slicer.org/u/christinah)\
**Post date:** [July 1, 2020, 1:57am UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311/1 "2020-07-01T01:57:32Z")

</div>

Operating system: MacOS Catalina  
Slicer version: 4.10.2

Hi there,

I’ve been using SPHARM-PDM and first want to say a really, truly huge thank you – both for the tool and for the extremely helpful Google slide tutorial, great answers to posts on here, and other documentation. I’m a cell biologist and have managed to use the tool to analyze the shape of tomograms of single parasitic cells, which is pretty amazing! I’ve also been able to import the meshes that SPHARM generated into FEM software for some fluid dynamics simulations. I tried so many things (and kept failing) before I stumbled on Slice and SPHARM… so you can imagine how grateful I feel to your team!

Second, I have a quick question. Is there some clever way to extract the medial axis line as a list of x, y, z coordinates? For the FEM simulations I mentioned above, I’d like to find an equation for the medial axis so that I can use it to define a coordinate system. I might fit a curve to x, y, z coordinates in matlab, for example. (If not, maybe I need to work harder to figure out how to do this starting with the .vtk file.)

Thanks so much for any advice! Apologies if this question is eye-rolling-ly simple 🙂  
Best,  
Christina

---

<div class="post-metadata">

**Author:** ![christinah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/christinah/32/7306_2.png) [@christinah](https://discourse.slicer.org/u/christinah)\
**Post date:** [July 2, 2020, 11:50pm UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311/2 "2020-07-02T23:50:31Z")

</div>

Quick update: as an alternative to extracting details about the medial axis and using that to set up a coordinate system for subsequent FEM simulations, maybe I could figure out how to use the mapped spherical coordinates already used for SPHARM’s central algorithm. Is there a way to access those, if the original idea in the post above is not possible?

There are text files with a long 1D list of phi’s and theta’s in the output folder from SPHARM mesh generation, which I know are used as color maps in the Shape Population viewer, but I’m not sure how to make use of those. Is there a way to obtain the actual spherical mapping information used during the SPHARM process?

Again, thank you very, very much for any help or tips! I am pretty stuck.

Best,  
Christina

---

<div class="post-metadata">

**Author:** ![bpaniagua](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bpaniagua/32/20_2.png) [@bpaniagua](https://discourse.slicer.org/u/bpaniagua)\
**Post date:** [July 3, 2020, 12:37pm UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311/3 "2020-07-03T12:37:36Z")

</div>

Hi Christina

For the medial axis you can use the parameterization derived medial axis that is produced as part of SPHARM, please [check this paper](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3630372/) and [slide 40](https://docs.google.com/presentation/d/1ZZ6UpONwTl_GKk66Kde9Brq0PIDujw2pKavm1RD1SBo/present?slide=id.p40) in the tutorial.

These files containing 1D vectors of the spherical parameterizations are a legacy file that we used on a Shape Population Viewer look alike program before. If you are using the SPHARM-PDM module within SlicerSALT (SPHARM-PDM generator) the phi and theta 1D color maps will be automatically mapped into the mesh and the unit sphere. If you want to do the mapping, you will have to use [MeshMath](https://github.com/NIRALUser/SPHARM-PDM/blob/master/Modules/CLI/MetaMeshTools/MeshMath.cxx), specifically the KWMToPolyData function.

```
MeshMath <vtkIn> <vtkOut> -KWMtoPolyData <txtFileIn> <nameScalarField> Writes a KWM scalar field (N Dimensions) into a PolyData Field Data Scalar to visualize in Slicer"

MeshMath fileIn.vtk fileOut.vtk -KWMtoPolyData phi.txt PhiFieldName

```

MeshMath is currently compiled within Slicer when you install the SPHARM-PDM extension, and available in the SALT package, please let me know if you need instructions on how to use it from there!

HTH  
Bea

ps. I almost miss your question! Please post SPHARM-PDM questions into the [SALT subforum the next time](https://discourse.slicer.org/c/community/slicer-salt), so me or somebody else within the SALT team can help you 🙂 .

---

<div class="post-metadata">

**Author:** ![christinah](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/christinah/32/7306_2.png) [@christinah](https://discourse.slicer.org/u/christinah)\
**Post date:** [July 3, 2020, 7:20pm UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311/4 "2020-07-03T19:20:31Z")

</div>

Dear Beatriz,

Thank you very much for your reply. Also, thanks for letting me know that I should be posting in the SALT subforum! Will do next time.

For the medial axis: thanks so much, yes, I have the .vtk file for the parameterization derived medial axis from SPHARM. I’m interested in obtaining the xyz coordinates of that axis (and finding an analytic equation to describe it, which I can use to generate a coordinate system for fem simulations). If that makes sense, do you have any advice about extracting the medial axis coordinates? Thank you very, very much! Possibly this is a very simple question, and I’m missing something… maybe the info is already in the vtk datafile below, and I just don’t know how to read it?

“ASCII  
DATASET POLYDATA  
POINTS 100 float  
-100.422 -310.532 34.3645 -100.303 -310.377 34.5271 -99.9777 -309.886 34.9144  
-99.4429 -309.069 35.4893 -98.6939 …”

On the second topic of extracting the actual spherical mapping matrix (which maps a given phi, theta on a sphere to its corresponding x, y, z in “real space”): thank you for point me to MeshMath! I’ll work on understanding the code and see if I can figure out how to get the mapping matrix/algorithm out using it.

Many thanks for your help. Have a great holiday weekend,  
Christina

---

<div class="post-metadata">

**Author:** ![bpaniagua](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/bpaniagua/32/20_2.png) [@bpaniagua](https://discourse.slicer.org/u/bpaniagua)\
**Post date:** [July 6, 2020, 1:58pm UTC](https://discourse.slicer.org/t/equation-for-medial-axis-from-spharm-pdm/12311/5 "2020-07-06T13:58:59Z")

</div>

Hi Christina,

The POINTS field in that vtk file should include 300 float values that are the x,y,z tuples for all your coordinates.

You can either use [vtk functions](https://vtk.org/Wiki/VTK/Examples/Cxx/PolyData/PolyDataGetPoint) to read those points, or just parse the ascii polydata manually.

HTH  
Bea
