1. Minimum Interface for a Function 2. Registering a function for the OpenGM file format 3. Built-in functions 4. Serialization and de-serialization ///////////////////////////////////////////////////////////// 1. Minimum Interface for a Function ///////////////////////////////////////////////////////////// template class CustomFunction : public opengm::FunctionBase, T> { typedef T ValueType; template ValueType operator()(Iterator) const; // function evaluation size_t shape(const size_t) const; // number of labels of the indicated input variable size_t dimension() const; // number of input variables size_t size(); // number of parameters } ///////////////////////////////////////////////////////////// 2. Registering a function for the OpenGM file format ///////////////////////////////////////////////////////////// To add a custom function to the OpenGM file format, one needs to specialize the class template 'FunctionRegistration': template struct FunctionRegistration > { enum ID { Id=1 }; }; The IDs of built-in function types start at opengm::FUNCTION_TYPE_ID_OFFSET = 16000. Custom functions should have smaller IDs. ///////////////////////////////////////////////////////////// 3. Built-in functions ///////////////////////////////////////////////////////////// This list contains only those functions that can be stored to a file. Note that there are functions, such as 'ViewFunction', that cannot be stored. Function Name FunctionRegistration Id opengm::Marray 16000 opengm::SparseMarray 16001 opengm::AbsoluteDifferenceFunction 16002 opengm::TruncatedAbsoluteDifferenceFunction 16003 opengm::SquaredDifferenceFunction 16004 opengm::TruncatedSquaredDifferenceFunction 16005 opengm::Potts 16006 opengm::PottsN 16007 opengm::ConstantFunction 16008 opengm::StaticSingleSideFunction 16009 opengm::DynamicSingleSideFunction 16010 opengm::PottsG 16011 opengm::LPotts 16165 opengm::LUnary 16166 opengm::SumOfExperts 16167 ///////////////////////////////////////////////////////////// 4. Serialization and de-serialization ///////////////////////////////////////////////////////////// To add a custom function to the OpenGM file format, one also needs to specialize the 'FunctionSerialization' class template: template class FunctionSerialization > { public: typedef typename Function::ValueType ValueType; static size_t indexSequenceSize(const Function &); // number of indices to be stored static size_t valueSequenceSize(const Function &); // number of values to be stored template static void serialize(const Function static void deserialize(INDEX_INPUT_ITERATOR, VALUE_INPUT_ITERATOR, Function&); };