1 // This is gel/vifa/vifa_int_faces_attr.h 2 #ifndef VIFA_INT_FACES_ATTR_H 3 #define VIFA_INT_FACES_ATTR_H 4 5 //----------------------------------------------------------------------------- 6 //: 7 // \file 8 // \brief Collect statistics about a group of regions. 9 // 10 // Collects statistics about a group of regions. (For region groups 11 // formed around a seed region, see IntFacesAdjAttr.) 12 // 13 // \author Roddy Collins, from DDB in TargetJr 14 // 15 // \verbatim 16 // Modifications: 17 // MPP May 2003, Ported to VXL 18 // \endverbatim 19 //----------------------------------------------------------------------------- 20 21 #include <iostream> 22 #include <vector> 23 #ifdef _MSC_VER 24 # include <vcl_msvc_warnings.h> 25 #endif 26 #include <vbl/vbl_smart_ptr.h> 27 #include <vdgl/vdgl_fit_lines_params.h> 28 #include <vtol/vtol_intensity_face_sptr.h> 29 #include <vifa/vifa_histogram.h> 30 #include <vifa/vifa_int_face_attr_common.h> 31 #include <vifa/vifa_int_face_attr.h> 32 #include <vifa/vifa_int_face_attr_factory.h> 33 #include <vifa/vifa_parallel.h> 34 #include <vifa/vifa_typedefs.h> 35 36 37 // Create the index for histogrammed attributes. Must indicate the 38 // position in attr_get_funcs[]. 39 #define NUM_HIST_ATTRIBUTES 15 40 41 // type needed for attr_get_funcs. 42 typedef float (vifa_int_face_attr::*AttrFuncPtr)(); 43 44 45 class vifa_int_faces_attr : public vifa_int_face_attr_common 46 { 47 protected: 48 iface_list faces_; 49 50 // should be a map, but until operator<() is const in smart_ptr.h... 51 // map<vifa_intensity_face_sptr, vifa_int_face_attr_sptr, less<vifa_intensity_face_sptr> > attr_map_; 52 attr_list attr_map_; 53 54 std::vector<float> centroid_; // cache for region group center-of-mass 55 float perimeter_; 56 float weighted_perimeter_; 57 58 // Vector of vifa_int_face_attr methods to get an attribute val for one 59 // face. Defines the histogrammed attribute vector. Length must be 60 // NUM_HIST_ATTRIBUTES. 61 static AttrFuncPtr attr_get_funcs[]; 62 static const char* const attr_names[]; 63 static float attr_min_vals[]; 64 65 // attribute slots 66 67 // Histogrammed attributes are grouped together into parallel 68 // vectors. Histograms compute mean and standard deviation. 69 // Attributes defined by attr_get_funcs. 70 //std::vector<vifa_histogram_sptr> attr_hists_; 71 incr_var_list attr_vec_; 72 73 float cached_2_parallel_; 74 float cached_4_parallel_; 75 float cached_80_parallel_; 76 vifa_parallel* npobj_; 77 vifa_int_face_attr_factory* factory_; 78 public: 79 vifa_int_faces_attr(vdgl_fit_lines_params* fitter_params = nullptr, 80 vifa_group_pgram_params* gpp_s = nullptr, 81 vifa_group_pgram_params* gpp_w = nullptr, 82 vifa_coll_lines_params* cpp = nullptr, 83 vifa_norm_params* np = nullptr, 84 vifa_int_face_attr_factory* factory = nullptr 85 ); 86 vifa_int_faces_attr(iface_list& v, 87 vdgl_fit_lines_params* fitter_params = nullptr, 88 vifa_group_pgram_params* gpp_s = nullptr, 89 vifa_group_pgram_params* gpp_w = nullptr, 90 vifa_coll_lines_params* cpp = nullptr, 91 vifa_norm_params* np = nullptr, 92 vifa_int_face_attr_factory* factory = nullptr 93 ); 94 95 ~vifa_int_faces_attr() override; 96 97 // --- 98 // Public functional methods 99 // --- 100 101 bool ComputeAttributes() override; 102 bool GetAttributes(std::vector<float>& attrs) override; 103 static void GetAttributeNames(std::vector<std::string>& names); 104 bool GetNativeAttributes(std::vector<float>& attrs) override; 105 106 // Data access for non-attributes GetFaces()107 virtual iface_list& GetFaces() { return faces_; } 108 virtual void SetFaces(iface_list& v); 109 edge_2d_list& GetEdges() override; 110 111 // hmm, need to think about this 112 113 vifa_int_face_attr_sptr factory_new_attr(const vtol_intensity_face_sptr& face); 114 115 //: centroid X 116 float Xo() override; 117 //: centroid Y 118 float Yo() override; 119 120 // --- 121 // Attribute computation 122 // --- 123 124 // Histogrammed attributes. See attr_get_funcs in .C file for 125 // attribute index. These are not weighted by area size. 126 float GetMeanAttr(int attr_index); // mean of indexed histogrammed attribute 127 float GetSDAttr(int attr_index); // sd of indexed histogrammed attribute 128 float GetMinAttr(int attr_index); // min of indexed histogrammed attribute 129 float GetMaxAttr(int attr_index); // max of indexed histogrammed attribute NumHistAttributes()130 static int NumHistAttributes() { return NUM_HIST_ATTRIBUTES; } 131 132 // non-histogrammed attributes (one value per vifa_int_faces_attr). 133 float Area() override; // area of all faces 134 float AspectRatio() override; // ratio of major moments 135 float PerimeterLength() override; // length of boundary, in pixels 136 float Complexity() override; // edge length^2 / detection area 137 float WeightedComplexity() override; 138 float WeightedPerimeterLength() override; 139 140 float TwoPeakParallel() override; 141 float FourPeakParallel() override; 142 float EightyPercentParallel() override; 143 144 // a hack for weird linking problems on Windows with attr_get_funcs[] 145 static float CallAttrFunction(vifa_int_face_attr* seed, int i); 146 147 static const char* GetBaseAttrName(int i); 148 149 protected: 150 void init() override; 151 void SetNP(); 152 void ComputeCentroid(); 153 virtual bool ComputeSingleFaceAttributes(bool forceP=false); 154 155 // Caller must delete returned edge_list when done 156 edge_list* GetPerimeterEdges(); 157 vifa_histogram_sptr MakeAttrHist(std::vector<float>& attr_vals); 158 }; 159 160 typedef vbl_smart_ptr<vifa_int_faces_attr> vifa_int_faces_attr_sptr; 161 162 163 #endif // VIFA_INT_FACES_ATTR_H 164