00001
00002 #ifndef _SEGMENT_HPP_
00003 #define _SEGMENT_HPP_
00004
00005 #include "Line.hpp"
00006
00007 namespace jafar {
00008 namespace geom {
00009 template<int dimension>
00010 class Point;
00023 template<int dimension>
00024 class Segment : public Line<dimension>
00025 {
00026 public:
00027 typedef typename Atom<dimension>::HomogenousVecD HomogenousVecD;
00028 typedef typename Atom<dimension>::HomogenousSymMatrixD HomogenousSymMatrixD;
00029 typedef typename Atom<dimension>::VecD VecD;
00030 typedef typename Atom<dimension>::HomogenousMatrixD HomogenousMatrixD;
00031 typedef Repere<dimension> RepereD;
00032 public:
00036 class Driver {
00037 public:
00038 virtual ~Driver() {}
00043 virtual Line<dimension> support() const = 0;
00048 virtual HomogenousVecD firstPoint() const = 0;
00049 virtual HomogenousSymMatrixD firstPointCov() const = 0;
00054 virtual HomogenousVecD lastPoint() const = 0;
00055 virtual HomogenousSymMatrixD lastPointCov() const = 0;
00059 virtual Driver* cloneSegmentDriver() const = 0;
00066 virtual typename Line<dimension>::Driver* asLineDriver() = 0;
00067 };
00068 class LineDriver : public Driver, public Line<dimension>::Driver {
00069 public:
00070 LineDriver(const Line<dimension>* support, double firstIndex, double lastIndex, const RepereD* reference = RepereD::global() );
00071 virtual ~LineDriver();
00072 public:
00073 virtual Line<dimension> support() const;
00074 virtual HomogenousVecD firstPoint() const;
00075 virtual HomogenousSymMatrixD firstPointCov() const;
00076 virtual HomogenousVecD lastPoint() const;
00077 virtual HomogenousSymMatrixD lastPointCov() const;
00078 virtual HomogenousVecD pointAt(double t) const;
00079 virtual HomogenousVecD origin() const;
00080 virtual HomogenousSymMatrixD originCov() const;
00081 virtual HomogenousVecD direction() const;
00082 virtual HomogenousSymMatrixD directionCov() const;
00083 virtual Driver* cloneSegmentDriver() const;
00084 virtual typename Line<dimension>::Driver* cloneLineDriver() const;
00085 virtual typename Line<dimension>::Driver* asLineDriver();
00086 virtual const RepereD* reference( ) const;
00087 virtual bool hasCov() const;
00088 private:
00089 struct Private;
00090 Private* const d;
00091 };
00092 class TwoPointsPointerDriver : public Driver, public Line<dimension>::TwoPointsPointerDriver {
00093 public:
00094 TwoPointsPointerDriver(const Point<dimension>* p1, const Point<dimension>* p2);
00095 virtual ~TwoPointsPointerDriver();
00096 public:
00097 virtual Line<dimension> support() const;
00098 virtual HomogenousVecD firstPoint() const;
00099 virtual HomogenousSymMatrixD firstPointCov() const;
00100 virtual HomogenousVecD lastPoint() const;
00101 virtual HomogenousSymMatrixD lastPointCov() const;
00102 virtual HomogenousVecD pointAt(double t) const;
00103 virtual Driver* cloneSegmentDriver() const;
00104 virtual typename Line<dimension>::Driver* asLineDriver();
00105 virtual const RepereD* reference( ) const;
00106 virtual bool hasCov() const;
00107 private:
00108 struct Private;
00109 Private* const d;
00110 };
00111 class TwoPointsDriver : public Driver, public Line<dimension>::Driver, public Transferrable<dimension>, public Transformable<dimension> {
00112 public:
00113 TwoPointsDriver(const HomogenousVecD& p1, const HomogenousVecD& p2, const RepereD* reference = RepereD::global());
00114 virtual ~TwoPointsDriver();
00115 void setCov(HomogenousSymMatrixD _firstPointCov, HomogenousSymMatrixD _lastPoint);
00116 public:
00117 virtual Line<dimension> support() const;
00118 virtual HomogenousVecD firstPoint() const;
00119 virtual HomogenousSymMatrixD firstPointCov() const;
00120 virtual HomogenousVecD lastPoint() const;
00121 virtual HomogenousSymMatrixD lastPointCov() const;
00122 virtual HomogenousVecD pointAt(double t) const;
00123 virtual Driver* cloneSegmentDriver() const;
00124 virtual void changeReference( const RepereD* reference );
00125 virtual const RepereD* reference( ) const;
00126 virtual typename Line<dimension>::Driver* asLineDriver();
00127 virtual HomogenousVecD origin() const;
00128 virtual HomogenousSymMatrixD originCov() const;
00129 virtual HomogenousVecD direction() const;
00130 virtual HomogenousSymMatrixD directionCov() const;
00131 virtual typename Line<dimension>::Driver* cloneLineDriver() const;
00132 virtual bool hasCov() const { return m_hasCov; }
00133 virtual void applyTransformation( const HomogenousMatrixD& _transformation );
00134 private:
00135 HomogenousVecD m_firstPoint, m_lastPoint;
00136 HomogenousSymMatrixD m_firstPointCov, m_lastPointCov;
00137 const RepereD* m_reference;
00138 bool m_hasCov;
00139 };
00140 public:
00144 Segment();
00149 template<class _TDriver_>
00150 explicit Segment(_TDriver_* );
00151 inline Segment(const Segment&);
00152 inline Segment& operator=(const Segment& rhs);
00153 ~Segment();
00154 virtual BoundingBox<dimension> boundingBox() const;
00155 virtual typename Atom<dimension>::Type type() const { return Atom<dimension>::T_Segment; }
00160 inline Line<dimension> support() const;
00165 inline HomogenousVecD firstPoint() const;
00166 inline HomogenousSymMatrixD firstPointCov() const;
00171 inline HomogenousVecD lastPoint() const;
00172 inline HomogenousSymMatrixD lastPointCov() const;
00176 inline double length() const;
00177 public:
00181 virtual std::string toString() const;
00182 public:
00183 GEN_DISTANCE_FUNCTIONS
00184 GEN_ANGLE_FUNCTIONS
00185 GEN_VISITOR_FUNCTIONS
00186 public:
00187 private:
00188 Driver* m_driver;
00189 };
00190 template<int dimension>
00191 std::ostream& operator <<(std::ostream& s, Segment<dimension> const& seg) {
00192 s << "Segment [" << seg.firstPoint() << " ; " << seg.lastPoint() << " ]";
00193 return s;
00194 }
00195 }
00196 }
00197
00198 #include "SegmentImpl.hpp"
00199
00200 #endif