Testable and default constructor
parent
022af8f9bc
commit
f44e39eb21
|
|
@ -29,19 +29,18 @@ namespace gtsam {
|
|||
/**
|
||||
* Factor that supports arbitrary expressions via AD
|
||||
*/
|
||||
template<class T>
|
||||
template<typename T>
|
||||
class ExpressionFactor: public NoiseModelFactor {
|
||||
|
||||
protected:
|
||||
|
||||
typedef ExpressionFactor<T> This;
|
||||
static const int Dim = traits<T>::dimension;
|
||||
|
||||
T measurement_; ///< the measurement to be compared with the expression
|
||||
Expression<T> expression_; ///< the expression that is AD enabled
|
||||
FastVector<int> dims_; ///< dimensions of the Jacobian matrices
|
||||
|
||||
static const int Dim = traits<T>::dimension;
|
||||
|
||||
public:
|
||||
|
||||
typedef boost::shared_ptr<ExpressionFactor<T> > shared_ptr;
|
||||
|
|
@ -62,6 +61,19 @@ public:
|
|||
boost::tie(keys_, dims_) = expression_.keysAndDims();
|
||||
}
|
||||
|
||||
/// print relies on Testable traits being defined for T
|
||||
void print(const std::string& s, const KeyFormatter& keyFormatter) const {
|
||||
NoiseModelFactor::print(s, keyFormatter);
|
||||
traits<T>::Print(measurement_, s + ".measurement_");
|
||||
}
|
||||
|
||||
/// equals relies on Testable traits being defined for T
|
||||
bool equals(const NonlinearFactor& f, double tol) const {
|
||||
const ExpressionFactor* p = dynamic_cast<const ExpressionFactor*>(&f);
|
||||
return p && NoiseModelFactor::equals(f, tol) &&
|
||||
traits<T>::Equals(measurement_, p->measurement_, tol);
|
||||
}
|
||||
|
||||
/**
|
||||
* Error function *without* the NoiseModel, \f$ h(x)-z \f$.
|
||||
* We override this method to provide
|
||||
|
|
@ -119,8 +131,17 @@ public:
|
|||
return boost::static_pointer_cast<gtsam::NonlinearFactor>(
|
||||
gtsam::NonlinearFactor::shared_ptr(new This(*this)));
|
||||
}
|
||||
|
||||
protected:
|
||||
/// Default constructor, for serialization
|
||||
ExpressionFactor() {}
|
||||
|
||||
};
|
||||
// ExpressionFactor
|
||||
|
||||
/// traits
|
||||
template <typename T>
|
||||
struct traits<ExpressionFactor<T> > : public Testable<ExpressionFactor<T> > {};
|
||||
|
||||
}// \ namespace gtsam
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue