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   void SetTableValue(vtkIdType indx, double rgba[4]);
00196 
00199   void SetTableValue(vtkIdType indx, double r, double g, double b, double a=1.0);
00200 
00203   double *GetTableValue(vtkIdType id);
00204 
00207   void GetTableValue(vtkIdType id, double rgba[4]);
00208 
00210 
00212   unsigned char *GetPointer(const vtkIdType id) {
00213     return this->Table->GetPointer(4*id); };
00215 
00220   unsigned char *WritePointer(const vtkIdType id, const int number);
00221 
00223 
00225   double *GetRange() { return this->GetTableRange(); };
00226   void SetRange(double min, double max) { this->SetTableRange(min, max); };
00227   void SetRange(double rng[2]) { this->SetRange(rng[0], rng[1]); };
00229 
00230   //BTX
00235   static void GetLogRange(const double range[2], double log_range[2]);
00236 
00238 
00239   static double ApplyLogScale(double v, const double range[2],
00240     const double log_range[2]);
00241   //ETX
00243 
00245 
00249   vtkSetClampMacro(NumberOfColors,vtkIdType,2,VTK_ID_MAX);
00250   vtkGetMacro(NumberOfColors,vtkIdType);
00252 
00254 
00257   void SetTable(vtkUnsignedCharArray *);
00258   vtkGetObjectMacro(Table,vtkUnsignedCharArray);
00260 
00262 
00263   void MapScalarsThroughTable2(void *input, unsigned char *output,
00264                                int inputDataType, int numberOfValues,
00265                                int inputIncrement, int outputIncrement);
00267 
00269   void DeepCopy(vtkScalarsToColors *lut);
00270 
00272 
00274   virtual int UsingLogScale()
00275     {
00276     return (this->GetScale() == VTK_SCALE_LOG10)? 1 : 0;
00277     }
00279 
00281   virtual vtkIdType GetNumberOfAvailableColors();
00282 
00286   virtual void GetIndexedColor(vtkIdType idx, double rgba[4]);
00287 
00288 protected:
00289   vtkLookupTable(int sze=256, int ext=256);
00290   ~vtkLookupTable();
00291 
00292   vtkIdType NumberOfColors;
00293   vtkUnsignedCharArray *Table;
00294   double TableRange[2];
00295   double HueRange[2];
00296   double SaturationRange[2];
00297   double ValueRange[2];
00298   double AlphaRange[2];
00299   double NanColor[4];
00300   int Scale;
00301   int Ramp;
00302   vtkTimeStamp InsertTime;
00303   vtkTimeStamp BuildTime;
00304   double RGBA[4]; //used during conversion process
00305   unsigned char NanColorChar[4];
00306 
00307   int OpaqueFlag;
00308   vtkTimeStamp OpaqueFlagBuildTime;
00309 
00310 private:
00311   vtkLookupTable(const vtkLookupTable&);  // Not implemented.
00312   void operator=(const vtkLookupTable&);  // Not implemented.
00313 };
00314 
00315 //----------------------------------------------------------------------------
00316 inline unsigned char *vtkLookupTable::WritePointer(const vtkIdType id,
00317                                                    const int number)
00318 {
00319   this->InsertTime.Modified();
00320   return this->Table->WritePointer(4*id,4*number);
00321 }
00322 
00323 #endif
00324 
00325 
00326