# How to create a mesh data from vtkPoints?

**URL:** https://discourse.vtk.org/t/how-to-create-a-mesh-data-from-vtkpoints/6585
**Category:** Support
**Created:** [September 9, 2021, 3:16am UTC](https://discourse.vtk.org/t/how-to-create-a-mesh-data-from-vtkpoints/6585 "2021-09-09T03:16:58Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [September 9, 2021, 8:47am UTC](https://discourse.vtk.org/t/how-to-create-a-mesh-data-from-vtkpoints/6585/4 "2021-09-09T08:47:00Z")

</div>

In VTK, points are only 3D coordinates. They serve as a support for cells.  
To have a valid point cloud, you need:

- a `vtkDataSet` that support explicit points, here we will use a `vtkPolyData`
- the `vtkPoints` containing the points, which you already have
- the `vtkCellArray` containing the cells so you have a valid VTK data set

We can construct one like that:

```cpp
   // vtk data set to fill
   vtkNew<vtkPolyData> myPolyData;

   // compute a vtkIdList that contains ids of each points
  vtkIdType numPoints = myVtkPoints->GetNumberOfPoints();
  vtkSmartPointer<vtkIdList> pointIds = vtkSmartPointer<vtkIdList>::New();
  pointIds->SetNumberOfIds(numPoints);
  for (vtkIdType i = 0; i < numPoints; ++i)
  {
    pointIds->SetId(i, i);
  }

   // create a vtkCellArray from this list
  vtkSmartPointer<vtkCellArray> polyPoint = vtkSmartPointer<vtkCellArray>::New();
  polyPoint->InsertNextCell(pointIds);

   // give the points and cells to the final poly data
  myPolyData->SetPoints(myVtkPoints);
  myPolyData->SetVerts(polyPoint);

```

In this code, I assume you have `myVtkPoints` that is the `vtkPoints` containing the positions of points in your point cloud

---

_[View the full topic](https://discourse.vtk.org/t/how-to-create-a-mesh-data-from-vtkpoints/6585)._
