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 
63  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
64  {return this->Ids[i];}
65 
70  void SetNumberOfIds(const vtkIdType number);
71 
77  void SetId(const vtkIdType i, const vtkIdType vtkid)
78  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
79  {this->Ids[i] = vtkid;}
80 
85  void InsertId(const vtkIdType i, const vtkIdType vtkid)
86  VTK_EXPECTS(0 <= i);
87 
91  vtkIdType InsertNextId(const vtkIdType vtkid);
92 
97  vtkIdType InsertUniqueId(const vtkIdType vtkid);
98 
103  void Sort();
104 
108  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
109 
115  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
116 
122  void SetArray(vtkIdType *array, vtkIdType size);
123 
127  void Reset() {this->NumberOfIds = 0;};
128 
132  void Squeeze() {this->Resize(this->NumberOfIds);};
133 
137  void DeepCopy(vtkIdList *ids);
138 
142  void DeleteId(vtkIdType vtkid);
143 
148  vtkIdType IsId(vtkIdType vtkid);
149 
154  void IntersectWith(vtkIdList* otherIds);
155 
160  vtkIdType *Resize(const vtkIdType sz);
161 
165  void IntersectWith(vtkIdList& otherIds) {
166  this->IntersectWith(&otherIds); };
167 
168 protected:
169  vtkIdList();
170  ~vtkIdList() override;
171 
175 
176 private:
177  vtkIdList(const vtkIdList&) = delete;
178  void operator=(const vtkIdList&) = delete;
179 };
180 
181 // In-lined for performance
182 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
183 {
184  if (i >= this->Size)
185  {
186  this->Resize(i + 1);
187  }
188  this->Ids[i] = vtkid;
189  if (i >= this->NumberOfIds)
190  {
191  this->NumberOfIds = i + 1;
192  }
193 }
194 
195 // In-lined for performance
197 {
198  if ( this->NumberOfIds >= this->Size )
199  {
200  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
201  {
202  return this->NumberOfIds-1;
203  }
204  }
205  this->Ids[this->NumberOfIds++] = vtkid;
206  return this->NumberOfIds-1;
207 }
208 
210 {
211  vtkIdType *ptr, i;
212  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
213  {
214  if ( vtkid == *ptr )
215  {
216  return i;
217  }
218  }
219  return (-1);
220 }
221 
222 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:182
vtkIdType Size
Definition: vtkIdList.h:173
abstract base class for most VTK objects
Definition: vtkObject.h:53
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:132
vtkIdType * Ids
Definition: vtkIdList.h:174
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:77
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:127
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:57
int vtkIdType
Definition: vtkType.h:347
vtkIdType NumberOfIds
Definition: vtkIdList.h:172
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:165
a simple class to control print indentation
Definition: vtkIndent.h:33
list of point or cell ids
Definition: vtkIdList.h:30
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:209
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:62
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on.
#define VTK_EXPECTS(x)
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:196
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:108
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).