# Initialize vtkPolyData coordinates using vtkFloatArray with three components

**URL:** https://discourse.vtk.org/t/initialize-vtkpolydata-coordinates-using-vtkfloatarray-with-three-components/7062
**Category:** Support
**Created:** [November 3, 2021, 7:48pm UTC](https://discourse.vtk.org/t/initialize-vtkpolydata-coordinates-using-vtkfloatarray-with-three-components/7062 "2021-11-03T19:48:38Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![brnk](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ecd19e/32.png) [@brnk](https://discourse.vtk.org/u/brnk)
#### Post date: [November 3, 2021, 7:48pm UTC](https://discourse.vtk.org/t/initialize-vtkpolydata-coordinates-using-vtkfloatarray-with-three-components/7062/1 "2021-11-03T19:48:38Z")

</div>

I want to initialize a `vtkPolyData` instance using a `vtkFloatArray` whose three components describe the Cartesian coordinates of the points of a point cloud.

Currently, I create a `vtkPoints` instance and do the following:

```auto
vtkNew<vtkPoints> points;
for (unsigned int i = 0; i < 1000; i++)
	points->InsertNextPoint(i, 2*i, 3*i); // arbitrarily chosen

vtkNew<vtkPolyData> polyData;
polyData->SetPoints(points);

```

However, I want to use a `vtkFloatArray` to store the coordinates as the coordinates are already stored in memory at `float *coordPtr`.

```auto
vtkNew<vtkFloatArray> coords;
coords->SetNumberOfComponents(3); // x, y, and z in Cartesian space
coords->SetNumberOfTuples(1000);
coords->SetArray(coordPtr, 1000, 1);

```

How can I link the `vtkPoints` instance to `coords` or can I set the coordinates of `polyData` directly using `coords`? The overall goal is to visualize a 3D point cloud.

---

<div class="post-metadata">

### Author: ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)
#### Post date: [November 3, 2021, 7:58pm UTC](https://discourse.vtk.org/t/initialize-vtkpolydata-coordinates-using-vtkfloatarray-with-three-components/7062/2 "2021-11-03T19:58:45Z")

</div>

You can call `vtkPoints::SetDataType(VTK_FLOAT)` to have the array you want.

I would advise trying to avoid to use `InsertNextPoint` if you know the final size up front because the internal array will be resized / reallocated pretty often. You should call in this order:

```auto
vtkNew<vtkPoints> points;
points->SetDataType(VTK_FLOAT);
points->SetNumberOfPoints(1000);
// insert points using SetPoint API

```

If you already have a `coords` array that you want to put inside your `vtkPoints`, you can use the `vtkPoints::SetData(vtkDataArray*)` API.
