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:
33  static vtkIdList *New();
34 
35  void Initialize();
36 
42  int Allocate(const vtkIdType sz, const int strategy=0);
43 
44  vtkTypeMacro(vtkIdList,vtkObject);
45  void PrintSelf(ostream& os, vtkIndent indent) override;
46 
50  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
51 
56  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
57  {return this->Ids[i];}
58 
63  void SetNumberOfIds(const vtkIdType number);
64 
70  void SetId(const vtkIdType i, const vtkIdType vtkid)
71  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
72  {this->Ids[i] = vtkid;}
73 
78  void InsertId(const vtkIdType i, const vtkIdType vtkid)
79  VTK_EXPECTS(0 <= i);
80 
84  vtkIdType InsertNextId(const vtkIdType vtkid);
85 
90  vtkIdType InsertUniqueId(const vtkIdType vtkid);
91 
95  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
96 
102  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
103 
109  void SetArray(vtkIdType *array, vtkIdType size);
110 
114  void Reset() {this->NumberOfIds = 0;};
115 
119  void Squeeze() {this->Resize(this->NumberOfIds);};
120 
124  void DeepCopy(vtkIdList *ids);
125 
129  void DeleteId(vtkIdType vtkid);
130 
135  vtkIdType IsId(vtkIdType vtkid);
136 
141  void IntersectWith(vtkIdList* otherIds);
142 
147  vtkIdType *Resize(const vtkIdType sz);
148 
149  // This method should become legacy
150  void IntersectWith(vtkIdList& otherIds) {
151  this->IntersectWith(&otherIds); };
152 
153 protected:
154  vtkIdList();
155  ~vtkIdList() override;
156 
160 
161 private:
162  vtkIdList(const vtkIdList&) = delete;
163  void operator=(const vtkIdList&) = delete;
164 };
165 
166 // In-lined for performance
167 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
168 {
169  if (i >= this->Size)
170  {
171  this->Resize(i + 1);
172  }
173  this->Ids[i] = vtkid;
174  if (i >= this->NumberOfIds)
175  {
176  this->NumberOfIds = i + 1;
177  }
178 }
179 
180 // In-lined for performance
182 {
183  if ( this->NumberOfIds >= this->Size )
184  {
185  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
186  {
187  return this->NumberOfIds-1;
188  }
189  }
190  this->Ids[this->NumberOfIds++] = vtkid;
191  return this->NumberOfIds-1;
192 }
193 
195 {
196  vtkIdType *ptr, i;
197  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
198  {
199  if ( vtkid == *ptr )
200  {
201  return i;
202  }
203  }
204  return (-1);
205 }
206 
207 #endif
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:167
vtkIdType Size
Definition: vtkIdList.h:158
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:119
vtkIdType * Ids
Definition: vtkIdList.h:159
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:70
void Reset()
Reset to an empty state.
Definition: vtkIdList.h:114
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:50
int vtkIdType
Definition: vtkType.h:345
vtkIdType NumberOfIds
Definition: vtkIdList.h:157
void IntersectWith(vtkIdList &otherIds)
Definition: vtkIdList.h:150
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:194
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:55
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:181
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:95
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).