VTK
|
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 vtkAbstractArray; 00056 class vtkDataArray; 00057 class vtkUnsignedCharArray; 00058 class vtkAbstractArray; 00059 class vtkStringArray; 00060 00061 00062 class VTKCOMMONCORE_EXPORT vtkScalarsToColors : public vtkObject 00063 { 00064 public: 00065 vtkTypeMacro(vtkScalarsToColors,vtkObject); 00066 void PrintSelf(ostream& os, vtkIndent indent); 00067 static vtkScalarsToColors *New(); 00068 00071 virtual int IsOpaque(); 00072 00075 virtual void Build() {} 00076 00078 00079 virtual double *GetRange(); 00080 virtual void SetRange(double min, double max); 00081 void SetRange(double rng[2]) 00082 {this->SetRange(rng[0],rng[1]);} 00084 00087 virtual unsigned char *MapValue(double v); 00088 00091 virtual void GetColor(double v, double rgb[3]); 00092 00094 00096 double *GetColor(double v) 00097 {this->GetColor(v,this->RGB); return this->RGB;} 00099 00103 virtual double GetOpacity(double v); 00104 00106 00109 double GetLuminance(double x) 00110 {double rgb[3]; this->GetColor(x,rgb); 00111 return static_cast<double>(rgb[0]*0.30 + rgb[1]*0.59 + rgb[2]*0.11);} 00113 00115 00119 virtual void SetAlpha(double alpha); 00120 vtkGetMacro(Alpha,double); 00122 00124 00138 virtual vtkUnsignedCharArray *MapScalars(vtkDataArray *scalars, int colorMode, 00139 int component); 00140 virtual vtkUnsignedCharArray *MapScalars(vtkAbstractArray *scalars, int colorMode, 00141 int component); 00143 00145 00148 vtkSetMacro(VectorMode, int); 00149 vtkGetMacro(VectorMode, int); 00150 void SetVectorModeToMagnitude(); 00151 void SetVectorModeToComponent(); 00152 void SetVectorModeToRGBColors(); 00154 00155 //BTX 00156 enum VectorModes { 00157 MAGNITUDE=0, 00158 COMPONENT=1, 00159 RGBCOLORS=2 00160 }; 00161 //ETX 00162 00163 00165 00167 vtkSetMacro(VectorComponent, int); 00168 vtkGetMacro(VectorComponent, int); 00170 00172 00177 vtkSetMacro(VectorSize, int); 00178 vtkGetMacro(VectorSize, int); 00180 00182 00187 void MapVectorsThroughTable(void *input, unsigned char *output, 00188 int inputDataType, int numberOfValues, 00189 int inputIncrement, int outputFormat, 00190 int vectorComponent, int vectorSize); 00191 void MapVectorsThroughTable(void *input, unsigned char *output, 00192 int inputDataType, int numberOfValues, 00193 int inputIncrement, int outputFormat) 00194 { this->MapVectorsThroughTable(input, output, inputDataType, numberOfValues, 00195 inputIncrement, outputFormat, -1, -1); } 00197 00199 00205 void MapScalarsThroughTable(vtkDataArray *scalars, 00206 unsigned char *output, 00207 int outputFormat); 00208 void MapScalarsThroughTable(vtkDataArray *scalars, 00209 unsigned char *output) 00210 {this->MapScalarsThroughTable(scalars,output,VTK_RGBA);} 00211 void MapScalarsThroughTable(void *input, unsigned char *output, 00212 int inputDataType, int numberOfValues, 00213 int inputIncrement, 00214 int outputFormat) 00215 {this->MapScalarsThroughTable2(input, output, inputDataType, 00216 numberOfValues, inputIncrement, outputFormat);} 00218 00220 00223 virtual void MapScalarsThroughTable2(void *input, unsigned char *output, 00224 int inputDataType, int numberOfValues, 00225 int inputIncrement, 00226 int outputFormat); 00228 00230 virtual void DeepCopy(vtkScalarsToColors *o); 00231 00233 00235 virtual int UsingLogScale() 00236 { return 0; } 00238 00240 virtual vtkIdType GetNumberOfAvailableColors(); 00241 00243 00252 virtual void SetAnnotations( vtkAbstractArray* values, vtkStringArray* annotations ); 00253 vtkGetObjectMacro(AnnotatedValues,vtkAbstractArray); 00254 vtkGetObjectMacro(Annotations,vtkStringArray); 00256 00260 virtual vtkIdType SetAnnotation(vtkVariant value, vtkStdString annotation); 00261 00264 virtual vtkIdType SetAnnotation(vtkStdString value, vtkStdString annotation); 00265 00268 vtkIdType GetNumberOfAnnotatedValues(); 00269 00272 vtkVariant GetAnnotatedValue(vtkIdType idx); 00273 00276 vtkStdString GetAnnotation(vtkIdType idx); 00277 00280 virtual void GetAnnotationColor(const vtkVariant& val, double rgba[4]); 00281 00284 vtkIdType GetAnnotatedValueIndex( vtkVariant val ); 00285 00288 vtkIdType GetAnnotatedValueIndexInternal(vtkVariant& val); 00289 00300 virtual void GetIndexedColor(vtkIdType i, double rgba[4]); 00301 00305 virtual bool RemoveAnnotation(vtkVariant value); 00306 00308 virtual void ResetAnnotations(); 00309 00311 00316 vtkSetMacro(IndexedLookup,int); 00317 vtkGetMacro(IndexedLookup,int); 00318 vtkBooleanMacro(IndexedLookup,int); 00320 00321 00323 00326 template<typename T> static 00327 unsigned char ColorToUChar(T t) 00328 { 00329 return t; 00330 } 00331 template<typename T> static 00332 void ColorToUChar(T t, unsigned char* dest) 00333 { 00334 *dest = ColorToUChar(t); 00335 } 00337 00338 00339 00340 protected: 00341 vtkScalarsToColors(); 00342 ~vtkScalarsToColors(); 00343 00345 00354 void MapColorsToColors(void *input, unsigned char *output, 00355 int inputDataType, int numberOfValues, 00356 int numberOfComponents, int vectorSize, 00357 int outputFormat); 00359 00361 00364 vtkUnsignedCharArray *ConvertToRGBA( 00365 vtkDataArray *colors, int numComp, int numTuples); 00367 00368 00370 00372 void MapVectorsToMagnitude(void *input, double *output, 00373 int inputDataType, int numberOfValues, 00374 int numberOfComponents, int vectorSize); 00376 00379 virtual vtkIdType CheckForAnnotatedValue( vtkVariant value ); 00380 00383 virtual void UpdateAnnotatedValueMap(); 00384 00385 // Annotations of specific values. 00386 vtkAbstractArray* AnnotatedValues; 00387 vtkStringArray* Annotations; 00388 00389 class vtkInternalAnnotatedValueMap; 00390 vtkInternalAnnotatedValueMap* AnnotatedValueMap; 00391 00392 int IndexedLookup; 00393 00394 double Alpha; 00395 00396 // How to map arrays with multiple components. 00397 int VectorMode; 00398 int VectorComponent; 00399 int VectorSize; 00400 00401 // Obsolete, kept so subclasses will still compile 00402 int UseMagnitude; 00403 00404 unsigned char RGBABytes[4]; 00405 00406 private: 00407 double RGB[3]; 00408 double InputRange[2]; 00409 00410 vtkScalarsToColors(const vtkScalarsToColors&); // Not implemented. 00411 void operator=(const vtkScalarsToColors&); // Not implemented. 00412 }; 00413 00415 00418 template<> inline 00419 unsigned char vtkScalarsToColors::ColorToUChar(double t) 00420 { 00421 return static_cast<unsigned char>(t*255 + 0.5); 00422 } 00423 template<> inline 00424 unsigned char vtkScalarsToColors::ColorToUChar(float t) 00425 { 00426 return static_cast<unsigned char>(t*255 + 0.5); 00427 } 00429 00430 00431 #endif