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.
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
mwestphal
(Mathieu Westphal (Kitware))
March 5, 2020, 2:15am
2
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!
mwestphal
(Mathieu Westphal (Kitware))
March 5, 2020, 7:28am
4
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
mwestphal
(Mathieu Westphal (Kitware))
March 5, 2020, 2:47pm
6