# Access point and cell data of surface mesh

**URL:** <https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426>\
**Category:** Development\
**Created:** [March 26, 2018, 2:59pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426 "2018-03-26T14:59:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 26, 2018, 2:59pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/1 "2018-03-26T14:59:31Z")

</div>

Hello everyone,

I used vtkMarchingCubes to generate isosurface, from volume file.  
I need to extract data from this surface, which mean print point and index in separate files.

Which mean, without passing via a writer.

Some steps are mentioned in[this post](https://discourse.slicer.org/t/how-to-get-correct-mask-value-from-one-segment-from-segment-editor/1895/9)

Any suggestion!

Thank you

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [March 26, 2018, 3:36pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/2 "2018-03-26T15:36:26Z")

</div>

The point set within a model’s poly data is accessible. The output of the vtkMarchingCubes algorithm is a vtkPolyData. I’m doing something similar. Here is how I loop over the point indices and get the position of each point via Python script:

```
modelNode = slicer.util.getNode(modelNodeID)
modelPolyData = modelNode.GetPolyData()
numPoints = modelPolyData.GetNumberOfPoints()
for ptId in range(numPoints):
    pointPos = [0,0,0]
    modelPolyData.GetPoint(ptId, pointPos)

```

GetPoint fills the three-element list with the position of the point corresponding to index ptId. You can then write these values to files.

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 26, 2018, 3:45pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/3 "2018-03-26T15:45:13Z")

</div>

> [@mschumaker](#):
>
> modelNode

Thank you @mschumaker for your fast reply.  
in fact, I already got the surface from MarchingCubes step, under vtk.

```
 vtkSmartPointer<vtkMarchingCubes> surface = vtkSmartPointer<vtkMarchingCubes>::New();
 surface->SetValue(0, isoValue);

```

I’m looking for a way to extract data from “surface”, with vtk method.

Do you have any idea ?

Thanks again

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [March 26, 2018, 3:53pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/4 "2018-03-26T15:53:22Z")

</div>

Oh, you’re working in C++. You can clean this up as necessary, but the next steps after that would be:

```
surface->SetInputData(<image data input>)
surface->ReleaseDataFlagOn()
surface->Update()
vtkSmartPointer<vtkPolyData> modelPolyData = surface->GetOutput()
int numPoints = modelPolyData->GetNumberOfPoints()
double pointPos[3]
for (ptId=0; ptId<numPoints; ptId++){
    modelPolyData->GetPoint(ptId, pointPos)
}

```

Here is the vtkPolyData class reference, which can give you other options for accessing the point data within the data structure (or cell data, if necessary).  
[https://www.vtk.org/doc/nightly/html/classvtkPolyData](https://www.vtk.org/doc/nightly/html/classvtkPolyData)

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 27, 2018, 9:11am UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/5 "2018-03-27T09:11:33Z")

</div>

Thank you a lot @mschumaker 🙂

just, I would like to take your advice :

I’m trying to find an IDE under Linux ( Ubuntu ), in order to work easily with vtk library, I mean which support gotoDefiniton functionality.

please, let me know your idea

Thanks again

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [March 27, 2018, 2:29pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/6 "2018-03-27T14:29:36Z")

</div>

You’re welcome.  
I don’t know much about IDEs for Linux, and I don’t know of one that has that functionality for VTK. All of my work with VTK in C++ was in Windows with Visual Studio.

Maybe other people here will have ideas?

---

<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:** [March 27, 2018, 2:33pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/7 "2018-03-27T14:33:14Z")

</div>

I think most of us uses PyCharm as Python IDE. But you can use Eclipse, LiClipse, Visual Studio. All can be connected to Slicer for interactive debugging. See more information here: [https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools](https://www.slicer.org/wiki/Documentation/Nightly/Extensions/DebuggingTools)

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 27, 2018, 2:53pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/8 "2018-03-27T14:53:02Z")

</div>

Thank you @mschumaker  
I really appreciate your help 🙂

By the way, it’s work, now I can extract points and index 😉

---

<div class="post-metadata">

**Author:** ![MGM](https://avatars.discourse-cdn.com/v4/letter/m/ebca7d/32.png) [@MGM](https://discourse.slicer.org/u/MGM)\
**Post date:** [March 27, 2018, 3:29pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/9 "2018-03-27T15:29:12Z")

</div>

Thank you @lassoan

the problem that I can’t find an IDE wich support vtk recursive sub-folder.  
I tried Visual studio code, Eclipse

---

<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:** [March 27, 2018, 3:36pm UTC](https://discourse.slicer.org/t/access-point-and-cell-data-of-surface-mesh/2426/10 "2018-03-27T15:36:40Z")

</div>

PyCharm works well for me, including documentation, auto-complete, etc. Of course only when the debugger is connected to Slicer, otherwise the IDE cannot figure out what type each variable is.
