Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class 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 
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 =========================================================================*/
00024 #ifndef __vtkBitArray_h
00025 #define __vtkBitArray_h
00026 
00027 #include "vtkDataArray.h"
00028 
00029 class VTK_COMMON_EXPORT vtkBitArray : public vtkDataArray
00030 {
00031 public:
00032   static vtkBitArray *New();
00033   vtkTypeRevisionMacro(vtkBitArray,vtkDataArray);
00034   void PrintSelf(ostream& os, vtkIndent indent);
00035 
00038   int Allocate(vtkIdType sz, vtkIdType ext=1000);
00039 
00041   void Initialize();
00042 
00043   // satisfy vtkDataArray API
00044   int GetDataType() {return VTK_BIT;};
00045   int GetDataTypeSize() { return 0; }
00046   
00048   void SetNumberOfTuples(vtkIdType number);
00049 
00052   double *GetTuple(vtkIdType i);
00053 
00055   void GetTuple(vtkIdType i, double * tuple);
00056   
00058 
00059   void SetTuple(vtkIdType i, const float * tuple);
00060   void SetTuple(vtkIdType i, const double * tuple);
00062   
00064 
00066   void InsertTuple(vtkIdType i, const float * tuple);
00067   void InsertTuple(vtkIdType i, const double * tuple);
00069 
00071 
00073   vtkIdType InsertNextTuple(const float * tuple);
00074   vtkIdType InsertNextTuple(const double * tuple);
00076 
00081   void SetComponent(vtkIdType i, int j, double c);
00082 
00084   void Squeeze();
00085 
00087   virtual void Resize(vtkIdType numTuples);
00088 
00090   int GetValue(vtkIdType id);
00091 
00097   void SetNumberOfValues(vtkIdType number);
00098 
00101   void SetValue(vtkIdType id, int value);
00102 
00104 
00105   void InsertValue(vtkIdType id, int i);
00106   vtkIdType InsertNextValue(int i);
00108 
00112   virtual void InsertComponent(vtkIdType i, int j, double c);
00113 
00115   unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
00116 
00118 
00121   unsigned char *WritePointer(vtkIdType id, vtkIdType number);
00122   void *GetVoidPointer(vtkIdType id)
00123     {return (void *)this->GetPointer(id);};
00125 
00127   void DeepCopy(vtkDataArray *da);
00128 
00130 
00136   void SetArray(unsigned char* array, vtkIdType size, int save);
00137   void SetVoidArray(void *array, vtkIdType size, int save) 
00138     {this->SetArray((unsigned char *)array, size, save);};
00140 
00141  
00142 protected:
00143   vtkBitArray(vtkIdType numComp=1);
00144   ~vtkBitArray();
00145 
00146   unsigned char *Array;   // pointer to data
00147   unsigned char *ResizeAndExtend(vtkIdType sz);
00148     // function to resize data
00149 
00150   int TupleSize; //used for data conversion
00151   double *Tuple;
00152 
00153   int SaveUserArray;
00154 
00155 private:
00156   // hide superclass' DeepCopy() from the user and the compiler
00157   void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00158   
00159 private:
00160   vtkBitArray(const vtkBitArray&);  // Not implemented.
00161   void operator=(const vtkBitArray&);  // Not implemented.
00162 };
00163 
00164 inline unsigned char *vtkBitArray::WritePointer(vtkIdType id,
00165                                                 vtkIdType number)
00166 {
00167   vtkIdType newSize=id+number;
00168   if ( newSize > this->Size )
00169     {
00170     this->ResizeAndExtend(newSize);
00171     }
00172   if ( (--newSize) > this->MaxId )
00173     {
00174     this->MaxId = newSize;
00175     }
00176   return this->Array + id/8;
00177 }
00178 
00179 inline void vtkBitArray::SetNumberOfValues(vtkIdType number) 
00180 {
00181   this->Allocate(number);
00182   this->MaxId = number - 1;
00183 }
00184 
00185 inline void vtkBitArray::SetValue(vtkIdType id, int value) 
00186 {
00187   if (value)
00188     {
00189     this->Array[id/8] |= (0x80 >> id%8);
00190     }
00191   else
00192     {
00193     this->Array[id/8] &= (~(0x80 >> id%8));
00194     }
00195 }
00196 
00197 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00198 {
00199   if ( id >= this->Size )
00200     {
00201     this->ResizeAndExtend(id+1);
00202     }
00203   if (i)
00204     {
00205     this->Array[id/8] |= (0x80 >> id%8);
00206     }
00207   else
00208     {
00209     this->Array[id/8] &= (~(0x80 >> id%8));
00210     }
00211   if ( id > this->MaxId )
00212     {
00213     this->MaxId = id;
00214     }
00215 }
00216 
00217 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00218 {
00219   this->InsertValue (++this->MaxId,i); return this->MaxId;
00220 }
00221 
00222 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00223 
00224 #endif
00225