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) VTK_OVERRIDE;
65  static vtkScalarsToColors *New();
66 
71  virtual int IsOpaque();
72 
77  virtual void Build() {}
78 
80 
83  virtual double *GetRange();
84  virtual void SetRange(double min, double max);
85  void SetRange(double rng[2])
86  {this->SetRange(rng[0],rng[1]);}
88 
93  virtual unsigned char *MapValue(double v);
94 
99  virtual void GetColor(double v, double rgb[3]);
100 
105  double *GetColor(double v)
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(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,int);
364  vtkGetMacro(IndexedLookup,int);
365  vtkBooleanMacro(IndexedLookup,int);
367 
368 
370 
375  template<typename T> static
376  unsigned char ColorToUChar(T t)
377  {
378  return 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() VTK_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.
439  vtkAbstractArray* AnnotatedValues;
440  vtkStringArray* Annotations;
441 
442  class vtkInternalAnnotatedValueMap;
443  vtkInternalAnnotatedValueMap* AnnotatedValueMap;
444 
445  int IndexedLookup;
446 
447  double Alpha;
448 
449  // How to map arrays with multiple components.
450  int VectorMode;
451  int VectorComponent;
452  int VectorSize;
453 
454  // Obsolete, kept so subclasses will still compile
455  int UseMagnitude;
456 
457  unsigned char RGBABytes[4];
458 
459 private:
460  double RGB[3];
461  double InputRange[2];
462 
463  vtkScalarsToColors(const vtkScalarsToColors&) VTK_DELETE_FUNCTION;
464  void operator=(const vtkScalarsToColors&) VTK_DELETE_FUNCTION;
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
void MapScalarsThroughTable(vtkDataArray *scalars, unsigned char *output)
Wrapper around std::string to keep symbols short.
Definition: vtkStdString.h:41
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:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
Abstract superclass for all arrays.
void SetRange(double rng[2])
Sets/Gets the range of scalars that will be mapped.
a vtkAbstractArray subclass for strings
int vtkIdType
Definition: vtkType.h:345
A atomic type representing the union of many types.
Definition: vtkVariant.h:69
Superclass for mapping scalar values to colors.
a simple class to control print indentation
Definition: vtkIndent.h:33
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
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)
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
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 ...
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.
vtkBooleanMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#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.