I’m trying to get data loaded in using the vtkGDALRasterReader class. My assumption is that it holds the elevation data in the scalars, similar to the vtkDEMReader. However, that doesn’t seem to be the case (or I’ve completely missed something). I need to be able to warp the input file (a GEOTIFF) into a 3d model of the terrain (in C++). Loading the file and using the vtkImageDataGeometryFilter causes the display to be a 2d flat plane with the elevations depicted in a grayscale, which tells me that the information is being read and I’m just being obtuse about how to access it to actually cause it to warp to the correct elevation.
This code is based on the Fit To Height example:
QString filename = "C:\\Users\\trevor\\Downloads\\GeoTIFF-Samples\\sample2.tif";
vtkNew<vtkGDALRasterReader> reader;
reader->SetFileName(filename.toUtf8().constData());
reader->Update();
double lo = reader->GetOutput()->GetScalarRange()[0];
double hi = reader->GetOutput()->GetScalarRange()[1];
vtkNew<vtkImageDataGeometryFilter> surface;
surface->SetInputConnection(reader->GetOutputPort());
auto temp = reader->GetOutput()->GetScalarRange();
// Warp the surface in the vertical direction
vtkNew<vtkWarpScalar> warp;
warp->SetInputConnection(surface->GetOutputPort());
warp->SetScaleFactor(10);
warp->UseNormalOn();
warp->SetNormal(0, 0, 1);
warp->Update();
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(surface->GetOutputPort());
actor->SetMapper(mapper);
renderer->AddActor(actor);
I have a few debug variables set so that I could check that there is scalar data, but it’s otherwise pretty much the example, just using the vtkGDALRasterReader instead of the vtkDEMReader. But vtkGDALRasterReader doesn’t seem to include the elevation data the same way that the vtkDEMReader did.
What am I not seeing or understanding here? Is there a different mapper I should be using? Is there an accessor in the underlying vtkImageReader2 that I missed (or even something in the vtkGDALRasterReader)? Should I be looking at doing it manually as in the Iterate Image Data example?