# The Slice Focus Fun seems still perfect

**URL:** <https://discourse.slicer.org/t/the-slice-focus-fun-seems-still-perfect/19909>\
**Category:** Development\
**Tags:** python\
**Created:** [September 29, 2021, 10:16am UTC](https://discourse.slicer.org/t/the-slice-focus-fun-seems-still-perfect/19909 "2021-09-29T10:16:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [September 29, 2021, 10:16am UTC](https://discourse.slicer.org/t/the-slice-focus-fun-seems-still-perfect/19909/1 "2021-09-29T10:16:18Z")

</div>

```auto

# ### P4SliceFocus
# - [[P4SliceFocus]]
# - From: [Set slice position and orientation from 3 markup fiducials](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#set-slice-position-and-orientation-from-3-markup-fiducials)
# - [TODO]: 2点聚焦, slice对正, 某个slice放大, 简化代码用循环

  def P4SliceFocus(self, oP, xP, yP, zP):
      '''
      Param:oP:原点
            xP:X轴上的一点
            yP:Y轴上的一点
            zP:Z轴上的一点
      return:在3个slic上聚焦
      
      '''
      oP = oP + [.01, .01, .01]
      yP = yP + [0, .01, 0]
      xP = xP + [.01, 0, 0]
      zP = zP + [0, 0, .01]
      sliceNode = slicer.app.layoutManager().sliceWidget("Red").mrmlSliceNode()
      points = np.array([list(zip(*np.array([oP,xP,yP])))])[0]
      planePosition = points.mean(axis=1)
      planeNormal = np.cross(points[:,1] - points[:,0], points[:,2] - points[:,0])
      planeX = points[:,1] - points[:,0]
      sliceNode.SetSliceToRASByNTP(planeNormal[0], planeNormal[1], planeNormal[2], planeX[0], planeX[1], planeX[2], planePosition[0], planePosition[1], planePosition[2], 0)

      sliceNode = slicer.app.layoutManager().sliceWidget("Yellow").mrmlSliceNode()
      points = np.array([list(zip(*np.array([yP,zP,oP])))])[0]
      planePosition = points.mean(axis=1)
      planeNormal = np.cross(points[:,1] - points[:,0], points[:,2] - points[:,0])
      planeX = points[:,1] - points[:,0]
      sliceNode.SetSliceToRASByNTP(planeNormal[0], planeNormal[1], planeNormal[2], planeX[0], planeX[1], planeX[2], planePosition[0], planePosition[1], planePosition[2], 0)

      sliceNode = slicer.app.layoutManager().sliceWidget("Green").mrmlSliceNode()
      points = np.array([list(zip(*np.array([oP,xP,zP])))])[0]
      planePosition = points.mean(axis=1)
      planeNormal = np.cross(points[:,1] - points[:,0], points[:,2] - points[:,0])
      planeX = points[:,1] - points[:,0]
      sliceNode.SetSliceToRASByNTP(planeNormal[0], planeNormal[1], planeNormal[2], planeX[0], planeX[1], planeX[2], planePosition[0], planePosition[1], planePosition[2], 0)

    

```

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

根据这段代码, 我做了上面这段代码, 我的目的是在3个slice里聚焦一个model…这段代码不够完美:

- 有2个点就可以完成聚焦任务了

- 如何对齐各个slice

- 如何放大某个slice

According to [Set slice position and orientation from 3 markup fiducials](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#set-slice-position-and-orientation-from-3-markup-fiducials), I wrote the above code, my purpose is to focus on a model in 3 slices… This code is not perfect:

- 2 points to complete the focus task
- How to align each slice
- How to enlarge a slice

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [September 29, 2021, 10:49am UTC](https://discourse.slicer.org/t/the-slice-focus-fun-seems-still-perfect/19909/2 "2021-09-29T10:49:44Z")

</div>

@lassoan@Juicy@jamesobutler @jcfr @pieperThanks @chir.set
