Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

common/vtkScalars.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkScalars.h,v $
00005   Language:  C++
00006 
00007 
00008 Copyright (c) 1993-2001 Ken Martin, Will Schroeder, Bill Lorensen 
00009 All rights reserved.
00010 
00011 Redistribution and use in source and binary forms, with or without
00012 modification, are permitted provided that the following conditions are met:
00013 
00014  * Redistributions of source code must retain the above copyright notice,
00015    this list of conditions and the following disclaimer.
00016 
00017  * Redistributions in binary form must reproduce the above copyright notice,
00018    this list of conditions and the following disclaimer in the documentation
00019    and/or other materials provided with the distribution.
00020 
00021  * Neither name of Ken Martin, Will Schroeder, or Bill Lorensen nor the names
00022    of any contributors may be used to endorse or promote products derived
00023    from this software without specific prior written permission.
00024 
00025  * Modified source versions must be plainly marked as such, and must not be
00026    misrepresented as being the original software.
00027 
00028 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00029 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00030 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00031 ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
00032 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00033 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00034 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00035 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00036 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00037 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00038 
00039 =========================================================================*/
00069 #ifndef __vtkScalars_h
00070 #define __vtkScalars_h
00071 
00072 #include "vtkAttributeData.h"
00073 
00074 #define VTK_COLOR_MODE_DEFAULT 0
00075 #define VTK_COLOR_MODE_MAP_SCALARS 1
00076 #define VTK_COLOR_MODE_LUMINANCE 2
00077 
00078 class vtkIdList;
00079 class vtkScalars;
00080 class vtkLookupTable;
00081 class vtkUnsignedCharArray;
00082 class vtkScalarsToColors;
00083 
00084 class VTK_EXPORT vtkScalars : public vtkAttributeData
00085 {
00086 public:
00087   static vtkScalars *New();
00088   static vtkScalars *New(int dataType, int numComp=1);
00089 
00090   vtkTypeMacro(vtkScalars,vtkAttributeData);
00091   void PrintSelf(ostream& os, vtkIndent indent);
00092 
00095   void SetData(vtkDataArray *);
00096 
00098   vtkAttributeData *MakeObject();
00099 
00102   void SetNumberOfScalars(int number) {this->Data->SetNumberOfTuples(number);};
00103 
00105   int GetNumberOfScalars() {return this->Data->GetNumberOfTuples();};
00106 
00108   float GetScalar(int id);
00109 
00113   void SetScalar(int id, float s);
00114 
00117   void InsertScalar(int id, float s);
00118 
00121   int InsertNextScalar(float s);
00122 
00124   void SetNumberOfComponents(int num);
00125   int GetNumberOfComponents() {return this->Data->GetNumberOfComponents();}
00126 
00130   vtkSetClampMacro(ActiveComponent,int,0,3);
00131   vtkGetMacro(ActiveComponent,int);
00132 
00133   // Special computational methods.
00134 
00136   void ComputeRange();
00137 
00138 
00141   float *GetRange();
00142 
00143 
00145   void GetRange(float range[2]);
00146 
00150   void GetDataTypeRange(double range[2]);
00151   double GetDataTypeMin();
00152   double GetDataTypeMax();
00153   
00156   virtual void CreateDefaultLookupTable();
00157 
00159   void SetLookupTable(vtkLookupTable *lut);
00160   vtkGetObjectMacro(LookupTable,vtkLookupTable);
00161 
00163   void GetScalars(vtkIdList *ptIds, vtkScalars *fv);
00164 
00168   void GetScalars(int p1, int p2, vtkScalars *fs);
00169   
00176   int InitColorTraversal(float alpha, vtkScalarsToColors *lut, 
00177           int colorMode=VTK_COLOR_MODE_DEFAULT);
00178   
00182   unsigned char *GetColor(int id) {
00183     return (this->*(this->CurrentColorFunction))(id);};
00184 
00185 #ifndef VTK_REMOVE_LEGACY_CODE
00186 
00187   void GetScalars(vtkIdList& ptIds, vtkScalars& fv) 
00188     {VTK_LEGACY_METHOD(GetScalars,"3.2"); this->GetScalars(&ptIds, &fv);}
00189   void GetScalars(int p1, int p2, vtkScalars& fs) 
00190     {VTK_LEGACY_METHOD(GetScalars,"3.2"); this->GetScalars(p1, p2, &fs);}
00191 #endif
00192   
00193 protected:
00194   vtkScalars();
00195   ~vtkScalars();
00196   vtkScalars(const vtkScalars&) {};
00197   void operator=(const vtkScalars&) {};
00198 
00199   float Range[8];
00200   vtkTimeStamp ComputeTime;
00201   vtkLookupTable *LookupTable;
00202   int ActiveComponent; //for multiple component scalars, the current component
00203 
00204   // following stuff is used for converting scalars to colors
00205   float CurrentAlpha;
00206   vtkScalarsToColors *CurrentLookupTable;
00207   //BTX
00208   unsigned char *(vtkScalars::*CurrentColorFunction)(int id);
00209   unsigned char *PassRGBA(int id);
00210   unsigned char *PassRGB(int id);
00211   unsigned char *PassIA(int id);
00212   unsigned char *PassI(int id);
00213   unsigned char *CompositeRGBA(int id);
00214   unsigned char *CompositeIA(int id);
00215   unsigned char *CompositeMapThroughLookupTable(int id);  
00216   unsigned char *MapThroughLookupTable(int id);  
00217   unsigned char *Luminance(int id);  
00218   vtkUnsignedCharArray *Colors;
00219   unsigned char RGBA[4];
00220   //ETX
00221 };
00222 
00223 inline vtkAttributeData *vtkScalars::MakeObject()
00224 {
00225   return vtkScalars::New(this->GetDataType(),this->GetNumberOfComponents());
00226 }
00227 
00228 inline void vtkScalars::SetNumberOfComponents(int num)
00229 {
00230   num = (num < 1 ? 1 : (num > 4 ? 4 : num));
00231   this->Data->SetNumberOfComponents(num);
00232 }
00233 
00234 inline float vtkScalars::GetScalar(int id)
00235 {
00236   return this->Data->GetComponent(id,this->ActiveComponent);
00237 }
00238 
00239 inline void vtkScalars::SetScalar(int id, float s)
00240 {
00241   this->Data->SetComponent(id,this->ActiveComponent,s);
00242 }
00243 
00244 inline void vtkScalars::InsertScalar(int id, float s)
00245 {
00246   this->Data->InsertComponent(id,this->ActiveComponent,s);
00247 }
00248 
00249 inline int vtkScalars::InsertNextScalar(float s)
00250 {
00251   int tupleSize = this->Data->GetNumberOfComponents();
00252   int id=(this->Data->GetMaxId() + tupleSize)/tupleSize;
00253   this->Data->InsertComponent(id,this->ActiveComponent,s);
00254   return id;
00255 }
00256 
00257 // These include files are placed here so that if Scalars.h is included 
00258 // all other classes necessary for compilation are also included. 
00259 #include "vtkIdList.h"
00260 
00261 #endif

Generated on Wed Nov 21 12:26:53 2001 for VTK by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001