Commit 12dff5fb authored by David Thompson's avatar David Thompson
Browse files

Merge `vtkBrewerColors` into `vtkColorSeries`.

Change-Id: I29bc1b3548ee326f9368dfc9cde743918b2f0c61
parent 1160c5a9
create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx
TestCategoricalColors.cxx
EXTRA_INCLUDE vtkTestDriver.h
)
vtk_module_test_executable(${vtk-module}CxxTests ${Tests})
set(TestsToRun ${Tests})
list(REMOVE_ITEM TestsToRun ${vtk-module}CxxTests.cxx)
# Add all the executables
foreach (test ${TestsToRun})
get_filename_component(TName ${test} NAME_WE)
add_test(NAME ${vtk-module}Cxx-${TName}
COMMAND ${vtk-module}CxxTests ${TName})
endforeach()
......@@ -14,7 +14,7 @@
=========================================================================*/
#include "vtkLookupTable.h"
#include "vtkBrewerColors.h"
#include "vtkColorSeries.h"
#include "vtkDoubleArray.h"
#include "vtkUnsignedCharArray.h"
......@@ -36,16 +36,16 @@ int TestCategoricalColors( int vtkNotUsed(argc), char* vtkNotUsed(argv)[] )
lut->SetAnnotation( 9, "Kyuu" );
lut->RemoveAnnotation( 2. );
vtkBrewerColors* schemes = vtkBrewerColors::New();
vtkColorSeries* palettes = vtkColorSeries::New();
#if 0
vtkIdType numSchemes = schemes->GetNumberOfSchemes();
vtkIdType numSchemes = palettes->GetNumberOfSchemes();
for ( vtkIdType i = 0; i < numSchemes; ++ i )
{
cout << i << ": " << schemes->GetScheme( i ) << "\n";
cout << i << ": " << palettes->GetScheme( i ) << "\n";
}
#endif
schemes->SetCurrentScheme( "Qualitative Accent (8)" );
schemes->CreateLookupTable( lut );
palettes->SetColorSchemeByName( "Brewer Qualitative Accent" );
palettes->BuildLookupTable( lut );
cout.setf( std::ios_base::hex, std::ios::basefield );
const unsigned char* rgba = lut->MapValue( 0. );
......@@ -92,6 +92,6 @@ int TestCategoricalColors( int vtkNotUsed(argc), char* vtkNotUsed(argv)[] )
color->Delete();
data->Delete();
lut->Delete();
schemes->Delete();
palettes->Delete();
return 0;
}
This diff is collapsed.
......@@ -16,17 +16,34 @@
// .NAME vtkColorSeries - stores a list of colors.
//
// .SECTION Description
// The vtkColorSeries stores a list of colors. There are several schemes
// available and functions to control several aspects of what colors are
// returned. In essence a color scheme is set and colors are returned based on
// the index requested.
// The vtkColorSeries stores palettes of colors. There are several default
// palettes (or schemes) available and functions to control several aspects
// of what colors are returned. In essence a color scheme is set and then
// the number of colors and individual color values may be requested.
//
// It is also possible to add schemes beyond the default palettes.
// Whenever \a SetColorScheme is called with a string for which no palette
// already exists, a new, empty palette is created.
// You may then use \a SetNumberOfColors and \a SetColor to populate the
// palette.
// You may not extend default palettes by calling functions that alter
// a scheme; if called while a predefined palette is in use, they
// will create a new non-default scheme and populate it with the current
// palette before continuing.
//
// The "Brewer" palettes are courtesy of
// Cynthia A. Brewer (Dept. of Geography, Pennsylvania State University)
// and present under the Apache License. See the source code for details.
#ifndef __vtkColorSeries_h
#define __vtkColorSeries_h
#include "vtkCommonColorModule.h" // For export macro
#include "vtkObject.h"
#include "vtkColor.h" // Needed for vtkColor3ub
#include "vtkColor.h" // Needed for vtkColor[34]ub
#include "vtkStdString.h" // Needed for arguments
class vtkLookupTable;
class VTKCOMMONCOLOR_EXPORT vtkColorSeries : public vtkObject
{
......@@ -48,21 +65,106 @@ public:
BLUES, ///< 7 different blues.
WILD_FLOWER, ///< 7 colors from blue to magenta.
CITRUS, ///< 6 colors from green to orange.
BREWER_DIVERGING_PURPLE_ORANGE_11, //!< purple-grey-orange diverging ColorBrewer scheme (11 colors)
BREWER_DIVERGING_PURPLE_ORANGE_10, //!< purple-grey-orange diverging ColorBrewer scheme (10 colors)
BREWER_DIVERGING_PURPLE_ORANGE_9, //!< purple-grey-orange diverging ColorBrewer scheme (9 colors)
BREWER_DIVERGING_PURPLE_ORANGE_8, //!< purple-grey-orange diverging ColorBrewer scheme (8 colors)
BREWER_DIVERGING_PURPLE_ORANGE_7, //!< purple-grey-orange diverging ColorBrewer scheme (7 colors)
BREWER_DIVERGING_PURPLE_ORANGE_6, //!< purple-grey-orange diverging ColorBrewer scheme (6 colors)
BREWER_DIVERGING_PURPLE_ORANGE_5, //!< purple-grey-orange diverging ColorBrewer scheme (5 colors)
BREWER_DIVERGING_PURPLE_ORANGE_4, //!< purple-grey-orange diverging ColorBrewer scheme (4 colors)
BREWER_DIVERGING_PURPLE_ORANGE_3, //!< purple-grey-orange diverging ColorBrewer scheme (3 colors)
BREWER_DIVERGING_SPECTRAL_11, //!< diverging spectral ColorBrewer scheme (11 colors)
BREWER_DIVERGING_SPECTRAL_10, //!< diverging spectral ColorBrewer scheme (10 colors)
BREWER_DIVERGING_SPECTRAL_9, //!< diverging spectral ColorBrewer scheme (9 colors)
BREWER_DIVERGING_SPECTRAL_8, //!< diverging spectral ColorBrewer scheme (8 colors)
BREWER_DIVERGING_SPECTRAL_7, //!< diverging spectral ColorBrewer scheme (7 colors)
BREWER_DIVERGING_SPECTRAL_6, //!< diverging spectral ColorBrewer scheme (6 colors)
BREWER_DIVERGING_SPECTRAL_5, //!< diverging spectral ColorBrewer scheme (5 colors)
BREWER_DIVERGING_SPECTRAL_4, //!< diverging spectral ColorBrewer scheme (4 colors)
BREWER_DIVERGING_SPECTRAL_3, //!< diverging spectral ColorBrewer scheme (3 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_11, //!< brown-blue-green diverging ColorBrewer scheme (11 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_10, //!< brown-blue-green diverging ColorBrewer scheme (10 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_9, //!< brown-blue-green diverging ColorBrewer scheme (9 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_8, //!< brown-blue-green diverging ColorBrewer scheme (8 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_7, //!< brown-blue-green diverging ColorBrewer scheme (7 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_6, //!< brown-blue-green diverging ColorBrewer scheme (6 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_5, //!< brown-blue-green diverging ColorBrewer scheme (5 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_4, //!< brown-blue-green diverging ColorBrewer scheme (4 colors)
BREWER_DIVERGING_BROWN_BLUE_GREEN_3, //!< brown-blue-green diverging ColorBrewer scheme (3 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_9, //!< blue to green sequential ColorBrewer scheme (9 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_8, //!< blue to green sequential ColorBrewer scheme (8 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_7, //!< blue to green sequential ColorBrewer scheme (7 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_6, //!< blue to green sequential ColorBrewer scheme (6 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_5, //!< blue to green sequential ColorBrewer scheme (5 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_4, //!< blue to green sequential ColorBrewer scheme (4 colors)
BREWER_SEQUENTIAL_BLUE_GREEN_3, //!< blue to green sequential ColorBrewer scheme (3 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_9, //!< yellow-orange-brown sequential ColorBrewer scheme (9 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_8, //!< yellow-orange-brown sequential ColorBrewer scheme (8 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_7, //!< yellow-orange-brown sequential ColorBrewer scheme (7 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_6, //!< yellow-orange-brown sequential ColorBrewer scheme (6 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_5, //!< yellow-orange-brown sequential ColorBrewer scheme (5 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_4, //!< yellow-orange-brown sequential ColorBrewer scheme (4 colors)
BREWER_SEQUENTIAL_YELLOW_ORANGE_BROWN_3, //!< yellow-orange-brown sequential ColorBrewer scheme (3 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_9, //!< blue to purple sequential ColorBrewer scheme (9 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_8, //!< blue to purple sequential ColorBrewer scheme (8 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_7, //!< blue to purple sequential ColorBrewer scheme (7 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_6, //!< blue to purple sequential ColorBrewer scheme (6 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_5, //!< blue to purple sequential ColorBrewer scheme (5 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_4, //!< blue to purple sequential ColorBrewer scheme (4 colors)
BREWER_SEQUENTIAL_BLUE_PURPLE_3, //!< blue to purple sequential ColorBrewer scheme (3 colors)
BREWER_QUALITATIVE_ACCENT, //!< qualitative ColorBrewer scheme good for accenting
BREWER_QUALITATIVE_DARK2, //!< a dark set of qualitative colors from ColorBrewer
BREWER_QUALITATIVE_SET2, //!< a qualitative ColorBrewer scheme useful for color set members
BREWER_QUALITATIVE_PASTEL2, //!< a qualitative ColorBrewer scheme composed of pastel colors
BREWER_QUALITATIVE_PASTEL1, //!< a qualitative ColorBrewer scheme composed of pastel colors
BREWER_QUALITATIVE_SET1, //!< a qualitative ColorBrewer scheme useful for color set members
BREWER_QUALITATIVE_PAIRED, //!< a qualitative ColorBrewer scheme with pairs of matching colors
BREWER_QUALITATIVE_SET3, //!< a qualitative ColorBrewer scheme useful for color set members
CUSTOM ///< User specified color scheme.
};
/// These enumerants describe the purpose for which a palette is best suited.
enum Purpose {
DIVERGING = 0, //!< Palette is suited for illustrating diverging data with a central tendency
SEQUENTIAL, //!< Palette is suited for illustrating sequential data where order is important
CATEGORICAL //!< Palette is suited for illustrating categorical data where there is no clear relationship between values
};
//ETX
// Description:
// Set the color scheme that should be used from those in the enum.
void SetColorScheme(int scheme);
// Set the color scheme that should be used.
// The variant of this function that takes an integer should pass a
// number from those in the enum, or a value returned by the string variant.
// The variant that accepts a string returns the integer index
// of the resulting palette (whether it already existed or is newly-created).
virtual void SetColorScheme(int scheme);
virtual int SetColorSchemeByName( vtkStdString schemeName );
// Description:
// Return the number of schemes currently defined.
int GetNumberOfColorSchemes();
// Description:
// Get the color scheme that is currently being used.
vtkGetMacro(ColorScheme, int);
virtual vtkStdString GetColorSchemeName();
// Description:
// Set the name of the current color scheme
virtual void SetColorSchemeName(vtkStdString scheme);
// Description:
// Return the ID of the color scheme currently in use.
virtual int GetColorScheme();
// Description:
// Get the number of colors available in the current color scheme.
int GetNumberOfColors();
virtual int GetNumberOfColors();
// Description:
// Set the number of colors to be stored in a non-default color scheme.
// Calling this function on a predefined color scheme will cause the scheme to be duplicated to a new custom scheme.
virtual void SetNumberOfColors( int numColors );
//BTX
// Description:
......@@ -78,43 +180,58 @@ public:
// Description:
// Set the color at the specified index. Does nothing if the index is out of
// range.
void SetColor(int index, const vtkColor3ub &color);
virtual void SetColor(int index, const vtkColor3ub &color);
// Description:
// Adds the color to the end of the list.
void AddColor(const vtkColor3ub &color);
virtual void AddColor(const vtkColor3ub &color);
// Description:
// Inserts the color at the specified index in the list.
void InsertColor(int index, const vtkColor3ub &color);
virtual void InsertColor(int index, const vtkColor3ub &color);
//ETX
// Description:
// Removes the color at the specified index in the list.
void RemoveColor(int index);
virtual void RemoveColor(int index);
// Description:
// Clears the list of colors.
void ClearColors();
virtual void ClearColors();
// Description:
// Make a deep copy of the supplied object.
void DeepCopy(vtkColorSeries *chartColors);
virtual void DeepCopy(vtkColorSeries *chartColors);
// Description:
// Populate a lookup table with all the colors in the current scheme.
//
// If \a lkup is a NULL pointer, a new vtkLookupTable will be created
// for you, but you are then responsible for deleting it.
vtkLookupTable* BuildLookupTable( vtkLookupTable* lkup );
//BTX
protected:
vtkColorSeries();
~vtkColorSeries();
// Description:
// If the current scheme is a predefined (read-only) scheme,
// copy the current colors to a new scheme and modify the new scheme instead.
virtual void CopyOnWrite();
// Description:
// Private data pointer of the class, stores the color list.
class Private;
Private *Storage;
Private* Storage;
// Description:
// The color scheme being used.
int ColorScheme;
/// The color scheme being used.
vtkStdString ColorSchemeName;
private:
vtkColorSeries(const vtkColorSeries &); // Not implemented.
void operator=(const vtkColorSeries &); // Not implemented.
......
......@@ -13,7 +13,6 @@ set(Module_SRCS
vtkBiQuadraticQuadraticWedge.cxx
vtkBiQuadraticTriangle.cxx
vtkBox.cxx
vtkBrewerColors.cxx
vtkBSPCuts.cxx
vtkBSPIntersections.cxx
vtkCell3D.cxx
......
......@@ -36,7 +36,6 @@ create_test_sourcelist(Tests ${vtk-module}CxxTests.cxx
TestPlane.cxx
TestStructuredData.cxx
TestDataObjectTypes.cxx
TestCategoricalColors.cxx
EXTRA_INCLUDE vtkTestDriver.h
)
......
#include "vtkBrewerColors.h"
#include "vtkColor.h"
#include "vtkObjectFactory.h"
#include "vtkStdString.h"
#include "vtkLookupTable.h"
#include <map>
#include <vector>
#include <vtksys/ios/sstream>
class vtkColorSchemeInternal : public std::map<vtkStdString,std::vector<vtkColor4ub> >
{
};
inline vtkColor4ub vtkColor4ubFromHex3( vtkTypeUInt32 hex )
{
int b = hex & 0xff; hex >>= 8;
int g = hex & 0xff; hex >>= 8;
int r = hex & 0xff;
return vtkColor4ub( r, g, b, 0xff );
}
static void constructDefaultSchemes( vtkBrewerColors* schemes )
{
/*
The following palettes are colors from www.ColorBrewer2.org by Cynthia A. Brewer, Geography, Pennsylvania State University.
Use the sentence above or the following bibliography entry to credit her:
+ Brewer, Cynthia A. and Mark Harrower and Andy Woodruff and David Heyman, 2010. http://ColorBrewer2.org, accessed 2010-Nov-9.
The color schemes below are copyright under the following license, excerpted
from http://www.personal.psu.edu/cab38/ColorBrewer/ColorBrewer_updates.html
on August 13, 2012:
Apache-Style Software License for ColorBrewer software and ColorBrewer Color Schemes
Copyright (c) 2002 Cynthia Brewer, Mark Harrower, and The Pennsylvania State University.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
This text from my earlier Apache License Version 1.1 also remains in place for guidance on attribution and permissions:
Redistribution and use in source and binary forms, with or without modification, are permitted
provided that the following conditions are met:
1. Redistributions as source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. The end-user documentation included with the redistribution, if any, must include the following acknowledgment:
"This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/)."
Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments
normally appear.
4. The name "ColorBrewer" must not be used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact Cynthia Brewer at cbrewer@psu.edu.
5. Products derived from this software may not be called "ColorBrewer", nor may "ColorBrewer" appear in their name,
without prior written permission of Cynthia Brewer.
*/
vtkTypeUInt32 colors[] =
{
// Diverging
// Purple-Orange
0x7F3B08, 0xB35806, 0xE08214, 0xFDB863, 0xFEE0B6, 0xF7F7F7, 0xD8DAEB, 0xB2ABD2, 0x8073AC, 0x542788, 0x2D004B,
0x7F3B08, 0xB35806, 0xE08214, 0xFDB863, 0xFEE0B6, 0xD8DAEB, 0xB2ABD2, 0x8073AC, 0x542788, 0x2D004B,
0xB35806, 0xE08214, 0xFDB863, 0xFEE0B6, 0xF7F7F7, 0xD8DAEB, 0xB2ABD2, 0x8073AC, 0x542788,
0xB35806, 0xE08214, 0xFDB863, 0xFEE0B6, 0xD8DAEB, 0xB2ABD2, 0x8073AC, 0x542788,
0xB35806, 0xF1A340, 0xFEE0B6, 0xF7F7F7, 0xD8DAEB, 0x998EC3, 0x542788,
0xB35806, 0xF1A340, 0xFEE0B6, 0xD8DAEB, 0x998EC3, 0x542788,
0xE66101, 0xFDB863, 0xF7F7F7, 0xB2ABD2, 0x5E3C99,
0xE66101, 0xFDB863, 0xB2ABD2, 0x5E3C99,
0xF1A340, 0xF7F7F7, 0x998EC3,
// Spectral
0x9E0142, 0xD53E4F, 0xF46D43, 0xFDAE61, 0xFEE08B, 0xFFFFBF, 0xE6F598, 0xABDDA4, 0x66C2A5, 0x3288BD, 0x5E4FA2,
0x9E0142, 0xD53E4F, 0xF46D43, 0xFDAE61, 0xFEE08B, 0xE6F598, 0xABDDA4, 0x66C2A5, 0x3288BD, 0x5E4FA2,
0xD53E4F, 0xF46D43, 0xFDAE61, 0xFEE08B, 0xFFFFBF, 0xE6F598, 0xABDDA4, 0x66C2A5, 0x3288BD,
0xD53E4F, 0xF46D43, 0xFDAE61, 0xFEE08B, 0xE6F598, 0xABDDA4, 0x66C2A5, 0x3288BD,
0xD53E4F, 0xFC8D59, 0xFEE08B, 0xFFFFBF, 0xE6F598, 0x99D594, 0x3288BD,
0xD53E4F, 0xFC8D59, 0xFEE08B, 0xE6F598, 0x99D594, 0x3288BD,
0xD7191C, 0xFDAE61, 0xFFFFBF, 0xABDDA4, 0x2B83BA,
0xD7191C, 0xFDAE61, 0xABDDA4, 0x2B83BA,
0xFC8D59, 0xFFFFBF, 0x99D594,
// Brown-Blue-Green
0x543005, 0x8C510A, 0xBF812D, 0xDFC27D, 0xF6E8C3, 0xF5F5F5, 0xC7EAE5, 0x80CDC1, 0x35978F, 0x01665E, 0x003C30,
0x543005, 0x8C510A, 0xBF812D, 0xDFC27D, 0xF6E8C3, 0xC7EAE5, 0x80CDC1, 0x35978F, 0x01665E, 0x003C30,
0x8C510A, 0xBF812D, 0xDFC27D, 0xF6E8C3, 0xF5F5F5, 0xC7EAE5, 0x80CDC1, 0x35978F, 0x01665E,
0x8C510A, 0xBF812D, 0xDFC27D, 0xF6E8C3, 0xC7EAE5, 0x80CDC1, 0x35978F, 0x01665E,
0x8C510A, 0xD8B365, 0xF6E8C3, 0xF5F5F5, 0xC7EAE5, 0x5AB4AC, 0x01665E,
0x8C510A, 0xD8B365, 0xF6E8C3, 0xC7EAE5, 0x5AB4AC, 0x01665E,
0xA6611A, 0xDFC27D, 0xF5F5F5, 0x80CDC1, 0x018571,
0xA6611A, 0xDFC27D, 0x80CDC1, 0x018571,
0xD8B365, 0xF5F5F5, 0x5AB4AC,
// Sequential Palettes
// Blue-Green
0xF7FCFD, 0xE5F5F9, 0xCCECE6, 0x99D8C9, 0x66C2A4, 0x41AE76, 0x238B45, 0x006D2C, 0x00441B,
0xF7FCFD, 0xE5F5F9, 0xCCECE6, 0x99D8C9, 0x66C2A4, 0x41AE76, 0x238B45, 0x005824,
0xEDF8FB, 0xCCECE6, 0xCCECE6, 0x66C2A4, 0x41AE76, 0x238B45, 0x005824,
0xEDF8FB, 0xCCECE6, 0x99D8C9, 0x66C2A4, 0x2CA25F, 0x006D2C,
0xEDF8FB, 0xB2E2E2, 0x66C2A4, 0x2CA25F, 0x006D2C,
0xEDF8FB, 0xB2E2E2, 0x66C2A4, 0x238B45,
0xE5F5F9, 0x99D8C9, 0x2CA25F,
// Yellow-Orange-Brown
0xFFFFE5, 0xFFF7BC, 0xFEE391, 0xFEC44F, 0xFE9929, 0xEC7014, 0xCC4C02, 0x993404, 0x662506,
0xFFFFE5, 0xFFF7BC, 0xFEE391, 0xFEC44F, 0xFE9929, 0xEC7014, 0xCC4C02, 0x8C2D04,
0xFFFFD4, 0xFEE391, 0xFEC44F, 0xFE9929, 0xEC7014, 0xCC4C02, 0x8C2D04,
0xFFFFD4, 0xFEE391, 0xFEC44F, 0xFE9929, 0xD95F0E, 0x993404,
0xFFFFD4, 0xFED98E, 0xFE9929, 0xD95F0E, 0x993404,
0xFFFFD4, 0xFED98E, 0xFE9929, 0xCC4C02,
0xFFF7BC, 0xFEC44F, 0xD95F0E,
// Blue-Purple
0xF7FCFD, 0xE0ECF4, 0xBFD3E6, 0x9EBCDA, 0x8C96C6, 0x8C6BB1, 0x88419D, 0x810F7C, 0x4D004B,
0xF7FCFD, 0xE0ECF4, 0xBFD3E6, 0x9EBCDA, 0x8C96C6, 0x8C6BB1, 0x88419D, 0x6E016B,
0xEDF8FB, 0xBFD3E6, 0x9EBCDA, 0x8C96C6, 0x8C6BB1, 0x88419D, 0x6E016B,
0xEDF8FB, 0xBFD3E6, 0x9EBCDA, 0x8C96C6, 0x8856A7, 0x810F7C,
0xEDF8FB, 0xB3CDE3, 0x8C96C6, 0x8856A7, 0x810F7C,
0xEDF8FB, 0xB3CDE3, 0x8C96C6, 0x88419D,
0xE0ECF4, 0x9EBCDA, 0x8856A7,
// Qualitative Palettes
// Accent
0x7FC97F, 0xBEAED4, 0xFDC086, 0xFFFF99, 0x386CB0, 0xF0027F, 0xBF5B17, 0x666666,
// Dark2
0x1B9E77, 0xD95F02, 0x7570B3, 0xE7298A, 0x66A61E, 0xE6AB02, 0xA6761D, 0x666666,
// Set2
0x66C2A5, 0xFC8D62, 0x8DA0CB, 0xE78AC3, 0xA6D854, 0xFFD92F, 0xE5C494, 0xB3B3B3,
// Pastel2
0xB3E2CD, 0xFDCDAC, 0xCBD5E8, 0xF4CAE4, 0xE6F5C9, 0xFFF2AE, 0xF1E2CC, 0xCCCCCC,
// Pastel1
0xFBB4AE, 0xB3CDE3, 0xCCEBC5, 0xDECBE4, 0xFED9A6, 0xFFFFCC, 0xE5D8BD, 0xFDDAEC, 0xF2F2F2,
// Set1
0xE41A1C, 0x377EB8, 0x4DAF4A, 0x984EA3, 0xFF7F00, 0xFFFF33, 0xA65628, 0xF781BF, 0x999999,
// Paired
0xA6CEE3, 0x1F78B4, 0xB2DF8A, 0x33A02C, 0xFB9A99, 0xE31A1C, 0xFDBF6F, 0xFF7F00, 0xCAB2D6, 0x6A3D9A, 0xFFFF99,
// Set3
0x8DD3C7, 0xFFFFB3, 0xBEBADA, 0xFB8072, 0x80B1D3, 0xFDB462, 0xB3DE69, 0xFCCDE5, 0xD9D9D9, 0xBC80BD, 0xCCEBC5, 0xFFED6F,
};
const char* names[] =
{
"Diverging Purple-Orange",
"Diverging Spectral",
"Diverging Brown-Blue-Green",
"Sequential Blue-Green",
"Sequential Yellow-Orange-Brown",
"Sequential Blue-Purple",
"Qualitative Accent",
"Qualitative Dark2",
"Qualitative Set2",
"Qualitative Pastel2",
"Qualitative Pastel1",
"Qualitative Set1",
"Qualitative Paired",
"Qualitative Set3"
};
int sizes[][2] =
{
{ 11, 3 },
{ 11, 3 },
{ 11, 3 },
{ 9, 3 },
{ 9, 3 },
{ 9, 3 },
{ 8, 8 },
{ 8, 8 },
{ 8, 8 },
{ 8, 8 },
{ 9, 9 },
{ 9, 9 },
{ 11, 11 },
{ 12, 12 }
};
vtkTypeUInt32* color = colors;
for ( unsigned i = 0; i < sizeof(names)/sizeof(names[0]); ++ i )
{
int start = sizes[i][0];
int stop = sizes[i][1];
int step = start > stop ? -1 : 1;
for ( int n = start; n != stop + step; n += step )
{
vtksys_ios::ostringstream os;
os << names[i] << " (" << n << ")";
schemes->CreateScheme( os.str().c_str() );
for ( int j = 0; j < n; ++ j )
{
schemes->AddColor( vtkColor4ubFromHex3( *(color ++) ) );
}
}
}
}
vtkStandardNewMacro(vtkBrewerColors);
vtkBrewerColors::vtkBrewerColors()
{
this->Storage = new vtkColorSchemeInternal;
this->CurrentColorCache = 0;
this->CurrentSize = -1;
constructDefaultSchemes( this );
this->SetCurrentScheme( "Diverging Purple-Orange (4)" );
}
vtkBrewerColors::~vtkBrewerColors()
{
delete this->Storage;
}
void vtkBrewerColors::PrintSelf( ostream& os, vtkIndent indent )
{
this->Superclass::PrintSelf( os, indent );
os << indent << "Storage: " << this->Storage->size() << " entries\n";
os << indent << "CurrentScheme: \"" << ( this->CurrentScheme.empty() ? "(EMPTY)" : this->CurrentScheme.c_str() ) << "\"\n";
os << indent << "CurrentColorCache: " << this->CurrentColorCache << "\n";
}
vtkIdType vtkBrewerColors::GetNumberOfSchemes()
{
return static_cast<vtkIdType>( this->Storage->size() );
}
const char* vtkBrewerColors::GetScheme( vtkIdType index )
{
if ( index < 0 || index > this->GetNumberOfSchemes() )
{
return 0;
}
vtkColorSchemeInternal::iterator it = this->Storage->begin();
for ( ; ( index != 0 ) && ( it != this->Storage->end() ) ; -- index )
{
++ it ;
}
if ( it == this->Storage->end() )
{
return 0;
}
return it->first.c_str();
}
void vtkBrewerColors::SetCurrentScheme( const char* schemeName )
{
if ( this->CurrentScheme == schemeName || ! schemeName || schemeName[0] == '\0' )
{
return;
}
vtkColorSchemeInternal::iterator it = this->Storage->find( schemeName );
if ( it == this->Storage->end() )
{
return;
}
this->CurrentScheme = it->first;
this->CurrentColorCache = &it->second[0];
this->CurrentSize = static_cast<vtkIdType>( it->second.size() );
}
bool vtkBrewerColors::CreateScheme( const char* schemeName )
{
if ( ! schemeName )
{ // bad name
return false;
}
vtkColorSchemeInternal::iterator it = this->Storage->find( schemeName );
if ( it != this->Storage->end() )
{ // already exists
return false;
}
std::vector<vtkColor4ub> blank;
(*this->Storage)[schemeName] = blank;
this->SetCurrentScheme( schemeName );
return true;
}
int vtkBrewerColors::GetNumberOfColors()
{
return this->CurrentSize;
}
vtkColor4ub vtkBrewerColors::GetColor( int index ) const
{
if ( this->CurrentColorCache && index >= 0 && index < this->CurrentSize )
return this->CurrentColorCache[index];
return vtkColor4ub();
}
vtkColor4ub vtkBrewerColors::GetColorRepeating( int index ) const
{
return this->GetColor( index % this->CurrentSize );
}
void vtkBrewerColors::SetColor( int index, const vtkColor4ub& color )
{
if ( this->CurrentSize >= 0 && index >= 0 && index < this->CurrentSize )
{
this->CurrentColorCache[index] = color;
}
else
{
vtkErrorMacro( "No current scheme or index " << index << " out of range." );
}
}
void vtkBrewerColors::AddColor( const vtkColor4ub& color )
{
if ( this->CurrentSize >= 0 )
{
(*this->Storage)[this->CurrentScheme].push_back( color );
this->CurrentColorCache = &(*this->Storage)[this->CurrentScheme][0];
this->CurrentSize = static_cast<vtkIdType>( (*this->Storage)[this->CurrentScheme].size() );