VTK
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 "vtkVariant.h" // Set/get annotation methods require variants.
57 #include "vtkObject.h"
58 
59 class vtkAbstractArray;
60 class vtkDataArray;
62 class vtkAbstractArray;
63 class vtkStringArray;
64 
65 
66 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
67 {
68 public:
70  void PrintSelf(ostream& os, vtkIndent indent) override;
71  static vtkScalarsToColors *New();
72 
77  virtual int IsOpaque();
78 
83  virtual void Build() {}
84 
86 
89  virtual double *GetRange() VTK_SIZEHINT(2);
90  virtual void SetRange(double min, double max);
91  virtual void SetRange(const double rng[2])
92  {this->SetRange(rng[0],rng[1]);}
94 
99  virtual const unsigned char *MapValue(double v);
100 
105  virtual void GetColor(double v, double rgb[3]);
106 
111  double *GetColor(double v) VTK_SIZEHINT(3)
112  {this->GetColor(v,this->RGB); return this->RGB;}
113 
119  virtual double GetOpacity(double v);
120 
126  double GetLuminance(double x)
127  {double rgb[3]; this->GetColor(x,rgb);
128  return static_cast<double>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);}
129 
131 
137  virtual void SetAlpha(double alpha);
138  vtkGetMacro(Alpha,double);
140 
142 
159  virtual vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode,
160  int component);
161  virtual vtkUnsignedCharArray *MapScalars(vtkAbstractArray *scalars, int colorMode,
162  int component);
164 
166 
171  vtkSetMacro(VectorMode, int);
172  vtkGetMacro(VectorMode, int);
173  void SetVectorModeToMagnitude();
174  void SetVectorModeToComponent();
175  void SetVectorModeToRGBColors();
177 
178  enum VectorModes {
179  MAGNITUDE=0,
180  COMPONENT=1,
181  RGBCOLORS=2
182  };
183 
185 
189  vtkSetMacro(VectorComponent, int);
190  vtkGetMacro(VectorComponent, int);
192 
194 
201  vtkSetMacro(VectorSize, int);
202  vtkGetMacro(VectorSize, int);
204 
212  void MapVectorsThroughTable(void *input, unsigned char *output,
213  int inputDataType, int numberOfValues,
214  int inputIncrement, int outputFormat,
215  int vectorComponent, int vectorSize);
216  void MapVectorsThroughTable(void *input, unsigned char *output,
217  int inputDataType, int numberOfValues,
218  int inputIncrement, int outputFormat)
219  { this->MapVectorsThroughTable(input, output, inputDataType, numberOfValues,
220  inputIncrement, outputFormat, -1, -1); }
221 
230  void MapScalarsThroughTable(vtkDataArray *scalars,
231  unsigned char *output,
232  int outputFormat);
234  unsigned char *output)
235  {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
236  void MapScalarsThroughTable(void *input, unsigned char *output,
237  int inputDataType, int numberOfValues,
238  int inputIncrement,
239  int outputFormat)
240  {this->MapScalarsThroughTable2(input, output, inputDataType,
241  numberOfValues, inputIncrement, outputFormat);}
242 
248  virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
249  int inputDataType, int numberOfValues,
250  int inputIncrement,
251  int outputFormat);
252 
256  virtual void DeepCopy(vtkScalarsToColors *o);
257 
262  virtual int UsingLogScale()
263  { 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 
374 
376 
381  template<typename T> static
382  unsigned char ColorToUChar(T t)
383  {
384  return static_cast<unsigned char>(t);
385  }
386  template<typename T> static
387  void ColorToUChar(T t, unsigned char* dest)
388  {
389  *dest = ColorToUChar(t);
390  }
392 
393 
394 
395 protected:
397  ~vtkScalarsToColors() override;
398 
410  void MapColorsToColors(void *input, unsigned char *output,
411  int inputDataType, int numberOfValues,
412  int numberOfComponents, int vectorSize,
413  int outputFormat);
414 
420  vtkUnsignedCharArray *ConvertToRGBA(
421  vtkDataArray *colors, int numComp, int numTuples);
422 
423 
428  void MapVectorsToMagnitude(void *input, double *output,
429  int inputDataType, int numberOfValues,
430  int numberOfComponents, int vectorSize);
431 
436  virtual vtkIdType CheckForAnnotatedValue( vtkVariant value );
437 
442  virtual void UpdateAnnotatedValueMap();
443 
444  // Annotations of specific values.
447 
448  class vtkInternalAnnotatedValueMap;
449  vtkInternalAnnotatedValueMap* AnnotatedValueMap;
450 
452 
453  double Alpha;
454 
455  // How to map arrays with multiple components.
459 
460  // Obsolete, kept so subclasses will still compile
462 
463  unsigned char RGBABytes[4];
464 
465 private:
466  double RGB[3];
467  double InputRange[2];
468 
469  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
470  void operator=(const vtkScalarsToColors&) = delete;
471 };
472 
474 
479 template<> inline
480 unsigned char vtkScalarsToColors::ColorToUChar(double t)
481 {
482  return static_cast<unsigned char>(t*255 + 0.5);
483 }
484 template<> inline
485 unsigned char vtkScalarsToColors::ColorToUChar(float t)
486 {
487  return static_cast<unsigned char>(t*255 + 0.5);
488 }
490 
491 
492 #endif
vtkVariant.h
vtkX3D::alpha
Definition: vtkX3D.h:250
vtkX3D::component
Definition: vtkX3D.h:175
vtkScalarsToColors::ColorToUChar
static void ColorToUChar(T t, unsigned char *dest)
Definition: vtkScalarsToColors.h:387
vtkScalarsToColors::VectorModes
VectorModes
Definition: vtkScalarsToColors.h:178
vtkX3D::value
Definition: vtkX3D.h:220
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkScalarsToColors::IndexedLookup
vtkTypeBool IndexedLookup
Definition: vtkScalarsToColors.h:451
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:41
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:59
vtkScalarsToColors::VectorComponent
int VectorComponent
Definition: vtkScalarsToColors.h:457
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:83
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
vtkScalarsToColors::VectorMode
int VectorMode
Definition: vtkScalarsToColors.h:456
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:216
vtkScalarsToColors::ColorToUChar
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
Definition: vtkScalarsToColors.h:382
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:236
VTK_SIZEHINT
#define VTK_SIZEHINT(...)
Definition: vtkWrappingHints.h:42
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:111
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:39
vtkScalarsToColors::AnnotatedValues
vtkAbstractArray * AnnotatedValues
Definition: vtkScalarsToColors.h:445
vtkVariant
A atomic type representing the union of many types.
Definition: vtkVariant.h:71
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:262
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:66
vtkObject.h
vtkAbstractArray
Abstract superclass for all arrays.
Definition: vtkAbstractArray.h:78
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:126
VTK_RGBA
#define VTK_RGBA
Definition: vtkSystemIncludes.h:100
vtkScalarsToColors::AnnotatedValueMap
vtkInternalAnnotatedValueMap * AnnotatedValueMap
Definition: vtkScalarsToColors.h:448
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:42
vtkScalarsToColors::Alpha
double Alpha
Definition: vtkScalarsToColors.h:453
vtkScalarsToColors::UseMagnitude
int UseMagnitude
Definition: vtkScalarsToColors.h:461
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:40
vtkScalarsToColors::Annotations
vtkStringArray * Annotations
Definition: vtkScalarsToColors.h:446
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Definition: vtkScalarsToColors.h:233
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkScalarsToColors::VectorSize
int VectorSize
Definition: vtkScalarsToColors.h:458