Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
IVT
src
DataStructures
KdTree
KdPriorityQueue.h
Go to the documentation of this file.
1
// ****************************************************************************
2
// This file is part of the Integrating Vision Toolkit (IVT).
3
//
4
// The IVT is maintained by the Karlsruhe Institute of Technology (KIT)
5
// (www.kit.edu) in cooperation with the company Keyetech (www.keyetech.de).
6
//
7
// Copyright (C) 2014 Karlsruhe Institute of Technology (KIT).
8
// All rights reserved.
9
//
10
// Redistribution and use in source and binary forms, with or without
11
// modification, are permitted provided that the following conditions are met:
12
//
13
// 1. Redistributions of source code must retain the above copyright
14
// notice, this list of conditions and the following disclaimer.
15
//
16
// 2. Redistributions in binary form must reproduce the above copyright
17
// notice, this list of conditions and the following disclaimer in the
18
// documentation and/or other materials provided with the distribution.
19
//
20
// 3. Neither the name of the KIT nor the names of its contributors may be
21
// used to endorse or promote products derived from this software
22
// without specific prior written permission.
23
//
24
// THIS SOFTWARE IS PROVIDED BY THE KIT AND CONTRIBUTORS “AS IS” AND ANY
25
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27
// DISCLAIMED. IN NO EVENT SHALL THE KIT OR CONTRIBUTORS BE LIABLE FOR ANY
28
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
// ****************************************************************************
35
// ****************************************************************************
36
// Filename: KdPriorityQueue.h
37
// Author: Kai Welke
38
// Date: 14.04.2005
39
// ****************************************************************************
40
41
#ifndef _KD_PRIORITY_QUEUE_H_
42
#define _KD_PRIORITY_QUEUE_H_
43
44
45
// ****************************************************************************
46
// Necessary includes
47
// ****************************************************************************
48
49
#include <new>
// for explicitly using correct new/delete operators on VC DSPs
50
51
52
53
// ****************************************************************************
54
// CKdPriorityQueue
55
// ****************************************************************************
56
57
class
CKdPriorityQueue
58
{
59
private
:
60
// structure for queue entry
61
struct
KdQueueEntry
62
{
63
float
fValue
;
64
void
*
pMeta
;
65
};
66
67
68
public
:
69
// constructor
70
CKdPriorityQueue
(
int
nMaxSize)
71
{
72
m_nMaxSize
= nMaxSize;
73
m_nSize
= 0;
74
75
// queue is array [1..max] of nodes
76
m_pQueue
=
new
KdQueueEntry
[nMaxSize + 1];
77
}
78
79
// destructor
80
~CKdPriorityQueue
()
81
{
82
delete
[]
m_pQueue
;
83
}
84
85
86
// public methods
87
void
Empty
()
88
{
89
m_nSize
= 0;
90
}
91
92
int
GetSize
()
93
{
94
return
m_nSize
;
95
}
96
97
inline
void
Push
(
float
fValue
,
void
*
pMeta
)
98
{
99
// check for oveflow
100
if
(++
m_nSize
>
m_nMaxSize
)
101
{
102
//printf("CKdPriorityQueue: Overflow!!\n");
103
return
;
104
}
105
106
register
int
nPos =
m_nSize
;
107
108
while
(nPos > 1) {
109
register
int
nHalf = nPos / 2;
110
111
// stop iterating, if queue value is smaller than insert position
112
if
(
m_pQueue
[nHalf].fValue <= fValue)
113
break
;
114
115
// swap elements in queue
116
m_pQueue
[nPos] =
m_pQueue
[nHalf];
117
nPos = nHalf;
118
}
119
120
// insert element
121
m_pQueue
[nPos].
fValue
=
fValue
;
122
m_pQueue
[nPos].
pMeta
=
pMeta
;
123
}
124
125
inline
void
Pop
(
float
&
fValue
,
void
*&
pMeta
)
126
{
127
// read minimum value
128
fValue =
m_pQueue
[1].
fValue
;
129
pMeta =
m_pQueue
[1].
pMeta
;
130
131
register
float
fLast =
m_pQueue
[
m_nSize
--].
fValue
;
132
133
register
int
nPos = 1;
134
register
int
nDouble = nPos << 1;
135
136
// while r is still within the heap
137
while
(nDouble <=
m_nSize
) {
138
// set r to smaller child of p
139
140
if
(nDouble <
m_nSize
&&
m_pQueue
[nDouble].fValue >
m_pQueue
[nDouble + 1].fValue)
141
nDouble++;
142
143
// stop if we arrived at last
144
if
(fLast <=
m_pQueue
[nDouble].fValue)
145
break
;
146
147
// swap elements
148
m_pQueue
[nPos] =
m_pQueue
[nDouble];
149
150
nPos = nDouble;
151
nDouble = nPos << 1;
152
}
153
154
// adjust last item
155
m_pQueue
[nPos] =
m_pQueue
[
m_nSize
+ 1];
156
}
157
158
159
private
:
160
// private attributes
161
int
m_nSize
;
162
int
m_nMaxSize
;
163
164
KdQueueEntry
*
m_pQueue
;
165
};
166
167
168
169
#endif
/* _KD_PRIORITY_QUEUE_H_ */
CKdPriorityQueue::m_nMaxSize
int m_nMaxSize
Definition:
KdPriorityQueue.h:162
CKdPriorityQueue::KdQueueEntry::fValue
float fValue
Definition:
KdPriorityQueue.h:63
CKdPriorityQueue::Pop
void Pop(float &fValue, void *&pMeta)
Definition:
KdPriorityQueue.h:125
CKdPriorityQueue::KdQueueEntry::pMeta
void * pMeta
Definition:
KdPriorityQueue.h:64
CKdPriorityQueue::~CKdPriorityQueue
~CKdPriorityQueue()
Definition:
KdPriorityQueue.h:80
CKdPriorityQueue::KdQueueEntry
Definition:
KdPriorityQueue.h:61
CKdPriorityQueue::m_pQueue
KdQueueEntry * m_pQueue
Definition:
KdPriorityQueue.h:164
CKdPriorityQueue::GetSize
int GetSize()
Definition:
KdPriorityQueue.h:92
CKdPriorityQueue
Definition:
KdPriorityQueue.h:57
CKdPriorityQueue::CKdPriorityQueue
CKdPriorityQueue(int nMaxSize)
Definition:
KdPriorityQueue.h:70
CKdPriorityQueue::m_nSize
int m_nSize
Definition:
KdPriorityQueue.h:161
CKdPriorityQueue::Empty
void Empty()
Definition:
KdPriorityQueue.h:87
CKdPriorityQueue::Push
void Push(float fValue, void *pMeta)
Definition:
KdPriorityQueue.h:97
asr_ivt
Author(s): Allgeyer Tobias, Hutmacher Robin, Kleinert Daniel, Meißner Pascal, Scholz Jonas, Stöckle Patrick
autogenerated on Mon Dec 2 2019 03:47:28