VTK  9.0.1
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 =========================================================================*/
46 #ifndef vtkScalarsToColors_h
47 #define vtkScalarsToColors_h
48 
49 #include "vtkCommonCoreModule.h" // For export macro
50 #include "vtkObject.h"
51 #include "vtkVariant.h" // Set/get annotation methods require variants.
52 
53 class vtkAbstractArray;
54 class vtkDataArray;
56 class vtkAbstractArray;
57 class vtkStringArray;
58 
59 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
60 {
61 public:
62  vtkTypeMacro(vtkScalarsToColors, vtkObject);
63  void PrintSelf(ostream& os, vtkIndent indent) override;
64  static vtkScalarsToColors* New();
65 
67 
72  virtual int IsOpaque();
73  virtual int IsOpaque(vtkAbstractArray* scalars, int colorMode, int component);
75 
80  virtual void Build() {}
81 
83 
86  virtual double* GetRange() VTK_SIZEHINT(2);
87  virtual void SetRange(double min, double max);
88  virtual void SetRange(const double rng[2]) { this->SetRange(rng[0], rng[1]); }
90 
95  virtual const unsigned char* MapValue(double v);
96 
101  virtual void GetColor(double v, double rgb[3]);
102 
107  double* GetColor(double v) VTK_SIZEHINT(3)
108  {
109  this->GetColor(v, this->RGB);
110  return this->RGB;
111  }
112 
118  virtual double GetOpacity(double v);
119 
125  double GetLuminance(double x)
126  {
127  double rgb[3];
128  this->GetColor(x, rgb);
129  return static_cast<double>(rgb[0] * 0.30 + rgb[1] * 0.59 + rgb[2] * 0.11);
130  }
131 
133 
139  virtual void SetAlpha(double alpha);
140  vtkGetMacro(Alpha, double);
142 
144 
163  virtual vtkUnsignedCharArray* MapScalars(
164  vtkDataArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
165  virtual vtkUnsignedCharArray* MapScalars(
166  vtkAbstractArray* scalars, int colorMode, int component, int outputFormat = VTK_RGBA);
168 
170 
175  vtkSetMacro(VectorMode, int);
176  vtkGetMacro(VectorMode, int);
177  void SetVectorModeToMagnitude();
178  void SetVectorModeToComponent();
179  void SetVectorModeToRGBColors();
181 
183  {
184  MAGNITUDE = 0,
185  COMPONENT = 1,
186  RGBCOLORS = 2
187  };
188 
190 
194  vtkSetMacro(VectorComponent, int);
195  vtkGetMacro(VectorComponent, int);
197 
199 
206  vtkSetMacro(VectorSize, int);
207  vtkGetMacro(VectorSize, int);
209 
217  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
218  int numberOfValues, int inputIncrement, int outputFormat, int vectorComponent, int vectorSize);
219  void MapVectorsThroughTable(void* input, unsigned char* output, int inputDataType,
220  int numberOfValues, int inputIncrement, int outputFormat)
221  {
222  this->MapVectorsThroughTable(
223  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat, -1, -1);
224  }
225 
234  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output, int outputFormat);
235  void MapScalarsThroughTable(vtkDataArray* scalars, unsigned char* output)
236  {
237  this->MapScalarsThroughTable(scalars, output, VTK_RGBA);
238  }
239  void MapScalarsThroughTable(void* input, unsigned char* output, int inputDataType,
240  int numberOfValues, int inputIncrement, int outputFormat)
241  {
242  this->MapScalarsThroughTable2(
243  input, output, inputDataType, numberOfValues, inputIncrement, outputFormat);
244  }
245 
251  virtual void MapScalarsThroughTable2(void* input, unsigned char* output, int inputDataType,
252  int numberOfValues, int inputIncrement, int outputFormat);
253 
257  virtual void DeepCopy(vtkScalarsToColors* o);
258 
263  virtual int UsingLogScale() { return 0; }
264 
268  virtual vtkIdType GetNumberOfAvailableColors();
269 
271 
284  virtual void SetAnnotations(vtkAbstractArray* values, vtkStringArray* annotations);
285  vtkGetObjectMacro(AnnotatedValues, vtkAbstractArray);
286  vtkGetObjectMacro(Annotations, vtkStringArray);
288 
293  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
294 
299  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
300 
304  vtkIdType GetNumberOfAnnotatedValues();
305 
309  vtkVariant GetAnnotatedValue(vtkIdType idx);
310 
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  vtkUnsignedCharArray* ConvertToRGBA(vtkDataArray* colors, int numComp, int numTuples);
416 
421  void MapVectorsToMagnitude(void* input, double* output, int inputDataType, int numberOfValues,
422  int numberOfComponents, int vectorSize);
423 
428  virtual vtkIdType CheckForAnnotatedValue(vtkVariant value);
429 
434  virtual void UpdateAnnotatedValueMap();
435 
436  // Annotations of specific values.
439 
440  class vtkInternalAnnotatedValueMap;
441  vtkInternalAnnotatedValueMap* AnnotatedValueMap;
442 
444 
445  double Alpha;
446 
447  // How to map arrays with multiple components.
451 
452  // Obsolete, kept so subclasses will still compile
454 
455  unsigned char RGBABytes[4];
456 
457 private:
458  double RGB[3];
459  double InputRange[2];
460 
461  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
462  void operator=(const vtkScalarsToColors&) = delete;
463 };
464 
466 
471 template <>
472 inline unsigned char vtkScalarsToColors::ColorToUChar(double t)
473 {
474  return static_cast<unsigned char>(t * 255 + 0.5);
475 }
476 template <>
477 inline unsigned char vtkScalarsToColors::ColorToUChar(float t)
478 {
479  return static_cast<unsigned char>(t * 255 + 0.5);
480 }
482 
483 #endif
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)
Definition: vtkScalarsToColors.h:386
vtkScalarsToColors::VectorModes
VectorModes
Definition: vtkScalarsToColors.h:182
vtkX3D::value
@ value
Definition: vtkX3D.h:226
vtkIdType
int vtkIdType
Definition: vtkType.h:338
vtkScalarsToColors::IndexedLookup
vtkTypeBool IndexedLookup
Definition: vtkScalarsToColors.h:443
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:62
vtkScalarsToColors::VectorComponent
int VectorComponent
Definition: vtkScalarsToColors.h:449
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:80
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:49
vtkScalarsToColors::VectorMode
int VectorMode
Definition: vtkScalarsToColors.h:448
max
#define max(a, b)
Definition: vtkX3DExporterFIWriterHelper.h:31
vtkScalarsToColors::MapVectorsThroughTable
void MapVectorsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:219
vtkScalarsToColors::ColorToUChar
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
Definition: vtkScalarsToColors.h:381
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:239
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:45
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:107
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkScalarsToColors::AnnotatedValues
vtkAbstractArray * AnnotatedValues
Definition: vtkScalarsToColors.h:437
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:65
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkScalarsToColors::UsingLogScale
virtual int UsingLogScale()
This should return 1 is the subclass is using log scale for mapping scalars to colors.
Definition: vtkScalarsToColors.h:263
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:59
vtkObject.h
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:75
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:125
VTK_RGBA
#define VTK_RGBA
Definition: vtkSystemIncludes.h:87
vtkScalarsToColors::AnnotatedValueMap
vtkInternalAnnotatedValueMap * AnnotatedValueMap
Definition: vtkScalarsToColors.h:440
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:36
vtkScalarsToColors::Alpha
double Alpha
Definition: vtkScalarsToColors.h:445
vtkScalarsToColors::UseMagnitude
int UseMagnitude
Definition: vtkScalarsToColors.h:453
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkScalarsToColors::Annotations
vtkStringArray * Annotations
Definition: vtkScalarsToColors.h:438
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Definition: vtkScalarsToColors.h:235
vtkScalarsToColors::SetRange
virtual void SetRange(const double rng[2])
Definition: vtkScalarsToColors.h:88
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkScalarsToColors::VectorSize
int VectorSize
Definition: vtkScalarsToColors.h:450