1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
|
/*=========================================================================
Program: Visualization Toolkit
Module: $RCSfile: vtkIdList.h,v $
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
All rights reserved.
See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkIdList - list of point or cell ids
// .SECTION Description
// vtkIdList is used to represent and pass data id's between
// objects. vtkIdList may represent any type of integer id, but
// usually represents point and cell ids.
#ifndef __vtkIdList_h
#define __vtkIdList_h
#include "vtkObject.h"
class VTK_COMMON_EXPORT vtkIdList : public vtkObject
{
public:
static vtkIdList *New();
void Initialize();
int Allocate(const int sz, const int strategy=0);
vtkTypeRevisionMacro(vtkIdList,vtkObject);
void PrintSelf(ostream& os, vtkIndent indent);
// Description:
// Return the number of id's in the list.
vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
// Description:
// Return the id at location i.
vtkIdType GetId(const int i) {return this->Ids[i];};
// Description:
// Specify the number of ids for this object to hold. Does an
// allocation as well as setting the number of ids.
void SetNumberOfIds(const vtkIdType number);
// Description:
// Set the id at location i. Doesn't do range checking so it's a bit
// faster than InsertId. Make sure you use SetNumberOfIds() to allocate
// memory prior to using SetId().
void SetId(const vtkIdType i, const vtkIdType id) {this->Ids[i] = id;};
// Description:
// Set the id at location i. Does range checking and allocates memory
// as necessary.
void InsertId(const vtkIdType i, const vtkIdType id);
// Description:
// Add the id specified to the end of the list. Range checking is performed.
vtkIdType InsertNextId(const vtkIdType id);
// Description:
// If id is not already in list, insert it and return location in
// list. Otherwise return just location in list.
vtkIdType InsertUniqueId(const vtkIdType id);
// Description:
// Get a pointer to a particular data index.
vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
// Description:
// Get a pointer to a particular data index. Make sure data is allocated
// for the number of items requested. Set MaxId according to the number of
// data values requested.
vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
// Description:
// Reset to an empty state.
void Reset() {this->NumberOfIds = 0;};
// Description:
// Free any unused memory.
void Squeeze() {this->Resize(this->NumberOfIds);};
// Description:
// Copy an id list by explicitly copying the internal array.
void DeepCopy(vtkIdList *ids);
// Description:
// Delete specified id from list. Will remove all occurrences of id in list.
void DeleteId(vtkIdType id);
// Description:
// Return -1 if id specified is not contained in the list; otherwise return
// the position in the list.
vtkIdType IsId(vtkIdType id);
// Description:
// Intersect this list with another vtkIdList. Updates current list according
// to result of intersection operation.
void IntersectWith(vtkIdList& otherIds);
protected:
vtkIdList();
~vtkIdList();
vtkIdType NumberOfIds;
vtkIdType Size;
vtkIdType *Ids;
vtkIdType *Resize(const vtkIdType sz);
private:
vtkIdList(const vtkIdList&); // Not implemented.
void operator=(const vtkIdList&); // Not implemented.
};
// In-lined for performance
inline vtkIdType vtkIdList::InsertNextId(const vtkIdType id)
{
if ( this->NumberOfIds >= this->Size )
{
this->Resize(this->NumberOfIds+1);
}
this->Ids[this->NumberOfIds++] = id;
return this->NumberOfIds-1;
}
inline vtkIdType vtkIdList::IsId(vtkIdType id)
{
vtkIdType *ptr, i;
for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
{
if ( id == *ptr )
{
return i;
}
}
return (-1);
}
#endif
|