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=========================================================================*/
133#ifndef vtkIdList_h
134#define vtkIdList_h
135
136#include "vtkCommonCoreModule.h" // For export macro
137#include "vtkObject.h"
138
139class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
140{
141public:
143
146 static vtkIdList* New();
147 vtkTypeMacro(vtkIdList, vtkObject);
148 void PrintSelf(ostream& os, vtkIndent indent) override;
150
155
161 int Allocate(const vtkIdType sz, const int strategy = 0);
162
166 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
167
171 vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
172 {
173 return this->Ids[i];
174 }
175
180 {
181 for (int i = 0; i < this->NumberOfIds; i++)
182 if (this->Ids[i] == id)
183 return i;
184 return -1;
185 }
186
191 void SetNumberOfIds(const vtkIdType number);
192
198 void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
199 {
200 this->Ids[i] = vtkid;
201 }
202
207 void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
208
212 vtkIdType InsertNextId(const vtkIdType vtkid);
213
219
224 void Sort();
225
230 void Fill(vtkIdType value);
231
235 vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
236
242 vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
243
249 void SetArray(vtkIdType* array, vtkIdType size);
250
254 void Reset() { this->NumberOfIds = 0; }
255
259 void Squeeze() { this->Resize(this->NumberOfIds); }
260
264 void DeepCopy(vtkIdList* ids);
265
269 void DeleteId(vtkIdType vtkid);
270
275 vtkIdType IsId(vtkIdType vtkid);
276
281 void IntersectWith(vtkIdList* otherIds);
282
288
292 void IntersectWith(vtkIdList& otherIds) { this->IntersectWith(&otherIds); }
293
294#ifndef __VTK_WRAP__
302#endif
303
305
308 vtkIdType* begin() { return this->Ids; }
309 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
310 const vtkIdType* begin() const { return this->Ids; }
311 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
313protected:
315 ~vtkIdList() override;
316
320
321private:
322 vtkIdList(const vtkIdList&) = delete;
323 void operator=(const vtkIdList&) = delete;
324};
325
326// In-lined for performance
327inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
328{
329 if (i >= this->Size)
330 {
331 this->Resize(i + 1);
332 }
333 this->Ids[i] = vtkid;
334 if (i >= this->NumberOfIds)
335 {
336 this->NumberOfIds = i + 1;
337 }
338}
339
340// In-lined for performance
342{
343 if (this->NumberOfIds >= this->Size)
344 {
345 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
346 {
347 return this->NumberOfIds - 1;
348 }
349 }
350 this->Ids[this->NumberOfIds++] = vtkid;
351 return this->NumberOfIds - 1;
352}
353
355{
356 vtkIdType *ptr, i;
357 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
358 {
359 if (vtkid == *ptr)
360 {
361 return i;
362 }
363 }
364 return (-1);
365}
366
367#endif
list of point or cell ids
Definition: vtkIdList.h:140
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:179
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:319
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:327
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:317
~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:318
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:341
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:259
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:309
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:166
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:198
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:354
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:254
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:171
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:235
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:308
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:311
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:292
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:310
a simple class to control print indentation
Definition: vtkIndent.h:113
abstract base class for most VTK objects
Definition: vtkObject.h:82
int vtkIdType
Definition: vtkType.h:332
#define VTK_EXPECTS(x)