Cannot call SetScalar()

I’m new to VTK and I try to use VTK9.1 + QT6 to display points cloud.
I found tutorials and examples for displaying points cloud with different color by calling SetScalar().
Here’s the code:

vtkSmartPointer points = vtkSmartPointer::New();
vtkSmartPointer colors = vtkSmartPointer::New();
colors->SetNumberOfComponents(3); // RGB
colors->SetName(“Colors”);

//Here’s code to read points cloud
points->InsertNextPoint(x,y,z);
//here’s code for color

unsigned char color[3] = {r, g, b};
colors->InsertNextTypedTuple(color);

//
// display
vtkSmartPointer polyData = vtkSmartPointer::New();
polyData->SetPoints(points);

// basically this is the typical way to add colors to points, but I cannot call SetScalars(colors) after “polyData->GetPointData()”. I don’t know how to fix this.
polyData->GetPointData()->SetScalars(colors);

can anyone help me ? I want a colorful points cloud model in the window.

I don’t do much VTK C++, but from the documentation, SetScalars requires a vtkDataArray, have you converted colors to a vtkDataArray?

yes, I found it should be declared by this type rather than use smartpointer

rexthor via VTK <noreply@discourse.vtk.org> 于2024年8月15日周四 20:25写道: