Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound 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 =========================================================================*/
00045 #ifndef __vtkUnsignedCharArray_h
00046 #define __vtkUnsignedCharArray_h
00047 
00048 #include "vtkDataArray.h"
00049 
00050 class VTK_COMMON_EXPORT vtkUnsignedCharArray : public vtkDataArray
00051 {
00052 public:
00053   static vtkUnsignedCharArray *New();
00054 
00055   vtkTypeRevisionMacro(vtkUnsignedCharArray,vtkDataArray);
00056   void PrintSelf(ostream& os, vtkIndent indent);
00057 
00060   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00061 
00063   void Initialize();
00064 
00066   int GetDataType() {return VTK_UNSIGNED_CHAR;};
00067 
00069   int GetDataTypeSize() { return sizeof(unsigned char); }
00070 
00072   void SetNumberOfTuples(const vtkIdType number);
00073 
00076   float *GetTuple(const vtkIdType i);
00077 
00079 
00080   void GetTuple(const vtkIdType i, float * tuple);
00081   void GetTuple(const vtkIdType i, double * tuple);
00083 
00085 
00086   void SetTuple(const vtkIdType i, const float * tuple);
00087   void SetTuple(const vtkIdType i, const double * tuple);
00089 
00091 
00093   void InsertTuple(const vtkIdType i, const float * tuple);
00094   void InsertTuple(const vtkIdType i, const double * tuple);
00096 
00098 
00100   vtkIdType InsertNextTuple(const float * tuple);
00101   vtkIdType InsertNextTuple(const double * tuple);
00103 
00105   void Squeeze() {this->ResizeAndExtend (this->MaxId+1);};
00106 
00108   virtual void Resize(vtkIdType numTuples);
00109 
00113   float GetComponent(const vtkIdType i, const int j);
00114 
00119   void SetComponent(const vtkIdType i, const int j, float c);
00120 
00124   void InsertComponent(const vtkIdType i, const int j, float c);
00125 
00127   unsigned char GetValue(const vtkIdType id) {return this->Array[id];};
00128 
00130 
00132   void SetValue(const vtkIdType id, const unsigned char value) {
00133     this->Array[id] = value;};
00135 
00139   void SetNumberOfValues(const vtkIdType number);
00140 
00142   void InsertValue(const vtkIdType id, const unsigned char c);
00143 
00146   vtkIdType InsertNextValue(const unsigned char c);
00147 
00149 
00151   unsigned char *GetPointer(const vtkIdType id) {return this->Array + id;}
00152   void *GetVoidPointer(const vtkIdType id)
00153     {return (void *)this->GetPointer(id);};
00155 
00159   unsigned char *WritePointer(const vtkIdType id, const vtkIdType number);
00160   
00162   void DeepCopy(vtkDataArray *da);
00163 
00165 
00171   void SetArray(unsigned char* array, vtkIdType size, int save);
00172   void SetVoidArray(void *array, vtkIdType size, int save) 
00173     {this->SetArray((unsigned char*)array, size, save);};
00175 
00176 
00177 protected:
00178   vtkUnsignedCharArray(vtkIdType numComp=1);
00179   ~vtkUnsignedCharArray();
00180 
00181   unsigned char *Array;   // pointer to data
00182   unsigned char *ResizeAndExtend(const vtkIdType sz);
00183     // function to resize data
00184 
00185   int TupleSize; //used for data conversion
00186   float *Tuple;
00187 
00188   int SaveUserArray;
00189 private:
00190   vtkUnsignedCharArray(const vtkUnsignedCharArray&);  // Not implemented.
00191   void operator=(const vtkUnsignedCharArray&);  // Not implemented.
00192 };
00193 
00194 inline void vtkUnsignedCharArray::SetNumberOfValues(const vtkIdType number) 
00195 {
00196   this->Allocate(number);
00197   this->MaxId = number - 1;
00198 }
00199 
00200 inline unsigned char *vtkUnsignedCharArray::WritePointer(const vtkIdType id,
00201                                                          const vtkIdType number) 
00202 {
00203   vtkIdType newSize=id+number;
00204   if ( newSize > this->Size )
00205     {
00206     this->ResizeAndExtend(newSize);
00207     }
00208   if ( (--newSize) > this->MaxId )
00209     {
00210     this->MaxId = newSize;
00211     }
00212   return this->Array + id;
00213 }
00214 
00215 inline void vtkUnsignedCharArray::InsertValue(const vtkIdType id,
00216                                               const unsigned char c)
00217 {
00218   if ( id >= this->Size )
00219     {
00220     this->ResizeAndExtend(id+1);
00221     }
00222   this->Array[id] = c;
00223   if ( id > this->MaxId )
00224     {
00225     this->MaxId = id;
00226     }
00227 }
00228 
00229 inline vtkIdType vtkUnsignedCharArray::InsertNextValue(const unsigned char c)
00230 {
00231   this->InsertValue (++this->MaxId,c); 
00232   return this->MaxId;
00233 }
00234 
00235 
00236 #endif