Skip to content

Commit

Permalink
Add annotations to lookup table, needed for display, and update test
Browse files Browse the repository at this point in the history
  • Loading branch information
johnkit committed Jun 16, 2016
1 parent 3bbfea3 commit 3d6a42c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 10 deletions.
2 changes: 1 addition & 1 deletion IO/GDAL/Testing/Cxx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
46 changes: 41 additions & 5 deletions IO/GDAL/Testing/Cxx/TestGDALRasterPalette.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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 =
Expand All @@ -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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
70aff17ba9e4a0d5c6cffb720f381d26
31 changes: 27 additions & 4 deletions IO/GDAL/vtkGDALRasterReader.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
// C/C++ includes
#include <cassert>
#include <iostream>
#include <sstream>
#include <vector>

vtkStandardNewMacro(vtkGDALRasterReader);
Expand Down Expand Up @@ -483,6 +484,7 @@ void vtkGDALRasterReader::vtkGDALRasterReaderInternal::GenericReadData()

if (paletteBand)
{
this->UniformGridData->GetPointData()->GetScalars()->SetName("Categories");
this->UniformGridData->GetPointData()->GetScalars()->SetLookupTable(
colorTable);
}
Expand Down Expand Up @@ -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());
}
}
}

Expand Down

0 comments on commit 3d6a42c

Please sign in to comment.