VTK  9.3.0
vtkScalarsToColors.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
49 #ifndef vtkScalarsToColors_h
50 #define vtkScalarsToColors_h
51 
52 #include "vtkCommonCoreModule.h" // For export macro
53 #include "vtkObject.h"
54 #include "vtkVariant.h" // Set/get annotation methods require variants.
55 
56 VTK_ABI_NAMESPACE_BEGIN
57 class vtkAbstractArray;
58 class vtkDataArray;
60 class vtkAbstractArray;
61 class vtkStringArray;
63 
64 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
65 {
66 public:
67  vtkTypeMacro(vtkScalarsToColors, vtkObject);
68  void PrintSelf(ostream& os, vtkIndent indent) override;
70 
72 
77  virtual vtkTypeBool IsOpaque();
78  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
79  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
80  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
82 
87  virtual void Build() {}
88 
90 
93  virtual double* GetRange() VTK_SIZEHINT(2);
94  virtual void SetRange(double min, double max);
95  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
97 
102  virtual const unsigned char* MapValue(double v);
103 
108  virtual void GetColor(double v, double rgb[3]);
109 
114  double* GetColor(double v) VTK_SIZEHINT(3)
115  {
116  this->GetColor(v, this->RGB);
117  return this->RGB;
118  }
119 
125  virtual double GetOpacity(double v);
126 
132  double GetLuminance(double x)
133  {
134  double rgb[3];
135  this->GetColor(x, rgb);
136  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
137  }
138 
140 
146  virtual void SetAlpha(double alpha);
147  vtkGetMacro(Alpha, double);
149 
151 
171  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
173  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
175 
177 
182  vtkSetMacro(VectorMode, int);
183  vtkGetMacro(VectorMode, int);
188 
190  {
191  MAGNITUDE = 0,
192  COMPONENT = 1,
193  RGBCOLORS = 2
194  };
195 
197 
201  vtkSetMacro(VectorComponent, int);
202  vtkGetMacro(VectorComponent, int);
204 
206 
213  vtkSetMacro(VectorSize, int);
214  vtkGetMacro(VectorSize, int);
216 
224  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
225  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
226  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
227  int numberOfValues, int inputIncrement, int outputFormat)
228  {
229  this->MapVectorsThroughTable(
230  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
231  }
232 
241  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
242  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
243  {
244  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
245  }
246  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
247  int numberOfValues, int inputIncrement, int outputFormat)
248  {
249  this->MapScalarsThroughTable2(
250  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
251  }
252 
258  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
259  int numberOfValues, int inputIncrement, int outputFormat);
260 
264  virtual void DeepCopy(vtkScalarsToColors* o);
265 
270  virtual vtkTypeBool UsingLogScale() { return 0; }
271 
276 
278 
291  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
292  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
293  vtkGetObjectMacro(Annotations, vtkStringArray);
295 
301 
307 
312 
318 
324 
328  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
329 
334 
341 
354  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
355 
363 
367  virtual void ResetAnnotations();
368 
370 
378  vtkSetMacro(IndexedLookup, vtkTypeBool);
379  vtkGetMacro(IndexedLookup, vtkTypeBool);
380  vtkBooleanMacro(IndexedLookup, vtkTypeBool);
382 
384 
389  template <typename T>
390  static unsigned char ColorToUChar(T t)
391  {
392  return static_cast<unsigned char>(t);
393  }
394  template <typename T>
395  static void ColorToUChar(T t, unsigned char* dest)
396  {
397  *dest = ColorToUChar(t);
398  }
400 
401 protected:
404 
416  void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
417  int numberOfComponents, int vectorSize, int outputFormat);
418 
424  vtkUnsignedCharArray* ConvertToRGBA(vtkDataArray* colors, int numComp, int numTuples);
425 
430  void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
431  int numberOfComponents, int vectorSize);
432 
438 
443  virtual void UpdateAnnotatedValueMap();
444 
445  // Annotations of specific values.
448 
449  class vtkInternalAnnotatedValueList;
450  vtkInternalAnnotatedValueList* AnnotatedValueList;
451 
453 
454  double Alpha;
455 
456  // How to map arrays with multiple components.
460 
461 #if !defined(VTK_LEGACY_REMOVE)
462  // Obsolete, kept so subclasses will still compile
464 #endif
465 
466  unsigned char RGBABytes[4];
467 
468 private:
469  double RGB[3];
470  double InputRange[2];
471 
472  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
473  void operator=(const vtkScalarsToColors&) = delete;
474 };
475 
477 
482 template <>
483 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
484 {
485  double temp = (t * 255.0) + 0.5;
486  return static_cast<unsigned char>(temp);
487 }
488 template <>
489 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
490 {
491  double temp = (t * 255.0) + 0.5;
492  return static_cast<unsigned char>(temp);
493 }
495 
496 VTK_ABI_NAMESPACE_END
497 #endif
Abstract superclass for all arrays.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
a simple class to control print indentation
Definition: vtkIndent.h:38
abstract base class for most VTK objects
Definition: vtkObject.h:61
Superclass for mapping scalar values to colors.
virtual vtkTypeBool UsingLogScale()
This should return 1 if the subclass is using log scale for mapping scalars to colors.
static vtkScalarsToColors * New()
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
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...
virtual void DeepCopy(vtkScalarsToColors *o)
Copy the contents from another object.
vtkVariant GetAnnotatedValue(vtkIdType idx)
Return the annotated value at a particular index in the list of annotations.
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output, int outputFormat)
Map a set of scalars through the lookup table in a single operation.
virtual void UpdateAnnotatedValueMap()
Update the map from annotated values to indices in the array of annotations.
virtual vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int component)
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual void SetAlpha(double alpha)
Specify an additional opacity (alpha) value to blend with.
double GetLuminance(double x)
Map one value through the lookup table and return the luminance 0.3*red + 0.59*green + 0....
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.
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
virtual void GetIndexedColor(vtkIdType i, double rgba[4])
Get the "indexed color" assigned to an index.
virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation)
This variant of SetAnnotation accepts the value as a string so ParaView can treat annotations as stri...
virtual vtkTypeBool IsOpaque()
Return true if all of the values defining the mapping have an opacity equal to 1.
virtual vtkIdType GetNumberOfAvailableColors()
Get the number of available colors for mapping to.
static void ColorToUChar(T t, unsigned char *dest)
Converts a color from numeric type T to uchar.
double * GetColor(double v)
Map one value through the lookup table and return the color as an RGB array of doubles between 0 and ...
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
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.
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.
virtual bool RemoveAnnotation(vtkVariant value)
Remove an existing entry from the list of annotated values.
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...
virtual double GetOpacity(double v)
Map one value through the lookup table and return the alpha value (the opacity) as a double between 0...
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
~vtkScalarsToColors() override
virtual void ResetAnnotations()
Remove all existing values and their annotations.
virtual vtkTypeBool IsOpaque(vtkAbstractArray *scalars, int colorMode, int component, vtkUnsignedCharArray *ghosts, unsigned char ghostsToSkip=0xff)
Return true if all of the values defining the mapping have an opacity equal to 1.
void SetVectorModeToComponent()
Change mode that maps vectors by magnitude vs.
void SetVectorModeToMagnitude()
Change mode that maps vectors by magnitude vs.
vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant &val)
Look up an index into the array of annotations given a value.
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 ...
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
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...
vtkIdType GetNumberOfAnnotatedValues()
Return the annotated value at a particular index in the list of annotations.
virtual void MapScalarsThroughTable2(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
An internal method typically not used in applications.
virtual void Build()
Perform any processing required (if any) before processing scalars.
virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation)
Add a new entry (or change an existing entry) to the list of annotated values.
virtual void GetAnnotationColor(const vtkVariant &val, double rgba[4])
Obtain the color associated with a particular annotated value (or NanColor if unmatched).
vtkInternalAnnotatedValueList * AnnotatedValueList
virtual double * GetRange()
Sets/Gets the range of scalars that will be mapped.
vtkAbstractArray * AnnotatedValues
virtual vtkIdType CheckForAnnotatedValue(vtkVariant value)
Allocate annotation arrays if needed, then return the index of the given value or -1 if not present.
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...
vtkIdType GetAnnotatedValueIndex(vtkVariant val)
Return the index of the given value in the list of annotated values (or -1 if not present).
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkUnsignedCharArray * ConvertToRGBA(vtkDataArray *colors, int numComp, int numTuples)
An internal method used to convert a color array to RGBA.
vtkStringArray * Annotations
void SetVectorModeToRGBColors()
Change mode that maps vectors by magnitude vs.
vtkStdString GetAnnotation(vtkIdType idx)
Return the annotation at a particular index in the list of annotations.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
a vtkAbstractArray subclass for strings
dynamic, self-adjusting array of unsigned char
A type representing the union of many types.
Definition: vtkVariant.h:62
@ component
Definition: vtkX3D.h:175
@ value
Definition: vtkX3D.h:220
@ alpha
Definition: vtkX3D.h:250
int vtkTypeBool
Definition: vtkABI.h:64
#define VTK_RGBA
int vtkIdType
Definition: vtkType.h:315
#define VTK_SIZEHINT(...)
#define max(a, b)