# How to replace markups with np.array in application MarkupsToModel

**URL:** https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000
**Category:** Development
**Tags:** python
**Created:** [August 30, 2022, 1:20pm UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000 "2022-08-30T13:20:02Z")
**Posts on this page:** 12
**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: [August 30, 2022, 1:20pm UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/1 "2022-08-30T13:20:02Z")

</div>

I want to convert a set of point clouds (np.array) to closed surfaces, How to use `np.array` directly in `MarkupsToModel` instead of converting `np.array` to `Markups`?

---

<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: [August 30, 2022, 6:49pm UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/2 "2022-08-30T18:49:24Z")

</div>

You need to convert the numpy array to a MRML model node to use it in Slicer modules. Bulk data (point coordinates) does not have to be copied, so the conversion should take negligible time.

---

<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: [August 30, 2022, 10:25pm UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/3 "2022-08-30T22:25:05Z")

</div>

Thanks!!!@lassosan  
I see 😇

> [@lassoan](#):
>
> convert the numpy array to a MRML model node

但是, 我想要这个👇面积, 可是转化为model后得到的表面积似乎有点大, 转化为curve后得到的面积似乎又太小了…

> However, I want 👇 this area, but the surface area obtained after converting to model seems to be too large, and the area obtained after converting to curve seems to be too small…what’s wrong?
> 
> ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/5/85df068ce23de1afd235e5016e1e5266f7229194.png)

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/1/e10d4f133a3a5b2e7f6761d408036e1aacdd6c7d.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: [August 31, 2022, 12:47am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/4 "2022-08-31T00:47:53Z")

</div>

What is your end goal?  
What the point cloud represents (points on a curve, points on surface, points in a 3D region,…)?  
Do you need to interact with the points or just create a model?

---

<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: [August 31, 2022, 12:53am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/5 "2022-08-31T00:53:55Z")

</div>

I want to get the area of ​​contours formed by a set of point clouds (np.array) that lie in a plane.  
👇

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/0/40f103cd20b45f8f8df4f8328a522c5895fc34e3.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: [August 31, 2022, 2:48am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/6 "2022-08-31T02:48:01Z")

</div>

Do you want to fit a plane to these points? You can do that directly using a markup plane, as shown [here](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html#fit-markups-plane-to-model). Note that points are imported into a model node instead of a markup point list node.

---

<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: [August 31, 2022, 3:12am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/7 "2022-08-31T03:12:43Z")

</div>

No…I want the surface Area of ​​contours formed by a set of point clouds (np.array) …

---

<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: [August 31, 2022, 3:20am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/8 "2022-08-31T03:20:48Z")

</div>

If you want to compute soap bubble surface from ordered points along a closed curve then you can do that by importing the points into a markup closed curve node and enabling the “area” measurement. If you want to see the generated surface then I would recommend to use the [Baffle Planner module in SlicerHeart extension](https://github.com/SlicerHeart/SlicerHeart/blob/master/Docs/BafflePlanner.md) and then get the surface area of the generated model from the Models module.

---

<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: [August 31, 2022, 11:52pm UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/9 "2022-08-31T23:52:40Z")

</div>

I tried to compute the [quote=“lassoan, post:8, topic:25000”]  
surface from ordered points along a closed curve then you can do that by importing the points into a markup closed curve node  
[/quote], but found that its efficiency is too low, especially when using `slicer.util.updateMarkupsControlPointsFromArray`, is there a better and faster method to get a curve from np.array?

---

<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: [September 3, 2022, 2:05am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/10 "2022-09-03T02:05:45Z")

</div>

I’ve fixed the performance issue in the latest Slicer Preview Release (that you download 2022-09-03 or later). Now `slicer.util.updateMarkupsControlPointsFromArray` should complete immediately.

---

<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 3, 2022, 2:43am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/11 "2022-09-03T02:43:33Z")

</div>

> [@lassoan](#):
>
> in the latest Slicer Preview Release (that you download 2022-09-03 or later)

Can I only replace the util.py file in the my current version (5.1.0-2022-05-08) Slicer with [util.py](https://github.com/Slicer/Slicer/blob/main/Base/Python/slicer/util.py) without updating the Slicer?

---

<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: [September 3, 2022, 3:21am UTC](https://discourse.slicer.org/t/how-to-replace-markups-with-np-array-in-application-markupstomodel/25000/12 "2022-09-03T03:21:47Z")

</div>

As I remember I’ve made some more improvements since Slicer-5.0.3 in C++ code, so updating util.py is probably not sufficient. Another complication may be that util.py of Slicer-5.1 may not be compatible with Slicer-5.0. I would recommend to download the Slicer Preview Release tomorrow and use that.
