00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00027 #ifndef __vtkBitArray_h
00028 #define __vtkBitArray_h
00029
00030 #include "vtkDataArray.h"
00031
00032 class vtkBitArrayLookup;
00033
00034 class VTK_COMMON_EXPORT vtkBitArray : public vtkDataArray
00035 {
00036 public:
00037 static vtkBitArray *New();
00038 vtkTypeRevisionMacro(vtkBitArray,vtkDataArray);
00039 void PrintSelf(ostream& os, vtkIndent indent);
00040
00043 int Allocate(vtkIdType sz, vtkIdType ext=1000);
00044
00046 void Initialize();
00047
00048
00049 int GetDataType() {return VTK_BIT;};
00050 int GetDataTypeSize() { return 0; }
00051
00053 void SetNumberOfTuples(vtkIdType number);
00054
00060 virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00061
00065 virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source);
00066
00070 virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source);
00071
00074 double *GetTuple(vtkIdType i);
00075
00077 void GetTuple(vtkIdType i, double * tuple);
00078
00080
00081 void SetTuple(vtkIdType i, const float * tuple);
00082 void SetTuple(vtkIdType i, const double * tuple);
00084
00086
00088 void InsertTuple(vtkIdType i, const float * tuple);
00089 void InsertTuple(vtkIdType i, const double * tuple);
00091
00093
00095 vtkIdType InsertNextTuple(const float * tuple);
00096 vtkIdType InsertNextTuple(const double * tuple);
00098
00100
00103 virtual void RemoveTuple(vtkIdType id);
00104 virtual void RemoveFirstTuple();
00105 virtual void RemoveLastTuple();
00107
00112 void SetComponent(vtkIdType i, int j, double c);
00113
00115 void Squeeze();
00116
00118 virtual int Resize(vtkIdType numTuples);
00119
00121 int GetValue(vtkIdType id);
00122
00128 void SetNumberOfValues(vtkIdType number);
00129
00132 void SetValue(vtkIdType id, int value);
00133
00135 void InsertValue(vtkIdType id, int i);
00136
00137
00139
00140 void InsertVariantValue(vtkIdType idx, vtkVariant value);
00141
00143
00144 vtkIdType InsertNextValue(int i);
00145
00149 virtual void InsertComponent(vtkIdType i, int j, double c);
00150
00152 unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
00153
00155
00158 unsigned char *WritePointer(vtkIdType id, vtkIdType number);
00159 void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00160 { return this->WritePointer(id, number); }
00161 void *GetVoidPointer(vtkIdType id)
00162 {
00163 return static_cast<void *>(this->GetPointer(id));
00164 }
00166
00168
00169 void DeepCopy(vtkDataArray *da);
00170 void DeepCopy(vtkAbstractArray* aa)
00171 { this->Superclass::DeepCopy(aa); }
00173
00175
00182 void SetArray(unsigned char* array, vtkIdType size, int save);
00183 void SetVoidArray(void *array, vtkIdType size, int save)
00184 {
00185 this->SetArray(static_cast<unsigned char *>(array), size, save);
00186 }
00188
00190 vtkArrayIterator* NewIterator();
00191
00192
00194
00195 virtual vtkIdType LookupValue(vtkVariant value);
00196 virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00197
00198 vtkIdType LookupValue(int value);
00199 void LookupValue(int value, vtkIdList* ids);
00201
00208 virtual void DataChanged();
00209
00213 virtual void ClearLookup();
00214
00215 protected:
00216 vtkBitArray(vtkIdType numComp=1);
00217 ~vtkBitArray();
00218
00219 unsigned char *Array;
00220 unsigned char *ResizeAndExtend(vtkIdType sz);
00221
00222
00223 int TupleSize;
00224 double *Tuple;
00225
00226 int SaveUserArray;
00227
00228 private:
00229
00230 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00231
00232 private:
00233 vtkBitArray(const vtkBitArray&);
00234 void operator=(const vtkBitArray&);
00235
00236
00237 vtkBitArrayLookup* Lookup;
00238 void UpdateLookup();
00239
00240 };
00241
00242 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
00243 {
00244 this->Allocate(number);
00245 this->MaxId = number - 1;
00246 this->DataChanged();
00247 }
00248
00249 inline void vtkBitArray::SetValue(vtkIdType id, int value)
00250 {
00251 if (value)
00252 {
00253 this->Array[id/8] |= (0x80 >> id%8);
00254 }
00255 else
00256 {
00257 this->Array[id/8] &= (~(0x80 >> id%8));
00258 }
00259 this->DataChanged();
00260 }
00261
00262 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00263 {
00264 if ( id >= this->Size )
00265 {
00266 this->ResizeAndExtend(id+1);
00267 }
00268 if (i)
00269 {
00270 this->Array[id/8] |= (0x80 >> id%8);
00271 }
00272 else
00273 {
00274 this->Array[id/8] &= (~(0x80 >> id%8));
00275 }
00276 if ( id > this->MaxId )
00277 {
00278 this->MaxId = id;
00279 }
00280 this->DataChanged();
00281 }
00282
00283 inline void vtkBitArray::InsertVariantValue(vtkIdType id, vtkVariant value)
00284 {
00285 this->InsertValue(id, value.ToInt());
00286 }
00287
00288 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00289 {
00290 this->InsertValue (++this->MaxId,i);
00291 this->DataChanged();
00292 return this->MaxId;
00293 }
00294
00295 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00296
00297 #endif
00298