VTK
dox/Common/Core/vtkScalarsToColors.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkScalarsToColors.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00048 #ifndef __vtkScalarsToColors_h
00049 #define __vtkScalarsToColors_h
00050 
00051 #include "vtkCommonCoreModule.h" // For export macro
00052 #include "vtkVariant.h" // Set/get annotation methods require variants.
00053 #include "vtkObject.h"
00054 
00055 class vtkDataArray;
00056 class vtkUnsignedCharArray;
00057 class vtkAbstractArray;
00058 class vtkStringArray;
00059 
00060 
00061 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject
00062 {
00063 public:
00064   vtkTypeMacro(vtkScalarsToColors,vtkObject);
00065   void PrintSelf(ostream& os, vtkIndent indent);
00066   static vtkScalarsToColors *New();
00067 
00070   virtual int IsOpaque();
00071 
00073   virtual void Build() {}
00074 
00076 
00077   virtual double *GetRange();
00078   virtual void SetRange(double min, double max);
00079   void SetRange(double rng[2])
00080     {this->SetRange(rng[0],rng[1]);}
00082 
00085   virtual unsigned char *MapValue(double v);
00086 
00089   virtual void GetColor(double v, double rgb[3]);
00090 
00092 
00094   double *GetColor(double v)
00095     {this->GetColor(v,this->RGB); return this->RGB;}
00097 
00100   virtual double GetOpacity(double v);
00101 
00103 
00106   double GetLuminance(double x)
00107     {double rgb[3]; this->GetColor(x,rgb);
00108     return static_cast<double>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);}
00110 
00112 
00116   virtual void SetAlpha(double alpha);
00117   vtkGetMacro(Alpha,double);
00119 
00121 
00130   virtual vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode,
00131                                    int component);
00133 
00135 
00138   vtkSetMacro(VectorMode, int);
00139   vtkGetMacro(VectorMode, int);
00140   void SetVectorModeToMagnitude();
00141   void SetVectorModeToComponent();
00142   void SetVectorModeToRGBColors();
00144 
00145 //BTX
00146   enum VectorModes {
00147     MAGNITUDE=0,
00148     COMPONENT=1,
00149     RGBCOLORS=2
00150   };
00151 //ETX
00152 
00153 
00155 
00157   vtkSetMacro(VectorComponent, int);
00158   vtkGetMacro(VectorComponent, int);
00160 
00162 
00167   vtkSetMacro(VectorSize, int);
00168   vtkGetMacro(VectorSize, int);
00170 
00172 
00177   void MapVectorsThroughTable(void *input, unsigned char *output,
00178                               int inputDataType, int numberOfValues,
00179                               int inputIncrement, int outputFormat,
00180                               int vectorComponent, int vectorSize);
00181   void MapVectorsThroughTable(void *input, unsigned char *output,
00182                               int inputDataType, int numberOfValues,
00183                               int inputIncrement, int outputFormat)
00184     { this->MapVectorsThroughTable(input, output, inputDataType, numberOfValues,
00185                                    inputIncrement, outputFormat, -1, -1); }
00187 
00189 
00195   void MapScalarsThroughTable(vtkDataArray *scalars,
00196                               unsigned char *output,
00197                               int outputFormat);
00198   void MapScalarsThroughTable(vtkDataArray *scalars,
00199                               unsigned char *output)
00200     {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);}
00201   void MapScalarsThroughTable(void *input, unsigned char *output,
00202                               int inputDataType, int numberOfValues,
00203                               int inputIncrement,
00204                               int outputFormat)
00205     {this->MapScalarsThroughTable2(input, output, inputDataType,
00206        numberOfValues, inputIncrement, outputFormat);}
00208 
00210 
00213   virtual void MapScalarsThroughTable2(void *input, unsigned char *output,
00214                                        int inputDataType, int numberOfValues,
00215                                        int inputIncrement,
00216                                        int outputFormat);
00218 
00220 
00223   virtual vtkUnsignedCharArray *ConvertUnsignedCharToRGBA(
00224     vtkUnsignedCharArray *colors, int numComp, int numTuples);
00226 
00228   virtual void DeepCopy(vtkScalarsToColors *o);
00229 
00231 
00233   virtual int UsingLogScale()
00234     { return 0; }
00236 
00238   virtual vtkIdType GetNumberOfAvailableColors();
00239 
00241 
00250   virtual void SetAnnotations( vtkAbstractArray* values, vtkStringArray* annotations );
00251   vtkGetObjectMacro(AnnotatedValues,vtkAbstractArray);
00252   vtkGetObjectMacro(Annotations,vtkStringArray);
00254 
00259   virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation);
00260 
00262   virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation);
00263 
00265   vtkIdType GetNumberOfAnnotatedValues();
00266 
00268   vtkVariant GetAnnotatedValue(vtkIdType idx);
00269 
00271   vtkStdString GetAnnotation(vtkIdType idx);
00272 
00274   virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]);
00275 
00277   vtkIdType GetAnnotatedValueIndex( vtkVariant val );
00278 
00280   vtkIdType GetAnnotatedValueIndexInternal(vtkVariant& val);
00281 
00293   virtual void GetIndexedColor(vtkIdType i, double rgba[4]);
00294 
00300   virtual bool RemoveAnnotation(vtkVariant value);
00301 
00303   virtual void ResetAnnotations();
00304 
00306 
00311   vtkSetMacro(IndexedLookup,int);
00312   vtkGetMacro(IndexedLookup,int);
00313   vtkBooleanMacro(IndexedLookup,int);
00315 
00316 protected:
00317   vtkScalarsToColors();
00318   ~vtkScalarsToColors();
00319 
00321 
00330   void MapColorsToColors(void *input, unsigned char *output,
00331                          int inputDataType, int numberOfValues,
00332                          int numberOfComponents, int vectorSize,
00333                          int outputFormat);
00335 
00337 
00339   void MapVectorsToMagnitude(void *input, double *output,
00340                              int inputDataType, int numberOfValues,
00341                              int numberOfComponents, int vectorSize);
00343 
00345   virtual vtkIdType CheckForAnnotatedValue( vtkVariant value );
00347   virtual void UpdateAnnotatedValueMap();
00348 
00349   // Annotations of specific values.
00350   class vtkInternalAnnotatedValueMap;
00351   vtkAbstractArray* AnnotatedValues;
00352   vtkStringArray* Annotations;
00353   vtkInternalAnnotatedValueMap* AnnotatedValueMap;
00354   int IndexedLookup;
00355 
00356   double Alpha;
00357 
00358   // How to map arrays with multiple components.
00359   int VectorMode;
00360   int VectorComponent;
00361   int VectorSize;
00362 
00363   // Obsolete, kept so subclasses will still compile
00364   int UseMagnitude;
00365 
00366 private:
00367   double RGB[3];
00368   unsigned char RGBABytes[4];
00369   double InputRange[2];
00370 
00371   vtkScalarsToColors(const vtkScalarsToColors&);  // Not implemented.
00372   void operator=(const vtkScalarsToColors&);  // Not implemented.
00373 };
00374 
00375 #endif
00376 
00377 
00378