get color array from PolyDataFilter

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/

I saw this post but there is no answer.

Is there any way to access this data?

Thanks
~Shane

Please precise your question.

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!

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

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

@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

https://vtk.org/doc/nightly/html/classvtkObjectBase.html#aedadf6378465fd81c2592ef64262e2a5