11#ifndef __MEAL_UnaryConvert_H
12#define __MEAL_UnaryConvert_H
14#include "MEAL/Convert.h"
23 template<
typename From,
typename To,
typename Method>
24 class UnaryConvert :
public Convert<From,To>
29 UnaryConvert (Method m) {
method = m; }
33 {
return "UnaryConvert<" + std::string(From::Name)
34 +
"," + std::string(To::Name)+
">"; }
39 virtual void calculate (
typename To::Result& result,
40 std::vector<typename To::Result>* grad)
42 std::vector<typename From::Result> from_grad;
43 typename From::Result from_result;
45 from_result = this->
get_model()->evaluate( (grad) ? &from_grad : 0 );
46 result =
method (from_result);
50 for (
unsigned i=0; i<this->get_nparam(); i++)
51 (*grad)[i] =
method (from_grad[i]);
58 template<
typename T,
typename M>
67 T* convert (T* function,
68 typename T::Result (*method) (
const typename T::Result&))
70 typedef typename T::Result (*M) (
const typename T::Result&);
71 UnaryConvert<T,T,M>* result =
new UnaryConvert<T,T,M> (method);
72 result->set_model (function);
Convert a function to another type.
Definition Convert.h:20
void set_model(From *_model)
Set the function to be converted.
Definition Convert.h:25
From * get_model()
Get the function to be converted.
Definition Convert.h:32
Convert a function to another type using a unary function.
Definition UnaryConvert.h:25
Method method
The Unary function used to complete the conversion.
Definition UnaryConvert.h:55
std::string get_name() const
Return the name of the class.
Definition UnaryConvert.h:32
virtual void calculate(typename To::Result &result, std::vector< typename To::Result > *grad)
Calculate the Mueller matrix and its gradient.
Definition UnaryConvert.h:39
Namespace in which all modeling and calibration related code is declared.
Definition ExampleComplex2.h:16