VTK
vtkBitArray.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkBitArray.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14=========================================================================*/
28#ifndef vtkBitArray_h
29#define vtkBitArray_h
30
31#include "vtkCommonCoreModule.h" // For export macro
32#include "vtkDataArray.h"
33
34class vtkBitArrayLookup;
35
36class VTKCOMMONCORE_EXPORT vtkBitArray : public vtkDataArray
37{
38public:
39 static vtkBitArray *New();
41 void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
42
47 int Allocate(vtkIdType sz, vtkIdType ext=1000) VTK_OVERRIDE;
48
52 void Initialize() VTK_OVERRIDE;
53
54 // satisfy vtkDataArray API
55 int GetDataType() VTK_OVERRIDE {return VTK_BIT;}
56 int GetDataTypeSize() VTK_OVERRIDE { return 0; }
57
61 void SetNumberOfTuples(vtkIdType number) VTK_OVERRIDE;
62
70 vtkAbstractArray* source) VTK_OVERRIDE;
71
77 vtkAbstractArray* source) VTK_OVERRIDE;
78
84 void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds,
85 vtkAbstractArray *source) VTK_OVERRIDE;
86
92 void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart,
93 vtkAbstractArray* source) VTK_OVERRIDE;
94
101 vtkAbstractArray* source) VTK_OVERRIDE;
102
107 double *GetTuple(vtkIdType i) VTK_OVERRIDE;
108
112 void GetTuple(vtkIdType i, double * tuple) VTK_OVERRIDE;
113
115
118 void SetTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
119 void SetTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
121
123
127 void InsertTuple(vtkIdType i, const float * tuple) VTK_OVERRIDE;
128 void InsertTuple(vtkIdType i, const double * tuple) VTK_OVERRIDE;
130
132
135 vtkIdType InsertNextTuple(const float * tuple) VTK_OVERRIDE;
136 vtkIdType InsertNextTuple(const double * tuple) VTK_OVERRIDE;
138
140
145 void RemoveTuple(vtkIdType id) VTK_OVERRIDE;
146 void RemoveFirstTuple() VTK_OVERRIDE;
147 void RemoveLastTuple() VTK_OVERRIDE;
149
156 void SetComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
157
161 void Squeeze() VTK_OVERRIDE;
162
166 int Resize(vtkIdType numTuples) VTK_OVERRIDE;
167
171 int GetValue(vtkIdType id);
172
180 void SetNumberOfValues(vtkIdType number) VTK_OVERRIDE;
181
186 void SetValue(vtkIdType id, int value);
187
191 void InsertValue(vtkIdType id, int i);
192
196 void SetVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
197
201 void InsertVariantValue(vtkIdType idx, vtkVariant value) VTK_OVERRIDE;
202
203 vtkIdType InsertNextValue(int i);
204
209 void InsertComponent(vtkIdType i, int j, double c) VTK_OVERRIDE;
210
214 unsigned char *GetPointer(vtkIdType id)
215 { return this->Array + id/8; }
216
222 unsigned char *WritePointer(vtkIdType id, vtkIdType number);
223
224 void* WriteVoidPointer(vtkIdType id, vtkIdType number) VTK_OVERRIDE
225 {
226 return this->WritePointer(id, number);
227 }
228
229 void *GetVoidPointer(vtkIdType id) VTK_OVERRIDE
230 {
231 return static_cast<void *>(this->GetPointer(id));
232 }
233
237 void DeepCopy(vtkDataArray *da) VTK_OVERRIDE;
238 void DeepCopy(vtkAbstractArray* aa) VTK_OVERRIDE
239 { this->Superclass::DeepCopy(aa); }
240
242
251#ifndef __VTK_WRAP__
252 void SetArray(unsigned char* array, vtkIdType size, int save);
253#endif
254 void SetVoidArray(void *array, vtkIdType size, int save) VTK_OVERRIDE
255 {
256 this->SetArray(static_cast<unsigned char *>(array), size, save);
257 }
258 void SetVoidArray(void *array, vtkIdType size, int save,
259 int vtkNotUsed(deleteMethod)) VTK_OVERRIDE
260 {
261 this->SetArray(static_cast<unsigned char *>(array), size, save);
262 }
264
269
271
274 vtkIdType LookupValue(vtkVariant value) VTK_OVERRIDE;
275 void LookupValue(vtkVariant value, vtkIdList* ids) VTK_OVERRIDE;
276 vtkIdType LookupValue(int value);
277 void LookupValue(int value, vtkIdList* ids);
279
288 void DataChanged() VTK_OVERRIDE;
289
295 void ClearLookup() VTK_OVERRIDE;
296
297protected:
299 ~vtkBitArray() VTK_OVERRIDE;
300
301 unsigned char *Array; // pointer to data
302 unsigned char *ResizeAndExtend(vtkIdType sz);
303 // function to resize data
304
305 int TupleSize; //used for data conversion
306 double *Tuple;
307
308 int SaveUserArray;
309
310private:
311 // hide superclass' DeepCopy() from the user and the compiler
312 void DeepCopy(vtkDataArray &da) {this->vtkDataArray::DeepCopy(&da);}
313
314private:
315 vtkBitArray(const vtkBitArray&) VTK_DELETE_FUNCTION;
316 void operator=(const vtkBitArray&) VTK_DELETE_FUNCTION;
317
318 vtkBitArrayLookup* Lookup;
319 void UpdateLookup();
320
321};
322
324{
325 this->Allocate(number);
326 this->MaxId = number - 1;
327 this->DataChanged();
328}
329
331{
332 if (value)
333 {
334 this->Array[id/8] = static_cast<unsigned char>(
335 this->Array[id/8] | (0x80 >> id%8));
336 }
337 else
338 {
339 this->Array[id/8] = static_cast<unsigned char>(
340 this->Array[id/8] & (~(0x80 >> id%8)));
341 }
342 this->DataChanged();
343}
344
346{
347 if ( id >= this->Size )
348 {
349 if (!this->ResizeAndExtend(id+1))
350 {
351 return;
352 }
353 }
354 if (i)
355 {
356 this->Array[id/8] = static_cast<unsigned char>(
357 this->Array[id/8] | (0x80 >> id%8));
358 }
359 else
360 {
361 this->Array[id/8] = static_cast<unsigned char>(
362 this->Array[id/8] & (~(0x80 >> id%8)));
363 }
364 if ( id > this->MaxId )
365 {
366 this->MaxId = id;
367 }
368 this->DataChanged();
369}
370
372{
373 this->SetValue(id, value.ToInt());
374}
375
377{
378 this->InsertValue(id, value.ToInt());
379}
380
382{
383 this->InsertValue (++this->MaxId,i);
384 this->DataChanged();
385 return this->MaxId;
386}
387
388inline void vtkBitArray::Squeeze() {this->ResizeAndExtend (this->MaxId+1);}
389
390#endif
Abstract superclass for all arrays.
virtual void DeepCopy(vtkAbstractArray *da)
Deep copy of data.
Abstract superclass to iterate over elements in an vtkAbstractArray.
dynamic, self-adjusting array of bits
Definition: vtkBitArray.h:37
void * WriteVoidPointer(vtkIdType id, vtkIdType number) override
Get the address of a particular data index.
Definition: vtkBitArray.h:224
unsigned char * WritePointer(vtkIdType id, vtkIdType number)
Get the address of a particular data index.
vtkIdType InsertNextTuple(vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at the end in this array.
vtkIdType InsertNextTuple(const double *tuple) override
void DataChanged() override
Tell the array explicitly that the data has changed.
void InsertTuples(vtkIdType dstStart, vtkIdType n, vtkIdType srcStart, vtkAbstractArray *source) override
Copy n consecutive tuples starting at srcStart from the source array to this array,...
void SetNumberOfTuples(vtkIdType number) override
Set the number of n-tuples in the array.
void SetVariantValue(vtkIdType idx, vtkVariant value) override
Set a value in the array from a variant.
Definition: vtkBitArray.h:371
int GetDataTypeSize() override
Return the size of the underlying data type.
Definition: vtkBitArray.h:56
void SetValue(vtkIdType id, int value)
Set the data at a particular index.
Definition: vtkBitArray.h:330
void InsertTuple(vtkIdType i, const double *tuple) override
void GetTuple(vtkIdType i, double *tuple) override
Copy the tuple value into a user-provided array.
void SetTuple(vtkIdType i, const double *tuple) override
VTK_NEWINSTANCE vtkArrayIterator * NewIterator() override
Returns a new vtkBitArrayIterator instance.
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
Definition: vtkBitArray.h:238
void SetTuple(vtkIdType i, const float *tuple) override
Set the tuple value at the ith location in the array.
vtkIdType InsertNextTuple(const float *tuple) override
Insert (memory allocation performed) the tuple onto the end of the array.
void InsertValue(vtkIdType id, int i)
Inserts values and checks to make sure there is enough memory.
Definition: vtkBitArray.h:345
void RemoveFirstTuple() override
void InsertTuple(vtkIdType i, const float *tuple) override
Insert (memory allocation performed) the tuple into the ith location in the array.
void SetNumberOfValues(vtkIdType number) override
Fast method based setting of values without memory checks.
Definition: vtkBitArray.h:323
int Allocate(vtkIdType sz, vtkIdType ext=1000) override
Allocate memory for this array.
void SetVoidArray(void *array, vtkIdType size, int save, int vtkNotUsed(deleteMethod)) override
Definition: vtkBitArray.h:258
vtkIdType InsertNextValue(int i)
Definition: vtkBitArray.h:381
double * GetTuple(vtkIdType i) override
Get a pointer to a tuple at the ith location.
void InsertTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Insert the jth tuple in the source array, at ith location in this array.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetVoidArray(void *array, vtkIdType size, int save) override
Definition: vtkBitArray.h:254
void RemoveTuple(vtkIdType id) override
These methods remove tuples from the data array.
void * GetVoidPointer(vtkIdType id) override
Return a void pointer.
Definition: vtkBitArray.h:229
unsigned char * ResizeAndExtend(vtkIdType sz)
unsigned char * Array
Definition: vtkBitArray.h:301
void SetTuple(vtkIdType i, vtkIdType j, vtkAbstractArray *source) override
Set the tuple at the ith location using the jth tuple in the source array.
void DeepCopy(vtkDataArray *da) override
Deep copy of another bit array.
void SetArray(unsigned char *array, vtkIdType size, int save)
This method lets the user specify data to be held by the array.
void InsertTuples(vtkIdList *dstIds, vtkIdList *srcIds, vtkAbstractArray *source) override
Copy the tuples indexed in srcIds from the source array to the tuple locations indexed by dstIds in t...
static vtkBitArray * New()
void InsertVariantValue(vtkIdType idx, vtkVariant value) override
Inserts values from a variant and checks to ensure there is enough memory.
Definition: vtkBitArray.h:376
void Squeeze() override
Free any unneeded memory.
Definition: vtkBitArray.h:388
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
void DeepCopy(vtkAbstractArray *aa) override
Deep copy of data.
list of point or cell ids
Definition: vtkIdList.h:37
a simple class to control print indentation
Definition: vtkIndent.h:40
A atomic type representing the union of many types.
Definition: vtkVariant.h:76
int ToInt(bool *valid) const
@ value
Definition: vtkX3D.h:220
@ size
Definition: vtkX3D.h:253
void DeepCopy(vtkPistonReference *self, vtkPistonReference *other)
boost::graph_traits< vtkGraph * >::vertex_descriptor source(boost::graph_traits< vtkGraph * >::edge_descriptor e, vtkGraph *)
int vtkIdType
Definition: vtkType.h:287
#define VTK_BIT
Definition: vtkType.h:48
void save(Archiver &ar, const vtkUnicodeString &str, const unsigned int vtkNotUsed(version))
#define VTK_NEWINSTANCE