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
00136 void InsertValue(vtkIdType id, int i);
00137 vtkIdType InsertNextValue(int i);
00139
00143 virtual void InsertComponent(vtkIdType i, int j, double c);
00144
00146 unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;}
00147
00149
00152 unsigned char *WritePointer(vtkIdType id, vtkIdType number);
00153 void* WriteVoidPointer(vtkIdType id, vtkIdType number)
00154 { return this->WritePointer(id, number); }
00155 void *GetVoidPointer(vtkIdType id)
00156 {
00157 return static_cast<void *>(this->GetPointer(id));
00158 }
00160
00162
00163 void DeepCopy(vtkDataArray *da);
00164 void DeepCopy(vtkAbstractArray* aa)
00165 { this->Superclass::DeepCopy(aa); }
00167
00169
00176 void SetArray(unsigned char* array, vtkIdType size, int save);
00177 void SetVoidArray(void *array, vtkIdType size, int save)
00178 {
00179 this->SetArray(static_cast<unsigned char *>(array), size, save);
00180 }
00182
00184 vtkArrayIterator* NewIterator();
00185
00186
00188
00189 virtual vtkIdType LookupValue(vtkVariant value);
00190 virtual void LookupValue(vtkVariant value, vtkIdList* ids);
00191
00192 vtkIdType LookupValue(int value);
00193 void LookupValue(int value, vtkIdList* ids);
00195
00202 virtual void DataChanged();
00203
00207 virtual void ClearLookup();
00208
00209 protected:
00210 vtkBitArray(vtkIdType numComp=1);
00211 ~vtkBitArray();
00212
00213 unsigned char *Array;
00214 unsigned char *ResizeAndExtend(vtkIdType sz);
00215
00216
00217 int TupleSize;
00218 double *Tuple;
00219
00220 int SaveUserArray;
00221
00222 private:
00223
00224 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00225
00226 private:
00227 vtkBitArray(const vtkBitArray&);
00228 void operator=(const vtkBitArray&);
00229
00230
00231 vtkBitArrayLookup* Lookup;
00232 void UpdateLookup();
00233
00234 };
00235
00236 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
00237 {
00238 this->Allocate(number);
00239 this->MaxId = number - 1;
00240 this->DataChanged();
00241 }
00242
00243 inline void vtkBitArray::SetValue(vtkIdType id, int value)
00244 {
00245 if (value)
00246 {
00247 this->Array[id/8] |= (0x80 >> id%8);
00248 }
00249 else
00250 {
00251 this->Array[id/8] &= (~(0x80 >> id%8));
00252 }
00253 this->DataChanged();
00254 }
00255
00256 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00257 {
00258 if ( id >= this->Size )
00259 {
00260 this->ResizeAndExtend(id+1);
00261 }
00262 if (i)
00263 {
00264 this->Array[id/8] |= (0x80 >> id%8);
00265 }
00266 else
00267 {
00268 this->Array[id/8] &= (~(0x80 >> id%8));
00269 }
00270 if ( id > this->MaxId )
00271 {
00272 this->MaxId = id;
00273 }
00274 this->DataChanged();
00275 }
00276
00277 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00278 {
00279 this->InsertValue (++this->MaxId,i);
00280 this->DataChanged();
00281 return this->MaxId;
00282 }
00283
00284 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00285
00286 #endif
00287