Once a contour is available, I would like to manually adjust it by grabbing and moving the contour points. Additionally, a magnetic effect should be there to pull the constructed contour closer to the surface.
Is it possible to achieve this kind of functionality?
Thinking about this more you may be thinking about editing a segmentation in 2D in a way that it has an effect in 3D? Slicer is an application that works with 3D data, so tools focusing on 2D operations are not really present. You could look into the Fill between slices effect in Segment Editor. In any case, more information would be useful.
Unfortunately there is no tool for that in Slicer. I actually developed this in MITK around 2004 and it worked, but the project was in the end abandoned. This is not something very easy to add (Slicer principally works on labelmaps not surface meshes, and it would have its own complications), so this would be a medium sized project, and so far there has not been enough need.
I wonder if deformation vector fields could be used for this somehow.
In any case, please look at the Fill between slices effect, maybe you find it useful.
It might be possible to do this by use of Fiducial Registration Wizard, TPS transform and moving points. But it would be a lot of work. Ultimately this is not segmentation but sculpting, for which there are software better suited to the task than Slicer (I imagine blender for one)…
One place I can see it can be of interest to Slicer community is forensic or fossil reconstructions (so that you can plastically deform things to see what they look like). But again that would probably work better at the polygon data then labelmaps anyways…
What you show in the video is not that much different than just painting the segmentation and having the 3D model regenerated. Depending on what you are trying to do, working directly on a mesh can have a lot of problems like triangles inverting or self intersecting. It’s even worse when there’s more than one segment involved. That’s why operating on the labelmap is preferred, especially when there’s a background reference volume involved.
I came across a VTK class called vtkContourWidget that seems to be exactly what I want in Slicer. Is it possible to integrate this class and use it for 2D segmentation to achieve what was shown in the earlier video?
I’m currently working on this feature as part of my master’s project. From what I understand so far, there seem to be two possible implementation approaches:
Modifying the segmentation directly using labelmaps, similar to how other effects in Slicer operate.
Implementing it more like a sculpting tool, as muratmaga mentioned.
The closest existing effects I’ve found are Fill Between Slices or Paint, as pointed out by @cpinter and @pieper. However, those effects directly modify the labelmap segmentation. In contrast, the behavior in the video you shared looks more like sculpting. When the contour is grabbed and moved, it appears that the model is regenerated, rather than the segmentation itself being updated — that is, it doesn’t relabel the voxels within the new contour area.
From this, I believe the feature would be better implemented as a sculpting tool rather than a traditional 2D segmentation effect, since the goal seems to be modifying the resulting mesh using the segmentation as a reference.
@cpinter — Since you’ve worked on this previously, would you be open to sharing some core ideas? I’m very interested in contributing to this feature and to Slicer in general as part of my thesis work.
@bernando I think some existing effects that are closer to this idea of editing a surface model would be “SurfaceCut” of the SegmentEditorExtraEffects extension which is limited to convex surface modeling (no concavities). There is also a custom markup type called “GridSurface” of the “SlicerSurfaceMarkup” extension that can model concave and convex features in a 2D surface however not as a 3D surface type that could then be used to convert to a labelmap like the SurfaceCut segment editor effect.
Another approach which might be helpful to users coming across this thread is the “Smudge” effect of the Paint tool. This works in the labelmap space, but, with a spherical brush, allows pretty intuitive modifications of segment boundaries in 3D which seem generally similar to what one might hope to achieve by surface point modification on slice views. You need to work in slice views, but it looks like that is what was being mostly proposed anyway.
Many people have asked about this feature in the past, and if you want to implement it, you could try, but I think the scope of this is beyond even a master’s degree, at least if you want to build it on the infrastructure currently exisitng in Slicer.
A summary of what the method I implemented back in the day looked like:
Take the closed surface representation of a segment
Define a “range”, starting from a point and specifying a radius, and it marked the cells within that distance from the seed point
Define a displacement vector (see First and Last below)
Select a function. As I remember we had Gaussian, Sinusoid, and Triangle
Move the points in the range along the displacement vector according to the selected function
Regularization of the resulting mesh. This is very important, and this was quite difficult. The displacement caused some triangles to deform considerably: they got very large/small, elongated, or both. An algorithm was implemented for splitting/merging triangles until all triangles conformed with certain rules (minimum angle, area, etc.). Without this step, subsequent deformations caused a very irregular, ill-formed, uneven mesh. Moreover, the combination of the initial shape and the applied function could cause triangles to cross each other, which is not necessarily solvable by such regularization.
Hopefully after 20 years I don’t break any NDAs by sharing this screenshot
All this said, I don’t think this would make sense to implement in today’s Slicer. The main reason is that this method worked on surface meshes, and the main representation of segmentations in Slicer is binary labelmap, and if you’d want to do this exact workflow, you’d need to break out from that framework and work on model nodes, in a completely new module.
What I could imagine is a Segment Editor effect, which could work the way the video you linked shows, but directly on labelmaps. So from the usage point of view there would be a radius and a “point drag&drop”. The main challenge is the algorithm. You’d need to somehow start from the surface of the segment defined by the start point and radius, and fill in (foreground or background) a shape defined by the function in a way that there are no holes or speckle.
If you like this idea I’d be happy to brainstorm more about it. However, I somehow think that whatever your use case may be, there are simpler ways to solve the need than implement this new tool. But if you definitely need this type of tool and you are (still) in the position to implement it, happy to provide guidance.
Sorry, I just bumped into this thread right now:
Isn’t maybe something the OP meant what we had at the very end of the Slicer 3 days, the tool with the control points? I think it was called ModelDraw
I might not exactly get the idea based on the description, but if yes, well… I know, I know… but I did like that tool, and the functionality!
Here is video on how it worked:
Yes, this seems to be exactly or almost exactly what was proposed.
A little brainstorming: as also mentioned above, this is very similar to the Fill between slices effect. If we want to reach the functionality of ModelDraw, maybe what could be done is:
In the current slice view (mouse over), create a temporary closed curve tracing the edge of the labelmap slice, with a desired density of control points. When the user moves a control point, modify that slice in the labelmap, or if it was an interpolated slice, create one, thus a new slice will be added to fill between slices.
This way the user will have this “ModelDraw-way” of modifying the slices, in addition to painting, as it was already possible in Fill between slices.
Yes, that pretty much could replicate the functionality of the ModelDraw tool.
One big shortcoming was that the number of control points could not be changed for a given label. I kinda know the reason, so this is not a criticism!
On the other hand, the big advantage was that we could use curves to delineate the structures and then apply the labelmap (would be segment nowadays ).
So yes, being able to use a closed curve tracing would be neat!