00001
00002
00003 #include "Line.hpp"
00004 #include "Repere.hpp"
00005
00006 #include <jmath/ublasExtra.hpp>
00007 #include <sstream>
00008
00009 #include <geom/BoundingBox.hpp>
00010
00011 namespace jafar {
00012 namespace geom {
00013
00014
00015 template<int dimension>
00016 Point<dimension>::HomogenousDriver::HomogenousDriver(const HomogenousVecD& coordinates , const RepereD* reference ) :
00017 Driver(),
00018 m_coordinates(coordinates),
00019 m_coordinatesCov( jblas::zero_mat( dimension + 1, dimension + 1) ),
00020 m_reference(reference),
00021 m_cov( false )
00022 {
00023 m_coordinates /= m_coordinates(dimension);
00024 }
00025
00026 template<int dimension>
00027 Point<dimension>::HomogenousDriver::HomogenousDriver(const HomogenousVecD& coordinates , const HomogenousSymMatrixD& matrix, const RepereD* reference ) :
00028 Driver(),
00029 m_coordinates(coordinates),
00030 m_coordinatesCov(matrix),
00031 m_reference(reference),
00032 m_cov( true )
00033 {
00034
00035 m_coordinates /= m_coordinates(dimension);
00036 }
00037
00038 template<int dimension>
00039 void Point<dimension>::HomogenousDriver::changeReference( const RepereD* reference )
00040 {
00041 typename Atom<dimension>::HomogenousMatrixD m;
00042 this->m_reference->localToRepere(m, reference);
00043 m_coordinates = ublas::prod(m, m_coordinates);
00044 this->m_reference = reference;
00045 }
00046
00047 template<int dimension>
00048 const Repere<dimension>* Point<dimension>::HomogenousDriver::reference( ) const
00049 {
00050 return m_reference;
00051 }
00052
00053
00054 template<int dimension>
00055 Point<dimension>::EuclideanDriver::EuclideanDriver(const VecD& coordinates, const RepereD* reference ) :
00056 Driver(),
00057 m_coordinatesCov( jblas::zero_mat( dimension + 1, dimension + 1) ),
00058 m_reference(reference),
00059 m_cov( false )
00060 {
00061 m_coordinates(dimension) = 1.0;
00062 ublas::vector_range<HomogenousVecD>(m_coordinates, this->rangeDimension) = coordinates;
00063 }
00064
00065 template<int dimension>
00066 Point<dimension>::EuclideanDriver::EuclideanDriver(const VecD& coordinates, const SymMatrixD& matrix, const RepereD* reference ) :
00067 Driver(),
00068 m_coordinatesCov( jblas::zero_mat( dimension + 1, dimension + 1) ),
00069 m_reference(reference),
00070 m_cov( true )
00071 {
00072 m_coordinates(dimension) = 1.0;
00073 ublas::vector_range<HomogenousVecD>(m_coordinates, this->rangeDimension) = coordinates;
00074 ublas::matrix_range<HomogenousSymMatrixD>( m_coordinatesCov, this->rangeDimension, this->rangeDimension ) = matrix;
00075 }
00076
00077 template<int dimension>
00078 void Point<dimension>::EuclideanDriver::changeReference( const RepereD* reference )
00079 {
00080 typename Atom<dimension>::HomogenousMatrixD m;
00081 this->m_reference->localToRepere(m, reference);
00082 m_coordinates = ublas::prod(m, m_coordinates);
00083 this->m_reference = reference;
00084 }
00085 template<int dimension>
00086 const Repere<dimension>* Point<dimension>::EuclideanDriver::reference( ) const
00087 {
00088 return m_reference;
00089 }
00090
00091
00092 template<int dimension>
00093 inline Point<dimension>& Point<dimension>::operator=(const Point& rhs)
00094 {
00095 delete m_driver;
00096 if(rhs.m_driver)
00097 {
00098 m_driver = rhs.m_driver->clone();
00099 Atom<dimension>::setDriver(m_driver);
00100 } else {
00101 m_driver = 0;
00102 this->setDriver(0);
00103 }
00104 this->setId( rhs.id() );
00105 return *this;
00106 }
00107 template<int dimension>
00108 inline BoundingBox<dimension> Point<dimension>::boundingBox() const
00109 {
00110 HomogenousVecD v = this->reference()->convertInGlobal( this->homogenousCoordinates());
00111 return BoundingBox<dimension>(v, v);
00112 }
00113 template<int dimension>
00114 std::string Point<dimension>::toString() const
00115 {
00116 std::ostringstream oss;
00117 oss << Atom<dimension>::toString() << " Coordinates = " << homogenousCoordinates();
00118 return oss.str();
00119 }
00120 }
00121 }