Python example code for splineWidget.GetSummedLength

I am trying use splineWidget.GetSummedLength() to get the length of spline, but I always get the same length data no matter how I moved spline around.

Please let know if there is example code for splineWidget.GetSummedLength?

Many thanks in advance.

David.

The following is the code:
######################################################
splineWidget =vtk.vtkSplineWidget()
splineWidget.SetInteractor(iren)
splineWidget.AddObserver(“EndInteractionEvent”, my_call_back)
##############################################
iren.Initialize()
renWin.Render()
distanceWidget.On()
angleWidget.On()
bidimensionalWidget.On()
splineWidget.On()
# Initialize the event loop and then start it.
iren.Start()

def my_call_back(pWidget,ev):

if (pWidget):
    print(pWidget.GetClassName(), "Event Id:", ev)
    if(ev == "EndInteractionEvent"):
        splineWidget = vtk.vtkSplineWidget()
        splineWidget.SetResolution(10)
        length = splineWidget.GetSummedLength()
        print("spline length = "+str(length))
    ####################################  

show(‘C:/results/interpolcontour/s.mhd’)

It looks like you are creating a new vtkSplineWidget every time it’s called that’s why the length is the same.

I have just written an example SplineWidget that shows you how to implement a callback. I’ll probably improve it and write a C++ example in the next few days.

Have a look at the example.

Dear Andrew,

Very appreciate for your generous help.

I am implementing your code into mine.

I will let you know any outcomes.

David.

Dear Andrew,

Your code is working perfectly.

I can get updated spline length.

Many thanks.

David.

Happy New Year

Andrew Maclean

The same wishes for you in New year.

Be safe and happy.

David