VTK  9.2.6
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 =========================================================================*/
52 #ifndef vtkScalarsToColors_h
53 #define vtkScalarsToColors_h
54 
55 #include "vtkCommonCoreModule.h" // For export macro
56 #include "vtkObject.h"
57 #include "vtkVariant.h" // Set/get annotation methods require variants.
58 
59 class vtkAbstractArray;
60 class vtkDataArray;
62 class vtkAbstractArray;
63 class vtkStringArray;
65 
66 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
67 {
68 public:
69  vtkTypeMacro(vtkScalarsToColors, vtkObject);
70  void PrintSelf(ostream& os, vtkIndent indent) override;
71  static vtkScalarsToColors* New();
72 
74 
79  virtual int IsOpaque();
80  virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
81  virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component,
82  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
84 
89  virtual void Build() {}
90 
92 
95  virtual double* GetRange() VTK_SIZEHINT(2);
96  virtual void SetRange(double min, double max);
97  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
99 
104  virtual const unsigned char* MapValue(double v);
105 
110  virtual void GetColor(double v, double rgb[3]);
111 
116  double* GetColor(double v) VTK_SIZEHINT(3)
117  {
118  this->GetColor(v, this->RGB);
119  return this->RGB;
120  }
121 
127  virtual double GetOpacity(double v);
128 
134  double GetLuminance(double x)
135  {
136  double rgb[3];
137  this->GetColor(x, rgb);
138  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
139  }
140 
142 
148  virtual void SetAlpha(double alpha);
149  vtkGetMacro(Alpha, double);
151 
153 
172  virtual vtkUnsignedCharArray* MapScalars(
173  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
174  virtual vtkUnsignedCharArray* MapScalars(
175  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
177 
179 
184  vtkSetMacro(VectorMode, int);
185  vtkGetMacro(VectorMode, int);
186  void SetVectorModeToMagnitude();
187  void SetVectorModeToComponent();
188  void SetVectorModeToRGBColors();
190 
192  {
193  MAGNITUDE = 0,
194  COMPONENT = 1,
195  RGBCOLORS = 2
196  };
197 
199 
203  vtkSetMacro(VectorComponent, int);
204  vtkGetMacro(VectorComponent, int);
206 
208 
215  vtkSetMacro(VectorSize, int);
216  vtkGetMacro(VectorSize, int);
218 
226  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
227  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
228  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
229  int numberOfValues, int inputIncrement, int outputFormat)
230  {
231  this->MapVectorsThroughTable(
232  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
233  }
234 
243  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
244  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
245  {
246  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
247  }
248  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
249  int numberOfValues, int inputIncrement, int outputFormat)
250  {
251  this->MapScalarsThroughTable2(
252  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
253  }
254 
260  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
261  int numberOfValues, int inputIncrement, int outputFormat);
262 
266  virtual void DeepCopy(vtkScalarsToColors* o);
267 
272  virtual int UsingLogScale() { return 0; }
273 
277  virtual vtkIdType GetNumberOfAvailableColors();
278 
280 
293  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
294  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
295  vtkGetObjectMacro(Annotations, vtkStringArray);
297 
302  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
303 
308  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
309 
313  vtkIdType GetNumberOfAnnotatedValues();
314 
318  vtkVariant GetAnnotatedValue(vtkIdType idx);
319 
323  vtkStdString GetAnnotation(vtkIdType idx);
324 
328  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
329 
333  vtkIdType GetAnnotatedValueIndex(vtkVariant val);
334 
340  vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant& val);
341 
354  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
355 
362  virtual bool RemoveAnnotation(vtkVariant value);
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:
403  ~vtkScalarsToColors() override;
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 
437  virtual vtkIdType CheckForAnnotatedValue(vtkVariant value);
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  // Obsolete, kept so subclasses will still compile
463 
464  unsigned char RGBABytes[4];
465 
466 private:
467  double RGB[3];
468  double InputRange[2];
469 
470  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
471  void operator=(const vtkScalarsToColors&) = delete;
472 };
473 
475 
480 template <>
481 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
482 {
483  return static_cast<unsigned char>(t * 255 + 0.5);
484 }
485 template <>
486 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
487 {
488  return static_cast<unsigned char>(t * 255 + 0.5);
489 }
491 
492 #endif
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:38
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:62
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:332
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
virtual void SetRange(const double rng[2])
Sets/Gets the range of scalars that will be mapped.
int vtkTypeBool
Definition: vtkABI.h:69
Superclass for mapping scalar values to colors.
a simple class to control print indentation
Definition: vtkIndent.h:39
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
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(...)
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...
virtual int UsingLogScale()
This should return 1 is the subclass is using log scale for mapping scalars to colors.