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 =========================================================================*/
30 #ifndef vtkIdList_h
31 #define vtkIdList_h
32 
33 #include "vtkCommonCoreModule.h" // For export macro
34 #include "vtkObject.h"
35 
36 class VTKCOMMONCORE_EXPORT vtkIdList : public vtkObject
37 {
38 public:
39  static vtkIdList *New();
40 
41  void Initialize();
42 
48  int Allocate(const vtkIdType sz, const int strategy=0);
49 
50  vtkTypeMacro(vtkIdList,vtkObject);
51  void PrintSelf(ostream& os, vtkIndent indent) override;
52 
56  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
57 
62  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
63  {return this->Ids[i];}
64 
69  void SetNumberOfIds(const vtkIdType number);
70 
76  void SetId(const vtkIdType i, const vtkIdType vtkid)
77  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
78  {this->Ids[i] = vtkid;}
79 
84  void InsertId(const vtkIdType i, const vtkIdType vtkid)
85  VTK_EXPECTS(0 <= i);
86 
90  vtkIdType InsertNextId(const vtkIdType vtkid);
91 
96  vtkIdType InsertUniqueId(const vtkIdType vtkid);
97 
101  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
102 
108  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
109 
115  void SetArray(vtkIdType *array, vtkIdType size);
116 
120  void Reset() {this->NumberOfIds = 0;};
121 
125  void Squeeze() {this->Resize(this->NumberOfIds);};
126 
130  void DeepCopy(vtkIdList *ids);
131 
135  void DeleteId(vtkIdType vtkid);
136 
141  vtkIdType IsId(vtkIdType vtkid);
142 
147  void IntersectWith(vtkIdList* otherIds);
148 
153  vtkIdType *Resize(const vtkIdType sz);
154 
155  // This method should become legacy
156  void IntersectWith(vtkIdList& otherIds) {
157  this->IntersectWith(&otherIds); };
158 
159 protected:
160  vtkIdList();
161  ~vtkIdList() override;
162 
166 
167 private:
168  vtkIdList(const vtkIdList&) = delete;
169  void operator=(const vtkIdList&) = delete;
170 };
171 
172 // In-lined for performance
173 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
174 {
175  if (i >= this->Size)
176  {
177  this->Resize(i + 1);
178  }
179  this->Ids[i] = vtkid;
180  if (i >= this->NumberOfIds)
181  {
182  this->NumberOfIds = i + 1;
183  }
184 }
185 
186 // In-lined for performance
188 {
189  if ( this->NumberOfIds >= this->Size )
190  {
191  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
192  {
193  return this->NumberOfIds-1;
194  }
195  }
196  this->Ids[this->NumberOfIds++] = vtkid;
197  return this->NumberOfIds-1;
198 }
199 
201 {
202  vtkIdType *ptr, i;
203  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
204  {
205  if ( vtkid == *ptr )
206  {
207  return i;
208  }
209  }
210  return (-1);
211 }
212 
213 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:173
vtkIdType Size
Definition: vtkIdList.h:164
abstract base class for most VTK objects
Definition: vtkObject.h:59
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:125
vtkIdType * Ids
Definition: vtkIdList.h:165
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:76
void Reset()
Reset to an empty state.
Definition: vtkIdList.h:120
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:56
int vtkIdType
Definition: vtkType.h:345
vtkIdType NumberOfIds
Definition: vtkIdList.h:163
void IntersectWith(vtkIdList &otherIds)
Definition: vtkIdList.h:156
a simple class to control print indentation
Definition: vtkIndent.h:39
list of point or cell ids
Definition: vtkIdList.h:36
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:200
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:61
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:187
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:101
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).