VTK
|
00001 /*========================================================================= 00002 00003 Program: Visualization Toolkit 00004 Module: vtkPriorityQueue.h 00005 00006 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 00007 All rights reserved. 00008 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 00009 00010 This software is distributed WITHOUT ANY WARRANTY; without even 00011 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00012 PURPOSE. See the above copyright notice for more information. 00013 00014 =========================================================================*/ 00037 #ifndef __vtkPriorityQueue_h 00038 #define __vtkPriorityQueue_h 00039 00040 #include "vtkCommonCoreModule.h" // For export macro 00041 #include "vtkObject.h" 00042 00043 #include "vtkIdTypeArray.h" // Needed for inline methods 00044 00045 class VTKCOMMONCORE_EXPORT vtkPriorityQueue : public vtkObject 00046 { 00047 public: 00048 //BTX 00049 class Item 00050 { 00051 public: 00052 double priority; 00053 vtkIdType id; 00054 }; 00055 //ETX 00056 00059 static vtkPriorityQueue *New(); 00060 00061 vtkTypeMacro(vtkPriorityQueue,vtkObject); 00062 void PrintSelf(ostream& os, vtkIndent indent); 00063 00065 void Allocate(const vtkIdType sz, const vtkIdType ext=1000); 00066 00069 void Insert(double priority, vtkIdType id); 00070 00071 //BTX 00073 00077 vtkIdType Pop(vtkIdType location, double &priority); 00078 //ETX 00080 00083 vtkIdType Pop(vtkIdType location=0); 00084 00085 //BTX 00087 00089 vtkIdType Peek(vtkIdType location, double &priority); 00090 //ETX 00092 00095 vtkIdType Peek(vtkIdType location=0); 00096 00099 double DeleteId(vtkIdType id); 00100 00103 double GetPriority(vtkIdType id); 00104 00106 vtkIdType GetNumberOfItems() {return this->MaxId+1;}; 00107 00110 void Reset(); 00111 00112 protected: 00113 vtkPriorityQueue(); 00114 ~vtkPriorityQueue(); 00115 00116 Item *Resize(const vtkIdType sz); 00117 00118 vtkIdTypeArray *ItemLocation; 00119 Item *Array; 00120 vtkIdType Size; 00121 vtkIdType MaxId; 00122 vtkIdType Extend; 00123 private: 00124 vtkPriorityQueue(const vtkPriorityQueue&); // Not implemented. 00125 void operator=(const vtkPriorityQueue&); // Not implemented. 00126 }; 00127 00128 inline double vtkPriorityQueue::DeleteId(vtkIdType id) 00129 { 00130 double priority=VTK_DOUBLE_MAX; 00131 int loc; 00132 00133 if ( id <= this->ItemLocation->GetMaxId() && 00134 (loc=this->ItemLocation->GetValue(id)) != -1 ) 00135 { 00136 this->Pop(loc,priority); 00137 } 00138 return priority; 00139 } 00140 00141 inline double vtkPriorityQueue::GetPriority(vtkIdType id) 00142 { 00143 int loc; 00144 00145 if ( id <= this->ItemLocation->GetMaxId() && 00146 (loc=this->ItemLocation->GetValue(id)) != -1 ) 00147 { 00148 return this->Array[loc].priority; 00149 } 00150 return VTK_DOUBLE_MAX; 00151 } 00152 00153 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location, double &priority) 00154 { 00155 if ( this->MaxId < 0 ) 00156 { 00157 return -1; 00158 } 00159 else 00160 { 00161 priority = this->Array[location].priority; 00162 return this->Array[location].id; 00163 } 00164 } 00165 00166 inline vtkIdType vtkPriorityQueue::Peek(vtkIdType location) 00167 { 00168 if ( this->MaxId < 0 ) 00169 { 00170 return -1; 00171 } 00172 else 00173 { 00174 return this->Array[location].id; 00175 } 00176 } 00177 00178 #endif