Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to output the radius from vtkvmtkPolyDataCenterlines #356

Closed
NeuZhangQiang opened this issue Sep 2, 2020 · 6 comments
Closed

How to output the radius from vtkvmtkPolyDataCenterlines #356

NeuZhangQiang opened this issue Sep 2, 2020 · 6 comments

Comments

@NeuZhangQiang
Copy link

The VMTK tutorial said that the vtkvmtkPolyDataCenterlines can provide the radius of every point. How can I obtain the radius?
I can obtain the points of center lines as following:

    Centerlines = centerlineFilter.GetOutput()
    centerLinePoints = Centerlines.GetPoints()
    voronoiDiagram = centerlineFilter.GetVoronoiDiagram()

    lines = Centerlines.GetLines()
    numberOfLines = lines.GetNumberOfCells()

    points = Centerlines.GetPoints()
    lines.InitTraversal()
    idList = vtk.vtkIdList()

    while lines.GetNextCell(idList):
        n = idList.GetNumberOfIds()

        for id in range(n):

            pointId = idList.GetId(id)
            point = points.GetPoint(pointId)

Even I can obtain the voronoi diagram voronoiDiagram = centerlineFilter.GetVoronoiDiagram(), I don't know how to obtain the radius.

@lassoan
Copy link
Contributor

lassoan commented Sep 3, 2020

You can get radius from the centerline extraction filter as point data array in the output polydata. You can set the array name using SetRadiusArrayName before executing the filter.

@NeuZhangQiang
Copy link
Author

NeuZhangQiang commented Sep 4, 2020

Thank you very much for your reply. But I still don't know how to obtain the radius. If I know the radius array name: centerlineFilter.SetRadiusArrayName('MaximumInscribedSphereRadius').

How can I obtain the radius? Could you please provide an example? Python or C++ is OK.

For example, I can obtain the point coordinate of center line as:

    while lines.GetNextCell(idList):
        n = idList.GetNumberOfIds()

        for id in range(n):

            pointId = idList.GetId(id)
            point = points.GetPoint(pointId)

How to obtain the radius for each point?

@lassoan
Copy link
Contributor

lassoan commented Sep 4, 2020

You can get point data as a numpy array as it is done in this convenience method:

https://github.com/Slicer/Slicer/blob/1ce740cc25e6f22f7a2816767656fd414a5973c7/Base/Python/slicer/util.py#L1262-L1274

@NeuZhangQiang
Copy link
Author

I can get the point as:

voronoiDiagram = centerlineFilter.GetVoronoiDiagram()
import vtk
narray = vtk.util.numpy_support.vtk_to_numpy(voronoiDiagram.GetPoints().GetData())

However, the shape of narray is: n*3, and I believe this array is the coordinate of center lines. I still can not obtain the radius.

@lassoan
Copy link
Contributor

lassoan commented Sep 7, 2020

You are right, to get point data arrays (not the point coordinates), you need to use a slightly different method: arrayFromModelPointData

https://github.com/Slicer/Slicer/blob/1ce740cc25e6f22f7a2816767656fd414a5973c7/Base/Python/slicer/util.py#L1283-L1293

@NeuZhangQiang
Copy link
Author

@lassoan Thank you for your nice reply. Finally, I can obtain the radius.

import vtk
voronoiDiagram = centerlineFilter.GetVoronoiDiagram()
centerlinePoints = vtk.util.numpy_support.vtk_to_numpy(voronoiDiagram.GetPoints().GetData())
radius = vtk.util.numpy_support.vtk_to_numpy(voronoiDiagram.GetPointData().GetArray('MaximumInscribedSphereRadius'))

Hope it may help others.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants