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=========================================================================*/
136#ifndef vtkIdList_h
137#define vtkIdList_h
138
139#include "vtkCommonCoreModule.h" // For export macro
140#include "vtkObject.h"
141
142class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
143{
144public:
146
149 static vtkIdList* New();
150 vtkTypeMacro(vtkIdList, vtkObject);
151 void PrintSelf(ostream& os, vtkIndent indent) override;
153
158
164 int Allocate(const vtkIdType sz, const int strategy = 0);
165
169 vtkIdType GetNumberOfIds() const noexcept { return this->NumberOfIds; }
170
174 vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
175 {
176 return this->Ids[i];
177 }
178
183 {
184 for (int i = 0; i < this->NumberOfIds; i++)
185 if (this->Ids[i] == id)
186 return i;
187 return -1;
188 }
189
194 void SetNumberOfIds(const vtkIdType number);
195
201 void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
202 {
203 this->Ids[i] = vtkid;
204 }
205
210 void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
211
215 vtkIdType InsertNextId(const vtkIdType vtkid);
216
222
227 void Sort();
228
234
238 vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
239
245 vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
246
252 void SetArray(vtkIdType* array, vtkIdType size, bool save = true);
253
257 void Reset() { this->NumberOfIds = 0; }
258
262 void Squeeze() { this->Resize(this->NumberOfIds); }
263
267 void DeepCopy(vtkIdList* ids);
268
272 void DeleteId(vtkIdType vtkid);
273
278 vtkIdType IsId(vtkIdType vtkid);
279
284 void IntersectWith(vtkIdList* otherIds);
285
291
292#ifndef __VTK_WRAP__
300#endif
301
303
306 vtkIdType* begin() { return this->Ids; }
307 vtkIdType* end() { return this->Ids + this->NumberOfIds; }
308 const vtkIdType* begin() const { return this->Ids; }
309 const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
311protected:
313 ~vtkIdList() override;
314
319
320private:
321 vtkIdList(const vtkIdList&) = delete;
322 void operator=(const vtkIdList&) = delete;
323};
324
325// In-lined for performance
326inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
327{
328 if (i >= this->Size)
329 {
330 this->Resize(i + 1);
331 }
332 this->Ids[i] = vtkid;
333 if (i >= this->NumberOfIds)
334 {
335 this->NumberOfIds = i + 1;
336 }
337}
338
339// In-lined for performance
341{
342 if (this->NumberOfIds >= this->Size)
343 {
344 if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
345 {
346 return this->NumberOfIds - 1;
347 }
348 }
349 this->Ids[this->NumberOfIds++] = vtkid;
350 return this->NumberOfIds - 1;
351}
352
354{
355 vtkIdType *ptr, i;
356 for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
357 {
358 if (vtkid == *ptr)
359 {
360 return i;
361 }
362 }
363 return (-1);
364}
365
366#endif
list of point or cell ids
Definition: vtkIdList.h:143
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:182
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkIdType * Ids
Definition: vtkIdList.h:317
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:326
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdType NumberOfIds
Definition: vtkIdList.h:315
~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:316
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:340
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:262
vtkIdType * end()
To support range-based for loops.
Definition: vtkIdList.h:307
vtkIdType GetNumberOfIds() const noexcept
Return the number of id's in the list.
Definition: vtkIdList.h:169
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:201
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:353
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:257
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:174
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:238
void Sort()
Sort the ids in the list in ascending id order.
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:306
bool ManageMemory
Definition: vtkIdList.h:318
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:309
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:308
a simple class to control print indentation
Definition: vtkIndent.h:119
abstract base class for most VTK objects
Definition: vtkObject.h:82
@ value
Definition: vtkX3D.h:226
@ size
Definition: vtkX3D.h:259
int vtkIdType
Definition: vtkType.h:332
void save(Archiver &ar, const std::string &str, const unsigned int vtkNotUsed(version))
#define VTK_EXPECTS(x)