VTK  9.1.0
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=========================================================================*/
33#ifndef vtkIdList_h
34#define vtkIdList_h
35
36#include "vtkCommonCoreModule.h" // For export macro
37#include "vtkObject.h"
38
39class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
40{
41public:
43
46 static vtkIdList* New();
47 vtkTypeMacro(vtkIdList, vtkObject);
48 void PrintSelf(ostream& os, vtkIndent indent) override;
50
54 void Initialize();
55
61 int Allocate(const vtkIdType sz, const int strategy = 0);
62
66 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
67
71 vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
72 {
73 return this->Ids[i];
74 }
75
80 {
81 for (int i = 0; i < this->NumberOfIds; i++)
82 if (this->Ids[i] == id)
83 return i;
84 return -1;
85 }
86
91 void SetNumberOfIds(const vtkIdType number);
92
98 void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
99 {
100 this->Ids[i] = vtkid;
101 }
102
107 void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
108
112 vtkIdType InsertNextId(const vtkIdType vtkid);
113
119
124 void Sort();
125
131
135 vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
136
142 vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
143
150
154 void Reset() { this->NumberOfIds = 0; }
155
159 void Squeeze() { this->Resize(this->NumberOfIds); }
160
164 void DeepCopy(vtkIdList* ids);
165
169 void DeleteId(vtkIdType vtkid);
170
175 vtkIdType IsId(vtkIdType vtkid);
176
181 void IntersectWith(vtkIdList* otherIds);
182
188
192 void IntersectWith(vtkIdList& otherIds) { this->IntersectWith(&otherIds); }
193
194#ifndef __VTK_WRAP__
202#endif
203
205
208 vtkIdType* begin() { return this->Ids; }
209 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
210 const vtkIdType* begin() const { return this->Ids; }
211 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
213protected:
215 ~vtkIdList() override;
216
220
221private:
222 vtkIdList(const vtkIdList&) = delete;
223 void operator=(const vtkIdList&) = delete;
224};
225
226// In-lined for performance
227inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
228{
229 if (i >= this->Size)
230 {
231 this->Resize(i + 1);
232 }
233 this->Ids[i] = vtkid;
234 if (i >= this->NumberOfIds)
235 {
236 this->NumberOfIds = i + 1;
237 }
238}
239
240// In-lined for performance
242{
243 if (this->NumberOfIds >= this->Size)
244 {
245 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
246 {
247 return this->NumberOfIds - 1;
248 }
249 }
250 this->Ids[this->NumberOfIds++] = vtkid;
251 return this->NumberOfIds - 1;
252}
253
255{
256 vtkIdType *ptr, i;
257 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
258 {
259 if (vtkid == *ptr)
260 {
261 return i;
262 }
263 }
264 return (-1);
265}
266
267#endif
list of point or cell ids
Definition: vtkIdList.h:40
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:79
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:219
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:227
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:217
~vtkIdList() override
void Fill(vtkIdType value)
Fill the ids with the input value.
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:218
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:241
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:159
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:209
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:66
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 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:98
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:254
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:154
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:71
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:135
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:208
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:211
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:192
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:210
a simple class to control print indentation
Definition: vtkIndent.h:43
abstract base class for most VTK objects
Definition: vtkObject.h:63
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
int vtkIdType
Definition: vtkType.h:332
#define VTK_EXPECTS(x)