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:
40 
43  static vtkIdList *New();
44  vtkTypeMacro(vtkIdList,vtkObject);
45  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
51  void Initialize();
52 
58  int Allocate(const vtkIdType sz, const int strategy=0);
59 
63  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
64 
69  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
70  {return this->Ids[i];}
71 
76  void SetNumberOfIds(const vtkIdType number);
77 
83  void SetId(const vtkIdType i, const vtkIdType vtkid)
84  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
85  {this->Ids[i] = vtkid;}
86 
91  void InsertId(const vtkIdType i, const vtkIdType vtkid)
92  VTK_EXPECTS(0 <= i);
93 
97  vtkIdType InsertNextId(const vtkIdType vtkid);
98 
103  vtkIdType InsertUniqueId(const vtkIdType vtkid);
104 
109  void Sort();
110 
114  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
115 
121  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
122 
128  void SetArray(vtkIdType *array, vtkIdType size);
129 
133  void Reset() {this->NumberOfIds = 0;};
134 
138  void Squeeze() {this->Resize(this->NumberOfIds);};
139 
143  void DeepCopy(vtkIdList *ids);
144 
148  void DeleteId(vtkIdType vtkid);
149 
154  vtkIdType IsId(vtkIdType vtkid);
155 
160  void IntersectWith(vtkIdList* otherIds);
161 
166  vtkIdType *Resize(const vtkIdType sz);
167 
171  void IntersectWith(vtkIdList& otherIds) {
172  this->IntersectWith(&otherIds); };
173 
174 protected:
175  vtkIdList();
176  ~vtkIdList() override;
177 
181 
182 private:
183  vtkIdList(const vtkIdList&) = delete;
184  void operator=(const vtkIdList&) = delete;
185 };
186 
187 // In-lined for performance
188 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
189 {
190  if (i >= this->Size)
191  {
192  this->Resize(i + 1);
193  }
194  this->Ids[i] = vtkid;
195  if (i >= this->NumberOfIds)
196  {
197  this->NumberOfIds = i + 1;
198  }
199 }
200 
201 // In-lined for performance
203 {
204  if ( this->NumberOfIds >= this->Size )
205  {
206  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
207  {
208  return this->NumberOfIds-1;
209  }
210  }
211  this->Ids[this->NumberOfIds++] = vtkid;
212  return this->NumberOfIds-1;
213 }
214 
216 {
217  vtkIdType *ptr, i;
218  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
219  {
220  if ( vtkid == *ptr )
221  {
222  return i;
223  }
224  }
225  return (-1);
226 }
227 
228 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:188
vtkIdType Size
Definition: vtkIdList.h:179
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:138
vtkIdType * Ids
Definition: vtkIdList.h:180
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:83
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:133
vtkIdType GetNumberOfIds()
Return the number of id&#39;s in the list.
Definition: vtkIdList.h:63
int vtkIdType
Definition: vtkType.h:347
vtkIdType NumberOfIds
Definition: vtkIdList.h:178
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:171
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:36
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:215
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:68
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define VTK_EXPECTS(x)
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:202
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:114