OpenGM  2.3.x
Discrete Graphical Model Library
simplediscretespace.hxx
Go to the documentation of this file.
1 #pragma once
2 #ifndef OPENGM_SIMPLE_DISCRETE_SPACE_HXX
3 #define OPENGM_SIMPLE_DISCRETE_SPACE_HXX
4 
5 #include "opengm/opengm.hxx"
7 
8 namespace opengm {
9 
13 template<class I = std::size_t, class L = std::size_t>
15 : public SpaceBase<SimpleDiscreteSpace<I, L>, I, L> {
16 public:
17  typedef I IndexType;
18  typedef L LabelType;
19 
21  SimpleDiscreteSpace(const IndexType, const LabelType);
22  void assign(const IndexType, const LabelType);
23  template<class Iterator> void assignDense(Iterator, Iterator);
24  IndexType addVariable(const LabelType);
25  IndexType numberOfVariables() const;
26  LabelType numberOfLabels(const IndexType) const;
27  bool isSimpleSpace() const ;
28 
29 private:
30  IndexType numberOfVariables_;
31  LabelType numberOfLabels_;
32 };
33 
34 template<class I, class L>
35 inline
37 : numberOfVariables_(),
38  numberOfLabels_()
39 {}
40 
41 template<class I, class L>
42 inline
44 (
45  const IndexType numberOfVariables,
46  const LabelType numberOfLabels
47 )
48 : numberOfVariables_(numberOfVariables),
49  numberOfLabels_(numberOfLabels)
50 {}
51 
52 template<class I, class L>
53 template<class Iterator>
54 inline void
56 (
57  Iterator begin,
58  Iterator end
59 ) {
60  numberOfVariables_ = std::distance(begin, end);
61  numberOfLabels_ = static_cast<L>(*begin);
62  while(begin != end) {
63  if(numberOfLabels_ != static_cast<LabelType>(*begin)) {
64  throw opengm::RuntimeError("*begin == SimpleDiscreteSpace.numberOfLabels_ is violated in SimpleDiscreteSpace::assignDense");
65  }
66  ++begin;
67  }
68 }
69 
70 template<class I, class L>
71 inline void
73 (
74  const IndexType numberOfVariables,
75  const LabelType numberOfLabels
76 ) {
77  numberOfVariables_ = numberOfVariables;
78  numberOfLabels_ = numberOfLabels;
79 }
80 
81 template<class I, class L>
84 (
85  const LabelType numberOfLabels
86 ) {
87  if(numberOfLabels != numberOfLabels_) {
88  throw opengm::RuntimeError("numberOfLabels == SimpleDiscreteSpace.numberOfLabels_ is violated in SimpleDiscreteSpace::addVariable");
89  }
90  ++numberOfVariables_;
91  return numberOfVariables_ - 1;
92 }
93 
94 template<class I, class L>
97  return numberOfVariables_;
98 }
99 
100 template<class I, class L>
103 (
104  const IndexType dimension
105 ) const {
106  return numberOfLabels_;
107 }
108 
109 template<class I, class L>
110 inline bool
112  return true;
113 }
114 
115 } // namespace opengm
116 
117 #endif // #ifndef OPENGM_SIMPLE_DISCRETE_SPACE_HXX
The OpenGM namespace.
Definition: config.hxx:43
Discrete space in which all variables have the same number of labels.
IndexType addVariable(const LabelType)
void assignDense(Iterator, Iterator)
Interface of label spaces.
Definition: space_base.hxx:15
IndexType numberOfVariables() const
void assign(const IndexType, const LabelType)
OpenGM runtime error.
Definition: opengm.hxx:100
LabelType numberOfLabels(const IndexType) const