diff --git a/cpp/VSLAMFactor.cpp b/cpp/VSLAMFactor.cpp index 67ed040fa..68e18fb92 100644 --- a/cpp/VSLAMFactor.cpp +++ b/cpp/VSLAMFactor.cpp @@ -35,11 +35,10 @@ void VSLAMFactor::print(const std::string& s) const { } /* ************************************************************************* */ -bool VSLAMFactor::equals(const NonlinearFactor& f, double tol) const { - const VSLAMFactor* p = dynamic_cast(&f); - if (p == NULL) return false; - if (cameraFrameNumber_ != p->cameraFrameNumber_ || landmarkNumber_ != p->landmarkNumber_) return false; - if (!equal_with_abs_tol(this->z_,p->z_,tol)) return false; + bool VSLAMFactor::equals(const VSLAMFactor& p, double tol) const { + if (&p == NULL) return false; + if (cameraFrameNumber_ != p.cameraFrameNumber_ || landmarkNumber_ != p.landmarkNumber_) return false; + if (!equal_with_abs_tol(this->z_,p.z_,tol)) return false; return true; } diff --git a/cpp/VSLAMFactor.h b/cpp/VSLAMFactor.h index b53c48a8e..2c023a388 100644 --- a/cpp/VSLAMFactor.h +++ b/cpp/VSLAMFactor.h @@ -9,6 +9,8 @@ #include "NonlinearFactor.h" #include "LinearFactor.h" #include "Cal3_S2.h" +#include "Testable.h" + namespace gtsam { @@ -18,7 +20,8 @@ class VSLAMConfig; * Non-linear factor for a constraint derived from a 2D measurement, * i.e. the main building block for visual SLAM. */ -class VSLAMFactor : public NonlinearFactor +//class VSLAMFactor : public NonlinearFactor, Testable > +class VSLAMFactor : public NonlinearFactor, Testable { private: @@ -51,7 +54,7 @@ class VSLAMFactor : public NonlinearFactor /** * equals */ - bool equals(const NonlinearFactor&, double tol=1e-9) const; + bool equals(const VSLAMFactor&, double tol=1e-9) const; /** * predict the measurement diff --git a/cpp/testVSLAMFactor.cpp b/cpp/testVSLAMFactor.cpp index f8b492751..83f111de8 100644 --- a/cpp/testVSLAMFactor.cpp +++ b/cpp/testVSLAMFactor.cpp @@ -70,6 +70,21 @@ TEST( VSLAMFactor, error ) CHECK(assert_equal(expected_config,actual_config,1e-9)); } +TEST( VSLAMFactor, equals ) +{ + // Create two identical factors and make sure they're equal + Vector z = Vector_(2,323.,240.); + double sigma=1.0; + int cameraFrameNumber=1, landmarkNumber=1; + boost::shared_ptr + factor1(new VSLAMFactor(z, sigma, cameraFrameNumber, landmarkNumber, K)); + + boost::shared_ptr + factor2(new VSLAMFactor(z, sigma, cameraFrameNumber, landmarkNumber, K)); + + CHECK(assert_equal(*factor1, *factor2)); +} + /* ************************************************************************* */ int main() { TestResult tr;