scaled_view.hxx

Go to the documentation of this file.
00001 #pragma once
00002 #ifndef OPENGM_SCALEDVIEWFUNCTION_HXX
00003 #define OPENGM_SCALEDVIEWFUNCTION_HXX
00004 
00005 #include "opengm/functions/function_properties_base.hxx"
00006 
00007 namespace opengm {
00008 
00012 template<class GM> class ScaledViewFunction
00013 : public FunctionBase<ScaledViewFunction<GM>,
00014    typename GM::ValueType,
00015    typename GM::IndexType,
00016    typename GM::LabelType>
00017 {
00018 public:
00019    typedef typename GM::ValueType ValueType;
00020    typedef typename GM::IndexType IndexType;
00021    typedef typename GM::LabelType LabelType;
00022    typedef typename GM::OperatorType OperatorType;
00023 
00024    ScaledViewFunction(const std::vector<IndexType>&);
00025    ScaledViewFunction(const GM&, const IndexType, const ValueType);
00026    template<class Iterator> ValueType operator()(Iterator begin) const;
00027    size_t dimension() const;
00028    size_t shape(const size_t) const;
00029    size_t size() const;
00030 
00031 private:
00032    GM const* gm_;
00033    IndexType factorIndex_;
00034    ValueType scale_;
00035    std::vector<IndexType> shape_;
00036    size_t size_;
00037 };
00038 
00043 template<class GM>
00044 inline
00045 ScaledViewFunction<GM>::ScaledViewFunction
00046 (
00047    const GM& gm,
00048    const typename ScaledViewFunction<GM>::IndexType factorIndex,
00049    const ValueType scale
00050 )
00051 :  gm_(&gm),
00052    factorIndex_(factorIndex),
00053    scale_(scale)
00054 {
00055    size_=1;
00056    shape_.resize(gm[factorIndex].numberOfVariables());
00057    for(size_t i=0; i<gm[factorIndex].numberOfVariables();++i) {
00058       shape_[i] = gm[factorIndex].numberOfLabels(i);
00059       size_*=gm[factorIndex].numberOfLabels(i);
00060    }
00061 }
00064 template<class GM>
00065 inline
00066 ScaledViewFunction<GM>::ScaledViewFunction
00067 (
00068    const std::vector<IndexType>& shape
00069 )
00070 :  gm_(NULL),
00071    factorIndex_(0),
00072    scale_(0),
00073    shape_(shape)
00074 {
00075    size_=1;
00076    for(size_t i=0; i<shape_.size();++i) {
00077       size_*=shape[i];
00078    }
00079 }
00080 
00081 template<class GM>
00082 inline size_t
00083 ScaledViewFunction<GM>::size()const
00084 {
00085    return size_;
00086 }
00087 
00088 template<class GM>
00089 template<class Iterator>
00090 inline typename ScaledViewFunction<GM>::ValueType
00091 ScaledViewFunction<GM>::operator()
00092 (
00093    Iterator begin
00094 ) const
00095 {
00096    if(gm_==NULL) {
00097       return OperatorType::template neutral<ValueType>();
00098    }
00099    else {
00100       return scale_*gm_->operator[](factorIndex_)(begin);
00101    }
00102 }
00103 
00104 template<class GM>
00105 inline size_t
00106 ScaledViewFunction<GM>::shape(
00107    const size_t i
00108 ) const {
00109    return shape_[i];
00110 }
00111 
00112 template<class GM>
00113 inline size_t
00114 ScaledViewFunction<GM>::dimension() const {
00115    return shape_.size();
00116 }
00117 
00118 } // namespace opengm
00119 
00120 #endif // #ifndef OPENGM_SCALEDVIEWFUNCTION_HXX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Mon Jun 17 16:31:06 2013 for OpenGM by  doxygen 1.6.3