# Import point cloud

**URL:** <https://discourse.slicer.org/t/import-point-cloud/30867>\
**Category:** Support\
**Created:** [July 27, 2023, 4:44pm UTC](https://discourse.slicer.org/t/import-point-cloud/30867 "2023-07-27T16:44:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jessdtate](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jessdtate/32/66993_2.png) [@jessdtate](https://discourse.slicer.org/u/jessdtate)\
**Post date:** [July 27, 2023, 4:44pm UTC](https://discourse.slicer.org/t/import-point-cloud/30867/1 "2023-07-27T16:44:23Z")

</div>

I’m having trouble generalizing this solution to unstructured point clouds. I have an example text file with x, y, z values [here](https://github.com/SCIInstitute/ShapeWorks/blob/master/Testing/data/ellipsoid_particles/seg.ellipsoid_0.isores.pad.com.aligned.cropped.tpSmoothDT_world.particles). I can read them as an numpy array easily enough, and I noticed that there is a new PointSet vtk data type. Is that the way to do this now?

---

<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:** [July 29, 2023, 3:19pm UTC](https://discourse.slicer.org/t/import-point-cloud/30867/2 "2023-07-29T15:19:32Z")

</div>

You can import and visualize point clouds in Slicer by creating a model node and loading the points into its `vtkPolyData` object:

- Create a vkPolyData object and set its points coordinates from numpy array
- Add a vertex cell at each point (or use vtkGlyph3D filter to add a small sphere or other object at each point position) to make something visible at those point positions
- Create a model node from the polydata object

Since VTK is widely used, has a logical and consistent API, documentation, and examples, you can usually generate fully functional Python code for it using bing chat or ChatGPT.

For example, bing chat `generate python code that creates a vtk point cloud from numpy array and generates a polydata from it by adding a small sphere at each point`:

```python
import vtk
import numpy as np

# Create a random point cloud.
points = np.random.rand(1000, 3) * 100

# Create the vtkPoints object.
vtk_points = vtk.vtkPoints()
vtk_points.SetData(vtk.util.numpy_support.numpy_to_vtk(points))

# Create the vtkPolyData object.
polydata = vtk.vtkPolyData()
polydata.SetPoints(vtk_points)

# Create the vtkSphereSource object.
sphere = vtk.vtkSphereSource()
sphere.SetRadius(2.0)

# Create the vtkGlyph3D object.
glyph = vtk.vtkGlyph3D()
glyph.SetInputData(polydata)
glyph.SetSourceConnection(sphere.GetOutputPort())

```

To display this point cloud in Slicer, you can do this:

```python
pointCloudModelNode = slicer.modules.models.logic().AddModel(glyph.GetOutputPort())

```
