00001
00002
00003 namespace jafar {
00004 namespace geom {
00005
00006
00007 template<int dimension>
00008 OrientedPlan<dimension>::VectorsDriver::VectorsDriver(const typename geom::Atom<dimension>::HomogenousVecD* repere, const typename geom::Atom<dimension>::HomogenousVecD& origin , const RepereD* reference ) : HyperPlaneD::Driver( ), m_reference(reference)
00009 {
00010 for(int i = 0; i < dimension; i++)
00011 {
00012 ublas::matrix_column<MatrixD> mc( m_matrix, i);
00013 HomogenousVecD v = repere[i];
00014 for(int j = 0; j < i; j++)
00015 {
00016 ublas::matrix_column<MatrixD> u( m_matrix, j);
00017 v -= ublas::inner_prod(repere[i], u) * u;
00018 }
00019 v(dimension) = 0.0;
00020 mc = v / ublas::norm_2(v);
00021 }
00022 ublas::matrix_column<MatrixD> mcOrig( m_matrix, dimension);
00023 mcOrig = origin;
00024 mcOrig /= mcOrig( dimension);
00025 }
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 template<int dimension>
00038 typename OrientedPlan<dimension>::HomogenousVecD OrientedPlan<dimension>::VectorsDriver::origin() const
00039 {
00040 return ublas::matrix_column<const MatrixD>( m_matrix, dimension);
00041 }
00042 template<int dimension>
00043 typename OrientedPlan<dimension>::HomogenousVecD OrientedPlan<dimension>::VectorsDriver::vec(unsigned int index) const
00044 {
00045 return ublas::matrix_column<const MatrixD>( m_matrix, index);
00046 }
00047 template<int dimension>
00048 void OrientedPlan<dimension>::VectorsDriver::localToReference(typename OrientedPlan<dimension>::MatrixD& dst) const
00049 {
00050 dst.assign(m_matrix);
00051 }
00052 template<int dimension>
00053 typename OrientedPlan<dimension>::HomogenousVecD OrientedPlan<dimension>::VectorsDriver::normal() const
00054 {
00055 return vec(dimension - 1);
00056 }
00057 template<int dimension>
00058 typename OrientedPlan<dimension>::HomogenousVecD OrientedPlan<dimension>::VectorsDriver::equation() const
00059 {
00060 HomogenousVecD eqn;
00061 ublas::subrange(eqn, 0, dimension ) = normal();
00062 eqn(dimension) = - ublas::inner_prod(ublas::subrange(eqn, 0, dimension ), ublas::subrange(origin(), 0, dimension));
00063 return eqn;
00064 }
00065 template<int dimension>
00066 void OrientedPlan<dimension>::VectorsDriver::changeReference( const RepereD* reference )
00067 {
00068 MatrixD m;
00069 reference->repereToLocal(m, this->m_reference);
00070
00071 m_matrix = ublas::prod(m, m_matrix);
00072
00073 this->m_reference = reference;
00074 }
00075 template<int dimension>
00076 const Repere<dimension>* OrientedPlan<dimension>::VectorsDriver::reference( ) const
00077 {
00078 return m_reference;
00079 }
00080 template<int dimension>
00081 typename HyperPlane<dimension>::Driver* OrientedPlan<dimension>::VectorsDriver::clone() const
00082 {
00083 return new VectorsDriver(*this);
00084 }
00085 template<int dimension>
00086 typename OrientedPlan<dimension>::Driver* OrientedPlan<dimension>::VectorsDriver::cloneOrientedPlanDriver() const
00087 {
00088 return new VectorsDriver(*this);
00089 }
00090 template<int dimension>
00091 typename HyperPlane<dimension>::Driver* OrientedPlan<dimension>::VectorsDriver::asHyperPlaneDriver()
00092 {
00093 return this;
00094 }
00095
00096
00097 template<int dimension>
00098 class OrientedPlan<dimension>::RepereDriver : public RepereD::Driver {
00099 typedef typename Atom<dimension>::HomogenousVecD HomogenousVecD;
00100 typedef typename Atom<dimension>::HomogenousMatrixD HomogenousMatrixD;
00101 public:
00102 RepereDriver(const OrientedPlan<dimension>* op) : RepereD::Driver( ), m_parent(op)
00103 {
00104
00105 }
00106 virtual const RepereD* reference() const
00107 {
00108 return m_parent->reference();
00109 }
00110 virtual HomogenousVecD origin() const
00111 {
00112 return m_parent->origin();
00113 }
00114 virtual HomogenousVecD vec(unsigned int index) const
00115 {
00116 return m_parent->vec(index);
00117 }
00118 virtual void localToReference(MatrixD& m) const
00119 {
00120 return m_parent->localToReference(m);
00121 }
00122 virtual bool hasCov() const {
00123 return m_parent->hasCov();
00124 }
00125 private:
00126 const OrientedPlan<dimension>* m_parent;
00127 };
00128 template<int dimension>
00129 OrientedPlan<dimension>::OrientedPlan() : HyperPlaneD(0), m_driver(0)
00130 {
00131 m_repere = new RepereD( new RepereDriver(this));
00132 }
00133 template<int dimension>
00134 template<typename _TDriver_>
00135 OrientedPlan<dimension>::OrientedPlan( _TDriver_* d) : HyperPlaneD(d), m_driver(d)
00136 {
00137 m_repere = new RepereD( new RepereDriver(this));
00138 }
00139 template<int dimension>
00140 OrientedPlan<dimension>::OrientedPlan(const OrientedPlan& op) : HyperPlaneD(0), m_driver(op.m_driver->cloneOrientedPlanDriver())
00141 {
00142 HyperPlaneD::setDriver( m_driver->asHyperPlaneDriver() );
00143 m_repere = new RepereD( new RepereDriver(this));
00144 this->setId( op.id() );
00145 }
00146 template<int dimension>
00147 inline OrientedPlan<dimension>& OrientedPlan<dimension>::operator=(const OrientedPlan& rhs)
00148 {
00149 m_driver = rhs.m_driver->cloneOrientedPlanDriver();
00150 HyperPlaneD::setDriver( m_driver->asHyperPlaneDriver() );
00151 this->setId( rhs.id() );
00152 return *this;
00153 }
00154 template<int dimension>
00155 OrientedPlan<dimension>::~OrientedPlan()
00156 {
00157 delete m_repere;
00158 }
00159 template<int dimension>
00160 inline typename OrientedPlan<dimension>::HomogenousVecD OrientedPlan<dimension>::vec(unsigned int index) const
00161 {
00162 return m_driver->vec( index );
00163 }
00164 template<int dimension>
00165 inline void OrientedPlan<dimension>::localToReference(MatrixD& m) const
00166 {
00167 m_driver->localToReference(m);
00168 }
00169 template<int dimension>
00170 inline const Repere<dimension>* OrientedPlan<dimension>::repere() const
00171 {
00172 return m_repere;
00173 }
00174
00175
00176 }
00177 }