# get color array from PolyDataFilter

**URL:** https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755
**Category:** Support
**Created:** [March 4, 2020, 10:12pm UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755 "2020-03-04T22:12:59Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![ShaneKirkbride](https://discourse.vtk.org/user_avatar/discourse.vtk.org/shanekirkbride/32/1392_2.png) [@ShaneKirkbride](https://discourse.vtk.org/u/ShaneKirkbride)
#### Post date: [March 4, 2020, 10:12pm UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/1 "2020-03-04T22:12:59Z")

</div>

I’m trying to get an array of colors and their corresponding vertices from a polyData distance filter similiar to this: [https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/DistancePolyDataFilter/](https://lorensen.github.io/VTKExamples/site/Cxx/PolyData/DistancePolyDataFilter/)

I saw this post but there is no answer.

> [@Getting color codes of the points](https://discourse.vtk.org/t/getting-color-codes-of-the-points/809):
>
> Hello, I used streamtracer and happily got my streamline(points). I color them with velocity magnitudes. I am using an external viewer, therefore (in order not to calculate all the look up table data, velocities and more) I want to get the color responding these points. Anyone has an experience with it ? Best regards,

Is there any way to access this data?

Thanks  
~Shane

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 5, 2020, 2:15am UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/2 "2020-03-05T02:15:38Z")

</div>

Please precise your question.

---

<div class="post-metadata">

### Author: ![ShaneKirkbride](https://discourse.vtk.org/user_avatar/discourse.vtk.org/shanekirkbride/32/1392_2.png) [@ShaneKirkbride](https://discourse.vtk.org/u/ShaneKirkbride)
#### Post date: [March 5, 2020, 4:18am UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/3 "2020-03-05T04:18:34Z")

</div>

Hi @mwestphal,  
I’m still trying to wrap my head completely around VTK so thank you so much for your help!

If I have a DistacePolyDataFilter like this:

```
  vtkSmartPointer<vtkDistancePolyDataFilter> distanceFilter = vtkSmartPointer<vtkDistancePolyDataFilter>::New();  
  distanceFilter->SetInputConnection( 0, clean1->GetOutputPort() );
  distanceFilter->SetInputConnection( 1, clean2->GetOutputPort() );
  distanceFilter->Update();

```

I can get the vertex data and corresponding faces like this:

```
  auto distanceFilterMesh = distanceFilter->GetOutput();
  vtkSmartPointer<vtkPoints> points1 = distanceFilterMesh->GetPoints();;
  vtkSmartPointer<vtkDataArray> dataArray1 = points1->GetData();
  vtkSmartPointer<vtkIdList> faceIndex = vtkSmartPointer<vtkIdList>::New();
  distanceFilterMesh->GetCellPoints(0, faceIndex);
   
  double vertexArray[3];
  auto vertexIndex = faceIndex->GetId(0);  
  vertexArray[0] = dataArray1->GetComponent(vertexIndex, 0);
  vertexArray[1] = dataArray1->GetComponent(vertexIndex, 1);
  vertexArray[2] = dataArray1->GetComponent(vertexIndex, 2);

```

How do I get the distances that the distance filter calculated? I need the distance values. I’m sure there’s a way to do this but i’m maybe overlooking the technique.  
Thanks!

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 5, 2020, 7:28am UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/4 "2020-03-05T07:28:39Z")

</div>

`distanceFilterMesh->GetPointData()->GetArray("Distance");`

In doubt, do not hesitate to use the Print method to get info about a dataset.

---

<div class="post-metadata">

### Author: ![ShaneKirkbride](https://discourse.vtk.org/user_avatar/discourse.vtk.org/shanekirkbride/32/1392_2.png) [@ShaneKirkbride](https://discourse.vtk.org/u/ShaneKirkbride)
#### Post date: [March 5, 2020, 1:47pm UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/5 "2020-03-05T13:47:37Z")

</div>

@mwestphal thanks for you help! How do I use the Print method? I’m sure there’s probably some example documentation I could read?

Specifically about the DistancePolyDataFilter and from the example provided:  
I do this to get the polyData information:

```
  vtkSmartPointer<vtkDistancePolyDataFilter> distanceFilter = vtkSmartPointer<vtkDistancePolyDataFilter>::New();  
  distanceFilter->SetInputConnection( 0, clean1->GetOutputPort() );
  distanceFilter->SetInputConnection( 1, clean2->GetOutputPort() );
  distanceFilter->Update();

  auto distanceFilterMesh = distanceFilter->GetOutput();

```

Then if I want to look at the distance and corresponding vertices is this the correct way:

```
vtkSmartPointer<vtkPoints> points1 = distanceFilterMesh->GetPoints();;
  vtkSmartPointer<vtkDataArray> dataArray1 = points1->GetData();
  vtkSmartPointer<vtkIdList> faceIndex = vtkSmartPointer<vtkIdList>::New();

  auto distances = distanceFilterMesh->GetPointData()->GetArray("Distance");

  distanceFilterMesh->GetCellPoints(0, faceIndex);   
  double vertexArray[3]; double distanceArray[3];
  auto vertexIndex0 = faceIndex->GetId(0);
  auto vertexIndex1 = faceIndex->GetId(1);
  
  distanceArray[0] = distances->GetComponent(vertexIndex0, 0);
  distanceArray[1] = distances->GetComponent(vertexIndex0, 1);
  distanceArray[2] = distances->GetComponent(vertexIndex0, 2);

  vertexArray[0] = dataArray1->GetComponent(vertexIndex0, 0);
  vertexArray[1] = dataArray1->GetComponent(vertexIndex0, 1);
  vertexArray[2] = dataArray1->GetComponent(vertexIndex0, 2);

```

Where `distanceArray[0]` is the distance `vertexArray[0]` moved?

what is the relationship between the vertex in input1 and the vertex in input2 in the example to the vertexArray?

thanks again! this is a great framework and I’m glad I found it…  
~Shane

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [March 5, 2020, 2:47pm UTC](https://discourse.vtk.org/t/get-color-array-from-polydatafilter/2755/6 "2020-03-05T14:47:10Z")

</div>

[https://vtk.org/doc/nightly/html/classvtkObjectBase.html#aedadf6378465fd81c2592ef64262e2a5](https://vtk.org/doc/nightly/html/classvtkObjectBase.html#aedadf6378465fd81c2592ef64262e2a5)
