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

Common/vtkBitArray.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    $RCSfile: vtkBitArray.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 =========================================================================*/
00043 #ifndef __vtkBitArray_h
00044 #define __vtkBitArray_h
00045 
00046 #include "vtkDataArray.h"
00047 
00048 class VTK_COMMON_EXPORT vtkBitArray : public vtkDataArray
00049 {
00050 public:
00051   static vtkBitArray *New();
00052   vtkTypeRevisionMacro(vtkBitArray,vtkDataArray);
00053   void PrintSelf(ostream& os, vtkIndent indent);
00054 
00057   int Allocate(const vtkIdType sz, const vtkIdType ext=1000);
00058 
00060   void Initialize();
00061 
00062   // satisfy vtkDataArray API
00063   int GetDataType() {return VTK_BIT;};
00064   int GetDataTypeSize() { return 0; }
00065   
00067   void SetNumberOfTuples(const vtkIdType number);
00068 
00071   float *GetTuple(const vtkIdType i);
00072 
00074 
00075   void GetTuple(const vtkIdType i, float * tuple);
00076   void GetTuple(const vtkIdType i, double * tuple);
00078   
00080 
00081   void SetTuple(const vtkIdType i, const float * tuple);
00082   void SetTuple(const vtkIdType i, const double * tuple);
00084   
00086 
00088   void InsertTuple(const vtkIdType i, const float * tuple);
00089   void InsertTuple(const vtkIdType i, const double * tuple);
00091 
00093 
00095   vtkIdType InsertNextTuple(const float * tuple);
00096   vtkIdType InsertNextTuple(const double * tuple);
00098 
00103   void SetComponent(const vtkIdType i, const int j, float c);
00104 
00106   void Squeeze();
00107 
00109   virtual void Resize(vtkIdType numTuples);
00110 
00112   int GetValue(const vtkIdType id);
00113 
00119   void SetNumberOfValues(const vtkIdType number);
00120 
00123   void SetValue(const vtkIdType id, const int value);
00124 
00126 
00127   void InsertValue(const vtkIdType id, const int i);
00128   vtkIdType InsertNextValue(const int i);
00130 
00134   virtual void InsertComponent(const vtkIdType i, const int j, float c);
00135 
00137   unsigned char *GetPointer(const vtkIdType id) {return this->Array + id/8;}
00138 
00140 
00143   unsigned char *WritePointer(const vtkIdType id, const vtkIdType number);
00144   void *GetVoidPointer(const vtkIdType id)
00145     {return (void *)this->GetPointer(id);};
00147 
00149   void DeepCopy(vtkDataArray *da);
00150 
00152 
00158   void SetArray(unsigned char* array, vtkIdType size, int save);
00159   void SetVoidArray(void *array, vtkIdType size, int save) 
00160     {this->SetArray((unsigned char *)array, size, save);};
00162 
00163  
00164 protected:
00165   vtkBitArray(vtkIdType numComp=1);
00166   ~vtkBitArray();
00167 
00168   unsigned char *Array;   // pointer to data
00169   unsigned char *ResizeAndExtend(const vtkIdType sz);
00170     // function to resize data
00171 
00172   int TupleSize; //used for data conversion
00173   float *Tuple;
00174 
00175   int SaveUserArray;
00176 
00177 private:
00178   // hide superclass' DeepCopy() from the user and the compiler
00179   void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00180   
00181 private:
00182   vtkBitArray(const vtkBitArray&);  // Not implemented.
00183   void operator=(const vtkBitArray&);  // Not implemented.
00184 };
00185 
00186 inline unsigned char *vtkBitArray::WritePointer(const vtkIdType id,
00187                                                 const vtkIdType number)
00188 {
00189   vtkIdType newSize=id+number;
00190   if ( newSize > this->Size )
00191     {
00192     this->ResizeAndExtend(newSize);
00193     }
00194   if ( (--newSize) > this->MaxId )
00195     {
00196     this->MaxId = newSize;
00197     }
00198   return this->Array + id/8;
00199 }
00200 
00201 inline void vtkBitArray::SetNumberOfValues(const vtkIdType number) 
00202 {
00203   this->Allocate(number);
00204   this->MaxId = number - 1;
00205 }
00206 
00207 inline void vtkBitArray::SetValue(const vtkIdType id, const int value) 
00208 {
00209   if (value)
00210     {
00211     this->Array[id/8] |= (0x80 >> id%8);
00212     }
00213   else
00214     {
00215     this->Array[id/8] &= (~(0x80 >> id%8));
00216     }
00217 }
00218 
00219 inline void vtkBitArray::InsertValue(const vtkIdType id, const int i)
00220 {
00221   if ( id >= this->Size )
00222     {
00223     this->ResizeAndExtend(id+1);
00224     }
00225   if (i)
00226     {
00227     this->Array[id/8] |= (0x80 >> id%8);
00228     }
00229   else
00230     {
00231     this->Array[id/8] &= (~(0x80 >> id%8));
00232     }
00233   if ( id > this->MaxId )
00234     {
00235     this->MaxId = id;
00236     }
00237 }
00238 
00239 inline vtkIdType vtkBitArray::InsertNextValue(const int i)
00240 {
00241   this->InsertValue (++this->MaxId,i); return this->MaxId;
00242 }
00243 
00244 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00245 
00246 #endif
00247