VTK  9.2.6
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 =========================================================================*/
27 #ifndef vtkIdList_h
28 #define vtkIdList_h
29 
30 #include "vtkCommonCoreModule.h" // For export macro
31 #include "vtkObject.h"
32 
33 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
34 {
35 public:
37 
40  static vtkIdList* New();
41  vtkTypeMacro(vtkIdList, vtkObject);
42  void PrintSelf(ostream& os, vtkIndent indent) override;
44 
48  void Initialize();
49 
55  int Allocate(const vtkIdType sz, const int strategy = 0);
56 
60  vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
61 
65  vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
66  {
67  return this->Ids[i];
68  }
69 
74  {
75  for (int i = 0; i < this->NumberOfIds; i++)
76  if (this->Ids[i] == id)
77  return i;
78  return -1;
79  }
80 
85  void SetNumberOfIds(const vtkIdType number);
86 
92  void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
93  {
94  this->Ids[i] = vtkid;
95  }
96 
101  void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
102 
106  vtkIdType InsertNextId(const vtkIdType vtkid);
107 
112  vtkIdType InsertUniqueId(const vtkIdType vtkid);
113 
118  void Sort();
119 
124  void Fill(vtkIdType value);
125 
129  vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
130 
136  vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
137 
143  void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
144 
148  void Reset() { this->NumberOfIds = 0; }
149 
153  void Squeeze() { this->Resize(this->NumberOfIds); }
154 
158  void DeepCopy(vtkIdList* ids);
159 
163  void DeleteId(vtkIdType vtkid);
164 
169  vtkIdType IsId(vtkIdType vtkid);
170 
175  void IntersectWith(vtkIdList* otherIds);
176 
181  vtkIdType* Resize(const vtkIdType sz);
182 
183 #ifndef __VTK_WRAP__
184 
190  vtkIdType* Release();
191 #endif
192 
194 
197  vtkIdType* begin() { return this->Ids; }
198  vtkIdType* end() { return this->Ids + this->NumberOfIds; }
199  const vtkIdType* begin() const { return this->Ids; }
200  const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
202 protected:
203  vtkIdList();
204  ~vtkIdList() override;
205 
210 
211 private:
212  vtkIdList(const vtkIdList&) = delete;
213  void operator=(const vtkIdList&) = delete;
214 };
215 
216 // In-lined for performance
217 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
218 {
219  if (i >= this->Size)
220  {
221  this->Resize(i + 1);
222  }
223  this->Ids[i] = vtkid;
224  if (i >= this->NumberOfIds)
225  {
226  this->NumberOfIds = i + 1;
227  }
228 }
229 
230 // In-lined for performance
232 {
233  if (this->NumberOfIds >= this->Size)
234  {
235  if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
236  {
237  return this->NumberOfIds - 1;
238  }
239  }
240  this->Ids[this->NumberOfIds++] = vtkid;
241  return this->NumberOfIds - 1;
242 }
243 
245 {
246  vtkIdType *ptr, i;
247  for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
248  {
249  if (vtkid == *ptr)
250  {
251  return i;
252  }
253  }
254  return (-1);
255 }
256 
257 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:217
vtkIdType Size
Definition: vtkIdList.h:207
abstract base class for most VTK objects
Definition: vtkObject.h:62
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:153
vtkIdType * Ids
Definition: vtkIdList.h:208
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:92
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:148
void Sort(RandomIt bitr, RandomIt eitr, BackToFront< T > &me)
int vtkIdType
Definition: vtkType.h:332
vtkIdType NumberOfIds
Definition: vtkIdList.h:206
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:33
const vtkIdType * end() const
To support range-based for loops.
Definition: vtkIdList.h:200
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:60
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:244
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:199
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:65
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:198
bool ManageMemory
Definition: vtkIdList.h:209
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:73
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
#define VTK_EXPECTS(x)
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:197
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:231
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:129
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).