MCPcopy Create free account
hub / github.com/Kitware/VTK / ReadColorTable

Method ReadColorTable

IO/GDAL/vtkGDALRasterReader.cxx:726–770  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

724
725//------------------------------------------------------------------------------
726void vtkGDALRasterReader::vtkGDALRasterReaderInternal::ReadColorTable(
727 GDALRasterBand* rasterBand, vtkLookupTable* colorTable) const
728{
729 GDALColorTable* gdalTable = rasterBand->GetColorTable();
730 if (gdalTable->GetPaletteInterpretation() != GPI_RGB)
731 {
732 std::cerr << "Color table palette type not supported " << gdalTable->GetPaletteInterpretation()
733 << std::endl;
734 return;
735 }
736
737 char** categoryNames = rasterBand->GetCategoryNames();
738
739 colorTable->IndexedLookupOn();
740 int numEntries = gdalTable->GetColorEntryCount();
741 colorTable->SetNumberOfTableValues(numEntries);
742 std::stringstream ss;
743 for (int i = 0; i < numEntries; ++i)
744 {
745 const GDALColorEntry* gdalEntry = gdalTable->GetColorEntry(i);
746 double r = static_cast<double>(gdalEntry->c1) / 255.0;
747 double g = static_cast<double>(gdalEntry->c2) / 255.0;
748 double b = static_cast<double>(gdalEntry->c3) / 255.0;
749 double a = static_cast<double>(gdalEntry->c4) / 255.0;
750 colorTable->SetTableValue(i, r, g, b, a);
751
752 // Copy category name to lookup table annotation
753 if (categoryNames)
754 {
755 // Only use non-empty names
756 if (strlen(categoryNames[i]) > 0)
757 {
758 colorTable->SetAnnotation(vtkVariant(i), categoryNames[i]);
759 }
760 }
761 else
762 {
763 // Create default annotation
764 ss.str("");
765 ss.clear();
766 ss << "Category " << i;
767 colorTable->SetAnnotation(vtkVariant(i), ss.str());
768 }
769 }
770}
771
772//------------------------------------------------------------------------------
773void vtkGDALRasterReader::vtkGDALRasterReaderInternal::SelectionCallback(vtkObject* vtkNotUsed(obj),

Callers 1

GenericReadDataMethod · 0.95

Calls 6

SetTableValueMethod · 0.80
SetAnnotationMethod · 0.80
vtkVariantClass · 0.50
strMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected