VTK
|
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 "vtkDataArray.h" 00031 00032 class vtkBitArrayLookup; 00033 00034 class VTK_COMMON_EXPORT vtkBitArray : public vtkDataArray 00035 { 00036 public: 00037 static vtkBitArray *New(); 00038 vtkTypeMacro(vtkBitArray,vtkDataArray); 00039 void PrintSelf(ostream& os, vtkIndent indent); 00040 00043 int Allocate(vtkIdType sz, vtkIdType ext=1000); 00044 00046 void Initialize(); 00047 00048 // satisfy vtkDataArray API 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 //BTX 00139 00140 void InsertVariantValue(vtkIdType idx, vtkVariant value); 00141 //ETX 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 //BTX 00194 00195 virtual vtkIdType LookupValue(vtkVariant value); 00196 virtual void LookupValue(vtkVariant value, vtkIdList* ids); 00197 //ETX 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; // pointer to data 00220 unsigned char *ResizeAndExtend(vtkIdType sz); 00221 // function to resize data 00222 00223 int TupleSize; //used for data conversion 00224 double *Tuple; 00225 00226 int SaveUserArray; 00227 00228 private: 00229 // hide superclass' DeepCopy() from the user and the compiler 00230 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);} 00231 00232 private: 00233 vtkBitArray(const vtkBitArray&); // Not implemented. 00234 void operator=(const vtkBitArray&); // Not implemented. 00235 00236 //BTX 00237 vtkBitArrayLookup* Lookup; 00238 void UpdateLookup(); 00239 //ETX 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] = static_cast<unsigned char>( 00254 this->Array[id/8] | (0x80 >> id%8)); 00255 } 00256 else 00257 { 00258 this->Array[id/8] = static_cast<unsigned char>( 00259 this->Array[id/8] & (~(0x80 >> id%8))); 00260 } 00261 this->DataChanged(); 00262 } 00263 00264 inline void vtkBitArray::InsertValue(vtkIdType id, int i) 00265 { 00266 if ( id >= this->Size ) 00267 { 00268 this->ResizeAndExtend(id+1); 00269 } 00270 if (i) 00271 { 00272 this->Array[id/8] = static_cast<unsigned char>( 00273 this->Array[id/8] | (0x80 >> id%8)); 00274 } 00275 else 00276 { 00277 this->Array[id/8] = static_cast<unsigned char>( 00278 this->Array[id/8] & (~(0x80 >> id%8))); 00279 } 00280 if ( id > this->MaxId ) 00281 { 00282 this->MaxId = id; 00283 } 00284 this->DataChanged(); 00285 } 00286 00287 inline void vtkBitArray::InsertVariantValue(vtkIdType id, vtkVariant value) 00288 { 00289 this->InsertValue(id, value.ToInt()); 00290 } 00291 00292 inline vtkIdType vtkBitArray::InsertNextValue(int i) 00293 { 00294 this->InsertValue (++this->MaxId,i); 00295 this->DataChanged(); 00296 return this->MaxId; 00297 } 00298 00299 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);} 00300 00301 #endif 00302