Commit 3d6a42c2 authored by John Tourtellott's avatar John Tourtellott
Browse files

Add annotations to lookup table, needed for display, and update test

parent 3bbfea3f
Pipeline #17166 passed with stage
......@@ -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)
......@@ -14,9 +14,16 @@
=========================================================================*/
#include <vtkDataArray.h>
#include <vtkGDALRasterReader.h>
#include <vtkImageActor.h>
#include <vtkImageProperty.h>
#include <vtkLookupTable.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkRegressionTestImage.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkUniformGrid.h>
#include <iostream>
......@@ -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<vtkRenderer> renderer;
vtkNew<vtkImageActor> 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<vtkRenderWindow> renderWindow;
vtkNew<vtkRenderWindowInteractor> 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;
}
......@@ -45,6 +45,7 @@
// C/C++ includes
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>
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<double>(gdalEntry->c1) / 255.0;
double g = static_cast<double>(gdalEntry->c2) / 255.0;
double b = static_cast<double>(gdalEntry->c3) / 255.0;
double a = static_cast<double>(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());
}
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment