contrib/gel/vifa/vifa_int_face_attr_common.h
Go to the documentation of this file.
00001 // This is gel/vifa/vifa_int_face_attr_common.h
00002 #ifndef VIFA_INT_FACE_ATTR_COMMON_H
00003 #define VIFA_INT_FACE_ATTR_COMMON_H
00004 
00005 //-----------------------------------------------------------------------------
00006 //:
00007 // \file
00008 // \brief Computes attribute data about one IntensityFace or a group of IntensityFaces.
00009 //
00010 // Computes attribute data about one IntensityFace or a group of IntensityFaces.
00011 // All attributes which apply to both are referenced in this class.
00012 //
00013 // \author Anthony Hoogs, from DDB in TargetJr
00014 //
00015 // \date Jan 2001
00016 //
00017 // \verbatim
00018 //  Modifications:
00019 //   MPP Mar/Apr 2003, Ported to VXL
00020 // \endverbatim
00021 //-----------------------------------------------------------------------------
00022 
00023 #include <vcl_vector.h>
00024 #include <vdgl/vdgl_fit_lines_params.h>
00025 #include <vtol/vtol_edge.h>
00026 #include <vtol/vtol_edge_sptr.h>
00027 #include <vifa/vifa_coll_lines.h>
00028 #include <vifa/vifa_incr_var.h>
00029 #include <vifa/vifa_int_face_attr_common_params.h>
00030 #include <vifa/vifa_typedefs.h>
00031 
00032 
00033 class vifa_int_face_attr_common : public vifa_int_face_attr_common_params
00034 {
00035  protected:
00036   //: Have the attributes been computed?
00037   bool      attributes_valid_;
00038 
00039   //: Cache of all edges from face(s).
00040   edge_2d_list  edges_;
00041 
00042   //: Cache of fitted line segments.
00043   edge_2d_list  fitted_edges_;
00044 
00045   //: Statistics about fitted edges in cache.
00046   vifa_incr_var  fitted_edges_stats_;
00047 
00048   //: Cache of collinear lines.
00049   coll_list    collinear_lines_;
00050   vifa_incr_var  col_span_;
00051   vifa_incr_var  col_support_;
00052   vifa_incr_var  col_contrib_;
00053 
00054   //: Face area, in pixels.
00055   float      area_;
00056 
00057   //: Ratio of major face moments.
00058   float      aspect_ratio_;
00059 
00060   //: Edge length^2 / detection area.
00061   float      complexity_;
00062 
00063   //: Weighted complexity measure.
00064   float      weighted_complexity_;
00065 
00066   //: Length of boundary.
00067   float      peri_length_;
00068 
00069   //: Weighted length of boundary.
00070   float      weighted_peri_length_;
00071 
00072   // Projective parallelism of face boundary.
00073   float      para_sal_strong_;
00074 
00075   // "Weak" projective parallelism of face boundary.
00076   float      para_sal_weak_;
00077 
00078  public:
00079   //: Default constructor
00080   vifa_int_face_attr_common(void);
00081 
00082   //: Full constructor
00083   vifa_int_face_attr_common(vdgl_fit_lines_params*    fitter_params,
00084                             vifa_group_pgram_params*  gpp_s,
00085                             vifa_group_pgram_params*  gpp_w,
00086                             vifa_coll_lines_params*   cpp,
00087                             vifa_norm_params*         np
00088                            );
00089 
00090   //: Destructor.
00091   virtual ~vifa_int_face_attr_common();
00092 
00093   // ---
00094   // Public functional methods
00095   // ---
00096   virtual bool  ComputeAttributes() = 0;
00097   virtual bool  GetAttributes(vcl_vector<float>&  attrs) = 0;
00098   virtual bool  GetNativeAttributes(vcl_vector<float>&  attrs) = 0;
00099   virtual bool  valid_p() const { return attributes_valid_; }
00100 
00101   // Data access for non-attributes
00102   virtual edge_2d_list&  GetEdges() = 0;
00103   edge_2d_list&          GetFittedEdges();
00104   double fitted_max() { return fitted_edges_stats_.get_max(); }
00105   double fitted_min() { return fitted_edges_stats_.get_min(); }
00106   double fitted_var() { return fitted_edges_stats_.get_var(); }
00107   double fitted_mean() { return fitted_edges_stats_.get_mean(); }
00108 
00109   coll_list&  get_collinear_lines();
00110   double col_span_mean() { return col_span_.get_mean(); }
00111   double col_span_var() { return col_span_.get_var(); }
00112   double col_support_mean() { return col_support_.get_mean(); }
00113   double col_support_var() { return col_support_.get_var(); }
00114   double col_contrib_mean() { return col_contrib_.get_mean(); }
00115   double col_contrib_var() { return col_contrib_.get_var(); }
00116   double col_collapse();
00117 
00118   vifa_group_pgram_params_sptr get_strong_group_pgram_params() {return gpp_s_;}
00119   vifa_group_pgram_params_sptr get_weak_group_pgram_params() { return gpp_w_; }
00120   void  set_strong_group_pgram_params(const vifa_group_pgram_params&  gp)
00121     { gpp_s_ = new vifa_group_pgram_params(gp); }
00122   void  set_weak_group_pgram_params(const vifa_group_pgram_params&  gp)
00123     { gpp_w_ = new vifa_group_pgram_params(gp); }
00124 
00125   void  set_norm_params(const vifa_norm_params&  np)
00126     { np_ = new vifa_norm_params(np); }
00127   float  normalize_intensity(float  raw_intensity)
00128     { return np_ ? np_->normalize(raw_intensity) : raw_intensity; }
00129 
00130   double      get_contrast_across_edge(vtol_edge_sptr  e,
00131                                        double          dflt_cont = 0.0);
00132   vifa_coll_lines_sptr  get_line_along_edge(vtol_edge* edge);
00133 
00134   // Get the face(s) centroid X.
00135   virtual float  Xo() = 0;
00136 
00137   // Get the face(s) centroid Y.
00138   virtual float  Yo() = 0;
00139 
00140   virtual float  Area() = 0;
00141   virtual float  AspectRatio() = 0;
00142   virtual float  PerimeterLength() = 0;
00143   virtual float  WeightedPerimeterLength() = 0;
00144   virtual float  Complexity() = 0;
00145   virtual float  WeightedComplexity() = 0;
00146 
00147   //: Get proportion of edges with projective parallelism.
00148   float      StrongParallelSal();
00149 
00150   //: Get proportion of edges with "weak" projective parallelism.
00151   float      WeakParallelSal();
00152 
00153   virtual float  TwoPeakParallel() = 0;
00154   virtual float  FourPeakParallel() = 0;
00155   virtual float  EightyPercentParallel() = 0;
00156 
00157  protected:
00158   virtual void  init();
00159   void      fit_lines();
00160   void      find_collinear_lines();
00161   bool      find_collinear_match(vtol_edge_2d_sptr edge,
00162                                  coll_list&        lines,
00163                                  double            dist_threshold,
00164                                  coll_iterator&    result
00165                                 );
00166   float      compute_parallel_sal(vifa_group_pgram_params_sptr  gpp);
00167 };
00168 
00169 #endif  // VIFA_INT_FACE_ATTR_COMMON_H