VTK  9.1.0
vtkScalarsToColors.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkScalarsToColors.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
95 #ifndef vtkScalarsToColors_h
96 #define vtkScalarsToColors_h
97 
98 #include "vtkCommonCoreModule.h" // For export macro
99 #include "vtkObject.h"
100 #include "vtkVariant.h" // Set/get annotation methods require variants.
101 
102 class vtkAbstractArray;
103 class vtkDataArray;
105 class vtkAbstractArray;
106 class vtkStringArray;
107 
108 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
109 {
110 public:
112  void PrintSelf(ostream& os, vtkIndent indent) override;
114 
116 
121  virtual int IsOpaque();
122  virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
124 
129  virtual void Build() {}
130 
132 
135  virtual double* GetRange() VTK_SIZEHINT(2);
136  virtual void SetRange(double min, double max);
137  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
139 
144  virtual const unsigned char* MapValue(double v);
145 
150  virtual void GetColor(double v, double rgb[3]);
151 
156  double* GetColor(double v) VTK_SIZEHINT(3)
157  {
158  this->GetColor(v, this->RGB);
159  return this->RGB;
160  }
161 
167  virtual double GetOpacity(double v);
168 
174  double GetLuminance(double x)
175  {
176  double rgb[3];
177  this->GetColor(x, rgb);
178  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
179  }
180 
182 
188  virtual void SetAlpha(double alpha);
189  vtkGetMacro(Alpha, double);
191 
193 
213  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
215  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
217 
219 
224  vtkSetMacro(VectorMode, int);
225  vtkGetMacro(VectorMode, int);
230 
232  {
233  MAGNITUDE = 0,
234  COMPONENT = 1,
235  RGBCOLORS = 2
236  };
237 
239 
243  vtkSetMacro(VectorComponent, int);
244  vtkGetMacro(VectorComponent, int);
246 
248 
255  vtkSetMacro(VectorSize, int);
256  vtkGetMacro(VectorSize, int);
258 
266  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
267  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
268  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
269  int numberOfValues, int inputIncrement, int outputFormat)
270  {
271  this->MapVectorsThroughTable(
272  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
273  }
274 
283  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
284  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
285  {
286  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
287  }
288  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
289  int numberOfValues, int inputIncrement, int outputFormat)
290  {
291  this->MapScalarsThroughTable2(
292  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
293  }
294 
300  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
301  int numberOfValues, int inputIncrement, int outputFormat);
302 
306  virtual void DeepCopy(vtkScalarsToColors* o);
307 
312  virtual int UsingLogScale() { return 0; }
313 
318 
320 
333  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
334  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
335  vtkGetObjectMacro(Annotations, vtkStringArray);
337 
343 
349 
354 
359 
364 
368  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
369 
374 
381 
394  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
395 
403 
407  virtual void ResetAnnotations();
408 
410 
418  vtkSetMacro(IndexedLookup, vtkTypeBool);
419  vtkGetMacro(IndexedLookup, vtkTypeBool);
420  vtkBooleanMacro(IndexedLookup, vtkTypeBool);
422 
424 
429  template <typename T>
430  static unsigned char ColorToUChar(T t)
431  {
432  return static_cast<unsigned char>(t);
433  }
434  template <typename T>
435  static void ColorToUChar(T t, unsigned char* dest)
436  {
437  *dest = ColorToUChar(t);
438  }
440 
441 protected:
444 
456  void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
457  int numberOfComponents, int vectorSize, int outputFormat);
458 
464  vtkUnsignedCharArray* ConvertToRGBA(vtkDataArray* colors, int numComp, int numTuples);
465 
470  void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
471  int numberOfComponents, int vectorSize);
472 
478 
483  virtual void UpdateAnnotatedValueMap();
484 
485  // Annotations of specific values.
488 
489  class vtkInternalAnnotatedValueList;
490  vtkInternalAnnotatedValueList* AnnotatedValueList;
491 
493 
494  double Alpha;
495 
496  // How to map arrays with multiple components.
500 
501  // Obsolete, kept so subclasses will still compile
503 
504  unsigned char RGBABytes[4];
505 
506 private:
507  double RGB[3];
508  double InputRange[2];
509 
510  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
511  void operator=(const vtkScalarsToColors&) = delete;
512 };
513 
515 
520 template <>
521 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
522 {
523  return static_cast<unsigned char>(t * 255 + 0.5);
524 }
525 template <>
526 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
527 {
528  return static_cast<unsigned char>(t * 255 + 0.5);
529 }
531 
532 #endif
vtkScalarsToColors::vtkScalarsToColors
vtkScalarsToColors()
vtkScalarsToColors::GetAnnotatedValue
vtkVariant GetAnnotatedValue(vtkIdType idx)
Return the annotated value at a particular index in the list of annotations.
vtkScalarsToColors::SetAnnotation
virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation)
Add a new entry (or change an existing entry) to the list of annotated values.
vtkScalarsToColors::GetAnnotatedValueIndexInternal
vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant &val)
Look up an index into the array of annotations given a value.
vtkVariant.h
vtkX3D::alpha
@ alpha
Definition: vtkX3D.h:256
vtkX3D::component
@ component
Definition: vtkX3D.h:181
vtkScalarsToColors::ColorToUChar
static void ColorToUChar(T t, unsigned char *dest)
Converts a color from numeric type T to uchar.
Definition: vtkScalarsToColors.h:435
vtkScalarsToColors::VectorModes
VectorModes
Definition: vtkScalarsToColors.h:232
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkIdType
int vtkIdType
Definition: vtkType.h:332
vtkScalarsToColors::IndexedLookup
vtkTypeBool IndexedLookup
Definition: vtkScalarsToColors.h:492
vtkScalarsToColors::MapColorsToColors
void MapColorsToColors(void *input, unsigned char *output, int inputDataType, int numberOfValues, int numberOfComponents, int vectorSize, int outputFormat)
An internal method that assumes that the input already has the right colors, and only remaps the rang...
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:145
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:82
vtkScalarsToColors::VectorComponent
int VectorComponent
Definition: vtkScalarsToColors.h:498
vtkScalarsToColors::RemoveAnnotation
virtual bool RemoveAnnotation(vtkVariant value)
Remove an existing entry from the list of annotated values.
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:129
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:159
vtkScalarsToColors::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkScalarsToColors::VectorMode
int VectorMode
Definition: vtkScalarsToColors.h:497
vtkScalarsToColors::GetIndexedColor
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
vtkScalarsToColors::SetAlpha
virtual void SetAlpha(double alpha)
Specify an additional opacity (alpha) value to blend with.
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkScalarsToColors::SetAnnotations
virtual void SetAnnotations(vtkAbstractArray *values, vtkStringArray *annotations)
Set a list of discrete values, either as a categorical set of values (when IndexedLookup is true) or ...
vtkScalarsToColors::SetVectorModeToMagnitude
void SetVectorModeToMagnitude()
Change mode that maps vectors by magnitude vs.
vtkScalarsToColors::IsOpaque
virtual int IsOpaque(vtkAbstractArray *scalars, int colorMode, int component)
Return true if all of the values defining the mapping have an opacity equal to 1.
vtkScalarsToColors::MapVectorsThroughTable
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:268
vtkScalarsToColors::GetOpacity
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
vtkScalarsToColors::~vtkScalarsToColors
~vtkScalarsToColors() override
vtkScalarsToColors::GetNumberOfAnnotatedValues
vtkIdType GetNumberOfAnnotatedValues()
Return the annotated value at a particular index in the list of annotations.
vtkScalarsToColors::ColorToUChar
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
Definition: vtkScalarsToColors.h:430
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:288
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:48
vtkScalarsToColors::DeepCopy
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkScalarsToColors::MapScalars
virtual vtkUnsignedCharArray * MapScalars(vtkDataArray *scalars, int colorMode, int component, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
vtkScalarsToColors::SetVectorModeToComponent
void SetVectorModeToComponent()
Change mode that maps vectors by magnitude vs.
vtkScalarsToColors::GetColor
double * GetColor(double v)
Map one value through the lookup table and return the color as an RGB array of doubles between 0 and ...
Definition: vtkScalarsToColors.h:156
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:113
vtkScalarsToColors::SetAnnotation
virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation)
This variant of SetAnnotation accepts the value as a string so ParaView can treat annotations as stri...
vtkScalarsToColors::AnnotatedValues
vtkAbstractArray * AnnotatedValues
Definition: vtkScalarsToColors.h:486
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output, int outputFormat)
Map a set of scalars through the lookup table in a single operation.
vtkScalarsToColors::GetAnnotationColor
virtual void GetAnnotationColor(const vtkVariant &val, double rgba[4])
Obtain the color associated with a particular annotated value (or NanColor if unmatched).
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:155
vtkScalarsToColors::ResetAnnotations
virtual void ResetAnnotations()
Remove all existing values and their annotations.
vtkScalarsToColors::UsingLogScale
virtual int UsingLogScale()
This should return 1 is the subclass is using log scale for mapping scalars to colors.
Definition: vtkScalarsToColors.h:312
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:109
vtkScalarsToColors::MapValue
virtual const unsigned char * MapValue(double v)
Map one value through the lookup table and return a color defined as an RGBA unsigned char tuple (4 b...
vtkScalarsToColors::MapVectorsToMagnitude
void MapVectorsToMagnitude(void *input, double *output, int inputDataType, int numberOfValues, int numberOfComponents, int vectorSize)
An internal method for converting vectors to magnitudes, used as a preliminary step before doing magn...
vtkScalarsToColors::AnnotatedValueList
vtkInternalAnnotatedValueList * AnnotatedValueList
Definition: vtkScalarsToColors.h:489
vtkObject.h
vtkScalarsToColors::GetColor
virtual void GetColor(double v, double rgb[3])
Map one value through the lookup table and store the color as an RGB array of doubles between 0 and 1...
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:76
vtkScalarsToColors::UpdateAnnotatedValueMap
virtual void UpdateAnnotatedValueMap()
Update the map from annotated values to indices in the array of annotations.
vtkScalarsToColors::ConvertToRGBA
vtkUnsignedCharArray * ConvertToRGBA(vtkDataArray *colors, int numComp, int numTuples)
An internal method used to convert a color array to RGBA.
vtkScalarsToColors::GetNumberOfAvailableColors
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
vtkScalarsToColors::GetAnnotation
vtkStdString GetAnnotation(vtkIdType idx)
Return the annotation at a particular index in the list of annotations.
vtkScalarsToColors::GetRange
virtual double * GetRange()
Sets/Gets the range of scalars that will be mapped.
vtkScalarsToColors::GetLuminance
double GetLuminance(double x)
Map one value through the lookup table and return the luminance 0.3*red + 0.59*green + 0....
Definition: vtkScalarsToColors.h:174
vtkScalarsToColors::MapVectorsThroughTable
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize)
Map vectors through the lookup table.
VTK_RGBA
#define VTK_RGBA
Definition: vtkSystemIncludes.h:87
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:146
vtkScalarsToColors::MapScalarsThroughTable2
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
vtkScalarsToColors::Alpha
double Alpha
Definition: vtkScalarsToColors.h:494
vtkScalarsToColors::UseMagnitude
int UseMagnitude
Definition: vtkScalarsToColors.h:502
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:105
vtkScalarsToColors::Annotations
vtkStringArray * Annotations
Definition: vtkScalarsToColors.h:487
vtkScalarsToColors::New
static vtkScalarsToColors * New()
vtkScalarsToColors::MapScalars
virtual vtkUnsignedCharArray * MapScalars(vtkAbstractArray *scalars, int colorMode, int component, int outputFormat=VTK_RGBA)
Internal methods that map a data array into an unsigned char array.
vtkScalarsToColors::GetAnnotatedValueIndex
vtkIdType GetAnnotatedValueIndex(vtkVariant val)
Return the index of the given value in the list of annotated values (or -1 if not present).
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Definition: vtkScalarsToColors.h:284
vtkScalarsToColors::SetRange
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
Definition: vtkScalarsToColors.h:137
vtkScalarsToColors::SetVectorModeToRGBColors
void SetVectorModeToRGBColors()
Change mode that maps vectors by magnitude vs.
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkScalarsToColors::CheckForAnnotatedValue
virtual vtkIdType CheckForAnnotatedValue(vtkVariant value)
Allocate annotation arrays if needed, then return the index of the given value or -1 if not present.
vtkScalarsToColors::VectorSize
int VectorSize
Definition: vtkScalarsToColors.h:499
vtkScalarsToColors::IsOpaque
virtual int IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.