diff --git a/IO/GDAL/Testing/Cxx/CMakeLists.txt b/IO/GDAL/Testing/Cxx/CMakeLists.txt index bcaf4923b0f..03691ce4253 100644 --- a/IO/GDAL/Testing/Cxx/CMakeLists.txt +++ b/IO/GDAL/Testing/Cxx/CMakeLists.txt @@ -9,6 +9,6 @@ vtk_add_test_cxx(${vtk-module}CxxTests tests TestGDALVectorReader.cxx TestGDALRasterReader.cxx TestGDALRasterNoDataValue.cxx,NO_VALID,NO_OUTPUT - TestGDALRasterPalette.cxx,NO_VALID,NO_OUTPUT + TestGDALRasterPalette.cxx ) vtk_test_cxx_executable(${vtk-module}CxxTests tests) diff --git a/IO/GDAL/Testing/Cxx/TestGDALRasterPalette.cxx b/IO/GDAL/Testing/Cxx/TestGDALRasterPalette.cxx index 5fe6e27d82e..88459ec95d5 100644 --- a/IO/GDAL/Testing/Cxx/TestGDALRasterPalette.cxx +++ b/IO/GDAL/Testing/Cxx/TestGDALRasterPalette.cxx @@ -14,9 +14,16 @@ =========================================================================*/ #include #include +#include +#include #include #include #include +#include +#include +#include +#include +#include #include #include @@ -44,13 +51,12 @@ int TestGDALRasterPalette(int argc, char** argv) std::cerr << "ERROR: Missing point data scalars" << std::endl; return 1; } - if (image->GetPointData()->GetScalars()->GetSize() != 300*300) + if (image->GetPointData()->GetScalars()->GetSize() == 0) { - std::cerr << "ERROR: Point data scalars wrong size, not." - << (300*300) << ". Instead " - << image->GetPointData()->GetScalars()->GetSize() << std::endl; + std::cerr << "ERROR: Point data scalars empty" << std::endl; return 1; } + //image->GetPointData()->GetScalars()->Print(std::cout); // Check that reader generated color table vtkLookupTable *colorTable = @@ -67,6 +73,36 @@ int TestGDALRasterPalette(int argc, char** argv) << std::endl; return 1; } + //colorTable->Print(std::cout); - return 0; + // Create a renderer and actor + vtkNew renderer; + vtkNew actor; + actor->SetInputData(reader->GetOutput()); + actor->InterpolateOff(); + //actor->GetProperty()->SetInterpolationTypeToNearest(); + actor->GetProperty()->SetLookupTable(colorTable); + actor->GetProperty()->UseLookupTableScalarRangeOn(); + renderer->AddActor(actor.GetPointer()); + + // Create a render window, and an interactor + vtkNew renderWindow; + vtkNew renderWindowInteractor; + renderWindow->AddRenderer(renderer.GetPointer()); + renderWindowInteractor->SetRenderWindow(renderWindow.GetPointer()); + + //Add the actor to the scene + renderer->SetBackground(1.0, 1.0, 1.0); + renderWindow->SetSize(400, 400); + renderWindow->Render(); + renderer->ResetCamera(); + renderWindow->Render(); + + int retVal = vtkRegressionTestImage(renderWindow.GetPointer()); + if (retVal == vtkRegressionTester::DO_INTERACTOR) + { + renderWindowInteractor->Start(); + } + + return !retVal; } diff --git a/IO/GDAL/Testing/Data/Baseline/TestGDALRasterPalette.png.md5 b/IO/GDAL/Testing/Data/Baseline/TestGDALRasterPalette.png.md5 new file mode 100644 index 00000000000..ef85ec463bd --- /dev/null +++ b/IO/GDAL/Testing/Data/Baseline/TestGDALRasterPalette.png.md5 @@ -0,0 +1 @@ +70aff17ba9e4a0d5c6cffb720f381d26 diff --git a/IO/GDAL/vtkGDALRasterReader.cxx b/IO/GDAL/vtkGDALRasterReader.cxx index 08bb6ca3e1c..64f653503e0 100644 --- a/IO/GDAL/vtkGDALRasterReader.cxx +++ b/IO/GDAL/vtkGDALRasterReader.cxx @@ -45,6 +45,7 @@ // C/C++ includes #include #include +#include #include vtkStandardNewMacro(vtkGDALRasterReader); @@ -483,6 +484,7 @@ void vtkGDALRasterReader::vtkGDALRasterReaderInternal::GenericReadData() if (paletteBand) { + this->UniformGridData->GetPointData()->GetScalars()->SetName("Categories"); this->UniformGridData->GetPointData()->GetScalars()->SetLookupTable( colorTable); } @@ -655,17 +657,38 @@ void vtkGDALRasterReader::vtkGDALRasterReaderInternal::ReadColorTable( return; } + char **categoryNames = rasterBand->GetCategoryNames(); + colorTable->IndexedLookupOn(); int numEntries = gdalTable->GetColorEntryCount(); colorTable->SetNumberOfTableValues(numEntries); + std::stringstream ss; for (int i=0; i< numEntries; ++i) { const GDALColorEntry *gdalEntry = gdalTable->GetColorEntry(i); - double r = gdalEntry->c1 / 255.0; - double g = gdalEntry->c2 / 255.0; - double b = gdalEntry->c3 / 255.0; - double a = gdalEntry->c4 / 255.0; + double r = static_cast(gdalEntry->c1) / 255.0; + double g = static_cast(gdalEntry->c2) / 255.0; + double b = static_cast(gdalEntry->c3) / 255.0; + double a = static_cast(gdalEntry->c4) / 255.0; colorTable->SetTableValue(i, r, g, b, a); + + // Copy category name to lookup table annotation + if (categoryNames) + { + // Only use non-empty names + if (strlen(categoryNames[i]) > 0) + { + colorTable->SetAnnotation(vtkVariant(i), categoryNames[i]); + } + } + else + { + // Create default annotation + ss.str(""); + ss.clear(); + ss << "Category " << i; + colorTable->SetAnnotation(vtkVariant(i), ss.str()); + } } }