Hello,
I have a nice polygonal anatomical model export to VTP format.
Paraview is employed to help visualize the surface model.
All is well.
I wish to add labels to certain “key points” or possibly specific cells.
I tried following the example–
https://kitware.github.io/vtk-examples/site/Cxx/Visualization/LabelPlacementMapper/
But I am still missing a concept as the labels are not visible under Paraview.
Any ideas would be appreciated.|
// Create a point set.
int NUM_PTS = 24;
vtkNew<vtkPointSource> pointSource;
pointSource->SetNumberOfPoints(NUM_PTS);
pointSource->Update();
vtkSmartPointer<vtkStringArray> labels = vtkSmartPointer<vtkStringArray>::New();
vtkSmartPointer<vtkIntArray> sizes = vtkSmartPointer<vtkIntArray>::New();
vtkSmartPointer<vtkPointSetToLabelHierarchy> pointSetToLabelHierarchyFilter = vtkSmartPointer<vtkPointSetToLabelHierarchy>::New();
vtkSmartPointer<vtkCellArray> celldata = vtkSmartPointer<vtkCellArray>::New();
vtkSmartPointer<vtkFloatArray> scalars = vtkSmartPointer<vtkFloatArray>::New();
vtkSmartPointer<vtkTextProperty> textprop = vtkSmartPointer<vtkTextProperty>::New();
// Add label array
labels->SetNumberOfValues(NUM_PTS);
labels->SetName("labels");
// Add priority array
sizes->SetNumberOfValues(NUM_PTS);
sizes->SetName("sizes");
for (vtkIdType i = 0; i < NUM_PTS; i++)
{
labels->SetValue(i, std::string("My Label ") + std::to_string(i));
sizes->SetValue(i, i);
}
pointSource->GetOutput()->GetPointData()->AddArray(labels);
pointSource->GetOutput()->GetPointData()->AddArray(sizes);
vtkPoints* points = pointSource->GetOutput()->GetPoints();
for (vtkIdType id = 0; id < points->GetNumberOfPoints(); id++)
{
scalars->InsertValue(id, float(id*10));
celldata->InsertNextCell(1);
celldata->InsertCellPoint(id);
}
vtkSmartPointer<vtkPolyData> polydata = vtkSmartPointer<vtkPolyData>::New();
polydata->SetPoints(points);
polydata->SetVerts(celldata);
polydata->GetPointData()->SetScalars(scalars);
polydata->GetPointData()->AddArray(labels);
polydata->GetPointData()->AddArray(sizes);
polydata->BuildCells();
pointSetToLabelHierarchyFilter->SetInputData(polydata);
pointSetToLabelHierarchyFilter->SetLabelArrayName("labels");
pointSetToLabelHierarchyFilter->SetPriorityArrayName("sizes");
pointSetToLabelHierarchyFilter->Update();
vtkSmartPointer<vtkXMLPolyDataWriter> writer = vtkSmartPointer<vtkXMLPolyDataWriter>::New();
writer->SetFileName("Y:\\data\\test_vtk_labels.vtp");
writer->SetInputData(polydata);
writer->SetDataModeToBinary(); // or writer->SetDataModeToAscii();
writer->Write();
thx e.-