00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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
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 int 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* WriteVoidPointer(vtkIdType id, vtkIdType number)
00123 { return this->WritePointer(id, number); }
00124 void *GetVoidPointer(vtkIdType id)
00125 {return (void *)this->GetPointer(id);};
00127
00129 void DeepCopy(vtkDataArray *da);
00130
00132
00138 void SetArray(unsigned char* array, vtkIdType size, int save);
00139 void SetVoidArray(void *array, vtkIdType size, int save)
00140 {this->SetArray((unsigned char *)array, size, save);};
00142
00143
00144 protected:
00145 vtkBitArray(vtkIdType numComp=1);
00146 ~vtkBitArray();
00147
00148 unsigned char *Array;
00149 unsigned char *ResizeAndExtend(vtkIdType sz);
00150
00151
00152 int TupleSize;
00153 double *Tuple;
00154
00155 int SaveUserArray;
00156
00157 private:
00158
00159 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
00160
00161 private:
00162 vtkBitArray(const vtkBitArray&);
00163 void operator=(const vtkBitArray&);
00164 };
00165
00166 inline void vtkBitArray::SetNumberOfValues(vtkIdType number)
00167 {
00168 this->Allocate(number);
00169 this->MaxId = number - 1;
00170 }
00171
00172 inline void vtkBitArray::SetValue(vtkIdType id, int value)
00173 {
00174 if (value)
00175 {
00176 this->Array[id/8] |= (0x80 >> id%8);
00177 }
00178 else
00179 {
00180 this->Array[id/8] &= (~(0x80 >> id%8));
00181 }
00182 }
00183
00184 inline void vtkBitArray::InsertValue(vtkIdType id, int i)
00185 {
00186 if ( id >= this->Size )
00187 {
00188 this->ResizeAndExtend(id+1);
00189 }
00190 if (i)
00191 {
00192 this->Array[id/8] |= (0x80 >> id%8);
00193 }
00194 else
00195 {
00196 this->Array[id/8] &= (~(0x80 >> id%8));
00197 }
00198 if ( id > this->MaxId )
00199 {
00200 this->MaxId = id;
00201 }
00202 }
00203
00204 inline vtkIdType vtkBitArray::InsertNextValue(int i)
00205 {
00206 this->InsertValue (++this->MaxId,i); return this->MaxId;
00207 }
00208
00209 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
00210
00211 #endif
00212