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 =========================================================================*/
46 #ifndef vtkScalarsToColors_h
47 #define vtkScalarsToColors_h
48 
49 #include "vtkCommonCoreModule.h" // For export macro
50 #include "vtkVariant.h" // Set/get annotation methods require variants.
51 #include "vtkObject.h"
52 
53 class vtkAbstractArray;
54 class vtkDataArray;
56 class vtkAbstractArray;
57 class vtkStringArray;
58 
59 
60 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
61 {
62 public:
64  void PrintSelf(ostream& os, vtkIndent indent) override;
65  static vtkScalarsToColors *New();
66 
71  virtual int IsOpaque();
72 
77  virtual void Build() {}
78 
80 
83  virtual double *GetRange() VTK_SIZEHINT(2);
84  virtual void SetRange(double min, double max);
85  virtual void SetRange(const double rng[2])
86  {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  {this->GetColor(v,this->RGB); return this->RGB;}
107 
113  virtual double GetOpacity(double v);
114 
120  double GetLuminance(double x)
121  {double rgb[3]; this->GetColor(x,rgb);
122  return static_cast<double>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);}
123 
125 
131  virtual void SetAlpha(double alpha);
132  vtkGetMacro(Alpha,double);
134 
136 
153  virtual vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode,
154  int component);
155  virtual vtkUnsignedCharArray *MapScalars(vtkAbstractArray *scalars, int colorMode,
156  int component);
158 
160 
165  vtkSetMacro(VectorMode, int);
166  vtkGetMacro(VectorMode, int);
167  void SetVectorModeToMagnitude();
168  void SetVectorModeToComponent();
169  void SetVectorModeToRGBColors();
171 
172  enum VectorModes {
173  MAGNITUDE=0,
174  COMPONENT=1,
175  RGBCOLORS=2
176  };
177 
179 
183  vtkSetMacro(VectorComponent, int);
184  vtkGetMacro(VectorComponent, int);
186 
188 
195  vtkSetMacro(VectorSize, int);
196  vtkGetMacro(VectorSize, int);
198 
206  void MapVectorsThroughTable(void *input, unsigned char *output,
207  int inputDataType, int numberOfValues,
208  int inputIncrement, int outputFormat,
209  int vectorComponent, int vectorSize);
210  void MapVectorsThroughTable(void *input, unsigned char *output,
211  int inputDataType, int numberOfValues,
212  int inputIncrement, int outputFormat)
213  { this->MapVectorsThroughTable(input, output, inputDataType, numberOfValues,
214  inputIncrement, outputFormat, -1, -1); }
215 
224  void MapScalarsThroughTable(vtkDataArray *scalars,
225  unsigned char *output,
226  int outputFormat);
228  unsigned char *output)
229  {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
230  void MapScalarsThroughTable(void *input, unsigned char *output,
231  int inputDataType, int numberOfValues,
232  int inputIncrement,
233  int outputFormat)
234  {this->MapScalarsThroughTable2(input, output, inputDataType,
235  numberOfValues, inputIncrement, outputFormat);}
236 
242  virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
243  int inputDataType, int numberOfValues,
244  int inputIncrement,
245  int outputFormat);
246 
250  virtual void DeepCopy(vtkScalarsToColors *o);
251 
256  virtual int UsingLogScale()
257  { return 0; }
258 
262  virtual vtkIdType GetNumberOfAvailableColors();
263 
265 
278  virtual void SetAnnotations( vtkAbstractArray* values, vtkStringArray* annotations );
279  vtkGetObjectMacro(AnnotatedValues,vtkAbstractArray);
280  vtkGetObjectMacro(Annotations,vtkStringArray);
282 
287  virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
288 
293  virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
294 
298  vtkIdType GetNumberOfAnnotatedValues();
299 
303  vtkVariant GetAnnotatedValue(vtkIdType idx);
304 
308  vtkStdString GetAnnotation(vtkIdType idx);
309 
313  virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
314 
318  vtkIdType GetAnnotatedValueIndex( vtkVariant val );
319 
325  vtkIdType GetAnnotatedValueIndexInternal(const vtkVariant& val);
326 
339  virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
340 
347  virtual bool RemoveAnnotation(vtkVariant value);
348 
352  virtual void ResetAnnotations();
353 
355 
363  vtkSetMacro(IndexedLookup,vtkTypeBool);
364  vtkGetMacro(IndexedLookup,vtkTypeBool);
365  vtkBooleanMacro(IndexedLookup,vtkTypeBool);
367 
368 
370 
375  template<typename T> static
376  unsigned char ColorToUChar(T t)
377  {
378  return static_cast<unsigned char>(t);
379  }
380  template<typename T> static
381  void ColorToUChar(T t, unsigned char* dest)
382  {
383  *dest = ColorToUChar(t);
384  }
386 
387 
388 
389 protected:
391  ~vtkScalarsToColors() override;
392 
404  void MapColorsToColors(void *input, unsigned char *output,
405  int inputDataType, int numberOfValues,
406  int numberOfComponents, int vectorSize,
407  int outputFormat);
408 
414  vtkUnsignedCharArray *ConvertToRGBA(
415  vtkDataArray *colors, int numComp, int numTuples);
416 
417 
422  void MapVectorsToMagnitude(void *input, double *output,
423  int inputDataType, int numberOfValues,
424  int numberOfComponents, int vectorSize);
425 
430  virtual vtkIdType CheckForAnnotatedValue( vtkVariant value );
431 
436  virtual void UpdateAnnotatedValueMap();
437 
438  // Annotations of specific values.
441 
442  class vtkInternalAnnotatedValueMap;
443  vtkInternalAnnotatedValueMap* AnnotatedValueMap;
444 
446 
447  double Alpha;
448 
449  // How to map arrays with multiple components.
453 
454  // Obsolete, kept so subclasses will still compile
456 
457  unsigned char RGBABytes[4];
458 
459 private:
460  double RGB[3];
461  double InputRange[2];
462 
463  vtkScalarsToColors(const vtkScalarsToColors&) = delete;
464  void operator=(const vtkScalarsToColors&) = delete;
465 };
466 
468 
473 template<> inline
474 unsigned char vtkScalarsToColors::ColorToUChar(double t)
475 {
476  return static_cast<unsigned char>(t*255 + 0.5);
477 }
478 template<> inline
479 unsigned char vtkScalarsToColors::ColorToUChar(float t)
480 {
481  return static_cast<unsigned char>(t*255 + 0.5);
482 }
484 
485 
486 #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:381
vtkScalarsToColors::VectorModes
VectorModes
Definition: vtkScalarsToColors.h:172
vtkX3D::value
Definition: vtkX3D.h:220
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkScalarsToColors::IndexedLookup
vtkTypeBool IndexedLookup
Definition: vtkScalarsToColors.h:445
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:53
vtkScalarsToColors::VectorComponent
int VectorComponent
Definition: vtkScalarsToColors.h:451
vtkScalarsToColors::Build
virtual void Build()
Perform any processing required (if any) before processing scalars.
Definition: vtkScalarsToColors.h:77
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkScalarsToColors::VectorMode
int VectorMode
Definition: vtkScalarsToColors.h:450
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:210
vtkScalarsToColors::ColorToUChar
static unsigned char ColorToUChar(T t)
Converts a color from numeric type T to uchar.
Definition: vtkScalarsToColors.h:376
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(void *input, unsigned char *output, int inputDataType, int numberOfValues, int inputIncrement, int outputFormat)
Definition: vtkScalarsToColors.h:230
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:105
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkScalarsToColors::AnnotatedValues
vtkAbstractArray * AnnotatedValues
Definition: vtkScalarsToColors.h:439
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:256
vtkScalarsToColors
Superclass for mapping scalar values to colors.
Definition: vtkScalarsToColors.h:60
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:120
VTK_RGBA
#define VTK_RGBA
Definition: vtkSystemIncludes.h:100
vtkScalarsToColors::AnnotatedValueMap
vtkInternalAnnotatedValueMap * AnnotatedValueMap
Definition: vtkScalarsToColors.h:442
vtkStringArray
a vtkAbstractArray subclass for strings
Definition: vtkStringArray.h:36
vtkScalarsToColors::Alpha
double Alpha
Definition: vtkScalarsToColors.h:447
vtkScalarsToColors::UseMagnitude
int UseMagnitude
Definition: vtkScalarsToColors.h:455
vtkStdString
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:34
vtkScalarsToColors::Annotations
vtkStringArray * Annotations
Definition: vtkScalarsToColors.h:440
vtkScalarsToColors::MapScalarsThroughTable
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Definition: vtkScalarsToColors.h:227
vtkTypeBool
int vtkTypeBool
Definition: vtkABI.h:69
vtkScalarsToColors::VectorSize
int VectorSize
Definition: vtkScalarsToColors.h:452