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 =========================================================================*/
24 #ifndef vtkIdList_h
25 #define vtkIdList_h
26 
27 #include "vtkCommonCoreModule.h" // For export macro
28 #include "vtkObject.h"
29 
30 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
31 {
32 public:
33  static vtkIdList *New();
34 
35  void Initialize();
36 
42  int Allocate(const vtkIdType sz, const int strategy=0);
43 
44  vtkTypeMacro(vtkIdList,vtkObject);
45  void PrintSelf(ostream& os, vtkIndent indent) VTK_OVERRIDE;
46 
50  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
51 
55  vtkIdType GetId(const vtkIdType i) {return this->Ids[i];};
56 
61  void SetNumberOfIds(const vtkIdType number);
62 
68  void SetId(const vtkIdType i, const vtkIdType vtkid) {this->Ids[i] = vtkid;};
69 
74  void InsertId(const vtkIdType i, const vtkIdType vtkid);
75 
79  vtkIdType InsertNextId(const vtkIdType vtkid);
80 
85  vtkIdType InsertUniqueId(const vtkIdType vtkid);
86 
90  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
91 
97  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
98 
104  void SetArray(vtkIdType *array, vtkIdType size);
105 
109  void Reset() {this->NumberOfIds = 0;};
110 
114  void Squeeze() {this->Resize(this->NumberOfIds);};
115 
119  void DeepCopy(vtkIdList *ids);
120 
124  void DeleteId(vtkIdType vtkid);
125 
130  vtkIdType IsId(vtkIdType vtkid);
131 
136  void IntersectWith(vtkIdList* otherIds);
137 
142  vtkIdType *Resize(const vtkIdType sz);
143 
144  // This method should become legacy
145  void IntersectWith(vtkIdList& otherIds) {
146  this->IntersectWith(&otherIds); };
147 
148 protected:
149  vtkIdList();
150  ~vtkIdList() VTK_OVERRIDE;
151 
155 
156 private:
157  vtkIdList(const vtkIdList&) VTK_DELETE_FUNCTION;
158  void operator=(const vtkIdList&) VTK_DELETE_FUNCTION;
159 };
160 
161 // In-lined for performance
162 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
163 {
164  if (i >= this->Size)
165  {
166  this->Resize(i + 1);
167  }
168  this->Ids[i] = vtkid;
169  if (i >= this->NumberOfIds)
170  {
171  this->NumberOfIds = i + 1;
172  }
173 }
174 
175 // In-lined for performance
177 {
178  if ( this->NumberOfIds >= this->Size )
179  {
180  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
181  {
182  return this->NumberOfIds-1;
183  }
184  }
185  this->Ids[this->NumberOfIds++] = vtkid;
186  return this->NumberOfIds-1;
187 }
188 
190 {
191  vtkIdType *ptr, i;
192  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
193  {
194  if ( vtkid == *ptr )
195  {
196  return i;
197  }
198  }
199  return (-1);
200 }
201 
202 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:162
vtkIdType Size
Definition: vtkIdList.h:153
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:114
vtkIdType * Ids
Definition: vtkIdList.h:154
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:68
void Reset()
Reset to an empty state.
Definition: vtkIdList.h:109
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:50
int vtkIdType
Definition: vtkType.h:345
vtkIdType NumberOfIds
Definition: vtkIdList.h:152
void IntersectWith(vtkIdList &otherIds)
Definition: vtkIdList.h:145
a simple class to control print indentation
Definition: vtkIndent.h:33
list of point or cell ids
Definition: vtkIdList.h:30
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:189
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:55
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:176
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:90