00001
00002
00003 #ifndef _GEOM_POINT_HPP_
00004 #define _GEOM_POINT_HPP_
00005
00006
00007 #include <kernel/jafarMacro.hpp>
00008 #include "geom/Atom.hpp"
00009 #include "geom/Distance.hpp"
00010 #include "geom/Angle.hpp"
00011 #include "geom/Transferrable.hpp"
00012
00013 namespace jafar {
00014 namespace geom {
00027 template<int dimension>
00028 class Point : public Atom<dimension> {
00029 typedef typename Atom<dimension>::HomogenousVecD HomogenousVecD;
00030 typedef typename Atom<dimension>::HomogenousSymMatrixD HomogenousSymMatrixD;
00031 typedef typename Atom<dimension>::VecD VecD;
00032 typedef typename Atom<dimension>::HomogenousMatrixD HomogenousMatrixD;
00033 typedef typename Atom<dimension>::SymMatrixD SymMatrixD;
00034 typedef Repere<dimension> RepereD;
00035 public:
00041 class Driver : public Atom<dimension>::Driver {
00042 public:
00043 Driver() : Atom<dimension>::Driver(), rangeDimension(0, dimension) { }
00044 virtual ~Driver() {}
00045 virtual Driver* clone() const = 0;
00049 virtual HomogenousVecD homogenousCoordinates() const = 0;
00053 virtual HomogenousSymMatrixD homogenousCoordinatesCov() const = 0;
00054 protected:
00055 ublas::range rangeDimension;
00056 };
00062 class EuclideanDriver : public Driver, public Transferrable<dimension>, public Transformable<dimension> {
00063 public:
00067 EuclideanDriver(const VecD& coordinates, const RepereD* reference = RepereD::global());
00068 EuclideanDriver(const VecD& coordinates, const SymMatrixD& matrix, const RepereD* reference = RepereD::global());
00069 virtual ~EuclideanDriver() {}
00070 virtual Driver* clone() const
00071 {
00072 return new EuclideanDriver(*this);
00073 }
00074 virtual HomogenousVecD homogenousCoordinates() const
00075 {
00076 return m_coordinates;
00077 }
00078 virtual HomogenousSymMatrixD homogenousCoordinatesCov() const
00079 {
00080 return m_coordinatesCov;
00081 }
00082 virtual void changeReference( const RepereD* reference );
00083 virtual const RepereD* reference( ) const;
00084 virtual bool hasCov() const { return m_cov; }
00085 void applyTransformation( const HomogenousMatrixD& _transformation )
00086 {
00087 m_coordinates = ublas::prod( _transformation, m_coordinates );
00088 JFR_ASSERT( not m_cov, "Transformation of covariance not supported" );
00089 }
00090 private:
00091 HomogenousVecD m_coordinates;
00092 HomogenousSymMatrixD m_coordinatesCov;
00093 const RepereD* m_reference;
00094 bool m_cov;
00095 };
00096 class HomogenousDriver : public Driver, public Transferrable<dimension>, public Transformable<dimension> {
00097 public:
00101 HomogenousDriver(const HomogenousVecD& coordinates, const RepereD* reference = RepereD::global());
00102 HomogenousDriver(const HomogenousVecD& coordinates, const HomogenousSymMatrixD& matrix, const RepereD* reference = RepereD::global());
00103 virtual ~HomogenousDriver() {}
00104 virtual Driver* clone() const
00105 {
00106 return new HomogenousDriver(*this);
00107 }
00108 virtual HomogenousVecD homogenousCoordinates() const
00109 {
00110 return m_coordinates;
00111 }
00112 virtual HomogenousSymMatrixD homogenousCoordinatesCov() const
00113 {
00114 return m_coordinatesCov;
00115 }
00116 virtual void changeReference( const RepereD* reference );
00117 virtual const RepereD* reference( ) const;
00118 virtual bool hasCov() const { return m_cov; }
00119 void applyTransformation( const HomogenousMatrixD& _transformation )
00120 {
00121 m_coordinates = ublas::prod( _transformation, m_coordinates );
00122 JFR_ASSERT( not m_cov, "Transformation of covariance not supported" );
00123 }
00124 private:
00125 HomogenousVecD m_coordinates;
00126 HomogenousSymMatrixD m_coordinatesCov;
00127 const RepereD* m_reference;
00128 bool m_cov;
00129 };
00130 public:
00134 inline Point() : Atom<dimension>(0), m_driver(0) {}
00135 inline Point(Driver* driver) : Atom<dimension>((typename Atom<dimension>::Driver*)driver), m_driver(driver)
00136 {
00137 }
00138 inline Point(const Point& p) : Atom<dimension>(0), m_driver(0)
00139 {
00140 *this = p;
00141 }
00142 virtual ~Point() { }
00143 virtual typename Atom<dimension>::Type type() const { return Atom<dimension>::T_Point; }
00144 virtual BoundingBox<dimension> boundingBox() const;
00148 inline HomogenousVecD homogenousCoordinates() const {
00149 return m_driver->homogenousCoordinates();
00150 }
00154 inline HomogenousSymMatrixD homogenousCoordinatesCov() const {
00155 JFR_ASSERT( this->hasCov(), "This point has no covariance");
00156 HomogenousSymMatrixD m;
00157 return m_driver->homogenousCoordinatesCov();
00158 }
00159 inline Point& operator=(const Point& rhs);
00160 public:
00161 GEN_DISTANCE_FUNCTIONS
00162 GEN_ANGLE_FUNCTIONS
00163 GEN_VISITOR_FUNCTIONS
00164 public:
00165 virtual std::string toString() const;
00166 private:
00167 Driver* m_driver;
00168 };
00169 template<int dimension>
00170 std::ostream& operator <<(std::ostream& s, Point<dimension> const& seg) {
00171 s << "Point [" << seg.homogenousCoordinates() << " ]";
00172 return s;
00173 }
00174 }
00175 }
00176
00177 #include "PointImpl.hpp"
00178
00179 #endif