How to place vtkDistanceWidget to vtkImageReslice to save it as the slice meta image

I created vtkDistanceWidget to measure distance on my reslice image. and it works fine but when I scroll through slices, the distanceWidget also appears.I want to display the measure tool only for current slice not all slices and also want to save the measure tool (points) to meta file.
So I don’t know how to add the widget to my image data and save to meta file and restore from.
Here is my snippet:

measure_widget = vtk.vtkDistanceWidget()
measure_repr = vtk.vtkDistanceRepresentation2D()
1 Like

You need to show/hide the widgets manually.

Note that this feature (and all the others that you have asked about in recent months) is already implemented in standard, free, open-source medical image viewers, such as 3D Slicer and MITK. There is no need to waste time with redeveloping all the basic features from scratch because you can customize and extend this applications to fulfill your needs.

Thanks for your help.but actually I don’t know how to use the 3d slicer source code of each part in my script.
Can you help me with that?

Thank you so much

You run your script within 3D Slicer’s Python interpreter. If you have further questions about how to use VTK in Slicer’s environment, how to customize and extend the application, etc. then post to the Slicer forum.

I’m developing a software and wants to implement this feature in my app not to use the feature.

If you are developing a phone or tablet app then I don’t have a helpful suggestion (other than you probably need to implement features that are not available in VTK).

If you are developing a desktop application then see this topic.

I’m developing desktop app and I understand what you mean. You are right but I have some issue about it and right now cannot do that.
could you please help me with my question for now?
I want to save the start and end point of ruler (vtkDistanceWidget) in meta file.I don’t know what class should I use and how to save each ruler points for each image slice all in one mhd file.
I created vtkArray and added to image’s fieldData then pass vtkPassArrays output as input of vtkDataSetWriter. but it writes each slice in one file.I want something that can write all slices data in one mhd file.