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  {
72  for (int i = 0; i < this->NumberOfIds; i++)
73  if (this->Ids[i] == id)
74  return i;
75  return -1;
76  }
77 
82  void SetNumberOfIds(const vtkIdType number);
83 
89  void SetId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
90  {
91  this->Ids[i] = vtkid;
92  }
93 
98  void InsertId(const vtkIdType i, const vtkIdType vtkid) VTK_EXPECTS(0 <= i);
99 
103  vtkIdType InsertNextId(const vtkIdType vtkid);
104 
109  vtkIdType InsertUniqueId(const vtkIdType vtkid);
110 
115  void Sort();
116 
120  vtkIdType* GetPointer(const vtkIdType i) { return this->Ids + i; }
121 
127  vtkIdType* WritePointer(const vtkIdType i, const vtkIdType number);
128 
134  void SetArray(vtkIdType* array, vtkIdType size);
135 
139  void Reset() { this->NumberOfIds = 0; }
140 
144  void Squeeze() { this->Resize(this->NumberOfIds); }
145 
149  void DeepCopy(vtkIdList* ids);
150 
154  void DeleteId(vtkIdType vtkid);
155 
160  vtkIdType IsId(vtkIdType vtkid);
161 
166  void IntersectWith(vtkIdList* otherIds);
167 
172  vtkIdType* Resize(const vtkIdType sz);
173 
177  void IntersectWith(vtkIdList& otherIds) { this->IntersectWith(&otherIds); }
178 
180 
183  vtkIdType* begin() { return this->Ids; }
184  vtkIdType* end() { return this->Ids + this->NumberOfIds; }
185  const vtkIdType* begin() const { return this->Ids; }
186  const vtkIdType* end() const { return this->Ids + this->NumberOfIds; }
188 protected:
189  vtkIdList();
190  ~vtkIdList() override;
191 
195 
196 private:
197  vtkIdList(const vtkIdList&) = delete;
198  void operator=(const vtkIdList&) = delete;
199 };
200 
201 // In-lined for performance
202 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
203 {
204  if (i >= this->Size)
205  {
206  this->Resize(i + 1);
207  }
208  this->Ids[i] = vtkid;
209  if (i >= this->NumberOfIds)
210  {
211  this->NumberOfIds = i + 1;
212  }
213 }
214 
215 // In-lined for performance
217 {
218  if (this->NumberOfIds >= this->Size)
219  {
220  if (!this->Resize(2 * this->NumberOfIds + 1)) // grow by factor of 2
221  {
222  return this->NumberOfIds - 1;
223  }
224  }
225  this->Ids[this->NumberOfIds++] = vtkid;
226  return this->NumberOfIds - 1;
227 }
228 
230 {
231  vtkIdType *ptr, i;
232  for (ptr = this->Ids, i = 0; i < this->NumberOfIds; i++, ptr++)
233  {
234  if (vtkid == *ptr)
235  {
236  return i;
237  }
238  }
239  return (-1);
240 }
241 
242 #endif
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:44
vtkIdType
int vtkIdType
Definition: vtkType.h:343
vtkIdList::InsertId
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:202
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:185
vtkIdList::end
vtkIdType * end()
Definition: vtkIdList.h:184
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:53
vtkIdList::Squeeze
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:144
vtkIdList::FindIdLocation
vtkIdType FindIdLocation(const vtkIdType id)
Find the location i of the provided id.
Definition: vtkIdList.h:70
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:89
vtkIdList::InsertNextId
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:216
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkIdList::end
const vtkIdType * end() const
Definition: vtkIdList.h:186
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:194
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:183
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:120
vtkIdList::IntersectWith
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:177
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:229
vtkIdList::NumberOfIds
vtkIdType NumberOfIds
Definition: vtkIdList.h:192
vtkIdList::Size
vtkIdType Size
Definition: vtkIdList.h:193
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:139