Added concept checking for "Poses", and made both Pose2 and Pose3 comply

release/4.3a0
Alex Cunningham 2011-10-06 20:47:30 +00:00
parent 541c1085db
commit c6e2547dad
6 changed files with 70 additions and 2 deletions

View File

@ -10,6 +10,9 @@ headers =
sources = sources =
check_PROGRAMS = check_PROGRAMS =
# Concept check
headers += concepts.h
# Points and poses # Points and poses
sources += Point2.cpp Rot2.cpp Pose2.cpp Point3.cpp Rot3.cpp Pose3.cpp sources += Point2.cpp Rot2.cpp Pose2.cpp Point3.cpp Rot3.cpp Pose3.cpp
check_PROGRAMS += tests/testPoint2 tests/testRot2 tests/testPose2 tests/testPoint3 tests/testRot3 tests/testPose3 check_PROGRAMS += tests/testPoint2 tests/testRot2 tests/testPose2 tests/testPoint3 tests/testRot3 tests/testPose3

View File

@ -17,6 +17,7 @@
#include <boost/foreach.hpp> #include <boost/foreach.hpp>
#include <gtsam/geometry/Pose2.h> #include <gtsam/geometry/Pose2.h>
#include <gtsam/base/Lie-inl.h> #include <gtsam/base/Lie-inl.h>
#include <gtsam/geometry/concepts.h>
using namespace std; using namespace std;
@ -25,6 +26,9 @@ namespace gtsam {
/** Explicit instantiation of base class to export members */ /** Explicit instantiation of base class to export members */
INSTANTIATE_LIE(Pose2); INSTANTIATE_LIE(Pose2);
/** instantiate concept checks */
GTSAM_CONCEPT_POSE(Pose2);
static const Matrix I3 = eye(3), Z12 = zeros(1,2); static const Matrix I3 = eye(3), Z12 = zeros(1,2);
static const Rot2 R_PI_2(Rot2::fromCosSin(0., 1.)); static const Rot2 R_PI_2(Rot2::fromCosSin(0., 1.));

View File

@ -35,6 +35,11 @@ namespace gtsam {
public: public:
static const size_t dimension = 3; static const size_t dimension = 3;
/** Pose Concept requirements */
typedef Rot2 Rotation;
typedef Point2 Translation;
private: private:
Rot2 r_; Rot2 r_;
Point2 t_; Point2 t_;
@ -213,9 +218,14 @@ namespace gtsam {
inline double y() const { return t_.y(); } inline double y() const { return t_.y(); }
inline double theta() const { return r_.theta(); } inline double theta() const { return r_.theta(); }
/** shorthand access functions */
inline const Point2& t() const { return t_; } inline const Point2& t() const { return t_; }
inline const Rot2& r() const { return r_; } inline const Rot2& r() const { return r_; }
/** full access functions required by Pose concept */
inline const Point2& translation() const { return t_; }
inline const Rot2& rotation() const { return r_; }
private: private:
// Serialization function // Serialization function
friend class boost::serialization::access; friend class boost::serialization::access;

View File

@ -17,6 +17,7 @@
#include <iostream> #include <iostream>
#include <gtsam/geometry/Pose3.h> #include <gtsam/geometry/Pose3.h>
#include <gtsam/base/Lie-inl.h> #include <gtsam/base/Lie-inl.h>
#include <gtsam/geometry/concepts.h>
using namespace std; using namespace std;
@ -25,7 +26,13 @@ namespace gtsam {
/** Explicit instantiation of base class to export members */ /** Explicit instantiation of base class to export members */
INSTANTIATE_LIE(Pose3); INSTANTIATE_LIE(Pose3);
static const Matrix I3 = eye(3), _I3=-I3, I6 = eye(6), Z3 = zeros(3, 3); /** instantiate concept checks */
GTSAM_CONCEPT_POSE(Pose3);
static const Matrix I3 = eye(3), Z3 = zeros(3, 3);
#ifdef CORRECT_POSE3_EXMAP
static const _I3=-I3, I6 = eye(6);
#endif
/* ************************************************************************* */ /* ************************************************************************* */
// Calculate Adjoint map // Calculate Adjoint map
@ -216,7 +223,6 @@ namespace gtsam {
} }
if (H2) { if (H2) {
#ifdef CORRECT_POSE3_EXMAP #ifdef CORRECT_POSE3_EXMAP
*H2 = I6; *H2 = I6;
#else #else
Matrix R1 = rotation().matrix(); Matrix R1 = rotation().matrix();

View File

@ -31,6 +31,10 @@ namespace gtsam {
public: public:
static const size_t dimension = 6; static const size_t dimension = 6;
/** Pose Concept requirements */
typedef Rot3 Rotation;
typedef Point3 Translation;
private: private:
Rot3 R_; Rot3 R_;
Point3 t_; Point3 t_;

41
gtsam/geometry/concepts.h Normal file
View File

@ -0,0 +1,41 @@
/**
* @file concepts.h
*
* @brief Concept-checking macros for geometric objects
* Each macro instantiates a concept check structure, which
* includes a static function that will fail to compile
* if the concept does not pass. Functions are made static
* to ensure they get instantiated.
*
* @date Oct 6, 2011
* @author Alex Cunningham
*/
#pragma once
namespace gtsam {
/**
* Pose Concept
* A must contain a translation and a rotation, with
* each structure accessable directly and a type provided
* for each.
*/
template<class POSE>
struct PoseConcept {
typedef typename POSE::Translation Translation;
typedef typename POSE::Rotation Rotation;
static Rotation checkRotationMemberAccess(const POSE& p) {
return p.rotation();
}
static Translation checkTranslationMemberAccess(const POSE& p) {
return p.translation();
}
};
/** Instantiation macro */
#define GTSAM_CONCEPT_POSE(T) template class PoseConcept<T>;
} // \namespace gtsam