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 00079 virtual vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray* source); 00080 00083 double *GetTuple(vtkIdType i); 00084 00086 void GetTuple(vtkIdType i, double * tuple); 00087 00089 00090 void SetTuple(vtkIdType i, const float * tuple); 00091 void SetTuple(vtkIdType i, const double * tuple); 00093 00095 00097 void InsertTuple(vtkIdType i, const float * tuple); 00098 void InsertTuple(vtkIdType i, const double * tuple); 00100 00102 00104 vtkIdType InsertNextTuple(const float * tuple); 00105 vtkIdType InsertNextTuple(const double * tuple); 00107 00109 00112 virtual void RemoveTuple(vtkIdType id); 00113 virtual void RemoveFirstTuple(); 00114 virtual void RemoveLastTuple(); 00116 00121 void SetComponent(vtkIdType i, int j, double c); 00122 00124 void Squeeze(); 00125 00127 virtual int Resize(vtkIdType numTuples); 00128 00130 int GetValue(vtkIdType id); 00131 00137 void SetNumberOfValues(vtkIdType number); 00138 00141 void SetValue(vtkIdType id, int value); 00142 00144 void InsertValue(vtkIdType id, int i); 00145 00147 void SetVariantValue(vtkIdType idx, vtkVariant value); 00148 00149 vtkIdType InsertNextValue(int i); 00150 00154 virtual void InsertComponent(vtkIdType i, int j, double c); 00155 00157 unsigned char *GetPointer(vtkIdType id) {return this->Array + id/8;} 00158 00160 00163 unsigned char *WritePointer(vtkIdType id, vtkIdType number); 00164 void* WriteVoidPointer(vtkIdType id, vtkIdType number) 00165 { return this->WritePointer(id, number); } 00166 void *GetVoidPointer(vtkIdType id) 00167 { 00168 return static_cast<void *>(this->GetPointer(id)); 00169 } 00171 00173 00174 void DeepCopy(vtkDataArray *da); 00175 void DeepCopy(vtkAbstractArray* aa) 00176 { this->Superclass::DeepCopy(aa); } 00178 00180 00187 #ifndef __WRAP__ 00188 void SetArray(unsigned char* array, vtkIdType size, int save); 00189 #endif 00190 void SetVoidArray(void *array, vtkIdType size, int save) 00191 { 00192 this->SetArray(static_cast<unsigned char *>(array), size, save); 00193 } 00195 00197 vtkArrayIterator* NewIterator(); 00198 00200 00201 virtual vtkIdType LookupValue(vtkVariant value); 00202 virtual void LookupValue(vtkVariant value, vtkIdList* ids); 00203 vtkIdType LookupValue(int value); 00204 void LookupValue(int value, vtkIdList* ids); 00206 00213 virtual void DataChanged(); 00214 00218 virtual void ClearLookup(); 00219 00220 protected: 00221 vtkBitArray(); 00222 ~vtkBitArray(); 00223 00224 unsigned char *Array; // pointer to data 00225 unsigned char *ResizeAndExtend(vtkIdType sz); 00226 // function to resize data 00227 00228 int TupleSize; //used for data conversion 00229 double *Tuple; 00230 00231 int SaveUserArray; 00232 00233 private: 00234 // hide superclass' DeepCopy() from the user and the compiler 00235 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);} 00236 00237 private: 00238 vtkBitArray(const vtkBitArray&); // Not implemented. 00239 void operator=(const vtkBitArray&); // Not implemented. 00240 00241 //BTX 00242 vtkBitArrayLookup* Lookup; 00243 void UpdateLookup(); 00244 //ETX 00245 }; 00246 00247 inline void vtkBitArray::SetNumberOfValues(vtkIdType number) 00248 { 00249 this->Allocate(number); 00250 this->MaxId = number - 1; 00251 this->DataChanged(); 00252 } 00253 00254 inline void vtkBitArray::SetValue(vtkIdType id, int value) 00255 { 00256 if (value) 00257 { 00258 this->Array[id/8] = static_cast<unsigned char>( 00259 this->Array[id/8] | (0x80 >> id%8)); 00260 } 00261 else 00262 { 00263 this->Array[id/8] = static_cast<unsigned char>( 00264 this->Array[id/8] & (~(0x80 >> id%8))); 00265 } 00266 this->DataChanged(); 00267 } 00268 00269 inline void vtkBitArray::InsertValue(vtkIdType id, int i) 00270 { 00271 if ( id >= this->Size ) 00272 { 00273 this->ResizeAndExtend(id+1); 00274 } 00275 if (i) 00276 { 00277 this->Array[id/8] = static_cast<unsigned char>( 00278 this->Array[id/8] | (0x80 >> id%8)); 00279 } 00280 else 00281 { 00282 this->Array[id/8] = static_cast<unsigned char>( 00283 this->Array[id/8] & (~(0x80 >> id%8))); 00284 } 00285 if ( id > this->MaxId ) 00286 { 00287 this->MaxId = id; 00288 } 00289 this->DataChanged(); 00290 } 00291 00292 inline void vtkBitArray::SetVariantValue(vtkIdType id, vtkVariant value) 00293 { 00294 this->SetValue(id, value.ToInt()); 00295 } 00296 00297 inline vtkIdType vtkBitArray::InsertNextValue(int i) 00298 { 00299 this->InsertValue (++this->MaxId,i); 00300 this->DataChanged(); 00301 return this->MaxId; 00302 } 00303 00304 inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);} 00305 00306 #endif 00307