I have this code in vtk
// Load the netCDF file
vtkSmartPointer<vtkNetCDFCFReader> reader = vtkSmartPointer<vtkNetCDFCFReader>::New();
reader->SetFileName("C:/Users/admin/Desktop/BOLTgui/BOLT/test.nc");
reader->Update();
// Create a vtkContourFilter to extract an isosurface
vtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New();
contourFilter->SetInputConnection(reader->GetOutputPort());
contourFilter->SetValue(0, 20); // set iso-value
contourFilter->Update();
// Set up the lookup table
vtkSmartPointer<vtkLookupTable> lookupTable = vtkSmartPointer<vtkLookupTable>::New();
lookupTable->SetNumberOfTableValues(256);
lookupTable->Build();
lookupTable->SetTableRange(contourFilter->GetOutput()->GetScalarRange());
// Create a color transfer function to map scalar values to colors
vtkSmartPointer<vtkColorTransferFunction> colorTransferFunction = vtkSmartPointer<vtkColorTransferFunction>::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 1.0); // blue
colorTransferFunction->AddRGBPoint(20.0, 0.0, 1.0, 0.0); // green
colorTransferFunction->AddRGBPoint(40.0, 1.0, 1.0, 0.0); // yellow
colorTransferFunction->AddRGBPoint(60.0, 1.0, 0.0, 0.0); // red
// Create a vtkPolyDataMapper to map the data to the renderer
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(contourFilter->GetOutputPort());
mapper->SetLookupTable(lookupTable);
mapper->UseLookupTableScalarRangeOn();
// Apply colors based on the scalar values using the color transfer function
mapper->ScalarVisibilityOn();
mapper->SetScalarModeToUsePointData();
mapper->SetLookupTable(lookupTable);
mapper->SetLookupTable(colorTransferFunction);
// Create a vtkActor to hold the mapper
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
// Create a renderer and add the actor to it
vtkSmartPointer<vtkRenderer> renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(actor);
// Create a render window and add the renderer to it
vtkSmartPointer<vtkRenderWindow> renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// Create an interactor and set the render window
vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
interactor->SetRenderWindow(renderWindow);
// Map the VTK renderer to the SFML window
sf::WindowHandle handle = window.getSystemHandle();
renderWindow->SetWindowInfo(reinterpret_cast<char*>(handle));
interactor->Start();
// Draw triangles
glBegin(GL_TRIANGLES);
glPointSize(4.666f);
// Calculate scaling factor
float scalingFactor = 1.0f / 2.111f;
// Set point color and opacity
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // Set alpha value to 1 for full opacity
vtkSmartPointer<vtkDataSet> data = vtkDataSet::SafeDownCast(reader->GetOutput());
for (vtkIdType i = 0; i < data->GetNumberOfCells(); i++) {
vtkCell* cell = data->GetCell(i);
vtkPoints* points = cell->GetPoints();
double point1[3];
double point2[3];
double point3[3];
points->GetPoint(0, point1);
points->GetPoint(1, point2);
points->GetPoint(2, point3);
// Scale the point coordinates to adjust the size
glVertex3f(point1[0] * scalingFactor, point1[1] * scalingFactor, point1[2] * scalingFactor);
glVertex3f(point2[0] * scalingFactor, point2[1] * scalingFactor, point2[2] * scalingFactor);
glVertex3f(point3[0] * scalingFactor, point3[1] * scalingFactor, point3[2] * scalingFactor);
}
glEnd();
i cant figure out how to display colors based off the netcdf data it currently only displays this tan color
does anyone know how to display colors based off of netcdf data
here is a example of what i am trying to do