How to resample curve nodes programmatically?

Operating system: windows 10
Slicer version:4.11
Expected behavior:
Actual behavior:
I just need to automatically resample a centerline curve to 20 control points from more than 100, similar to the resample section in markups module. Can anyone tell me where I can find documentation on the resample function or any code for it?

Resampling is implemented in the curve node. Note that you can access this function from anywhere, not just from Slicer GUI and Python console, but from a command-line script, Jupyter, etc. so there should be no need to reimplement this feature outside Slicer.

1 Like

@lassoan I want to access it from the python console. Can you tell me how I can do that?

For example, if name of your curve node is ā€œCā€ then you can resample at 10mm sampling distance like this:

getNode('C').ResampleCurveWorld(10)
1 Like

Hey @lassoan , is there any way I can do this to vtkPolyData? I want to resample the vtkpolydata in the python code for extract centerline(centerline extraction logic)

Extract centerline module already does this. You can use this module as is or extract the code that you need from it.

@lassoan thanks. I see that extract centerline has these :
centerlineFilter.SetCenterlineResampling(0)
centerlineFilter.SetResamplingStepLength(1.0)

but they are set to 0 and 1. Do I have to change one of these for the actual resampling like resampleCurveWorld(10) above? Iā€™m sorry if this is a stupid question

You can resample the centerline either in centerlineFilter (by enabling CenterlineResampling and setting the ResamplingStepLength you need) or later using the curve node. Currently, no resampling is performed, so the distances in the output curve depend on the resolution of the input mesh only.

1 Like

Thanks, that worked.