VTK  9.3.1
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
40 #ifndef vtkScalarsToColors_h
41 #define vtkScalarsToColors_h
42 
43 #include "vtkCommonCoreModule.h" // For export macro
44 #include "vtkObject.h"
45 #include "vtkVariant.h" // Set/get annotation methods require variants.
46 
47 VTK_ABI_NAMESPACE_BEGIN
48 class vtkAbstractArray;
49 class vtkDataArray;
51 class vtkAbstractArray;
52 class vtkStringArray;
54 
55 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
56 {
57 public:
58  vtkTypeMacro(vtkScalarsToColors, vtkObject);
59  void PrintSelf(ostream& os, vtkIndent indent) override;
60  static vtkScalarsToColors* New();
61 
63 
68  virtual vtkTypeBool IsOpaque();
69  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
70  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
71  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
73 
78  virtual void Build() {}
79 
81 
84  virtual double* GetRange() VTK_SIZEHINT(2);
85  virtual void SetRange(double min, double max);
86  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
88 
93  virtual const unsigned char* MapValue(double v);
94 
99  virtual void GetColor(double v, double rgb[3]);
100 
105  double* GetColor(double v) VTK_SIZEHINT(3)
106  {
107  this->GetColor(v, this->RGB);
108  return this->RGB;
109  }
110 
116  virtual double GetOpacity(double v);
117 
123  double GetLuminance(double x)
124  {
125  double rgb[3];
126  this->GetColor(x, rgb);
127  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
128  }
129 
131 
137  virtual void SetAlpha(double alpha);
138  vtkGetMacro(Alpha, double);
140 
142 
161  virtual VTK_NEWINSTANCE vtkUnsignedCharArray* MapScalars(
162  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
163  virtual VTK_NEWINSTANCE vtkUnsignedCharArray* MapScalars(
164  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
166 
168 
173  vtkSetMacro(VectorMode, int);
174  vtkGetMacro(VectorMode, int);
175  void SetVectorModeToMagnitude();
176  void SetVectorModeToComponent();
177  void SetVectorModeToRGBColors();
179 
181  {
182  MAGNITUDE = 0,
183  COMPONENT = 1,
184  RGBCOLORS = 2
185  };
186 
188 
192  vtkSetMacro(VectorComponent, int);
193  vtkGetMacro(VectorComponent, int);
195 
197 
204  vtkSetMacro(VectorSize, int);
205  vtkGetMacro(VectorSize, int);
207 
215  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
216  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
217  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
218  int numberOfValues, int inputIncrement, int outputFormat)
219  {
220  this->MapVectorsThroughTable(
221  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
222  }
223 
232  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
233  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
234  {
235  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
236  }
237  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
238  int numberOfValues, int inputIncrement, int outputFormat)
239  {
240  this->MapScalarsThroughTable2(
241  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
242  }
243 
249  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
250  int numberOfValues, int inputIncrement, int outputFormat);
251 
255  virtual void DeepCopy(vtkScalarsToColors* o);
256 
261  virtual vtkTypeBool UsingLogScale() { return 0; }
262 
266  virtual vtkIdType GetNumberOfAvailableColors();
267 
269 
282  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
283  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
284  vtkGetObjectMacro(Annotations, vtkStringArray);
286 
291  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
292 
297  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
298 
302  vtkIdType GetNumberOfAnnotatedValues();
303 
308  vtkVariant GetAnnotatedValue(vtkIdType idx);
309 
314  vtkStdString GetAnnotation(vtkIdType idx);
315 
319  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
320 
324  vtkIdType GetAnnotatedValueIndex(vtkVariant val);
325 
331  vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant& val);
332 
345  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
346 
353  virtual bool RemoveAnnotation(vtkVariant value);
354 
358  virtual void ResetAnnotations();
359 
361 
369  vtkSetMacro(IndexedLookup, vtkTypeBool);
370  vtkGetMacro(IndexedLookup, vtkTypeBool);
371  vtkBooleanMacro(IndexedLookup, vtkTypeBool);
373 
375 
380  template <typename T>
381  static unsigned char ColorToUChar(T t)
382  {
383  return static_cast<unsigned char>(t);
384  }
385  template <typename T>
386  static void ColorToUChar(T t, unsigned char* dest)
387  {
388  *dest = ColorToUChar(t);
389  }
391 
392 protected:
394  ~vtkScalarsToColors() override;
395 
407  void MapColorsToColors(void* input, unsigned char* output, int inputDataType, int numberOfValues,
408  int numberOfComponents, int vectorSize, int outputFormat);
409 
415  VTK_NEWINSTANCE vtkUnsignedCharArray* ConvertToRGBA(
416  vtkDataArray* colors, int numComp, int numTuples);
417 
422  void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
423  int numberOfComponents, int vectorSize);
424 
429  virtual vtkIdType CheckForAnnotatedValue(vtkVariant value);
430 
435  virtual void UpdateAnnotatedValueMap();
436 
437  // Annotations of specific values.
440 
441  class vtkInternalAnnotatedValueList;
442  vtkInternalAnnotatedValueList* AnnotatedValueList;
443 
445 
446  double Alpha;
447 
448  // How to map arrays with multiple components.
452 
453 #if !defined(VTK_LEGACY_REMOVE)
454  // Obsolete, kept so subclasses will still compile
456 #endif
457 
458  unsigned char RGBABytes[4];
459 
460 private:
461  double RGB[3];
462  double InputRange[2];
463 
464  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
465  void operator=(const vtkScalarsToColors&) = delete;
466 };
467 
469 
474 template <>
475 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
476 {
477  double temp = (t * 255.0) + 0.5;
478  return static_cast<unsigned char>(temp);
479 }
480 template <>
481 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
482 {
483  double temp = (t * 255.0) + 0.5;
484  return static_cast<unsigned char>(temp);
485 }
487 
488 VTK_ABI_NAMESPACE_END
489 #endif
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:28
static void ColorToUChar(T t, unsigned char *dest)
Converts a color from numeric type T to uchar.
abstract base class for most VTK objects
Definition: vtkObject.h:51
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Abstract superclass for all arrays.
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:315
A type representing the union of many types.
Definition: vtkVariant.h:52
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
int vtkTypeBool
Definition: vtkABI.h:64
Superclass for mapping scalar values to colors.
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
virtual vtkTypeBool UsingLogScale()
This should return 1 if the subclass is using log scale for mapping scalars to colors.
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
#define VTK_SIZEHINT(...)
#define VTK_NEWINSTANCE
dynamic, self-adjusting array of unsigned char
#define VTK_RGBA
double * GetColor(double v)
Map one value through the lookup table and return the color as an RGB array of doubles between 0 and ...
vtkInternalAnnotatedValueList * AnnotatedValueList
vtkStringArray * Annotations
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
virtual void Build()
Perform any processing required (if any) before processing scalars.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkAbstractArray * AnnotatedValues
#define max(a, b)
double GetLuminance(double x)
Map one value through the lookup table and return the luminance 0.3*red + 0.59*green + 0...