VTK
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 =========================================================================*/
24 #ifndef vtkIdList_h
25 #define vtkIdList_h
26 
27 #include "vtkCommonCoreModule.h" // For export macro
28 #include "vtkObject.h"
29 
30 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
31 {
32 public:
34 
37  static vtkIdList* New();
38  vtkTypeMacro(vtkIdList, vtkObject);
39  void PrintSelf(ostream& os, vtkIndent indent) override;
41 
45  void Initialize();
46 
52  int Allocate(const vtkIdType sz, const int strategy = 0);
53 
57  vtkIdType GetNumberOfIds() { return this->NumberOfIds; }
58 
62  vtkIdType GetId(const vtkIdType i) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
63  {
64  return this->Ids[i];
65  }
66 
71  void SetNumberOfIds(const vtkIdType number);
72 
78  void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
79  {
80  this->Ids[i] = vtkid;
81  }
82 
87  void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
88 
92  vtkIdType InsertNextId(const vtkIdType vtkid);
93 
98  vtkIdType InsertUniqueId(const vtkIdType vtkid);
99 
104  void Sort();
105 
109  vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
110 
116  vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
117 
123  void SetArray(vtkIdType* array, vtkIdType size);
124 
128  void Reset() { this->NumberOfIds = 0; }
129 
133  void Squeeze() { this->Resize(this->NumberOfIds); }
134 
138  void DeepCopy(vtkIdList* ids);
139 
143  void DeleteId(vtkIdType vtkid);
144 
149  vtkIdType IsId(vtkIdType vtkid);
150 
155  void IntersectWith(vtkIdList* otherIds);
156 
161  vtkIdType* Resize(const vtkIdType sz);
162 
166  void IntersectWith(vtkIdList& otherIds) { this->IntersectWith(&otherIds); }
167 
169 
172  vtkIdType* begin() { return this->Ids; }
173  vtkIdType* end() { return this->Ids + this->NumberOfIds; }
174  const vtkIdType* begin() const { return this->Ids; }
175  const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
177 protected:
178  vtkIdList();
179  ~vtkIdList() override;
180 
184 
185 private:
186  vtkIdList(const vtkIdList&) = delete;
187  void operator=(const vtkIdList&) = delete;
188 };
189 
190 // In-lined for performance
191 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
192 {
193  if (i >= this->Size)
194  {
195  this->Resize(i + 1);
196  }
197  this->Ids[i] = vtkid;
198  if (i >= this->NumberOfIds)
199  {
200  this->NumberOfIds = i + 1;
201  }
202 }
203 
204 // In-lined for performance
206 {
207  if (this->NumberOfIds >= this->Size)
208  {
209  if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
210  {
211  return this->NumberOfIds - 1;
212  }
213  }
214  this->Ids[this->NumberOfIds++] = vtkid;
215  return this->NumberOfIds - 1;
216 }
217 
219 {
220  vtkIdType *ptr, i;
221  for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
222  {
223  if (vtkid == *ptr)
224  {
225  return i;
226  }
227  }
228  return (-1);
229 }
230 
231 #endif
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:44
vtkIdType
int vtkIdType
Definition: vtkType.h:349
vtkIdList::InsertId
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:191
vtkObject::New
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
vtkIdList::begin
const vtkIdType * begin() const
Definition: vtkIdList.h:174
vtkIdList::end
vtkIdType * end()
Definition: vtkIdList.h:173
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdList::Squeeze
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:133
vtkIdList::Resize
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdList::SetId
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:78
vtkIdList::InsertNextId
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:205
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkIdList::end
const vtkIdType * end() const
Definition: vtkIdList.h:175
vtkIdList::GetId
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:62
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:30
vtkX3D::size
Definition: vtkX3D.h:259
vtkIdList::Ids
vtkIdType * Ids
Definition: vtkIdList.h:183
vtkObject::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkObject.h
vtkIdList::begin
vtkIdType * begin()
To support range-based for loops.
Definition: vtkIdList.h:172
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:109
vtkIdList::IntersectWith
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:166
vtkIdList::IsId
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:218
vtkIdList::NumberOfIds
vtkIdType NumberOfIds
Definition: vtkIdList.h:181
vtkIdList::Size
vtkIdType Size
Definition: vtkIdList.h:182
vtkIdList::GetNumberOfIds
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:57
vtkIdList::Reset
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:128