VTK
vtkPriorityQueue.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkPriorityQueue.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 =========================================================================*/
37 #ifndef vtkPriorityQueue_h
38 #define vtkPriorityQueue_h
39 
40 #include "vtkCommonCoreModule.h" // For export macro
41 #include "vtkObject.h"
42 
43 #include "vtkIdTypeArray.h" // Needed for inline methods
44 
46 {
47 public:
48  //BTX
49  class Item
50  {
51  public:
52  double priority;
54  };
55  //ETX
56 
59  static vtkPriorityQueue *New();
60 
61  vtkTypeMacro(vtkPriorityQueue,vtkObject);
62  void PrintSelf(ostream& os, vtkIndent indent);
63 
65  void Allocate(const vtkIdType sz, const vtkIdType ext=1000);
66 
69  void Insert(double priority, vtkIdType id);
70 
71 //BTX
73 
77  vtkIdType Pop(vtkIdType location, double &priority);
78 //ETX
80 
84 
85 //BTX
87 
89  vtkIdType Peek(vtkIdType location, double &priority);
90 //ETX
92 
96 
99  double DeleteId(vtkIdType id);
100 
103  double GetPriority(vtkIdType id);
104 
106  vtkIdType GetNumberOfItems() {return this->MaxId+1;};
107 
110  void Reset();
111 
112 protected:
114  ~vtkPriorityQueue();
115 
116  Item *Resize(const vtkIdType sz);
117 
123 private:
124  vtkPriorityQueue(const vtkPriorityQueue&); // Not implemented.
125  void operator=(const vtkPriorityQueue&); // Not implemented.
126 };
127 
129 {
130  double priority=VTK_DOUBLE_MAX;
131  vtkIdType loc;
132 
133  if ( id <= this->ItemLocation->GetMaxId() &&
134  (loc=this->ItemLocation->GetValue(id)) != -1 )
135  {
136  this->Pop(loc,priority);
137  }
138  return priority;
139 }
140 
142 {
143  vtkIdType loc;
144 
145  if ( id <= this->ItemLocation->GetMaxId() &&
146  (loc=this->ItemLocation->GetValue(id)) != -1 )
147  {
148  return this->Array[loc].priority;
149  }
150  return VTK_DOUBLE_MAX;
151 }
152 
154 {
155  if ( this->MaxId < 0 )
156  {
157  return -1;
158  }
159  else
160  {
161  priority = this->Array[location].priority;
162  return this->Array[location].id;
163  }
164 }
165 
167 {
168  if ( this->MaxId < 0 )
169  {
170  return -1;
171  }
172  else
173  {
174  return this->Array[location].id;
175  }
176 }
177 
178 #endif
vtkIdType GetMaxId()
abstract base class for most VTK objects
Definition: vtkObject.h:61
#define VTK_DOUBLE_MAX
Definition: vtkType.h:140
#define VTKCOMMONCORE_EXPORT
vtkIdTypeArray * ItemLocation
vtkIdType Peek(vtkIdType location, double &priority)
dynamic, self-adjusting array of vtkIdType
int vtkIdType
Definition: vtkType.h:247
a list of ids arranged in priority order
virtual void PrintSelf(ostream &os, vtkIndent indent)
double GetPriority(vtkIdType id)
vtkIdType Pop(vtkIdType location, double &priority)
a simple class to control print indentation
Definition: vtkIndent.h:38
vtkIdType GetNumberOfItems()
double DeleteId(vtkIdType id)
static vtkObject * New()