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

vtkBitArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkBitArray.h,v $
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 =========================================================================*/
00038 #ifndef __vtkBitArray_h
00039 #define __vtkBitArray_h
00040 
00041 #include "vtkDataArray.h"
00042 
00043 class VTK_COMMON_EXPORT vtkBitArray : public vtkDataArray
00044 {
00045 public:
00046   static vtkBitArray *New();
00047   vtkTypeRevisionMacro(vtkBitArray,vtkDataArray);
00048   void PrintSelf(ostream& os, vtkIndent indent);
00049 
00052   int Allocate(vtkIdType sz, vtkIdType ext=1000);
00053 
00055   void Initialize();
00056 
00057   // satisfy vtkDataArray API
00058   int GetDataType() {return VTK_BIT;};
00059   int GetDataTypeSize() { return 0; }
00060   
00062   void SetNumberOfTuples(vtkIdType number);
00063 
00066   double *GetTuple(vtkIdType i);
00067 
00069   void GetTuple(vtkIdType i, double * tuple);
00070   
00072 
00073   void SetTuple(vtkIdType i, const float * tuple);
00074   void SetTuple(vtkIdType i, const double * tuple);
00076   
00078 
00080   void InsertTuple(vtkIdType i, const float * tuple);
00081   void InsertTuple(vtkIdType i, const double * tuple);
00083 
00085 
00087   vtkIdType InsertNextTuple(const float * tuple);
00088   vtkIdType InsertNextTuple(const double * tuple);
00090 
00095   void SetComponent(vtkIdType i, int j, double c);
00096 
00098   void Squeeze();
00099 
00101   virtual void Resize(vtkIdType numTuples);
00102 
00104   int GetValue(vtkIdType id);
00105 
00111   void SetNumberOfValues(vtkIdType number);
00112 
00115   void SetValue(vtkIdType id, int value);
00116 
00118 
00119   void InsertValue(vtkIdType id, int i);
00120   vtkIdType InsertNextValue(int i);
00122 
00126   virtual void InsertComponent(vtkIdType i, int j, double c);
00127 
00129   unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
00130 
00132 
00135   unsigned char *WritePointer(vtkIdType id, vtkIdType number);
00136   void *GetVoidPointer(vtkIdType id)
00137     {return (void *)this->GetPointer(id);};
00139 
00141   void DeepCopy(vtkDataArray *da);
00142 
00144 
00150   void SetArray(unsigned char* array, vtkIdType size, int save);
00151   void SetVoidArray(void *array, vtkIdType size, int save) 
00152     {this->SetArray((unsigned char *)array, size, save);};
00154 
00155  
00156 protected:
00157   vtkBitArray(vtkIdType numComp=1);
00158   ~vtkBitArray();
00159 
00160   unsigned char *Array;   // pointer to data
00161   unsigned char *ResizeAndExtend(vtkIdType sz);
00162     // function to resize data
00163 
00164   int TupleSize; //used for data conversion
00165   double *Tuple;
00166 
00167   int SaveUserArray;
00168 
00169 private:
00170   // hide superclass' DeepCopy() from the user and the compiler
00171   void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00172   
00173 private:
00174   vtkBitArray(const vtkBitArray&);  // Not implemented.
00175   void operator=(const vtkBitArray&);  // Not implemented.
00176 };
00177 
00178 inline unsigned char *vtkBitArray::WritePointer(vtkIdType id,
00179                                                 vtkIdType number)
00180 {
00181   vtkIdType newSize=id+number;
00182   if ( newSize > this->Size )
00183     {
00184     this->ResizeAndExtend(newSize);
00185     }
00186   if ( (--newSize) > this->MaxId )
00187     {
00188     this->MaxId = newSize;
00189     }
00190   return this->Array + id/8;
00191 }
00192 
00193 inline void vtkBitArray::SetNumberOfValues(vtkIdType number) 
00194 {
00195   this->Allocate(number);
00196   this->MaxId = number - 1;
00197 }
00198 
00199 inline void vtkBitArray::SetValue(vtkIdType id, int value) 
00200 {
00201   if (value)
00202     {
00203     this->Array[id/8] |= (0x80 >> id%8);
00204     }
00205   else
00206     {
00207     this->Array[id/8] &= (~(0x80 >> id%8));
00208     }
00209 }
00210 
00211 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00212 {
00213   if ( id >= this->Size )
00214     {
00215     this->ResizeAndExtend(id+1);
00216     }
00217   if (i)
00218     {
00219     this->Array[id/8] |= (0x80 >> id%8);
00220     }
00221   else
00222     {
00223     this->Array[id/8] &= (~(0x80 >> id%8));
00224     }
00225   if ( id > this->MaxId )
00226     {
00227     this->MaxId = id;
00228     }
00229 }
00230 
00231 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00232 {
00233   this->InsertValue (++this->MaxId,i); return this->MaxId;
00234 }
00235 
00236 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00237 
00238 #endif
00239