[bf78f2]: src / libpanomatic / localfeatures / Sieve.h  Maximize  Restore  History

Download this file

92 lines (76 with data), 2.5 kB

 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
/*
* Copyright (C) 2007-2008 Anael Orlinski
*
* This file is part of Panomatic.
*
* Panomatic is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Panomatic is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Panomatic; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __lfeat_sieve_h
#define __lfeat_sieve_h
#include "BoundedSet.h"
namespace lfeat
{
template <typename _Key>
class SieveExtractor
{
public:
virtual void operator()(const _Key &k) = 0;
};
template <typename _Key, typename _Compare = std::less<_Key> >
class Sieve
{
public:
Sieve(int iWidth, int iHeight, int iLength);
void insert(_Key& iElem, int iWidth, int iHeight);
// extract
void extract(SieveExtractor<_Key>& iEx);
private:
std::vector<lfeat::bounded_set< _Key, _Compare > > _buckets;
int _width, _height;
};
template <typename _Key, typename _Compare>
Sieve<_Key, _Compare>::Sieve(int iWidth, int iHeight, int iLength) :
_buckets(std::vector<bounded_set< _Key, _Compare > >(iWidth * iHeight)),
_width(iWidth), _height(iHeight)
{
typename std::vector<bounded_set< _Key, _Compare > >::iterator aVB, aVE;
aVB = _buckets.begin();
aVE = _buckets.end();
for (; aVB != aVE; ++aVB)
aVB->setMaxSize(iLength);
}
template <typename _Key, typename _Compare>
void Sieve<_Key, _Compare>::insert(_Key& iElem, int iWidth, int iHeight)
{
_buckets[iWidth * _height + iHeight].insert(iElem);
}
template <typename _Key, typename _Compare>
void Sieve<_Key, _Compare>::extract(SieveExtractor<_Key>& iEx)
{
typename std::vector<bounded_set< _Key, _Compare > >::iterator aVB, aVE;
aVB = _buckets.begin();
aVE = _buckets.end();
for (; aVB != aVE; ++aVB)
{
typename std::set<_Key, _Compare>::iterator aSB, aSE;
std::set<_Key, _Compare>& aS = aVB->getSet();
aSB = aS.begin();
aSE = aS.end();
for (; aSB != aSE; ++aSB)
iEx(*aSB);
}
}
}
#endif // __lfeat_sieve_h

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks