Access point and cell data of surface mesh

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 inthis post

Any suggestion!

Thank you

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.

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

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

Thank you a lot @mschumaker :slight_smile:

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

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?

1 Like

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

1 Like

Thank you @mschumaker
I really appreciate your help :slight_smile:

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

2 Likes

Thank you @lassoan

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

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.

1 Like