OpenGM  2.3.x
Discrete Graphical Model Library
discretespace.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_DISCRETE_SPACE_HXX
3 #define OPENGM_DISCRETE_SPACE_HXX
4 
5 #include <vector>
6 #include <limits>
7 
8 #include "opengm/opengm.hxx"
10 
11 namespace opengm {
12 
16 template<class I = std::size_t, class L = std::size_t>
18 : public SpaceBase<DiscreteSpace<I, L>, I, L> {
19 public:
20  typedef I IndexType;
21  typedef L LabelType;
22 
23  DiscreteSpace();
24  template<class Iterator> DiscreteSpace(Iterator, Iterator);
25  template<class Iterator> void assign(Iterator, Iterator);
26  template<class Iterator> void assignDense(Iterator, Iterator);
27  IndexType addVariable(const LabelType);
28  IndexType numberOfVariables() const;
29  LabelType numberOfLabels(const IndexType) const;
30  void reserve(const IndexType);
31 
32 private:
33  std::vector<LabelType> numbersOfLabels_;
34 };
35 
37 template<class I, class L>
38 inline
40 : numbersOfLabels_() {
41 }
42 
43 
53 template<class I, class L>
54 template<class Iterator>
55 inline
57 (
58  Iterator begin,
59  Iterator end
60 )
61 : numbersOfLabels_(begin, end) {
62  OPENGM_ASSERT(numbersOfLabels_.size()>=0);
63  OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
64 }
65 
69 template<class I, class L>
70 template<class Iterator>
71 inline void
73 (
74  Iterator begin,
75  Iterator end
76 ) {
77  numbersOfLabels_.assign(begin, end);
78  OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
79 }
80 
82 template<class I, class L>
83 inline void
85 (
86  const I numberOfVariables
87 ) {
88  this->numbersOfLabels_.reserve(numberOfVariables);
89 }
90 
91 template<class I, class L>
92 template<class Iterator>
93 inline void
95 (
96  Iterator begin,
97  Iterator end
98 ) {
99  this->assign(begin, end);
100 }
101 
103 template<class I, class L>
104 inline typename DiscreteSpace<I, L>::IndexType
106 (
107  const LabelType numberOfLabels
108 ) {
109  numbersOfLabels_.push_back(numberOfLabels);
110  OPENGM_ASSERT(std::numeric_limits<IndexType>::max()>numbersOfLabels_.size());
111  return numbersOfLabels_.size() - 1;
112 }
113 
114 template<class I, class L>
115 inline typename DiscreteSpace<I, L>::IndexType
117 {
118  return static_cast<IndexType>(numbersOfLabels_.size());
119 }
120 
121 template<class I, class L>
122 inline typename DiscreteSpace<I, L>::LabelType
124 (
125  const IndexType dimension
126 ) const
127 {
128  return numbersOfLabels_[dimension];
129 }
130 
131 } // namespace opengm
132 
133 #endif // #ifndef OPENGM_DISCRETE_SPACE_HXX
DiscreteSpace()
construct an empty label space (with zero variables)
The OpenGM namespace.
Definition: config.hxx:43
Discrete space in which variables can have differently many labels.
#define OPENGM_ASSERT(expression)
Definition: opengm.hxx:77
IndexType addVariable(const LabelType)
add one more variable
IndexType numberOfVariables() const
Interface of label spaces.
Definition: space_base.hxx:15
void assign(Iterator, Iterator)
assign a new sequence of numbers of labels to an existing space
void reserve(const IndexType)
allocate memory for a fixed number of variables
LabelType numberOfLabels(const IndexType) const
void assignDense(Iterator, Iterator)