1 // This is gel/vifa/vifa_int_faces_adj_attr.h
2 #ifndef VIFA_INT_FACES_ADJ_ATTR_H
3 #define VIFA_INT_FACES_ADJ_ATTR_H
4 
5 //-----------------------------------------------------------------------------
6 //:
7 // \file
8 // \brief Collects statistics about a group of faces.
9 // Collects statistics about a group of faces that have been grown from
10 // a seed face.  Will either take a seed and grow the regions itself or
11 // take a collection of faces on faith.
12 //
13 // *** WARNING *** Probably does not calculate neighborhoods correctly
14 // for depths > 1 (probably includes the seed face back into the neighborhood.)
15 //
16 // \author Roddy Collins, from DDB in TargetJr
17 //
18 // \verbatim
19 //  Modifications:
20 //   MPP May 2003, Ported to VXL
21 // \endverbatim
22 //-----------------------------------------------------------------------------
23 
24 #include <iostream>
25 #include <vector>
26 #ifdef _MSC_VER
27 #  include <vcl_msvc_warnings.h>
28 #endif
29 #include <vdgl/vdgl_fit_lines_params.h>
30 #include <vtol/vtol_intensity_face_sptr.h>
31 #include <vifa/vifa_coll_lines_params.h>
32 #include <vifa/vifa_group_pgram_params.h>
33 #include <vifa/vifa_int_faces_attr.h>
34 #include <vifa/vifa_typedefs.h>
35 
36 
37 class vifa_int_faces_adj_attr: public vifa_int_faces_attr
38 {
39  protected:
40   enum
41   {
42     BAD_DEPTH = -1
43   };
44 
45   bool closure_valid_{false};
46 
47   vtol_intensity_face_sptr  seed_;
48   vifa_int_face_attr_sptr    seed_attr_;
49   int depth_{BAD_DEPTH};
50   int              size_filter_;
51 
52   float            junk_area_percentage_;
53   int              junk_count_;
54   float            junk_percent_;
55   float            junk_area_ratio_;
56 
57   // attribute slots
58 
59   // ratios of seed attr to neighborhood mean
60   std::vector<float>      mean_ratios_;
61   std::vector<float>      min_ratios_;
62 
63  public:
64   vifa_int_faces_adj_attr();
65   vifa_int_faces_adj_attr(const vtol_intensity_face_sptr&  seed,
66                           int              depth,
67                           int              size_filter = -1,
68                           vdgl_fit_lines_params*    fitter_params = nullptr,
69                           vifa_group_pgram_params*  gpp_s = nullptr,
70                           vifa_group_pgram_params*  gpp_w = nullptr,
71                           vifa_coll_lines_params*    cpp = nullptr,
72                           vifa_norm_params*      np = nullptr,
73                           vifa_int_face_attr_factory*  factory = nullptr,
74                           float          junk_area_percentage = 0.2
75                          );
76 
77   vifa_int_faces_adj_attr(const vtol_intensity_face_sptr&  seed,
78                           int                       depth,
79                           iface_list&               neighborhood,
80                           int                       size_filter  =  -1,
81                           vdgl_fit_lines_params*    fitter_params  =  nullptr,
82                           vifa_group_pgram_params*  gpp_s  =  nullptr,
83                           vifa_group_pgram_params*  gpp_w  =  nullptr,
84                           vifa_coll_lines_params*   cpp  =  nullptr,
85                           vifa_norm_params*         np  =  nullptr,
86                           vifa_int_face_attr_factory*    factory  =  nullptr,
87                           float                     junk_area_percentage  =  0.2
88                          );
89 
90   iface_list&    GetFaces() override;
91   iface_list*        GetFaceList();
92 
93   bool  ComputeAttributes() override;
94   bool  GetAttributes(std::vector<float>&  attrs) override;
95   static  void  GetAttributeNames(std::vector<std::string>&  names);
96   bool  GetNativeAttributes(std::vector<float>&  attrs) override;
97 
GetSeed()98   vtol_intensity_face_sptr  GetSeed() { return seed_; }
99   void                      SetSeed(const vtol_intensity_face_sptr&  seed);
100 
GetDepth()101   int    GetDepth() const { return depth_; }
SetDepth(int depth)102   void   SetDepth(int depth) { depth_ = depth; closure_valid_ = false; }
103 
104   int    NeighborhoodSize();
105 
GetJunkCount()106   int    GetJunkCount()     const { return junk_count_; }
GetJunkPercent()107   float  GetJunkPercent()   const { return junk_percent_; }
GetJunkAreaRatio()108   float  GetJunkAreaRatio() const { return junk_area_ratio_; }
109 
110   bool  compute_closure();
111   float  Collinearity();
112 
113   //
114   // attribute gets here
115   //
116 
117   // Ratio of seed to neighbors
118   float  GetRatioAttr(int  attr_index);
119 
120   // Ratio of seed to min of neighbors
121   float  GetMinRatioAttr(int  attr_index);
122 
123  protected:
124   void  init() override;
125   bool  add_unique_face(iface_list&               facelist,
126                         const vtol_intensity_face_sptr&  face,
127                         int                       size_filter);
128   void  compute_closure_step(int                       current_depth,
129                              vtol_intensity_face_sptr  seed);
130 
131   // Retrieve the iface adjacent to a given iface at an edge (if available)
132   vtol_intensity_face_sptr
133     get_adjacent_face_at_edge(vtol_intensity_face_sptr&  known_face,
134                               vtol_edge_2d*              e);
135 
136   // Retrieve all ifaces adjacent to a given face
137   iface_list*  get_adjacent_faces(vtol_intensity_face_sptr&  known_face);
138 };
139 
140 
141 #endif  // VIFA_INT_FACES_ADJ_ATTR_H
142