# New Dynamic Modeler Tool: Select by Points

**URL:** <https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165>\
**Category:** Support\
**Tags:** feature\
**Created:** [February 24, 2022, 8:08pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165 "2022-02-24T20:08:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [February 24, 2022, 8:08pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/1 "2022-02-24T20:08:53Z")

</div>

[![](https://img.youtube.com/vi/Klsi6x3F5D4/maxresdefault.jpg "Select By Points Tool, Dynamic Modeler, 3D Slicer") ](https://www.youtube.com/watch?v=Klsi6x3F5D4)

Select by points tool is available on the Dynamic Modeler module since end of October 2021 Slicer Preview Release

This tools allows you to create 2 types of output models from an input model, a fiducial list, a selection-distance and a selection-algorithm.

One of the possible outputs is copy of the input model with selection scalars (unselected=0, selected=1) according to the selection-algorithm and selection-distance using the fiducial points as seeds.

The other possible output crops out the part of the input model that is selected.

This tool was developed ad-honorem by:

- Mauro I. Dominguez
- Andras Lasso (Perklab)

This tool allows partial mesh registration workflows like weight-painting ICP on Blender.

Related: [Partial Surface Registration Tutorial](https://discourse.slicer.org/t/partial-surface-registration-tutorial/21118)

---

<div class="post-metadata">

**Author:** ![Moh\_d\_Al-Watary](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moh_d_al-watary/32/14124_2.png) [@Moh\_d\_Al-Watary](https://discourse.slicer.org/u/Moh_d_Al-Watary)\
**Post date:** [June 12, 2022, 1:38pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/2 "2022-06-12T13:38:32Z")

</div>

Hi dear, thank you so much for sharing. Actually I am conducting a project to measure the distance of zygoma bone between T1 (taken after a week of operation) and T2 (taken after 6 months of operation).  
I want to know if there is a displacement and if yes how much was in mm and in which direction.

My questions:

1. I am using Pick’n paint, model to model distance, and mesh statistics to export the value in excel file: in the new release of the 3d slicer, I can not use pick’n paint properly: as when trying to add a fiducial point: automatically a lot of points are added!!! previously you send me this answer of using dynamic modeler tool: when I have watched this demo, it is on the same bone not in two models as my case! so how can I solve this problem?  
Thank you again and sorry to bother you.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 12, 2022, 1:42pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/3 "2022-06-12T13:42:38Z")

</div>

You can consider your two bones at different timestamps as two different models

---

<div class="post-metadata">

**Author:** ![Moh\_d\_Al-Watary](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moh_d_al-watary/32/14124_2.png) [@Moh\_d\_Al-Watary](https://discourse.slicer.org/u/Moh_d_Al-Watary)\
**Post date:** [June 12, 2022, 1:49pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/4 "2022-06-12T13:49:37Z")

</div>

actually they are, I am doing the followings:

1. import both DICOM, transformation, rigid registration with Elastix module, then segment each one as volume, saved each one independently.
2. open again both models to start doing the steps mentioned in previous message.

My question:  
how to solve the problem of automatic many points addition that I am facing with the new release version of the 3D Slicer?’  
How dynamic modeler could be used to add fiducial points on T1 model then measure the distance between these points and their matching ones on T2 model? as you mentioned in previous answer.  
Thank you

---

<div class="post-metadata">

**Author:** ![Moh\_d\_Al-Watary](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moh_d_al-watary/32/14124_2.png) [@Moh\_d\_Al-Watary](https://discourse.slicer.org/u/Moh_d_Al-Watary)\
**Post date:** [June 12, 2022, 1:54pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/5 "2022-06-12T13:54:25Z")

</div>

thank you, but what do you mean by (at different timestampes)!

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 12, 2022, 2:04pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/6 "2022-06-12T14:04:45Z")

</div>

Please see this link

> [@Partial Surface Registration Tutorial](https://discourse.slicer.org/t/partial-surface-registration-tutorial/21118):
>
> Hi devs. I have made a tutorial for Partial Surface Registration, something similar to weight-painting ICP that is done in Blender. Here you can access it: If there are no suggestions for corrections I’ll later upload it to Youtube. Mauro

You just need to replace the deformed and normal bone from the video for your T1 and T2 bone models…

If it is not clear enough please let me know

---

<div class="post-metadata">

**Author:** ![Moh\_d\_Al-Watary](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moh_d_al-watary/32/14124_2.png) [@Moh\_d\_Al-Watary](https://discourse.slicer.org/u/Moh_d_Al-Watary)\
**Post date:** [June 12, 2022, 2:18pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/7 "2022-06-12T14:18:21Z")

</div>

Thank you so much for your rapid reply.  
Actually it is so clear and this is to do registration of two models.  
My question actually was how to calculate the displacement amount after doing the registration step of the two models in regard to the ROI which is in my case the zygoma bone?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 12, 2022, 2:21pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/8 "2022-06-12T14:21:02Z")

</div>

@manjula could you help?

I think you need to use the model2model distance extension

---

<div class="post-metadata">

**Author:** ![Moh\_d\_Al-Watary](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/moh_d_al-watary/32/14124_2.png) [@Moh\_d\_Al-Watary](https://discourse.slicer.org/u/Moh_d_Al-Watary)\
**Post date:** [June 12, 2022, 2:26pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/9 "2022-06-12T14:26:42Z")

</div>

exactly, so you mean after doing the registration the next step is to do partial surface registration ( formed by the zygomatic bone of T1, in my case) in the dynamic modeler module then using model to model distance and then mesh statistics to export the values?

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [June 12, 2022, 2:33pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/10 "2022-06-12T14:33:17Z")

</div>

I think it is as you explained but I would only do the partial surface registration

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 22, 2023, 2:44pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/11 "2023-02-22T14:44:38Z")

</div>

Hello,

Thank you for this function! Though, I found that there are only two possibilities for output nodes at the moment: “Model with selection scalars” and “Model of the selected cells”. Is there a way to obtain a “model of the unselected cells” as output? I tried multiple things, but can’t seem to obtain the required model.

What I tried: I can visualize the selection with the “Model with selection scalars” and even “remove (i.e. turn invisible)” the “Model of the selected cells” by lowering the scalar threshold under 1. So, it is only showing the unselected cells, but I don’t find how the export this visualisation/selection as a model.  
I also tried to subtract the “Model of the selected cells” from the input node with the “combine models” function from the Sandbox extension. This gives me an error message, the one that is discussed on this page: [Difference of meshes sometimes an empty mesh · Issue #40 · zippy84/vtkbool · GitHub](https://github.com/zippy84/vtkbool/issues/40).

Is there another way to obtain this “Model of the unselected cells”?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [February 22, 2023, 3:49pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/12 "2023-02-22T15:49:10Z")

</div>

> [@eliagre](#):
>
> Is there a way to obtain a “model of the unselected cells” as output?

Yes, you should use vtkThreshold and vtkGeometryFilter on the “Model with selection scalars” Polydata

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 22, 2023, 4:31pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/13 "2023-02-22T16:31:02Z")

</div>

> [@mau\_igna\_06](#):
>
> Yes, you should use vtkThreshold and vtkGeometryFilter on the “Model with selection scalars” Polydata

Thank you for your fast reply! Could you tell me how should I use these vtkThreshold and vtkGeometryFilter? (My apologies, I’m not familiar with coding in python and quite new to 3DSlicer).  
I found how to call on my model (see under), but do not know how to apply the mentioned functions.

```auto
modelNode = slicer.util.getNode("Model")

```

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 22, 2023, 10:41pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/14 "2023-02-22T22:41:29Z")

</div>

I compilated this piece of code just now. While it gives me an output, this output is empty. Could you tell what I’m doing wrong, please?

```auto
modelNode = slicer.util.getNode("Model")
threshold = vtk.vtkThreshold()
threshold.SetInputConnection(modelNode.GetPolyDataConnection())
threshold.SetThresholdFunction(threshold.THRESHOLD_UPPER)
threshold.SetUpperThreshold(0.9)
surface = vtk.vtkGeometryFilter()
surface.SetInputConnection(threshold.GetOutputPort())
thresholdedModel = slicer.modules.models.logic().AddModel(surface.GetOutputPort())

```

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [February 22, 2023, 11:12pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/15 "2023-02-22T23:12:05Z")

</div>

I think you need to do:

```auto
surface.SetInputConnection(threshold.GetOutputPort())
surface.Update() #This is needed on the last filter to chain execute them
thresholdedModel = slicer.modules.models.logic().AddModel(surface.GetOutput()) # GetOutput() returns Polydata while GetOutputPort() is a cable connection to the geometryFilter

```

Let me know how it goes

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 22, 2023, 11:27pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/16 "2023-02-22T23:27:23Z")

</div>

Thank you for the advice, but it still doesn’t work. The script returns a new Surface Mesh (vtkPolyData), but it is empty (surface area and such are still 0).

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [February 22, 2023, 11:32pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/17 "2023-02-22T23:32:19Z")

</div>

Please check here:

> <https://github.com/Slicer/SlicerSurfaceToolbox/blob/master/DynamicModeler/Logic/vtkSlicerDynamicModelerSelectByPointsTool.cxx>

And use it as example

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 23, 2023, 9:07am UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/18 "2023-02-23T09:07:18Z")

</div>

> [@mau\_igna\_06](#):
>
> And use it as example

I’ve been trying to use your script as an example, but it is hard for me (I’m a newbie and not familiar with python or C++ (I think?) at all). So my apologies for the questions.

```auto
modelNode = slicer.util.getNode("Model")

#it seems these lines from your script may be useful here, but I don't know how to translate them to python
vtkPointData* pointScalars = vtkPointData::SafeDownCast(inputMesh_WorldWithSelection->GetPointData());
    pointScalars->AddArray(outputSelectionArray);
#inputMesh_WorldWithSelection should be replaced with modelNode

threshold = vtk.vtkThreshold()
threshold.SetInputConnection(modelNode.GetPolyDataConnection())
threshold.SetThresholdFunction(threshold.THRESHOLD_UPPER)
threshold.SetUpperThreshold(0.5)
threshold.Update() #added this line
surface = vtk.vtkGeometryFilter()
surface.SetInputConnection(threshold.GetOutputPort())
surface.Update()
thresholdedModel = slicer.modules.models.logic().AddModel(surface.GetOutput())

```

As this didn’t seem to work out (couldn’t figure out how to convert from one language to the other), I tried a different approach, but ran into another error message. Would this approach even be viable?

```auto
modelNode = slicer.util.getNode("Model")
scalars = arrayFromModelPointData(modelNode, 'Selection')
filter_arr = []
for element in scalars:
	if element > 1: 
		filter_arr.append(True)
	else: 
		filter_arr.append(False)
filtered = modelNode[filter_arr]
thresholdedModel = slicer.modules.models.logic().AddModel(filtered.GetOutput())

```

```auto
Error message: 
Traceback (most recent call last):
  File "<string>", line 9, in <module>
TypeError: 'MRMLCore.vtkMRMLModelNode' object is not subscriptable

```

Could you please help me out with this code? I’m quite lost how to make this work.

---

<div class="post-metadata">

**Author:** ![mau\_igna\_06](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mau_igna_06/32/9056_2.png) [@mau\_igna\_06](https://discourse.slicer.org/u/mau_igna_06)\
**Post date:** [February 23, 2023, 9:56am UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/19 "2023-02-23T09:56:49Z")

</div>

> [@eliagre](#):
>
> I’ve been trying to use your script as an example, but it is hard for me (I’m a newbie and not familiar with python or C++ (I think?) at all).

I usually find vtk python examples here:

> **[Python Code Examples - HotExamples](https://python.hotexamples.com/)**
>
> This service was created to help programmers find real examples of using classes and methods as well as documentation. Our system automatically searches, retrieves and ranks examples of source code from more than 1 million opensource projects. A key...

---

<div class="post-metadata">

**Author:** ![eliagre](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/eliagre/32/18509_2.png) [@eliagre](https://discourse.slicer.org/u/eliagre)\
**Post date:** [February 23, 2023, 3:58pm UTC](https://discourse.slicer.org/t/new-dynamic-modeler-tool-select-by-points/22165/20 "2023-02-23T15:58:31Z")

</div>

Thank you for the examples, they helped! Here is the updated code to get the ‘Model of the Unselected Cells’.

```auto
modelNode = slicer.util.getNode("Model")
threshold = vtk.vtkThreshold()
threshold.SetInputConnection(modelNode.GetPolyDataConnection())
threshold.SetThresholdFunction(threshold.THRESHOLD_LOWER)
threshold.SetLowerThreshold(0.5)
threshold.SetInputArrayToProcess(0,0,0, vtk.vtkDataObject.FIELD_ASSOCIATION_POINTS, "Selection")
threshold.Update()
surface = vtk.vtkGeometryFilter()
surface.SetInputConnection(threshold.GetOutputPort())
surface.Update() 
thresholdedModel = slicer.modules.models.logic().AddModel(surface.GetOutput())

```
