00001
00002
00003 #ifndef _GEOM_LINE_HPP_
00004 #define _GEOM_LINE_HPP_
00005
00006 #include "geom/Atom.hpp"
00007 #include "geom/Distance.hpp"
00008 #include "geom/Angle.hpp"
00009 #include "geom/Transferrable.hpp"
00010
00011 namespace jafar {
00012 namespace geom {
00013 template<int dimension>
00014 class Point;
00015 template<int dimension>
00020 class Line : public Atom<dimension> {
00021 typedef typename Atom<dimension>::HomogenousVecD HomogenousVecD;
00022 typedef typename Atom<dimension>::HomogenousMatrixD HomogenousMatrixD;
00023 typedef typename Atom<dimension>::HomogenousSymMatrixD HomogenousSymMatrixD;
00024 typedef typename Atom<dimension>::VecD VecD;
00025 typedef Repere<dimension> RepereD;
00026 public:
00030 class Driver : public Atom<dimension>::Driver {
00031 public:
00032 Driver() : Atom<dimension>::Driver(), rangeDimension(0, dimension){}
00033 virtual ~Driver() {}
00038 virtual HomogenousVecD pointAt(double t) const = 0;
00043 virtual HomogenousVecD origin() const = 0;
00044 virtual HomogenousSymMatrixD originCov() const = 0;
00048 virtual HomogenousVecD direction() const = 0;
00049 virtual HomogenousSymMatrixD directionCov() const = 0;
00053 virtual Driver* cloneLineDriver() const = 0;
00054 protected:
00055 ublas::range rangeDimension;
00056 };
00061 class EuclideanDriver : public Driver, public Transferrable<dimension> {
00062 public:
00067 EuclideanDriver(const HomogenousVecD& origin, const HomogenousVecD& direction, const RepereD* reference = RepereD::global());
00068 EuclideanDriver(const VecD& origin, const VecD& direction, const RepereD* reference = RepereD::global());
00069 void setCov(HomogenousSymMatrixD m_originCov, HomogenousSymMatrixD m_directionCov);
00070 virtual HomogenousVecD pointAt(double t) const;
00071 virtual HomogenousVecD origin() const;
00072 virtual HomogenousSymMatrixD originCov() const;
00073 virtual HomogenousVecD direction() const;
00074 virtual HomogenousSymMatrixD directionCov() const;
00075 virtual Driver* cloneLineDriver() const;
00076 virtual void changeReference( const RepereD* reference );
00077 virtual const RepereD* reference( ) const;
00078 virtual bool hasCov() const { return m_hasCov; }
00079 private:
00080 HomogenousVecD m_origin, m_direction;
00081 HomogenousSymMatrixD m_originCov, m_directionCov;
00082 const RepereD* m_reference;
00083 bool m_hasCov;
00084 };
00089 class TwoPointsPointerDriver : public Driver {
00090 public:
00091 TwoPointsPointerDriver(const Point<dimension>* p1, const Point<dimension>* p2);
00092 ~TwoPointsPointerDriver();
00093 virtual HomogenousVecD pointAt(double t) const;
00094 virtual HomogenousVecD origin() const;
00095 virtual HomogenousSymMatrixD originCov() const;
00096 virtual HomogenousVecD direction() const;
00097 virtual HomogenousSymMatrixD directionCov() const;
00098 virtual Driver* cloneLineDriver() const;
00099 virtual const RepereD* reference( ) const;
00100 virtual bool hasCov() const;
00101 private:
00102 struct Private;
00103 Private* const d;
00104 };
00105 public:
00106 Line( Driver* d );
00107 Line( const Line& l );
00108 inline Line& operator=(const Line& rhs);
00109 virtual ~Line();
00110 virtual typename Atom<dimension>::Type type() const { return Atom<dimension>::T_Line; }
00111 virtual BoundingBox<dimension> boundingBox() const;
00117 inline HomogenousVecD pointAt(double t) const;
00123 inline HomogenousSymMatrixD pointAtCov(double t, double tCov) const;
00129 inline HomogenousVecD origin() const;
00130 inline HomogenousSymMatrixD originCov() const;
00135 inline HomogenousVecD direction() const;
00136 inline HomogenousSymMatrixD directionCov() const;
00140 inline HomogenousVecD project(const HomogenousVecD& p) const;
00144 inline HomogenousVecD project(const Point<dimension>& p) const;
00148 inline void projectCov( const HomogenousVecD& p, const HomogenousSymMatrixD& pCov, HomogenousVecD& v, HomogenousSymMatrixD& vCov) const;
00152 inline void projectCov( const Point<dimension>& p, HomogenousVecD& v, HomogenousSymMatrixD& cov) const;
00153 inline void closestPoint( const Line<dimension>& l, HomogenousVecD& v1, HomogenousVecD& v2) const;
00154 inline void closestPointCov( const Line<dimension>& l, HomogenousVecD& v1, HomogenousSymMatrixD& cov1, HomogenousVecD& v2, HomogenousSymMatrixD& cov2) const;
00158 inline Driver* clonedDriver() const;
00159 public:
00160 GEN_DISTANCE_FUNCTIONS
00161 GEN_ANGLE_FUNCTIONS
00162 GEN_VISITOR_FUNCTIONS
00163 protected:
00164 void setDriver(Driver* d);
00165 private:
00166 inline void closestPointJac( const HomogenousVecD& O1, const HomogenousVecD& u1, const HomogenousVecD& O2, const HomogenousVecD& u2, HomogenousMatrixD& O1Jac, HomogenousMatrixD& u1Jac, HomogenousMatrixD& O2Jac, HomogenousMatrixD& u2Jac) const;
00167 Driver* m_driver;
00168 };
00169
00170 typedef Line<3> Line3D;
00171 typedef Line<2> Line2D;
00172 }
00173 }
00174
00175 #include "geom/LineImpl.hpp"
00176
00177 #endif