vtkIdList.h 4.34 KB
Newer Older
Will Schroeder's avatar
Will Schroeder committed
1
2
/*=========================================================================

Ken Martin's avatar
Ken Martin committed
3
  Program:   Visualization Toolkit
Ken Martin's avatar
Ken Martin committed
4
  Module:    vtkIdList.h
Will Schroeder's avatar
Will Schroeder committed
5

6
  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7
8
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
Ken Martin's avatar
Ken Martin committed
9

10
11
     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12
     PURPOSE.  See the above copyright notice for more information.
Will Schroeder's avatar
Will Schroeder committed
13
14

=========================================================================*/
Ken Martin's avatar
Ken Martin committed
15
// .NAME vtkIdList - list of point or cell ids
Will Schroeder's avatar
Will Schroeder committed
16
// .SECTION Description
17
18
19
// 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.
Will Schroeder's avatar
Will Schroeder committed
20

Will Schroeder's avatar
Will Schroeder committed
21
22
#ifndef __vtkIdList_h
#define __vtkIdList_h
Ken Martin's avatar
Ken Martin committed
23

Ken Martin's avatar
Ken Martin committed
24
#include "vtkObject.h"
Ken Martin's avatar
Ken Martin committed
25

26
class VTK_COMMON_EXPORT vtkIdList : public vtkObject
27
{
28
public:
29
  static vtkIdList *New();
30

31
  void Initialize();
32
  int Allocate(const vtkIdType sz, const int strategy=0);
33
  vtkTypeMacro(vtkIdList,vtkObject);
34
  void PrintSelf(ostream& os, vtkIndent indent);
Will Schroeder's avatar
Will Schroeder committed
35

Ken Martin's avatar
Ken Martin committed
36
37
  // Description:
  // Return the number of id's in the list.
38
  vtkIdType GetNumberOfIds() {return this->NumberOfIds;};
Ken Martin's avatar
Ken Martin committed
39
40
41
  
  // Description:
  // Return the id at location i.
42
  vtkIdType GetId(const vtkIdType i) {return this->Ids[i];};
Ken Martin's avatar
Ken Martin committed
43
44
45
  
  // Description:
  // Specify the number of ids for this object to hold. Does an
46
  // allocation as well as setting the number of ids.
47
  void SetNumberOfIds(const vtkIdType number);
Ken Martin's avatar
Ken Martin committed
48
49
50
51
52

  // 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().
53
  void SetId(const vtkIdType i, const vtkIdType vtkid) {this->Ids[i] = vtkid;};
Ken Martin's avatar
Ken Martin committed
54
55
56
57

  // Description:
  // Set the id at location i. Does range checking and allocates memory
  // as necessary.
58
  void InsertId(const vtkIdType i, const vtkIdType vtkid);
Ken Martin's avatar
Ken Martin committed
59
60
61

  // Description:
  // Add the id specified to the end of the list. Range checking is performed.
62
  vtkIdType InsertNextId(const vtkIdType vtkid);
Ken Martin's avatar
Ken Martin committed
63
64
65
66

  // Description:
  // If id is not already in list, insert it and return location in
  // list. Otherwise return just location in list.
67
  vtkIdType InsertUniqueId(const vtkIdType vtkid);
Ken Martin's avatar
Ken Martin committed
68
69
70

  // Description:
  // Get a pointer to a particular data index.
71
  vtkIdType *GetPointer(const vtkIdType i) {return this->Ids + i;};
Ken Martin's avatar
Ken Martin committed
72
73
74
75
76

  // 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.
77
  vtkIdType *WritePointer(const vtkIdType i, const vtkIdType number);
Ken Martin's avatar
Ken Martin committed
78
79

  // Description:
80
81
  // Reset to an empty state.
  void Reset() {this->NumberOfIds = 0;};
Ken Martin's avatar
Ken Martin committed
82
83
84

  // Description:
  // Free any unused memory.
85
  void Squeeze() {this->Resize(this->NumberOfIds);};
86

Ken Martin's avatar
Ken Martin committed
87
88
  // Description:
  // Copy an id list by explicitly copying the internal array.
89
  void DeepCopy(vtkIdList *ids);
Will Schroeder's avatar
Will Schroeder committed
90

Ken Martin's avatar
Ken Martin committed
91
  // Description:
Bill Lorensen's avatar
Bill Lorensen committed
92
  // Delete specified id from list. Will remove all occurrences of id in list.
93
  void DeleteId(vtkIdType vtkid);
94

Ken Martin's avatar
Ken Martin committed
95
  // Description:
96
97
  // Return -1 if id specified is not contained in the list; otherwise return
  // the position in the list.
98
  vtkIdType IsId(vtkIdType vtkid);
99

100
  // Description:
101
102
  // Intersect this list with another vtkIdList. Updates current list according
  // to result of intersection operation.
103
104
105
106
107
108
109
  void IntersectWith(vtkIdList* otherIds);

  //BTX
  // This method should become legacy
  void IntersectWith(vtkIdList& otherIds) {
    return this->IntersectWith(&otherIds); };
  //ETX
110

Will Schroeder's avatar
Will Schroeder committed
111
protected:
112
  vtkIdList();
113
114
  ~vtkIdList();

115
116
117
  vtkIdType NumberOfIds;
  vtkIdType Size; 
  vtkIdType *Ids;
Will Schroeder's avatar
Will Schroeder committed
118

119
  vtkIdType *Resize(const vtkIdType sz);
120
121
122
private:
  vtkIdList(const vtkIdList&);  // Not implemented.
  void operator=(const vtkIdList&);  // Not implemented.
123
};
124

Will Schroeder's avatar
Will Schroeder committed
125
// In-lined for performance
126
inline vtkIdType vtkIdList::InsertNextId(const vtkIdType vtkid)
Will Schroeder's avatar
Will Schroeder committed
127
128
129
130
131
{
  if ( this->NumberOfIds >= this->Size )
    {
    this->Resize(this->NumberOfIds+1);
    }
132
  this->Ids[this->NumberOfIds++] = vtkid;
Will Schroeder's avatar
Will Schroeder committed
133
134
135
  return this->NumberOfIds-1;
}

136
inline vtkIdType vtkIdList::IsId(vtkIdType vtkid)
Will Schroeder's avatar
Will Schroeder committed
137
{
138
  vtkIdType *ptr, i;
139
  for (ptr=this->Ids, i=0; i<this->NumberOfIds; i++, ptr++)
Jim Miller's avatar
Style    
Jim Miller committed
140
    {
141
    if ( vtkid == *ptr )
Jim Miller's avatar
Style    
Jim Miller committed
142
      {
143
      return i;
Jim Miller's avatar
Style    
Jim Miller committed
144
145
      }
    }
146
  return (-1);
Will Schroeder's avatar
Will Schroeder committed
147
148
}

Ken Martin's avatar
Ken Martin committed
149
#endif