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:
40 
43  static vtkIdList *New();
44  vtkTypeMacro(vtkIdList,vtkObject);
45  void PrintSelf(ostream& os, vtkIndent indent) override;
47 
51  void Initialize();
52 
58  int Allocate(const vtkIdType sz, const int strategy=0);
59 
63  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
64 
69  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
70  {return this->Ids[i];}
71 
76  void SetNumberOfIds(const vtkIdType number);
77 
83  void SetId(const vtkIdType i, const vtkIdType vtkid)
84  VTK_EXPECTS(0 <= i && i < GetNumberOfIds())
85  {this->Ids[i] = vtkid;}
86 
91  void InsertId(const vtkIdType i, const vtkIdType vtkid)
92  VTK_EXPECTS(0 <= i);
93 
97  vtkIdType InsertNextId(const vtkIdType vtkid);
98 
104 
109  void Sort();
110 
114  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
115 
121  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
122 
129 
133  void Reset() {this->NumberOfIds = 0;};
134 
138  void Squeeze() {this->Resize(this->NumberOfIds);};
139 
143  void DeepCopy(vtkIdList *ids);
144 
148  void DeleteId(vtkIdType vtkid);
149 
154  vtkIdType IsId(vtkIdType vtkid);
155 
160  void IntersectWith(vtkIdList* otherIds);
161 
167 
171  void IntersectWith(vtkIdList& otherIds) {
172  this->IntersectWith(&otherIds); };
173 
174 protected:
176  ~vtkIdList() override;
177 
181 
182 private:
183  vtkIdList(const vtkIdList&) = delete;
184  void operator=(const vtkIdList&) = delete;
185 };
186 
187 // In-lined for performance
188 inline void vtkIdList::InsertId(const vtkIdType i, const vtkIdType vtkid)
189 {
190  if (i >= this->Size)
191  {
192  this->Resize(i + 1);
193  }
194  this->Ids[i] = vtkid;
195  if (i >= this->NumberOfIds)
196  {
197  this->NumberOfIds = i + 1;
198  }
199 }
200 
201 // In-lined for performance
203 {
204  if ( this->NumberOfIds >= this->Size )
205  {
206  if (!this->Resize(2*this->NumberOfIds+1)) //grow by factor of 2
207  {
208  return this->NumberOfIds-1;
209  }
210  }
211  this->Ids[this->NumberOfIds++] = vtkid;
212  return this->NumberOfIds-1;
213 }
214 
216 {
217  vtkIdType *ptr, i;
218  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
219  {
220  if ( vtkid == *ptr )
221  {
222  return i;
223  }
224  }
225  return (-1);
226 }
227 
228 #endif
vtkIdList::Allocate
int Allocate(const vtkIdType sz, const int strategy=0)
Allocate a capacity for sz ids in the list and set the number of stored ids in the list to 0.
vtkIdList::IntersectWith
void IntersectWith(vtkIdList *otherIds)
Intersect this list with another vtkIdList.
vtkIdList::DeepCopy
void DeepCopy(vtkIdList *ids)
Copy an id list by explicitly copying the internal array.
vtkIdList::InsertUniqueId
vtkIdType InsertUniqueId(const vtkIdType vtkid)
If id is not already in list, insert it and return location in list.
VTK_EXPECTS
#define VTK_EXPECTS(x)
Definition: vtkWrappingHints.h:41
vtkIdList::New
static vtkIdList * New()
Standard methods for instantiation, type information, and printing.
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkIdList::InsertId
void InsertId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:188
vtkObject
abstract base class for most VTK objects
Definition: vtkObject.h:60
vtkIdList::Squeeze
void Squeeze()
Free any unused memory.
Definition: vtkIdList.h:138
vtkIdList::Sort
void Sort()
Sort the ids in the list in ascending id order.
vtkIdList::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkIdList::Resize
vtkIdType * Resize(const vtkIdType sz)
Adjust the size of the id list while maintaining its content (except when being truncated).
vtkIdList::~vtkIdList
~vtkIdList() override
vtkIdList::SetId
void SetId(const vtkIdType i, const vtkIdType vtkid)
Set the id at location i.
Definition: vtkIdList.h:83
vtkIdList::WritePointer
vtkIdType * WritePointer(const vtkIdType i, const vtkIdType number)
Get a pointer to a particular data index.
vtkIdList::InsertNextId
vtkIdType InsertNextId(const vtkIdType vtkid)
Add the id specified to the end of the list.
Definition: vtkIdList.h:202
vtkIdList::Initialize
void Initialize()
Release memory and restore to unallocated state.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:40
vtkIdList::GetId
vtkIdType GetId(const vtkIdType i)
Return the id at location i.
Definition: vtkIdList.h:68
vtkIdList
list of point or cell ids
Definition: vtkIdList.h:37
vtkIdList::DeleteId
void DeleteId(vtkIdType vtkid)
Delete specified id from list.
vtkX3D::size
@ size
Definition: vtkX3D.h:253
vtkIdList::Ids
vtkIdType * Ids
Definition: vtkIdList.h:180
vtkObject.h
vtkIdList::vtkIdList
vtkIdList()
vtkIdList::SetArray
void SetArray(vtkIdType *array, vtkIdType size)
Specify an array of vtkIdType to use as the id list.
vtkIdList::GetPointer
vtkIdType * GetPointer(const vtkIdType i)
Get a pointer to a particular data index.
Definition: vtkIdList.h:114
vtkIdList::SetNumberOfIds
void SetNumberOfIds(const vtkIdType number)
Specify the number of ids for this object to hold.
vtkIdList::IntersectWith
void IntersectWith(vtkIdList &otherIds)
Intersect one id list with another.
Definition: vtkIdList.h:171
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:215
vtkIdList::NumberOfIds
vtkIdType NumberOfIds
Definition: vtkIdList.h:178
vtkIdList::Size
vtkIdType Size
Definition: vtkIdList.h:179
vtkIdList::GetNumberOfIds
vtkIdType GetNumberOfIds()
Return the number of id's in the list.
Definition: vtkIdList.h:63
vtkIdList::Reset
void Reset()
Reset to an empty state but retain previously allocated memory.
Definition: vtkIdList.h:133