VTK  9.7.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 "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_7_0
45 #include "vtkObject.h"
46 #include "vtkVariant.h" // Set/get annotation methods require variants.
47 #include "vtkWrappingHints.h" // For VTK_MARSHALMANUAL
48 
49 VTK_ABI_NAMESPACE_BEGIN
50 class vtkAbstractArray;
51 class vtkBitArray;
52 class vtkDataArray;
53 class vtkStringArray;
55 
56 class VTKCOMMONCORE_EXPORT VTK_MARSHALMANUAL vtkScalarsToColors : public vtkObject
57 {
58 public:
59  vtkTypeMacro(vtkScalarsToColors, vtkObject);
60  void PrintSelf(ostream& os, vtkIndent indent) override;
61  static vtkScalarsToColors* New();
62 
64 
69  virtual vtkTypeBool IsOpaque();
70  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int vectorComponent);
71  virtual vtkTypeBool IsOpaque(vtkAbstractArray* scalars, int colorMode, int vectorComponent,
72  vtkUnsignedCharArray* ghosts, unsigned char ghostsToSkip = 0xff);
74 
79  virtual void Build() {}
80 
82 
85  virtual double* GetRange() VTK_SIZEHINT(2);
86  virtual void SetRange(double min, double max);
87  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
89 
94  virtual const unsigned char* MapValue(double v);
95 
100  virtual void GetColor(double v, double rgb[3]);
101 
106  double* GetColor(double v) VTK_SIZEHINT(3)
107  {
108  this->GetColor(v, this->RGB);
109  return this->RGB;
110  }
111 
117  virtual double GetOpacity(double v);
118 
124  double GetLuminance(double x)
125  {
126  double rgb[3];
127  this->GetColor(x, rgb);
128  return rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11;
129  }
130 
132 
138  virtual void SetAlpha(double alpha);
139  vtkGetMacro(Alpha, double);
141 
143 
162  virtual VTK_NEWINSTANCE vtkUnsignedCharArray* MapScalars(
163  vtkDataArray* scalars, int colorMode, int vectorComponent, int outputFormat = VTK_RGBA);
164  virtual VTK_NEWINSTANCE vtkUnsignedCharArray* MapScalars(
165  vtkAbstractArray* scalars, int colorMode, int vectorComponent, int outputFormat = VTK_RGBA);
167 
169 
174  vtkSetMacro(VectorMode, int);
175  vtkGetMacro(VectorMode, int);
176  void SetVectorModeToMagnitude();
177  void SetVectorModeToComponent();
178  void SetVectorModeToRGBColors();
180 
182  {
183  MAGNITUDE = 0,
184  COMPONENT = 1,
185  RGBCOLORS = 2
186  };
187 
189 
193  vtkSetMacro(VectorComponent, int);
194  vtkGetMacro(VectorComponent, int);
196 
198 
205  vtkSetMacro(VectorSize, int);
206  vtkGetMacro(VectorSize, int);
208 
210 
217  void MapVectorsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
218  int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat,
219  int vectorComponent, int vectorSize);
220  void MapVectorsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
221  int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
222  {
223  this->MapVectorsThroughTable(
224  input, output, inputDataType, numberOfTuples, numberOfComponents, outputFormat, -1, -1);
225  }
226  void MapVectorsThroughTable(vtkDataArray* input, unsigned char* output, int numberOfTuples,
227  int numberOfComponents, int vectorComponent, int vectorSize, int outputFormat);
228  void MapVectorsThroughTable(vtkDataArray* input, unsigned char* output, int numberOfTuples,
229  int numberOfComponents, int outputFormat)
230  {
231  this->MapVectorsThroughTable(
232  input, output, numberOfTuples, numberOfComponents, -1, -1, outputFormat);
233  }
235 
237 
245  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
246  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
247  {
248  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
249  }
251 
253 
258  virtual void MapScalarsThroughTable(vtkAbstractArray* input, unsigned char* output,
259  int numberOfTuples, int numberOfComponents, int vectorComponent, int outputFormat);
260  void MapScalarsThroughTable(VTK_FUTURE_CONST void* input, unsigned char* output,
261  int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat);
262  VTK_DEPRECATED_IN_9_7_0("Use the MapScalarsThroughTable overload instead")
263  virtual void MapScalarsThroughTable2(VTK_FUTURE_CONST void* input, unsigned char* output,
264  int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat);
266 
270  virtual void DeepCopy(vtkScalarsToColors* o);
271 
276  virtual vtkTypeBool UsingLogScale() { return 0; }
277 
281  virtual vtkIdType GetNumberOfAvailableColors();
282 
284 
297  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
298  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
299  vtkGetObjectMacro(Annotations, vtkStringArray);
301 
306  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
307 
312  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
313 
317  vtkIdType GetNumberOfAnnotatedValues();
318 
323  vtkVariant GetAnnotatedValue(vtkIdType idx);
324 
329  vtkStdString GetAnnotation(vtkIdType idx);
330 
334  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
335 
339  vtkIdType GetAnnotatedValueIndex(vtkVariant val);
340 
346  vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant& val);
347 
360  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
361 
368  virtual bool RemoveAnnotation(vtkVariant value);
369 
373  virtual void ResetAnnotations();
374 
376 
384  vtkSetMacro(IndexedLookup, vtkTypeBool);
385  vtkGetMacro(IndexedLookup, vtkTypeBool);
386  vtkBooleanMacro(IndexedLookup, vtkTypeBool);
388 
390 
395  template <typename T>
396  static unsigned char ColorToUChar(T t)
397  {
398  return static_cast<unsigned char>(t);
399  }
400  template <typename T>
401  static void ColorToUChar(T t, unsigned char* dest)
402  {
403  *dest = ColorToUChar(t);
404  }
406 
407 protected:
409  ~vtkScalarsToColors() override;
410 
415  static vtkSmartPointer<vtkUnsignedCharArray> UnpackBits(
416  vtkBitArray* colors, int numComp, vtkIdType numTuples);
417 
419 
430  VTK_DEPRECATED_IN_9_7_0("Use the overload taking vtkDataArray* instead")
431  void MapColorsToColors(VTK_FUTURE_CONST void* input, unsigned char* output, int inputDataType,
432  int numberOfTuples, int numberOfComponents, int vectorSize, int outputFormat);
433  void MapColorsToColors(vtkDataArray* input, unsigned char* output, int numberOfTuples,
434  int numberOfComponents, int vectorComponent, int vectorSize, int outputFormat);
436 
442  VTK_NEWINSTANCE vtkUnsignedCharArray* ConvertToRGBA(
443  vtkDataArray* colors, int numComp, int numTuples);
444 
446 
450  VTK_DEPRECATED_IN_9_7_0("Use the overload taking vtkDataArray* instead")
451  void MapVectorsToMagnitude(VTK_FUTURE_CONST void* input, double* output, int inputDataType,
452  int numberOfTuples, int numberOfComponents, int vectorSize);
453  void MapVectorsToMagnitude(vtkDataArray* input, double* output, int numberOfTuples,
454  int numberOfComponents, int vectorComponent, int vectorSize);
456 
461  virtual vtkIdType CheckForAnnotatedValue(vtkVariant value);
462 
467  virtual void UpdateAnnotatedValueMap();
468 
469  // Annotations of specific values.
470  vtkAbstractArray* AnnotatedValues;
471  vtkStringArray* Annotations;
472 
473  class vtkInternalAnnotatedValueList;
474  vtkInternalAnnotatedValueList* AnnotatedValueList;
475 
476  vtkTypeBool IndexedLookup;
477 
478  double Alpha;
479 
480  // How to map arrays with multiple components.
481  int VectorMode;
482  int VectorComponent;
483  int VectorSize;
484 
485  unsigned char RGBABytes[4];
486 
487 private:
488  double RGB[3];
489  double InputRange[2];
490 
491  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
492  void operator=(const vtkScalarsToColors&) = delete;
493 };
494 
496 
501 template <>
502 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
503 {
504  double temp = (t * 255.0) + 0.5;
505  return static_cast<unsigned char>(temp);
506 }
507 template <>
508 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
509 {
510  double temp = (t * 255.0) + 0.5;
511  return static_cast<unsigned char>(temp);
512 }
514 
515 VTK_ABI_NAMESPACE_END
516 #endif
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Map a set of scalars through the lookup table in a single operation.
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:27
void MapVectorsThroughTable(vtkDataArray *input, unsigned char *output, int numberOfTuples, int numberOfComponents, int outputFormat)
Map vectors through the lookup table.
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:52
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:363
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.
#define VTK_MARSHALMANUAL
a simple class to control print indentation
Definition: vtkIndent.h:28
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:44
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
#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 ...
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:32
void MapVectorsThroughTable(VTK_FUTURE_CONST void *input, unsigned char *output, int inputDataType, int numberOfTuples, int numberOfComponents, int outputFormat)
Map vectors through the lookup table.
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...
#define VTK_DEPRECATED_IN_9_7_0(reason)
#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...