messagepassing_buffer.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_MESSAGE_PASSING_BUFFER_HXX
00003 #define OPENGM_MESSAGE_PASSING_BUFFER_HXX
00004 
00006 
00007 namespace opengm {
00008 
00009    template<class ARRAY>
00010    class MessageBuffer {
00011    public:
00012       typedef ARRAY ArrayType;
00013       typedef typename ARRAY::ValueType ValueType;
00014 
00015       // construction and assignment
00016       MessageBuffer();
00017       template<class SHAPE_ITERATOR>
00018       MessageBuffer(SHAPE_ITERATOR, SHAPE_ITERATOR, const ValueType& = ValueType());
00019       template<class SHAPE_ITERATOR>
00020       void assign(SHAPE_ITERATOR, SHAPE_ITERATOR, const ValueType& = ValueType()); 
00021       template<class SHAPE>
00022       void assign(SHAPE, const ValueType& = ValueType());
00023 /*
00024       template<class GRAPHICAL_MODEL, class INDEX_ITERATOR>
00025       MessageBuffer(const GRAPHICAL_MODEL& , INDEX_ITERATOR, INDEX_ITERATOR, const ValueType& = ValueType());
00026       template<class GRAPHICAL_MODEL, class INDEX_ITERATOR>
00027       void assign(const GRAPHICAL_MODEL& , INDEX_ITERATOR, INDEX_ITERATOR, const ValueType& = ValueType());
00028 */
00029       // query
00030       const ARRAY& current() const;
00031       const ARRAY& old() const;
00032       template<class DIST>
00033       ValueType dist() const; // distance between current and old
00034 
00035       ARRAY& current();
00036       ARRAY& old();
00037 
00038       // manipulation
00039       void toggle();
00040 
00041    private:
00042       bool flag_;
00043       ARRAY buffer1_;
00044       ARRAY buffer2_;
00045    };
00046 
00047 
00048    //**********************
00049    // IMPLEMENTATION
00050    //**********************
00051 
00052    template<class ARRAY>
00053    inline MessageBuffer<ARRAY>::MessageBuffer()
00054    {}
00055 
00056    template<class ARRAY>
00057    template<class SHAPE_ITERATOR>
00058    inline  MessageBuffer<ARRAY>::MessageBuffer
00059    (
00060       SHAPE_ITERATOR begin,
00061       SHAPE_ITERATOR end,
00062       const typename ARRAY::ValueType& constant
00063    ) {
00064       assign(begin, end, constant);
00065    }
00066 /*
00067    template<class ARRAY>
00068    template<class GRAPHICAL_MODEL, class INDEX_ITERATOR>
00069    inline
00070    MessageBuffer<ARRAY>::MessageBuffer
00071    (
00072       const GRAPHICAL_MODEL& gm,
00073       INDEX_ITERATOR begin,
00074       INDEX_ITERATOR end,
00075       const typename ARRAY::ValueType& constant
00076    ) {
00077       assign(gm, begin, end, constant);
00078    }
00079 */
00080    template<class ARRAY>
00081    template<class SHAPE_ITERATOR>
00082    inline void  MessageBuffer<ARRAY>::assign
00083    (
00084       SHAPE_ITERATOR begin,
00085       SHAPE_ITERATOR end,
00086       const typename ARRAY::ValueType& constant
00087    )
00088    {
00089       if(begin == end) {
00090          buffer1_ = constant;
00091          buffer2_ = constant;
00092       }
00093       else {
00094          buffer1_.assign(begin, end, constant);
00095          buffer2_.assign(begin, end, constant);
00096       }
00097       flag_ = false;
00098    } 
00099 
00100    template<class ARRAY>
00101    template<class SHAPE>
00102    inline void  MessageBuffer<ARRAY>::assign
00103    (
00104       SHAPE shape,
00105       const typename ARRAY::ValueType& constant
00106    )
00107    {
00108       if(shape == 0) {
00109          buffer1_ = constant;
00110          buffer2_ = constant;
00111       }
00112       else {
00113          buffer1_.resize(&shape, &shape+1, constant);
00114          buffer2_.resize(&shape, &shape+1, constant);
00115       }
00116       flag_ = false;
00117    }
00118 /*
00119    template<class ARRAY>
00120    template<class GRAPHICAL_MODEL, class INDEX_ITERATOR>
00121    inline void  MessageBuffer<ARRAY>::assign
00122    (
00123       const GRAPHICAL_MODEL& gm,
00124       INDEX_ITERATOR begin,
00125       INDEX_ITERATOR end,
00126       const typename ARRAY::ValueType& constant
00127    )
00128    {
00129       if(begin == end) {
00130          buffer1_.assign(constant);
00131          buffer2_.assign(constant);
00132       }
00133       else {
00134          buffer1_.assign(gm, begin, end, constant);
00135          buffer2_.assign(gm, begin, end, constant);
00136       }
00137       flag_ = false;
00138    }
00139 */
00140 
00141    template<class ARRAY>
00142    inline ARRAY& MessageBuffer<ARRAY>::current() {
00143       return flag_ ? buffer1_ : buffer2_;
00144    }
00145 
00146    template<class ARRAY>
00147    inline const ARRAY& MessageBuffer<ARRAY>::current() const {
00148       return flag_ ? buffer1_ : buffer2_;
00149    }
00150 
00151    template<class ARRAY>
00152    inline ARRAY& MessageBuffer<ARRAY>::old() {
00153       return flag_ ? buffer2_ : buffer1_;
00154    }
00155 
00156    template<class ARRAY>
00157    inline const ARRAY& MessageBuffer<ARRAY>::old() const {
00158       return flag_ ? buffer2_ : buffer1_;
00159    }
00160 
00161    template<class ARRAY>
00162    inline void MessageBuffer<ARRAY>::toggle() {
00163       flag_ = flag_ ? false : true;
00164    }
00165 
00166    template<class ARRAY>
00167    template<class DIST>
00168    inline typename ARRAY::ValueType MessageBuffer<ARRAY>::dist() const {
00169       return DIST::op(buffer1_, buffer2_);
00170    }
00171 }
00172 
00174 
00175 #endif // #ifndef OPENGM_MESSAGE_PASSING_BUFFER_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:04 2013 for OpenGM by  doxygen 1.6.3