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

Common/vtkUnsignedCharArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkUnsignedCharArray.h,v $
00005   Language:  C++
00006 
00007   Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen 
00008   All rights reserved.
00009   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00010 
00011      This software is distributed WITHOUT ANY WARRANTY; without even 
00012      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00013      PURPOSE.  See the above copyright notice for more information.
00014 
00015 =========================================================================*/
00042 #ifndef __vtkUnsignedCharArray_h
00043 #define __vtkUnsignedCharArray_h
00044 
00045 #include "vtkDataArray.h"
00046 
00047 class VTK_COMMON_EXPORT vtkUnsignedCharArray : public vtkDataArray
00048 {
00049 public:
00050   static vtkUnsignedCharArray *New();
00051 
00052   vtkTypeRevisionMacro(vtkUnsignedCharArray,vtkDataArray);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00057   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00058 
00060   void Initialize();
00061 
00063   int GetDataType() {return VTK_UNSIGNED_CHAR;};
00064 
00066   int GetDataTypeSize() { return sizeof(unsigned char); }
00067 
00069   void SetNumberOfTuples(const vtkIdType number);
00070 
00073   float *GetTuple(const vtkIdType i);
00074 
00076 
00077   void GetTuple(const vtkIdType i, float * tuple);
00078   void GetTuple(const vtkIdType i, double * tuple);
00080 
00082 
00083   void SetTuple(const vtkIdType i, const float * tuple);
00084   void SetTuple(const vtkIdType i, const double * tuple);
00086 
00088 
00090   void InsertTuple(const vtkIdType i, const float * tuple);
00091   void InsertTuple(const vtkIdType i, const double * tuple);
00093 
00095 
00097   vtkIdType InsertNextTuple(const float * tuple);
00098   vtkIdType InsertNextTuple(const double * tuple);
00100 
00102   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
00103 
00105   virtual void Resize(vtkIdType numTuples);
00106 
00110   float GetComponent(const vtkIdType i, const int j);
00111 
00116   void SetComponent(const vtkIdType i, const int j, float c);
00117 
00121   void InsertComponent(const vtkIdType i, const int j, float c);
00122 
00124   unsigned char GetValue(const vtkIdType id) {return this->Array[id];};
00125 
00127 
00129   void SetValue(const vtkIdType id, const unsigned char value) {
00130     this->Array[id] = value;};
00132 
00136   void SetNumberOfValues(const vtkIdType number);
00137 
00139   void InsertValue(const vtkIdType id, const unsigned char c);
00140 
00143   vtkIdType InsertNextValue(const unsigned char c);
00144 
00146 
00148   unsigned char *GetPointer(const vtkIdType id) {return this->Array + id;}
00149   void *GetVoidPointer(const vtkIdType id)
00150     {return (void *)this->GetPointer(id);};
00152 
00156   unsigned char *WritePointer(const vtkIdType id, const vtkIdType number);
00157   
00159   void DeepCopy(vtkDataArray *da);
00160 
00162 
00168   void SetArray(unsigned char* array, vtkIdType size, int save);
00169   void SetVoidArray(void *array, vtkIdType size, int save) 
00170     {this->SetArray((unsigned char*)array, size, save);};
00172 
00173 
00174 protected:
00175   vtkUnsignedCharArray(vtkIdType numComp=1);
00176   ~vtkUnsignedCharArray();
00177 
00178   unsigned char *Array;   // pointer to data
00179   unsigned char *ResizeAndExtend(const vtkIdType sz);
00180     // function to resize data
00181 
00182   int TupleSize; //used for data conversion
00183   float *Tuple;
00184 
00185   int SaveUserArray;
00186 private:
00187   vtkUnsignedCharArray(const vtkUnsignedCharArray&);  // Not implemented.
00188   void operator=(const vtkUnsignedCharArray&);  // Not implemented.
00189 };
00190 
00191 inline void vtkUnsignedCharArray::SetNumberOfValues(const vtkIdType number) 
00192 {
00193   this->Allocate(number);
00194   this->MaxId = number - 1;
00195 }
00196 
00197 inline unsigned char *vtkUnsignedCharArray::WritePointer(const vtkIdType id,
00198                                                          const vtkIdType number) 
00199 {
00200   vtkIdType newSize=id+number;
00201   if ( newSize > this->Size )
00202     {
00203     this->ResizeAndExtend(newSize);
00204     }
00205   if ( (--newSize) > this->MaxId )
00206     {
00207     this->MaxId = newSize;
00208     }
00209   return this->Array + id;
00210 }
00211 
00212 inline void vtkUnsignedCharArray::InsertValue(const vtkIdType id,
00213                                               const unsigned char c)
00214 {
00215   if ( id >= this->Size )
00216     {
00217     this->ResizeAndExtend(id+1);
00218     }
00219   this->Array[id] = c;
00220   if ( id > this->MaxId )
00221     {
00222     this->MaxId = id;
00223     }
00224 }
00225 
00226 inline vtkIdType vtkUnsignedCharArray::InsertNextValue(const unsigned char c)
00227 {
00228   this->InsertValue (++this->MaxId,c); 
00229   return this->MaxId;
00230 }
00231 
00232 
00233 #endif