I want to to plot angular values on a sphere with evenly spaced points in C++/VTK. Therefore I want to color points on a custom VTKPolyData with selected colors. As a starting point I used https://kitware.github.io/vtk-examples/site/Cxx/Visualization/ScalarBarActor/ which creates a similiar picture.
I successfully created the custom PolyData as I wanted and calculated the values for the Points (all are positive doubles, mostly smaller than 1.0), but the coloring doesn't fit with the values I set:
//create evenly spaced out angular coordinates Phi and Theta ...
...
//make a sphere object
sphere = vtkPolyData::New();
vtkPoints* spherepoints = vtkPoints::New();
//create Points on Phi and Theta to (x,y,z)
...spherepoints->InsertNextPoint(P);...
//Add points to PolyData
sphere->SetPoints(spherepoints);
sphere->Allocate();
//Create Connectivity in PolyData by
...
vtkIdList* indices = vtkIdList::New();
indices->Allocate(3);
indices->InsertId(0, integer0);
indices->InsertId(1, integer1);
indices->InsertId(2, integer2);
sphere->InsertNextCell(VTK_TRIANGLE, indices);
...
vtkFloatArray* scalars = vtkFloatArray::New();
//for all points calculate the local value
for (int i = 0; ...; i++) {
double I = f(i);
scalars->InsertTuple1(i, I);
}
// add scalars
sphere->GetPointData()->SetScalars(scalars);
//set a custom threshold
double threshold = 1e-4;
// build a lookuptable (low values: blue, high: red)
vtkLookupTable* lut = vtkLookupTable::New();
lut->SetIndexedLookup(false);
lut->Build();
lut->SetTableValue(0.01 * threshold, 0.0, 0.0, 1.0, 0.1);
lut->SetTableValue(0.1 * threshold, 1.0, 1.0, 1.0, 0.3);
lut->SetTableValue(1 * threshold, 1.0, 1.0, 0.0, 0.5);
lut->SetTableValue(10 * threshold,1.0, 0.0, 0.0, 0.7);
lut->SetTableRange(0, 10* threshold);
//build mapper
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputData(sphere);
mapper->ScalarVisibilityOn();
mapper->SetLookupTable(lut);
mapper->SetScalarModeToUsePointData();
mapper->SetColorModeToMapScalars();
//create actor
this->sphereactor = vtkSmartPointer<vtkActor>::New();
sphereactor->SetMapper(mapper);
sphereactor->VisibilityOn();
I also tried using only integer values (e.g. by mapping to 0-1000) for scalars, only indexing my colors (0-3), using more custom interpolating color points or using the SetTableRange or SetValueRange command with no success. The picture I get everytime is mostly one or two colors, which do or don't correspont to the scalars in a way, I can understand. What is the correct way to color the surface by the scalar values?