~ubuntu-branches/ubuntu/trusty/hugin/trusty-proposed

« back to all changes in this revision

Viewing changes to src/hugin_cpfind/localfeatures/BoundedSet.h

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Metzler
  • Date: 2011-01-06 14:28:24 UTC
  • mfrom: (1.1.9 upstream) (0.1.21 experimental)
  • Revision ID: james.westby@ubuntu.com-20110106142824-zn9lxylg5z44dynn
* Drop Cyril Brulebois from Uploaders. Thank you very much for your work.
* Bump package version. (rc3 was re-released as 2010.4.0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Copyright (C) 2007-2008 Anael Orlinski
 
3
*
 
4
* This file is part of Panomatic.
 
5
*
 
6
* Panomatic is free software; you can redistribute it and/or modify
 
7
* it under the terms of the GNU General Public License as published by
 
8
* the Free Software Foundation; either version 2 of the License, or
 
9
* (at your option) any later version.
 
10
 
11
* Panomatic is distributed in the hope that it will be useful,
 
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
* GNU General Public License for more details.
 
15
 
16
* You should have received a copy of the GNU General Public License
 
17
* along with Panomatic; if not, write to the Free Software
 
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
*/
 
20
 
 
21
#ifndef __detectpano_boundedset_h
 
22
#define __detectpano_boundedset_h
 
23
 
 
24
#include <set>
 
25
#include <limits>
 
26
 
 
27
// a container that keeps the N best elements during insertion.
 
28
// then the container has a maximum size of N
 
29
 
 
30
// TEMPLATE CLASS limited_multiset
 
31
// by default will keep the N largest values.
 
32
// to keep the N smallest values, use greater as comparator
 
33
 
 
34
#ifdef _WIN32
 
35
#undef max
 
36
#undef min
 
37
#endif
 
38
 
 
39
namespace lfeat
 
40
{
 
41
 
 
42
template <typename _Key, typename _Compare = std::less<_Key> >
 
43
class bounded_set
 
44
{
 
45
private:
 
46
        size_t                                          _maxSize;
 
47
        std::set< _Key, _Compare>       _set;
 
48
        
 
49
public:
 
50
        typedef typename std::set<_Key, _Compare>::iterator iterator;
 
51
 
 
52
        // define the constructors
 
53
    bounded_set() : _maxSize(std::numeric_limits<size_t>::max()), _set(std::set<_Key, _Compare>()) {}
 
54
 
 
55
        bounded_set(size_t iMaxSize) : _set(std::set<_Key, _Compare>()), _maxSize (iMaxSize) {}
 
56
        
 
57
        /// sets the max size of bounded set
 
58
        void setMaxSize(int iMax)
 
59
        {
 
60
                _maxSize = iMax;
 
61
        }
 
62
        
 
63
        ///  Returns the maximum size of the bounded_set
 
64
        size_t max_size() const
 
65
        { 
 
66
                return _maxSize;
 
67
        }
 
68
 
 
69
        ///  Returns the size of the limited_multiset.
 
70
        size_t size() const
 
71
        { 
 
72
                return _set.size();
 
73
        }
 
74
 
 
75
        iterator begin()
 
76
        {
 
77
                return _set.begin();
 
78
        }
 
79
 
 
80
        iterator end()
 
81
        {
 
82
                return _set.end();
 
83
        }
 
84
 
 
85
        //      void swap(limited_multiset<_Key,_MaxLen ,_Compare, _Alloc>& __x)
 
86
        //      {
 
87
        //              multiset::swap(__x);
 
88
        //      }
 
89
 
 
90
        void truncate()
 
91
        {
 
92
                while (_set.size() > _maxSize)
 
93
                        _set.erase(_set.begin());
 
94
        }
 
95
 
 
96
        // be careful, the returned iterator is always end !!!
 
97
        // in fact we don't know if the added value is truncated.
 
98
        void insert(const _Key & x)
 
99
        { 
 
100
                _set.insert(x);
 
101
                truncate();
 
102
        }
 
103
 
 
104
        std::set< _Key, _Compare>& getSet()
 
105
        {
 
106
                return _set;
 
107
        }
 
108
 
 
109
};
 
110
 
 
111
}
 
112
 
 
113
#endif // __detectpano_boundedset_h