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 00138 void SetVariantValue(vtkIdType idx, vtkVariant value); 00139 00140 vtkIdType InsertNextValue(int i); 00141 00145 virtual void InsertComponent(vtkIdType i, int j, double c); 00146 00148 unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;} 00149 00151 00154 unsigned char *WritePointer(vtkIdType id, vtkIdType number); 00155 void* WriteVoidPointer(vtkIdType id, vtkIdType number) 00156 { return this->WritePointer(id, number); } 00157 void *GetVoidPointer(vtkIdType id) 00158 { 00159 return static_cast<void *>(this->GetPointer(id)); 00160 } 00162 00164 00165 void DeepCopy(vtkDataArray *da); 00166 void DeepCopy(vtkAbstractArray* aa) 00167 { this->Superclass::DeepCopy(aa); } 00169 00171 00178 void SetArray(unsigned char* array, vtkIdType size, int save); 00179 void SetVoidArray(void *array, vtkIdType size, int save) 00180 { 00181 this->SetArray(static_cast<unsigned char *>(array), size, save); 00182 } 00184 00186 vtkArrayIterator* NewIterator(); 00187 00189 00190 virtual vtkIdType LookupValue(vtkVariant value); 00191 virtual void LookupValue(vtkVariant value, vtkIdList* ids); 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; // pointer to data 00214 unsigned char *ResizeAndExtend(vtkIdType sz); 00215 // function to resize data 00216 00217 int TupleSize; //used for data conversion 00218 double *Tuple; 00219 00220 int SaveUserArray; 00221 00222 private: 00223 // hide superclass' DeepCopy() from the user and the compiler 00224 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);} 00225 00226 private: 00227 vtkBitArray(const vtkBitArray&); // Not implemented. 00228 void operator=(const vtkBitArray&); // Not implemented. 00229 00230 //BTX 00231 vtkBitArrayLookup* Lookup; 00232 void UpdateLookup(); 00233 //ETX 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] = static_cast<unsigned char>( 00248 this->Array[id/8] | (0x80 >> id%8)); 00249 } 00250 else 00251 { 00252 this->Array[id/8] = static_cast<unsigned char>( 00253 this->Array[id/8] & (~(0x80 >> id%8))); 00254 } 00255 this->DataChanged(); 00256 } 00257 00258 inline void vtkBitArray::InsertValue(vtkIdType id, int i) 00259 { 00260 if ( id >= this->Size ) 00261 { 00262 this->ResizeAndExtend(id+1); 00263 } 00264 if (i) 00265 { 00266 this->Array[id/8] = static_cast<unsigned char>( 00267 this->Array[id/8] | (0x80 >> id%8)); 00268 } 00269 else 00270 { 00271 this->Array[id/8] = static_cast<unsigned char>( 00272 this->Array[id/8] & (~(0x80 >> id%8))); 00273 } 00274 if ( id > this->MaxId ) 00275 { 00276 this->MaxId = id; 00277 } 00278 this->DataChanged(); 00279 } 00280 00281 inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value) 00282 { 00283 this->SetValue(id, value.ToInt()); 00284 } 00285 00286 inline vtkIdType vtkBitArray::InsertNextValue(int i) 00287 { 00288 this->InsertValue (++this->MaxId,i); 00289 this->DataChanged(); 00290 return this->MaxId; 00291 } 00292 00293 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);} 00294 00295 #endif 00296