VTK
vtkIdList.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkIdList.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 =========================================================================*/
30 #ifndef vtkIdList_h
31 #define vtkIdList_h
32 
33 #include "vtkCommonCoreModule.h" // For export macro
34 #include "vtkObject.h"
35 
36 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
37 {
38 public:
39  static vtkIdList *New();
40 
41  void Initialize();
42 
48  int Allocate(const vtkIdType sz, const int strategy=0);
49 
50  vtkTypeMacro(vtkIdList,vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
52 
56  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
57 
61  vtkIdType GetId(const vtkIdType i) {return this->Ids[i];};
62 
67  void SetNumberOfIds(const vtkIdType number);
68 
74  void SetId(const vtkIdType i, const vtkIdType vtkid) {this->Ids[i] = vtkid;};
75 
80  void InsertId(const vtkIdType i, const vtkIdType vtkid);
81 
85  vtkIdType InsertNextId(const vtkIdType vtkid);
86 
92 
96  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
97 
103  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
104 
111 
115  void Reset() {this->NumberOfIds = 0;};
116 
120  void Squeeze() {this->Resize(this->NumberOfIds);};
121 
125  void DeepCopy(vtkIdList *ids);
126 
130  void DeleteId(vtkIdType vtkid);
131 
136  vtkIdType IsId(vtkIdType vtkid);
137 
142  void IntersectWith(vtkIdList* otherIds);
143 
149 
150  // This method should become legacy
151  void IntersectWith(vtkIdList& otherIds) {
152  this->IntersectWith(&otherIds); };
153 
154 protected:
156  ~vtkIdList() VTK_OVERRIDE;
157 
158  vtkIdType NumberOfIds;
159  vtkIdType Size;
160  vtkIdType *Ids;
161 
162 private:
163  vtkIdList(const vtkIdList&) VTK_DELETE_FUNCTION;
164  void operator=(const vtkIdList&) VTK_DELETE_FUNCTION;
165 };
166 
167 // In-lined for performance
168 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
169 {
170  if (i >= this->Size)
171  {
172  this->Resize(i + 1);
173  }
174  this->Ids[i] = vtkid;
175  if (i >= this->NumberOfIds)
176  {
177  this->NumberOfIds = i + 1;
178  }
179 }
180 
181 // In-lined for performance
183 {
184  if ( this->NumberOfIds >= this->Size )
185  {
186  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
187  {
188  return this->NumberOfIds-1;
189  }
190  }
191  this->Ids[this->NumberOfIds++] = vtkid;
192  return this->NumberOfIds-1;
193 }
194 
196 {
197  vtkIdType *ptr, i;
198  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
199  {
200  if ( vtkid == *ptr )
201  {
202  return i;
203  }
204  }
205  return (-1);
206 }
207 
208 #endif
list of point or cell ids
Definition: vtkIdList.h:37
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:96
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:56
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
~vtkIdList() override
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:182
vtkIdType InsertUniqueId(const vtkIdType vtkid)
If id is not already in list, insert it and return location in list.
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:120
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
void Initialize()
int Allocate(const vtkIdType sz, const int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
void SetArray(vtkIdType *array, vtkIdType size)
Specify an array of vtkIdType to use as the id list.
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:74
vtkIdType IsId(vtkIdType vtkid)
Return -1 if id specified is not contained in the list; otherwise return the position in the list.
Definition: vtkIdList.h:195
void Reset()
Reset to an empty state.
Definition: vtkIdList.h:115
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:61
static vtkIdList * New()
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType * WritePointer(const vtkIdType i, const vtkIdType number)
Get a pointer to a particular data index.
void IntersectWith(vtkIdList &otherIds)
Definition: vtkIdList.h:151
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:60
@ size
Definition: vtkX3D.h:253
int vtkIdType
Definition: vtkType.h:287