# Attach cube on segmented surface

**URL:** <https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [November 19, 2019, 5:08am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209 "2019-11-19T05:08:28Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [November 19, 2019, 5:08am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/1 "2019-11-19T05:08:28Z")

</div>

Is there any editing tools like “Fill between slices”

I want to attach cube(below pupple colored cube) on the surface(it means segmented region on the slice)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/8/e83c6ccb3c07e8e2449f074772a8979dc320e1de.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 20, 2019, 5:20am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/2 "2019-11-20T05:20:27Z")

</div>

> [@lausiv](#):
>
> Is there any editing tools like “Fill between slices”

There is an effect called “Fill between slices” in Segment Editor module.

> [@lausiv](#):
>
> I want to attach cube(below pupple colored cube) on the surface

Would you like to 3D print a template that fits on the segmented surface? You can do that by the following steps:

- Add a new segment
- Select Scissors effect, set “Operation” to “Fill inside”, “Shape” to “Rectangle”, and “Editable area” to “Outside all segments”, then draw the rectangle in 3D view
- You can use Islands effect’s “Keep selected island” method to keep only that part of the cube that sits on the surface

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [November 20, 2019, 3:53pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/3 "2019-11-20T15:53:27Z")

</div>

Thank you. i will do that 🙂  
i think 3d slicer is very powerful tool as i think.  
3d image processing is very interesting for me  
i m in flow in that field. i love it. i am enthusiast!

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [December 25, 2019, 7:22am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/4 "2019-12-25T07:22:24Z")

</div>

So, I am now automate below behavior using python script.  
but, python scrip for effect of hollow and scissors by fiducial was not found

# behavior

after generating mesh,

1. new segment \<== it is ok
2. threshold-smooth \<== ok
3. markup by fiducial \<== ok  
**4. hollow effect \<== not found**  
**5. scissors effect using markup \<== c++ code founded but python not found**

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/7/b760a97ae64ac7715689edd5335cb526b923b5d5.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/1/6/1605f3c24b56ccbf2a3d1f01499b81811c6b5bef.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/b/7b198167dcbed32fe9a6cbb5f255b615605b0f23.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [December 26, 2019, 11:34pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/5 "2019-12-26T23:34:18Z")

</div>

Scissors effect is developed for interactive use. If you want to place a box on a surface from a script then it is probably much easier to create a box-shaped model node from output of a vtkCurbeSource, then set its pose using a transform node (set translation based on a markups fiducial point position, set orientation by getting the surface normal at the fiducial point), then import the model into a segment in the segmentation node (using `segmentationNode.AddSegmentFromClosedSurfaceRepresentation`).

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [January 10, 2020, 4:27am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/6 "2020-01-10T04:27:54Z")

</div>

From your advise, i did 1 box but now extend 9 boxes.  
If python script is completed well, let it share this page.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/c/acdcd1bb14c36ab931e0e79c7fbef0fc056c2150.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/a/c/ac75a58285165de6ef12fbc685db7ddb16789272.jpeg)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 16, 2020, 9:07pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/11 "2020-01-16T21:07:35Z")

</div>

You can apply a transform by setting the parent transform node (`SetAndObserveTransformNodeID`). See in example in [Transforms module documentation](https://www.slicer.org/wiki/Documentation/Nightly/Modules/Transforms#Examples).

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [January 20, 2020, 4:18am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/12 "2020-01-20T04:18:12Z")

</div>

purpose : I make 9 segmentation pads for generating mesh with the brain skin.

I successfully transformed the pad(cylinder object) on the surface of skin by transform module. and i make segmentation node each pad. but like below picture. when i merge segments to one Segementation Node To Send Segment Mesher, but the transformed setting(Rotation,Trans) is disappeard, in other words, my pad object go to (0,0,0) coordinates. I think this is small bug.

Or, Is there any suggestion for generating mesh with **multiple Segementation Nodes**?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/a/ca78e6957ce88d0263b8b071163fe06211b77ca6.jpeg)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/7/27c2156e0dd0e46d54b992c3690d507a0c6b2223.png)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/3/634f5677ebbc5b2eceb0f8d76fd86e9ddda0a0c9.png)  
![image|634x222](upload:/ ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/0/e0a072d8c6e7b5655e105eeef1c5cbf8040ffb74.png)

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [January 20, 2020, 5:53am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/13 "2020-01-20T05:53:06Z")

</div>

I make 9 cylinder object, -\> transform node -\> segmentation node

```
cylSource = vtk.vtkCylinderSource()
cylSource.SetRadius(10)
cylSource.SetResolution(50)
cylSource.SetHeight(10)
cylSource.SetCenter([0,0,0])
cylSource.Update()

transform = vtk.vtkTransform()
applyTransform = vtk.vtkTransformPolyDataFilter()
applyTransform.SetTransform(transform)
applyTransform.SetInputConnection(cylSource.GetOutputPort())
applyTransform.Update()

nOfPad = 9
for i in range(0,nOfPad):
    transformlNode = slicer.mrmlScene.AddNode(slicer.vtkMRMLTransformNode())
    segmentationNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
    segmentationNode.AddSegmentFromClosedSurfaceRepresentation(cylSource.GetOutput(), "Pad", [1.0,0.0,0.0])
```

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2020, 8:58am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/14 "2020-01-20T08:58:25Z")

</div>

`applyTransform` is a filter (you chose a somewhat misleading name). You need to add the _output_ of that filter to the segmentation: `segmentationNode.AddSegmentFromClosedSurfaceRepresentation(applyTransform.GetOutput()) `

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [January 20, 2020, 9:31am UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/15 "2020-01-20T09:31:55Z")

</div>

Thank you Lasso^^ Aha 🙂 🙂

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2020, 4:50pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/17 "2020-01-20T16:50:34Z")

</div>

You should not add new segmentation node for each pad. Instead, create a single segmentation node and add all the pads to that.

---

<div class="post-metadata">

**Author:** ![lausiv](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lausiv/32/4984_2.png) [@lausiv](https://discourse.slicer.org/u/lausiv)\
**Post date:** [January 20, 2020, 9:38pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/19 "2020-01-20T21:38:49Z")

</div>

but i don not set Rotation on Matrix ^^ . I want to know the fomular or **python function t** o set Matrix from Rx,Ry,Rz

in other words, i want to access python script function for setting below UI Rotation&Translation Value on transformation module, so i can get the transform matrix using

`transformNode.SetMatrixTransformToParent(transformMatrix)`

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/2/a/2af324b2863b298f16d024da13b9b31d84df5817.png)

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 20, 2020, 10:21pm UTC](https://discourse.slicer.org/t/attach-cube-on-segmented-surface/9209/20 "2020-01-20T22:21:35Z")

</div>

> [@lausiv](#):
>
> You should not add new segmentation node for each pad. Instead, create a single segmentation node and add all the pads to that.  
> ==\> Yes. But this case, can i transform for each pad(segmentation) on the Transforms Module?

Yes, you can. The transformation that was applied to the model at the time of import will be preserved in the imported segment.
