Commit 8da2de29 authored by Marcus Hanwell's avatar Marcus Hanwell

ENH: New color series class to support charts.

This class contains several default color series ported from the
vtkQtChartColors class. More could be added to it and it is general
enough that it should be useful outside of the chart classes.
parent af8b57ac
......@@ -21,6 +21,7 @@ SET(Kit_SRCS
vtkBrush.cxx
vtkChart.cxx
vtkChartXY.cxx
vtkColorSeries.cxx
vtkContext2D.cxx
vtkContextActor.cxx
vtkContextDevice2D.cxx
......@@ -56,6 +57,7 @@ SET_SOURCE_FILES_PROPERTIES(
SET_SOURCE_FILES_PROPERTIES(
vtkBarMark
vtkChartColors
vtkDataElement
vtkDataValue
vtkLineMark
......
/*=========================================================================
Program: Visualization Toolkit
Module: vtkColorSeries.cxx
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
#include "vtkColorSeries.h"
#include "vtkObjectFactory.h"
// My STL container
#include <vtkstd/vector>
//-----------------------------------------------------------------------------
class vtkColorSeries::Private
{
public:
vtkstd::vector<vtkColor3ub> Colors; // List of colors
};
//-----------------------------------------------------------------------------
vtkCxxRevisionMacro(vtkColorSeries, "1.1");
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkColorSeries);
//-----------------------------------------------------------------------------
vtkColorSeries::vtkColorSeries()
{
this->ColorScheme = -1;
this->Storage = new vtkColorSeries::Private;
this->SetColorScheme(vtkColorSeries::SPECTRUM);
}
//-----------------------------------------------------------------------------
vtkColorSeries::~vtkColorSeries()
{
delete this->Storage;
this->Storage = NULL;
}
//-----------------------------------------------------------------------------
void vtkColorSeries::SetColorScheme(int scheme)
{
if (this->ColorScheme == scheme)
{
return;
}
// Clear the list, then save the scheme and load in the colors.
this->ColorScheme = scheme;
this->Storage->Colors.clear();
switch (this->ColorScheme)
{
case vtkColorSeries::SPECTRUM:
{
this->Storage->Colors.push_back(vtkColor3ub(0, 0, 0));
this->Storage->Colors.push_back(vtkColor3ub(228, 26, 28));
this->Storage->Colors.push_back(vtkColor3ub(55, 126, 184));
this->Storage->Colors.push_back(vtkColor3ub(77, 175, 74));
this->Storage->Colors.push_back(vtkColor3ub(152, 78, 163));
this->Storage->Colors.push_back(vtkColor3ub(255, 127, 0));
this->Storage->Colors.push_back(vtkColor3ub(166, 86, 40));
}
default: // Should never happen.
{
this->Storage->Colors.push_back(vtkColor3ub(0, 0, 0));
}
}
}
//-----------------------------------------------------------------------------
int vtkColorSeries::GetNumberOfColors()
{
return static_cast<int>(this->Storage->Colors.size());
}
//-----------------------------------------------------------------------------
vtkColor3ub vtkColorSeries::GetColor(int index) const
{
if (index >=0 && index < this->Storage->Colors.size())
{
return this->Storage->Colors[index];
}
else
{
return vtkColor3ub();
}
}
//-----------------------------------------------------------------------------
vtkColor3ub vtkColorSeries::GetColorRepeating(int index) const
{
return this->Storage->Colors[index % this->Storage->Colors.size()];
}
//-----------------------------------------------------------------------------
void vtkColorSeries::SetColor(int index, const vtkColor3ub &color)
{
if (index >=0 && index < this->Storage->Colors.size())
{
this->ColorScheme = vtkColorSeries::CUSTOM;
this->Storage->Colors[index] = color;
}
}
//-----------------------------------------------------------------------------
void vtkColorSeries::AddColor(const vtkColor3ub &color)
{
this->ColorScheme = vtkColorSeries::CUSTOM;
this->Storage->Colors.push_back(color);
}
//-----------------------------------------------------------------------------
void vtkColorSeries::InsertColor(int index, const vtkColor3ub &color)
{
if (index >=0 && index < this->Storage->Colors.size())
{
this->ColorScheme = vtkColorSeries::CUSTOM;
this->Storage->Colors.insert(this->Storage->Colors.begin()+index, color);
}
}
//-----------------------------------------------------------------------------
void vtkColorSeries::RemoveColor(int index)
{
if (index >=0 && index < this->Storage->Colors.size())
{
this->ColorScheme = vtkColorSeries::CUSTOM;
this->Storage->Colors.erase(this->Storage->Colors.begin()+index);
}
}
//-----------------------------------------------------------------------------
void vtkColorSeries::ClearColors()
{
this->ColorScheme = vtkColorSeries::CUSTOM;
this->Storage->Colors.clear();
}
//-----------------------------------------------------------------------------
void vtkColorSeries::DeepCopy(vtkColorSeries *colors)
{
this->ColorScheme = colors->ColorScheme;
this->Storage->Colors = colors->Storage->Colors;
}
//-----------------------------------------------------------------------------
void vtkColorSeries::PrintSelf(ostream &os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
os << indent << "Color Scheme: " << this->ColorScheme << endl;
}
/*=========================================================================
Program: Visualization Toolkit
Module: vtkColorSeries.h
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .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.
#ifndef __vtkColorSeries_h
#define __vtkColorSeries_h
#include "vtkObject.h"
#include "vtkVector.h" // Needed for vtkColor3ub
class VTK_CHARTS_EXPORT vtkColorSeries : public vtkObject
{
public:
vtkTypeRevisionMacro(vtkColorSeries, vtkObject);
virtual void PrintSelf(ostream &os, vtkIndent indent);
// Description:
// Create a new vtkColorSeries with the SPECTRUM color scheme.
static vtkColorSeries* New();
//BTX
// Description:
// Enum of the available color schemes
enum {
SPECTRUM = 0, ///< 7 different hues.
WARM, ///< 6 warm colors (red to yellow).
COOL, ///< 7 cool colors (green to purple).
BLUES, ///< 7 different blues.
WILD_FLOWER, ///< 7 colors from blue to magenta.
CITRUS, ///< 6 colors from green to orange.
CUSTOM ///< User specified color scheme.
};
//ETX
// Description:
// Set the color scheme that should be used from those in the enum.
void SetColorScheme(int scheme);
// Description:
// Get the color scheme that is currently being used.
vtkGetMacro(ColorScheme, int);
// Description:
// Get the number of colors available in the current color scheme.
int GetNumberOfColors();
//BTX
// Description:
// Get the color at the specified index. If the index is out of range then
// black will be returned.
vtkColor3ub GetColor(int index) const;
// Description:
// Get the color at the specified index. If the index is out of range then
// the call wraps around, i.e. uses the mod operator.
vtkColor3ub GetColorRepeating(int index) const;
// Description:
// Set the color at the specified index. Does nothing if the index is out of
// range.
void SetColor(int index, const vtkColor3ub &color);
// Description:
// Adds the color to the end of the list.
void AddColor(const vtkColor3ub &color);
// Description:
// Inserts the color at the specified index in the list.
void InsertColor(int index, const vtkColor3ub &color);
//ETX
// Description:
// Removes the color at the specified index in the list.
void RemoveColor(int index);
// Description:
// Clears the list of colors.
void ClearColors();
// Description:
// Make a deep copy of the supplied object.
void DeepCopy(vtkColorSeries *chartColors);
//BTX
protected:
vtkColorSeries();
~vtkColorSeries();
// Description:
// Private data pointer of the class, stores the color list.
class Private;
Private *Storage;
// Description:
// The color scheme being used.
int ColorScheme;
private:
vtkColorSeries(const vtkColorSeries &); // Not implemented.
void operator=(const vtkColorSeries &); // Not implemented.
//ETX
};
#endif //__vtkColorSeries_h
Markdown is supported
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