contrib/gel/vifa/vifa_int_faces_attr.h
Go to the documentation of this file.
00001 // This is gel/vifa/vifa_int_faces_attr.h
00002 #ifndef VIFA_INT_FACES_ATTR_H
00003 #define VIFA_INT_FACES_ATTR_H
00004 
00005 //-----------------------------------------------------------------------------
00006 //:
00007 // \file
00008 // \brief Collect statistics about a group of regions.
00009 //
00010 // Collects statistics about a group of regions.  (For region groups
00011 // formed around a seed region, see IntFacesAdjAttr.)
00012 //
00013 // \author Roddy Collins, from DDB in TargetJr
00014 //
00015 // \verbatim
00016 //  Modifications:
00017 //   MPP May 2003, Ported to VXL
00018 // \endverbatim
00019 //-----------------------------------------------------------------------------
00020 
00021 #include <vcl_vector.h>
00022 #include <vbl/vbl_smart_ptr.h>
00023 #include <vdgl/vdgl_fit_lines_params.h>
00024 #include <vtol/vtol_intensity_face_sptr.h>
00025 #include <vifa/vifa_histogram.h>
00026 #include <vifa/vifa_int_face_attr_common.h>
00027 #include <vifa/vifa_int_face_attr.h>
00028 #include <vifa/vifa_int_face_attr_factory.h>
00029 #include <vifa/vifa_parallel.h>
00030 #include <vifa/vifa_typedefs.h>
00031 
00032 
00033 // Create the index for histogrammed attributes.  Must indicate the
00034 // position in attr_get_funcs[].
00035 #define NUM_HIST_ATTRIBUTES 15
00036 
00037 // type needed for attr_get_funcs.
00038 typedef float (vifa_int_face_attr::*AttrFuncPtr)();
00039 
00040 
00041 class vifa_int_faces_attr : public vifa_int_face_attr_common
00042 {
00043  protected:
00044   iface_list     faces_;
00045 
00046   // should be a map, but until operator<() is const in smart_ptr.h...
00047   //  map<vifa_intensity_face_sptr, vifa_int_face_attr_sptr, less<vifa_intensity_face_sptr> > attr_map_;
00048   attr_list      attr_map_;
00049 
00050   vcl_vector<float>  centroid_;      // cache for region group center-of-mass
00051   float          perimeter_;
00052   float          weighted_perimeter_;
00053 
00054   // Vector of vifa_int_face_attr methods to get an attribute val for one
00055   // face.  Defines the histogrammed attribute vector.  Length must be
00056   // NUM_HIST_ATTRIBUTES.
00057   static AttrFuncPtr attr_get_funcs[];
00058   static const char* const attr_names[];
00059   static float attr_min_vals[];
00060 
00061   // attribute slots
00062 
00063   // Histogrammed attributes are grouped together into parallel
00064   // vectors.  Histograms compute mean and standard deviation.
00065   // Attributes defined by attr_get_funcs.
00066   //vcl_vector<vifa_histogram_sptr> attr_hists_;
00067   incr_var_list  attr_vec_;
00068 
00069   float cached_2_parallel_;
00070   float cached_4_parallel_;
00071   float cached_80_parallel_;
00072   vifa_parallel* npobj_;
00073   vifa_int_face_attr_factory* factory_;
00074  public:
00075   vifa_int_faces_attr(vdgl_fit_lines_params*       fitter_params = NULL,
00076                       vifa_group_pgram_params*     gpp_s = NULL,
00077                       vifa_group_pgram_params*     gpp_w = NULL,
00078                       vifa_coll_lines_params*      cpp = NULL,
00079                       vifa_norm_params*            np = NULL,
00080                       vifa_int_face_attr_factory*  factory = NULL
00081                      );
00082   vifa_int_faces_attr(iface_list&                  v,
00083                       vdgl_fit_lines_params*       fitter_params = NULL,
00084                       vifa_group_pgram_params*     gpp_s = NULL,
00085                       vifa_group_pgram_params*     gpp_w = NULL,
00086                       vifa_coll_lines_params*      cpp = NULL,
00087                       vifa_norm_params*            np = NULL,
00088                       vifa_int_face_attr_factory*  factory = NULL
00089                      );
00090 
00091   virtual ~vifa_int_faces_attr();
00092 
00093   // ---
00094   // Public functional methods
00095   // ---
00096 
00097   virtual bool  ComputeAttributes();
00098   virtual bool  GetAttributes(vcl_vector<float>& attrs);
00099   static void    GetAttributeNames(vcl_vector<vcl_string>& names);
00100   virtual bool  GetNativeAttributes(vcl_vector<float>& attrs);
00101 
00102   // Data access for non-attributes
00103   virtual iface_list&  GetFaces() { return faces_; }
00104   virtual void    SetFaces(iface_list& v);
00105   edge_2d_list&    GetEdges();
00106 
00107   // hmm, need to think about this
00108 
00109   vifa_int_face_attr_sptr factory_new_attr(vtol_intensity_face_sptr face);
00110 
00111   //: centroid X
00112   float Xo();
00113   //: centroid Y
00114   float Yo();
00115 
00116   // ---
00117   // Attribute computation
00118   // ---
00119 
00120   // Histogrammed attributes.  See attr_get_funcs in .C file for
00121   // attribute index.  These are not weighted by area size.
00122   float GetMeanAttr(int attr_index); // mean of indexed histogrammed attribute
00123   float GetSDAttr(int attr_index); // sd of indexed histogrammed attribute
00124   float GetMinAttr(int attr_index); // min of indexed histogrammed attribute
00125   float GetMaxAttr(int attr_index); // max of indexed histogrammed attribute
00126   static int NumHistAttributes() { return NUM_HIST_ATTRIBUTES; }
00127 
00128   // non-histogrammed attributes (one value per vifa_int_faces_attr).
00129   float Area();                 // area of all faces
00130   float AspectRatio();          // ratio of major moments
00131   float PerimeterLength();      // length of boundary, in pixels
00132   float Complexity();           // edge length^2 / detection area
00133   float WeightedComplexity();
00134   float WeightedPerimeterLength();
00135 
00136   float TwoPeakParallel();
00137   float FourPeakParallel();
00138   float EightyPercentParallel();
00139 
00140   // a hack for weird linking problems on Windows with attr_get_funcs[]
00141   static float  CallAttrFunction(vifa_int_face_attr* seed, int i);
00142 
00143   static const char*  GetBaseAttrName(int i);
00144 
00145  protected:
00146   virtual void  init();
00147   void          SetNP();
00148   void          ComputeCentroid();
00149   virtual bool  ComputeSingleFaceAttributes(bool forceP=false);
00150 
00151   // Caller must delete returned edge_list when done
00152   edge_list*    GetPerimeterEdges();
00153   vifa_histogram_sptr  MakeAttrHist(vcl_vector<float>& attr_vals);
00154 };
00155 
00156 typedef vbl_smart_ptr<vifa_int_faces_attr>  vifa_int_faces_attr_sptr;
00157 
00158 
00159 #endif  // VIFA_INT_FACES_ATTR_H