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 "vtkCommonCoreModule.h" // For export macro 00031 #include "vtkDataArray.h" 00032 00033 class vtkBitArrayLookup; 00034 00035 class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray 00036 { 00037 public: 00038 static vtkBitArray *New(); 00039 vtkTypeMacro(vtkBitArray,vtkDataArray); 00040 void PrintSelf(ostream& os, vtkIndent indent); 00041 00044 int Allocate(vtkIdType sz, vtkIdType ext=1000); 00045 00047 void Initialize(); 00048 00049 // satisfy vtkDataArray API 00050 int GetDataType() {return VTK_BIT;}; 00051 int GetDataTypeSize() { return 0; } 00052 00054 void SetNumberOfTuples(vtkIdType number); 00055 00061 virtual void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source); 00062 00066 virtual void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray* source); 00067 00069 00072 virtual void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, 00073 vtkAbstractArray *source); 00075 00077 00080 virtual void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, 00081 vtkAbstractArray* source); 00083 00087 virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source); 00088 00091 double *GetTuple(vtkIdType i); 00092 00094 void GetTuple(vtkIdType i, double * tuple); 00095 00097 00098 void SetTuple(vtkIdType i, const float * tuple); 00099 void SetTuple(vtkIdType i, const double * tuple); 00101 00103 00105 void InsertTuple(vtkIdType i, const float * tuple); 00106 void InsertTuple(vtkIdType i, const double * tuple); 00108 00110 00112 vtkIdType InsertNextTuple(const float * tuple); 00113 vtkIdType InsertNextTuple(const double * tuple); 00115 00117 00120 virtual void RemoveTuple(vtkIdType id); 00121 virtual void RemoveFirstTuple(); 00122 virtual void RemoveLastTuple(); 00124 00129 void SetComponent(vtkIdType i, int j, double c); 00130 00132 void Squeeze(); 00133 00135 virtual int Resize(vtkIdType numTuples); 00136 00138 int GetValue(vtkIdType id); 00139 00145 void SetNumberOfValues(vtkIdType number); 00146 00149 void SetValue(vtkIdType id, int value); 00150 00152 void InsertValue(vtkIdType id, int i); 00153 00155 void SetVariantValue(vtkIdType idx, vtkVariant value); 00156 00157 vtkIdType InsertNextValue(int i); 00158 00162 virtual void InsertComponent(vtkIdType i, int j, double c); 00163 00165 unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;} 00166 00168 00171 unsigned char *WritePointer(vtkIdType id, vtkIdType number); 00172 void* WriteVoidPointer(vtkIdType id, vtkIdType number) 00173 { return this->WritePointer(id, number); } 00174 void *GetVoidPointer(vtkIdType id) 00175 { 00176 return static_cast<void *>(this->GetPointer(id)); 00177 } 00179 00181 00182 void DeepCopy(vtkDataArray *da); 00183 void DeepCopy(vtkAbstractArray* aa) 00184 { this->Superclass::DeepCopy(aa); } 00186 00188 00195 #ifndef __WRAP__ 00196 void SetArray(unsigned char* array, vtkIdType size, int save); 00197 #endif 00198 void SetVoidArray(void *array, vtkIdType size, int save) 00199 { 00200 this->SetArray(static_cast<unsigned char *>(array), size, save); 00201 } 00203 00205 vtkArrayIterator* NewIterator(); 00206 00208 00209 virtual vtkIdType LookupValue(vtkVariant value); 00210 virtual void LookupValue(vtkVariant value, vtkIdList* ids); 00211 vtkIdType LookupValue(int value); 00212 void LookupValue(int value, vtkIdList* ids); 00214 00221 virtual void DataChanged(); 00222 00226 virtual void ClearLookup(); 00227 00228 protected: 00229 vtkBitArray(); 00230 ~vtkBitArray(); 00231 00232 unsigned char *Array; // pointer to data 00233 unsigned char *ResizeAndExtend(vtkIdType sz); 00234 // function to resize data 00235 00236 int TupleSize; //used for data conversion 00237 double *Tuple; 00238 00239 int SaveUserArray; 00240 00241 private: 00242 // hide superclass' DeepCopy() from the user and the compiler 00243 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);} 00244 00245 private: 00246 vtkBitArray(const vtkBitArray&); // Not implemented. 00247 void operator=(const vtkBitArray&); // Not implemented. 00248 00249 //BTX 00250 vtkBitArrayLookup* Lookup; 00251 void UpdateLookup(); 00252 //ETX 00253 }; 00254 00255 inline void vtkBitArray::SetNumberOfValues(vtkIdType number) 00256 { 00257 this->Allocate(number); 00258 this->MaxId = number - 1; 00259 this->DataChanged(); 00260 } 00261 00262 inline void vtkBitArray::SetValue(vtkIdType id, int value) 00263 { 00264 if (value) 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 this->DataChanged(); 00275 } 00276 00277 inline void vtkBitArray::InsertValue(vtkIdType id, int i) 00278 { 00279 if ( id >= this->Size ) 00280 { 00281 this->ResizeAndExtend(id+1); 00282 } 00283 if (i) 00284 { 00285 this->Array[id/8] = static_cast<unsigned char>( 00286 this->Array[id/8] | (0x80 >> id%8)); 00287 } 00288 else 00289 { 00290 this->Array[id/8] = static_cast<unsigned char>( 00291 this->Array[id/8] & (~(0x80 >> id%8))); 00292 } 00293 if ( id > this->MaxId ) 00294 { 00295 this->MaxId = id; 00296 } 00297 this->DataChanged(); 00298 } 00299 00300 inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value) 00301 { 00302 this->SetValue(id, value.ToInt()); 00303 } 00304 00305 inline vtkIdType vtkBitArray::InsertNextValue(int i) 00306 { 00307 this->InsertValue (++this->MaxId,i); 00308 this->DataChanged(); 00309 return this->MaxId; 00310 } 00311 00312 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);} 00313 00314 #endif 00315