VTK  9.2.20220926
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 =========================================================================*/
136 #ifndef vtkIdList_h
137 #define vtkIdList_h
138 
139 #include "vtkCommonCoreModule.h" // For export macro
140 #include "vtkObject.h"
141 
142 VTK_ABI_NAMESPACE_BEGIN
143 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
144 {
145 public:
147 
150  static vtkIdList* New();
151  vtkTypeMacro(vtkIdList, vtkObject);
152  void PrintSelf(ostream& os, vtkIndent indent) override;
154 
158  void Initialize();
159 
165  int Allocate(const vtkIdType sz, const int strategy = 0);
166 
170  vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
171 
175  vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
176  {
177  return this->Ids[i];
178  }
179 
184  {
185  for (int i = 0; i < this->NumberOfIds; i++)
186  if (this->Ids[i] == id)
187  return i;
188  return -1;
189  }
190 
195  void SetNumberOfIds(const vtkIdType number);
196 
202  void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
203  {
204  this->Ids[i] = vtkid;
205  }
206 
211  void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
212 
216  vtkIdType InsertNextId(const vtkIdType vtkid);
217 
223 
228  void Sort();
229 
235 
239  vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
240 
246  vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
247 
253  void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
254 
258  void Reset() { this->NumberOfIds = 0; }
259 
263  void Squeeze() { this->Resize(this->NumberOfIds); }
264 
268  void DeepCopy(vtkIdList* ids);
269 
273  void DeleteId(vtkIdType vtkid);
274 
279  vtkIdType IsId(vtkIdType vtkid);
280 
285  void IntersectWith(vtkIdList* otherIds);
286 
292 
293 #ifndef __VTK_WRAP__
301 #endif
302 
304 
307  vtkIdType* begin() { return this->Ids; }
308  vtkIdType* end() { return this->Ids + this->NumberOfIds; }
309  const vtkIdType* begin() const { return this->Ids; }
310  const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
312 protected:
314  ~vtkIdList() override;
315 
320 
321 private:
322  vtkIdList(const vtkIdList&) = delete;
323  void operator=(const vtkIdList&) = delete;
324 };
325 
326 // In-lined for performance
327 inline 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 
368 #endif
list of point or cell ids
Definition: vtkIdList.h:144
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:183
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:239
vtkIdType * Ids
Definition: vtkIdList.h:318
const vtkIdType * end() const
To support range-based for loops.
Definition: vtkIdList.h:310
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:327
const vtkIdType * begin() const
To support range-based for loops.
Definition: vtkIdList.h:309
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:316
~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 Size
Definition: vtkIdList.h:317
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:263
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:308
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:170
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.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:307
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:202
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:258
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:175
void Sort()
Sort the ids in the list in ascending id order.
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
bool ManageMemory
Definition: vtkIdList.h:319
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdType * Release()
This releases the ownership of the internal vtkIdType array and returns the pointer to it.
vtkIdType * WritePointer(const vtkIdType i, const vtkIdType number)
Get a pointer to a particular data index.
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
a simple class to control print indentation
Definition: vtkIndent.h:120
abstract base class for most VTK objects
Definition: vtkObject.h:83
@ value
Definition: vtkX3D.h:232
@ size
Definition: vtkX3D.h:265
int vtkIdType
Definition: vtkType.h:326
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)