VTK  9.2.5
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
33class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
34{
35public:
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
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
182
183#ifndef __VTK_WRAP__
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; }
202protected:
204 ~vtkIdList() override;
205
210
211private:
212 vtkIdList(const vtkIdList&) = delete;
213 void operator=(const vtkIdList&) = delete;
214};
215
216// In-lined for performance
217inline 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
list of point or cell ids
Definition: vtkIdList.h:34
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:73
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:208
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:217
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:206
~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:207
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:231
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:153
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:198
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:60
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:92
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
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:148
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:65
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:129
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:197
bool ManageMemory
Definition: vtkIdList.h:209
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:200
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:199
a simple class to control print indentation
Definition: vtkIndent.h:40
abstract base class for most VTK objects
Definition: vtkObject.h:63
int vtkIdType
Definition: vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)