VTK
dox/Common/Core/vtkBitArray.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkBitArray.h
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 =========================================================================*/
00027 #ifndef __vtkBitArray_h
00028 #define __vtkBitArray_h
00029 
00030 #include "vtkCommonCoreModule.h" // For export macro
00031 #include "vtkDataArray.h"
00032 
00033 class vtkBitArrayLookup;
00034 
00035 class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
00036 {
00037 public:
00038   static vtkBitArray *New();
00039   vtkTypeMacro(vtkBitArray,vtkDataArray);
00040   void PrintSelf(ostream& os, vtkIndent indent);
00041 
00044   int Allocate(vtkIdType sz, vtkIdType ext=1000);
00045 
00047   void Initialize();
00048 
00049   // satisfy vtkDataArray API
00050   int GetDataType() {return VTK_BIT;};
00051   int GetDataTypeSize() { return 0; }
00052 
00054   void SetNumberOfTuples(vtkIdType number);
00055 
00061   virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00062 
00066   virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00067 
00071   virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
00072 
00075   double *GetTuple(vtkIdType i);
00076 
00078   void GetTuple(vtkIdType i, double * tuple);
00079 
00081 
00082   void SetTuple(vtkIdType i, const float * tuple);
00083   void SetTuple(vtkIdType i, const double * tuple);
00085 
00087 
00089   void InsertTuple(vtkIdType i, const float * tuple);
00090   void InsertTuple(vtkIdType i, const double * tuple);
00092 
00094 
00096   vtkIdType InsertNextTuple(const float * tuple);
00097   vtkIdType InsertNextTuple(const double * tuple);
00099 
00101 
00104   virtual void RemoveTuple(vtkIdType id);
00105   virtual void RemoveFirstTuple();
00106   virtual void RemoveLastTuple();
00108 
00113   void SetComponent(vtkIdType i, int j, double c);
00114 
00116   void Squeeze();
00117 
00119   virtual int Resize(vtkIdType numTuples);
00120 
00122   int GetValue(vtkIdType id);
00123 
00129   void SetNumberOfValues(vtkIdType number);
00130 
00133   void SetValue(vtkIdType id, int value);
00134 
00136   void InsertValue(vtkIdType id, int i);
00137 
00139   void SetVariantValue(vtkIdType idx, vtkVariant value);
00140 
00141   vtkIdType InsertNextValue(int i);
00142 
00146   virtual void InsertComponent(vtkIdType i, int j, double c);
00147 
00149   unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
00150 
00152 
00155   unsigned char *WritePointer(vtkIdType id, vtkIdType number);
00156   void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00157     { return this->WritePointer(id, number); }
00158   void *GetVoidPointer(vtkIdType id)
00159     {
00160       return static_cast<void *>(this->GetPointer(id));
00161     }
00163 
00165 
00166   void DeepCopy(vtkDataArray *da);
00167   void DeepCopy(vtkAbstractArray* aa)
00168     { this->Superclass::DeepCopy(aa); }
00170 
00172 
00179   void SetArray(unsigned char* array, vtkIdType size, int save);
00180   void SetVoidArray(void *array, vtkIdType size, int save)
00181     {
00182       this->SetArray(static_cast<unsigned char *>(array), size, save);
00183     }
00185 
00187   vtkArrayIterator* NewIterator();
00188 
00190 
00191   virtual vtkIdType LookupValue(vtkVariant value);
00192   virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00193   vtkIdType LookupValue(int value);
00194   void LookupValue(int value, vtkIdList* ids);
00196 
00203   virtual void DataChanged();
00204 
00208   virtual void ClearLookup();
00209 
00210 protected:
00211   vtkBitArray(vtkIdType numComp=1);
00212   ~vtkBitArray();
00213 
00214   unsigned char *Array;   // pointer to data
00215   unsigned char *ResizeAndExtend(vtkIdType sz);
00216     // function to resize data
00217 
00218   int TupleSize; //used for data conversion
00219   double *Tuple;
00220 
00221   int SaveUserArray;
00222 
00223 private:
00224   // hide superclass' DeepCopy() from the user and the compiler
00225   void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00226 
00227 private:
00228   vtkBitArray(const vtkBitArray&);  // Not implemented.
00229   void operator=(const vtkBitArray&);  // Not implemented.
00230 
00231   //BTX
00232   vtkBitArrayLookup* Lookup;
00233   void UpdateLookup();
00234   //ETX
00235 };
00236 
00237 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
00238 {
00239   this->Allocate(number);
00240   this->MaxId = number - 1;
00241   this->DataChanged();
00242 }
00243 
00244 inline void vtkBitArray::SetValue(vtkIdType id, int value)
00245 {
00246   if (value)
00247     {
00248     this->Array[id/8] = static_cast<unsigned char>(
00249       this->Array[id/8] | (0x80 >> id%8));
00250     }
00251   else
00252     {
00253     this->Array[id/8] = static_cast<unsigned char>(
00254       this->Array[id/8] & (~(0x80 >> id%8)));
00255     }
00256   this->DataChanged();
00257 }
00258 
00259 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00260 {
00261   if ( id >= this->Size )
00262     {
00263     this->ResizeAndExtend(id+1);
00264     }
00265   if (i)
00266     {
00267     this->Array[id/8] = static_cast<unsigned char>(
00268       this->Array[id/8] | (0x80 >> id%8));
00269     }
00270   else
00271     {
00272     this->Array[id/8] = static_cast<unsigned char>(
00273       this->Array[id/8] & (~(0x80 >> id%8)));
00274     }
00275   if ( id > this->MaxId )
00276     {
00277     this->MaxId = id;
00278     }
00279   this->DataChanged();
00280 }
00281 
00282 inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value)
00283 {
00284   this->SetValue(id, value.ToInt());
00285 }
00286 
00287 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00288 {
00289   this->InsertValue (++this->MaxId,i);
00290   this->DataChanged();
00291   return this->MaxId;
00292 }
00293 
00294 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00295 
00296 #endif
00297