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=========================================================================*/
36#ifndef vtkIdList_h
37#define vtkIdList_h
38
39#include "vtkCommonCoreModule.h" // For export macro
40#include "vtkObject.h"
41
42class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
43{
44public:
46
49 static vtkIdList* New();
50 vtkTypeMacro(vtkIdList, vtkObject);
51 void PrintSelf(ostream& os, vtkIndent indent) override;
53
57 void Initialize();
58
64 int Allocate(const vtkIdType sz, const int strategy = 0);
65
69 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
70
74 vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
75 {
76 return this->Ids[i];
77 }
78
83 {
84 for (int i = 0; i < this->NumberOfIds; i++)
85 if (this->Ids[i] == id)
86 return i;
87 return -1;
88 }
89
94 void SetNumberOfIds(const vtkIdType number);
95
101 void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
102 {
103 this->Ids[i] = vtkid;
104 }
105
110 void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
111
115 vtkIdType InsertNextId(const vtkIdType vtkid);
116
122
127 void Sort();
128
133 void Fill(vtkIdType value);
134
138 vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
139
145 vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
146
152 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
153
157 void Reset() { this->NumberOfIds = 0; }
158
162 void Squeeze() { this->Resize(this->NumberOfIds); }
163
167 void DeepCopy(vtkIdList* ids);
168
172 void DeleteId(vtkIdType vtkid);
173
178 vtkIdType IsId(vtkIdType vtkid);
179
184 void IntersectWith(vtkIdList* otherIds);
185
191
192#ifndef __VTK_WRAP__
200#endif
201
203
206 vtkIdType* begin() { return this->Ids; }
207 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
208 const vtkIdType* begin() const { return this->Ids; }
209 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
211protected:
213 ~vtkIdList() override;
214
219
220private:
221 vtkIdList(const vtkIdList&) = delete;
222 void operator=(const vtkIdList&) = delete;
223};
224
225// In-lined for performance
226inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
227{
228 if (i >= this->Size)
229 {
230 this->Resize(i + 1);
231 }
232 this->Ids[i] = vtkid;
233 if (i >= this->NumberOfIds)
234 {
235 this->NumberOfIds = i + 1;
236 }
237}
238
239// In-lined for performance
241{
242 if (this->NumberOfIds >= this->Size)
243 {
244 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
245 {
246 return this->NumberOfIds - 1;
247 }
248 }
249 this->Ids[this->NumberOfIds++] = vtkid;
250 return this->NumberOfIds - 1;
251}
252
254{
255 vtkIdType *ptr, i;
256 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
257 {
258 if (vtkid == *ptr)
259 {
260 return i;
261 }
262 }
263 return (-1);
264}
265
266#endif
list of point or cell ids
Definition vtkIdList.h:43
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition vtkIdList.h:82
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition vtkIdList.h:217
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:226
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition vtkIdList.h:215
~vtkIdList() override
void Fill(vtkIdType value)
Fill the ids with the input value.
void SetArray(vtkIdType *array, vtkIdType size, bool save=true)
Specify an array of vtkIdType to use as the id list.
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdType Size
Definition vtkIdList.h:216
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition vtkIdList.h:240
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:162
vtkIdType * end()
To support range-based for loops.
Definition vtkIdList.h:207
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition vtkIdList.h:69
void Initialize()
Release memory and restore to unallocated state.
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 SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition vtkIdList.h:101
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:253
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition vtkIdList.h:157
vtkIdType * WritePointer(const vtkIdType i, const vtkIdType number)
Get a pointer to a particular data index.
void PrintSelf(ostream &os, vtkIndent indent) override
Standard methods for instantiation, type information, and printing.
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition vtkIdList.h:74
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition vtkIdList.h:138
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition vtkIdList.h:206
bool ManageMemory
Definition vtkIdList.h:218
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
const vtkIdType * end() const
To support range-based for loops.
Definition vtkIdList.h:209
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
const vtkIdType * begin() const
To support range-based for loops.
Definition vtkIdList.h:208
a simple class to control print indentation
Definition vtkIndent.h:49
abstract base class for most VTK objects
Definition vtkObject.h:72
int vtkIdType
Definition vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)