VTK
dox/Common/Core/vtkLookupTable.h
Go to the documentation of this file.
00001  /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkLookupTable.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 =========================================================================*/
00050 #ifndef __vtkLookupTable_h
00051 #define __vtkLookupTable_h
00052 
00053 #include "vtkCommonCoreModule.h" // For export macro
00054 #include "vtkScalarsToColors.h"
00055 
00056 #include "vtkUnsignedCharArray.h" // Needed for inline method
00057 
00058 #define VTK_RAMP_LINEAR 0
00059 #define VTK_RAMP_SCURVE 1
00060 #define VTK_RAMP_SQRT 2
00061 #define VTK_SCALE_LINEAR 0
00062 #define VTK_SCALE_LOG10 1
00063 
00064 class VTKCOMMONCORE_EXPORT vtkLookupTable : public vtkScalarsToColors
00065 {
00066 public:
00069   static vtkLookupTable *New();
00070 
00071   vtkTypeMacro(vtkLookupTable,vtkScalarsToColors);
00072   void PrintSelf(ostream& os, vtkIndent indent);
00073 
00076   virtual int IsOpaque();
00077 
00079   int Allocate(int sz=256, int ext=256);
00080 
00083   virtual void Build();
00084 
00090   virtual void ForceBuild();
00091 
00093 
00100   vtkSetMacro(Ramp,int);
00101   void SetRampToLinear() { this->SetRamp(VTK_RAMP_LINEAR); };
00102   void SetRampToSCurve() { this->SetRamp(VTK_RAMP_SCURVE); };
00103   void SetRampToSQRT() { this->SetRamp(VTK_RAMP_SQRT); };
00104   vtkGetMacro(Ramp,int);
00106 
00108 
00111   void SetScale(int scale);
00112   void SetScaleToLinear() { this->SetScale(VTK_SCALE_LINEAR); };
00113   void SetScaleToLog10() { this->SetScale(VTK_SCALE_LOG10); };
00114   vtkGetMacro(Scale,int);
00116 
00118 
00123   void SetTableRange(double r[2]);
00124   virtual void SetTableRange(double min, double max);
00125   vtkGetVectorMacro(TableRange,double,2);
00127 
00129 
00131   vtkSetVector2Macro(HueRange,double);
00132   vtkGetVector2Macro(HueRange,double);
00134 
00136 
00138   vtkSetVector2Macro(SaturationRange,double);
00139   vtkGetVector2Macro(SaturationRange,double);
00141 
00143 
00145   vtkSetVector2Macro(ValueRange,double);
00146   vtkGetVector2Macro(ValueRange,double);
00148 
00150 
00152   vtkSetVector2Macro(AlphaRange,double);
00153   vtkGetVector2Macro(AlphaRange,double);
00155 
00157 
00159   vtkSetVector4Macro(NanColor, double);
00160   vtkGetVector4Macro(NanColor, double);
00162 
00165   unsigned char* GetNanColorAsUnsignedChars();
00166 
00168   unsigned char* MapValue(double v);
00169 
00172   void GetColor(double x, double rgb[3]);
00173 
00176   double GetOpacity(double v);
00177 
00183   virtual vtkIdType GetIndex(double v);
00184 
00186 
00187   void SetNumberOfTableValues(vtkIdType number);
00188   vtkIdType GetNumberOfTableValues() { return this->NumberOfColors; };
00190 
00195   virtual void SetTableValue(vtkIdType indx, double rgba[4]);
00196 
00198 
00200   virtual void SetTableValue(vtkIdType indx,
00201                               double r, double g, double b, double a=1.0);
00203 
00206   double *GetTableValue(vtkIdType id);
00207 
00210   void GetTableValue(vtkIdType id, double rgba[4]);
00211 
00213 
00215   unsigned char *GetPointer(const vtkIdType id) {
00216     return this->Table->GetPointer(4*id); };
00218 
00223   unsigned char *WritePointer(const vtkIdType id, const int number);
00224 
00226 
00228   double *GetRange() { return this->GetTableRange(); };
00229   void SetRange(double min, double max) { this->SetTableRange(min, max); };
00230   void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
00232 
00233   //BTX
00238   static void GetLogRange(const double range[2], double log_range[2]);
00239 
00241 
00242   static double ApplyLogScale(double v, const double range[2],
00243     const double log_range[2]);
00244   //ETX
00246 
00248 
00252   vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
00253   vtkGetMacro(NumberOfColors,vtkIdType);
00255 
00257 
00260   void SetTable(vtkUnsignedCharArray *);
00261   vtkGetObjectMacro(Table,vtkUnsignedCharArray);
00263 
00265 
00266   void MapScalarsThroughTable2(void *input, unsigned char *output,
00267                                int inputDataType, int numberOfValues,
00268                                int inputIncrement, int outputIncrement);
00270 
00272   void DeepCopy(vtkScalarsToColors *lut);
00273 
00275 
00277   virtual int UsingLogScale()
00278     {
00279     return (this->GetScale() == VTK_SCALE_LOG10)? 1 : 0;
00280     }
00282 
00284   virtual vtkIdType GetNumberOfAvailableColors();
00285 
00289   virtual void GetIndexedColor(vtkIdType idx, double rgba[4]);
00290 
00291 protected:
00292   vtkLookupTable(int sze=256, int ext=256);
00293   ~vtkLookupTable();
00294 
00295   vtkIdType NumberOfColors;
00296   vtkUnsignedCharArray *Table;
00297   double TableRange[2];
00298   double HueRange[2];
00299   double SaturationRange[2];
00300   double ValueRange[2];
00301   double AlphaRange[2];
00302   double NanColor[4];
00303   int Scale;
00304   int Ramp;
00305   vtkTimeStamp InsertTime;
00306   vtkTimeStamp BuildTime;
00307   double RGBA[4]; //used during conversion process
00308   unsigned char NanColorChar[4];
00309 
00310   int OpaqueFlag;
00311   vtkTimeStamp OpaqueFlagBuildTime;
00312 
00313 private:
00314   vtkLookupTable(const vtkLookupTable&);  // Not implemented.
00315   void operator=(const vtkLookupTable&);  // Not implemented.
00316 };
00317 
00318 //----------------------------------------------------------------------------
00319 inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
00320                                                    const int number)
00321 {
00322   this->InsertTime.Modified();
00323   return this->Table->WritePointer(4*id,4*number);
00324 }
00325 
00326 #endif
00327 
00328 
00329