diff --git a/gtsam/geometry/CameraSet.h b/gtsam/geometry/CameraSet.h index defdbe494..b1bd20c4a 100644 --- a/gtsam/geometry/CameraSet.h +++ b/gtsam/geometry/CameraSet.h @@ -20,6 +20,7 @@ #include #include // for Cheirality exception +#include #include namespace gtsam { @@ -53,17 +54,16 @@ public: CameraSet() { } - /** Virtual destructor */ - virtual ~CameraSet() { - } - - /** - * Add a new camera - */ + /// Add a new camera void add(const CAMERA& camera) { cameras_.push_back(camera); } + /// Retrieve ith camera + const CAMERA& operator[](size_t i) const { + return cameras_[i]; + } + /** * print * @param s optional string naming the factor @@ -72,7 +72,7 @@ public: void print(const std::string& s = "") const { std::cout << s << "CameraSet, cameras = \n"; for (size_t k = 0; k < cameras_.size(); ++k) - cameras_[k]->print(); + cameras_[k].print(); } /// equals @@ -90,13 +90,17 @@ public: * project, with derivatives in this, point, and calibration * throws CheiralityException */ - std::vector project(const Point3& point, boost::optional F=boost::none, - boost::optional E=boost::none, boost::optional H=boost::none) const { + std::vector project(const Point3& point, boost::optional F = + boost::none, boost::optional E = boost::none, + boost::optional H = boost::none) const { size_t nrCameras = cameras_.size(); - if (F) F->resize(ZDim * nrCameras, 6); - if (E) E->resize(ZDim * nrCameras, 3); - if (H && Dim>6) H->resize(ZDim * nrCameras, Dim - 6); + if (F) + F->resize(ZDim * nrCameras, 6); + if (E) + E->resize(ZDim * nrCameras, 3); + if (H && Dim > 6) + H->resize(ZDim * nrCameras, Dim - 6); std::vector z(nrCameras); for (size_t i = 0; i < cameras_.size(); i++) { @@ -104,9 +108,12 @@ public: Eigen::Matrix Ei; Eigen::Matrix Hi; z[i] = cameras_[i].project(point, F ? &Fi : 0, E ? &Ei : 0, H ? &Hi : 0); - if (F) F->block(ZDim * i, 0) = Fi; - if (E) E->block(ZDim * i, 0) = Ei; - if (H) H->block(ZDim * i, 0) = Hi; + if (F) + F->block(ZDim * i, 0) = Fi; + if (E) + E->block(ZDim * i, 0) = Ei; + if (H) + H->block(ZDim * i, 0) = Hi; } return z; } @@ -124,4 +131,12 @@ private: template const int CameraSet::ZDim; +template +struct traits > : public Testable > { +}; + +template +struct traits > : public Testable > { +}; + } // \ namespace gtsam diff --git a/gtsam/geometry/tests/testCameraSet.cpp b/gtsam/geometry/tests/testCameraSet.cpp index c1ff5476f..c24ba39b1 100644 --- a/gtsam/geometry/tests/testCameraSet.cpp +++ b/gtsam/geometry/tests/testCameraSet.cpp @@ -37,6 +37,10 @@ TEST(CameraSet, Pinhole) { set.add(camera); set.add(camera); Point3 p(0, 0, 1); + CHECK(assert_equal(set,set)); + CameraSet set2 = set; + set2.add(camera); + CHECK(!assert_equal(set,set2)); // Check measurements Point2 expected;