00001 #ifndef _FACET_HPP_
00002 #define _FACET_HPP_
00003
00004 #include "camera/cameraPinhole.hpp"
00005 #include "image/Image.hpp"
00006 #include "jmath/jblas.hpp"
00007 #include "gfm/InterestFeature.hpp"
00008
00009 #include "facetsmap/FacetsGroupBase.hpp"
00010 #include "facetsmap/params.hpp"
00011 #include "facetsmap/repere.hpp"
00012 #include "facetsmap/types.hpp"
00013 #include "homography/HomographyEstimator.hpp"
00014
00015 namespace jafar {
00016 namespace facetsmap {
00017 class AmersMap;
00018 class FacetsParams;
00019 struct CamParam {
00020 jblas::mat33 intrinsec, intrinsecInv, rot;
00021 };
00024 class Facet : private Repere {
00025 friend bool FacetsGroupBase::add(Facet*);
00026 friend vFacets_it FacetsGroupBase::remove(const vFacets_it&);
00027 friend class AmersMap;
00028 friend class FacetsMap;
00029 friend FacetsGroupBase::~FacetsGroupBase();
00030 public:
00040 Facet(const FacetsParams* params, unsigned int id, const ::jafar::gfm::InterestFeature& lpoint, const ::jafar::gfm::InterestFeature& rpoint, const jafar::image::Image& imgl, const homography::ImageGradients& imggradl, const jafar::image::Image& imgr, const homography::ImageGradients& imggradr, const camera::StereoBench& stereoBench, int time);
00041 ~Facet();
00042 private:
00045 inline Facet() : Repere(Repere::global()) {};
00046 public:
00056 void update( const Facet* f, int time);
00065 void updatePreviousObservation(const boost::numeric::ublas::bounded_matrix<double,4,4>& robotmovement);
00066 public:
00067
00068 public:
00069 inline void changeRef(const jafar::facetsmap::Repere* r) { Repere::changeRef(r); }
00070 inline void setRef(const jafar::facetsmap::Repere* r) { Repere::setRef(r); }
00071 inline jblas::vec3 localOrigin() const { return origin(); };
00072 inline jblas::vec3 globalOrigin() const { return ref()->localToGlobal(origin(), 1); };
00073 inline jafar::facetsmap::Repere* repere() { return this; };
00074 inline double halfSize() const { return m_halfSize; };
00079 inline jblas::vec3 globalAxe1() const { return ref()->localToGlobal(j(), 0); };
00080 inline jblas::vec3 localAxe1() const { return j(); };
00081 inline jblas::vec3 globalAxe2() const { return ref()->localToGlobal(k(), 0); };
00082 inline jblas::vec3 localAxe2() const { return k(); };
00086 inline jblas::vec3 globalNormal() const { return ref()->localToGlobal(i(), 0); };
00087 inline jblas::vec3 localNormal() const { return i(); };
00088 std::vector<jblas::vec3> t_points;
00089 inline const jafar::image::Image* image() const { return m_imagette; };
00090 inline unsigned int id() const { return m_id; };
00091 inline int time() const { return m_time; };
00092 private:
00093 inline void setNormal(jblas::vec3 n) { setI(n); };
00094 inline void setAxe1(jblas::vec3 n) { setJ(n); };
00095 inline void setAxe2(jblas::vec3 n) { setK(n); };
00096 public:
00097 inline double distanceTo(jblas::vec3 pos) const { return ublas::norm_2( pos - globalOrigin()) ; };
00098 inline bool insideValidity(jblas::vec3 pos) const { return insideValidity( distanceTo(pos) ); }
00099 inline bool insideValidity(double d) const { return (m_inf_distance < d ) && ( d < m_sup_distance ); }
00100 bool insideFacet(jblas::vec3 pos);
00101 inline vUints_cit neighborhoodBegin() const { return m_neighborhood.begin(); };
00102 inline vUints_cit neighborhoodEnd() const { return m_neighborhood.end(); };
00103 inline void neighborhoodAdd(uint fid) { m_neighborhood.push_back(fid); };
00104 inline void neighborhoodAdd(Facet* f) { neighborhoodAdd(f->id()); };
00105 inline double orientation() const { return m_orientation; };
00106 inline double quality() const { return 1.-m_squareError/THRESHOLD_GOOD_PLAN; }
00107 double compare(Facet*f);
00111 inline FacetsGroupBase* group() const { return m_facetsGroup; };
00112 inline geom::InterestPoint ipDetection() { return m_ipDetection; };
00113
00114 inline jblas::mat33 positionVariance() const { return m_positionVariance; }
00115 public:
00116 inline int countSeen() { return m_countSeen; }
00117 inline int age() { return m_age; }
00118 inline void incAge() { m_age++; }
00119 private:
00120 inline void seenAgain() { m_countSeen++; }
00121 public:
00122 inline const jblas::vec3& previousObservationOrigin() const
00123 {return m_previousObservationOrigin;}
00124 inline const jblas::vec3& previousObservationNormal() const
00125 {return m_previousObservationNormal;}
00126 inline const jblas::vec3& previousObservationAxe1() const
00127 {return m_previousObservationAxe1;}
00128 inline const jblas::vec3& previousObservationAxe2() const
00129 {return m_previousObservationAxe2;}
00130
00131 public:
00132 void print();
00134 friend std::ostream& operator<< (std::ostream& , const Facet&);
00135 private:
00140 inline void setGroup(FacetsGroupBase* fg) { m_facetsGroup = fg; };
00141 private:
00142
00143 static void computeAxes( jblas::vec3&, jblas::vec3&, jblas::vec3 normal, double orientation);
00144 void computeHomography(const FacetsParams* params, jblas::mat33& homography, const ::jafar::gfm::InterestFeature& lpoint, const ::jafar::gfm::InterestFeature& rpoint, const jafar::image::Image& imgl, const homography::ImageGradients& imggradl, const jafar::image::Image& imgr, const homography::ImageGradients& imggradr);
00145 static void computeOriginAndNormal(jblas::vec3& origin, jblas::mat33& positionJac, jblas::vec3& vnormal, const jblas::mat33& homography, const ::jafar::gfm::InterestFeature& lpoint, const camera::StereoBench& stereoBench);
00146 public:
00147 static void computeTexture(const FacetsParams* params, image::Image& texdst, const image::Image& imgl, const jblas::vec3& origin, const jblas::vec3& axe1, const jblas::vec3 axe2, const camera::StereoBench& stereoBench);
00148 private:
00149 int m_sizefacet;
00150 int m_time;
00151 uint m_id;
00152
00153
00154 double m_squareError;
00155 double m_halfSize;
00156 double m_inf_distance, m_sup_distance;
00157 double m_best_distance;
00158 double m_best_angle;
00159
00160 image::Image* m_imagette;
00161 vUints m_neighborhood;
00162 double m_orientation;
00163 FacetsGroupBase* m_facetsGroup;
00164 homography::HomographyEstimator::Statistics m_stats;
00165 geom::InterestPoint m_ipDetection;
00166 int m_countSeen;
00167 int m_age;
00168 jblas::mat33 m_positionVariance;
00169 jblas::mat66 m_variance;
00170 jblas::vec m_mean;
00171 bool meannotset;
00172 jblas::vec3 m_previousObservationOrigin, m_previousObservationNormal, m_previousObservationAxe1, m_previousObservationAxe2;
00173 };
00174 };
00175 };
00176
00177 #endif