1 // This is gel/vifa/vifa_group_pgram.h
2 #ifndef VIFA_GROUP_PGRAM_H
3 #define VIFA_GROUP_PGRAM_H
4 
5 //-----------------------------------------------------------------------------
6 //:
7 // \file
8 // \brief Process-type class to find groups of approximately parallel lines.
9 //
10 // The vifa_group_pgram class is a grouper which finds relatively parallellogram-
11 // like shapes.  That is, there are groups of parallel line segments having
12 // projection overlap
13 //
14 // \author J.L. Mundy (11/27/1998)
15 //
16 // \verbatim
17 //  Modifications:
18 //   MPP Jun 2003, Ported to VXL from TargetJr
19 // \endverbatim
20 //-----------------------------------------------------------------------------
21 
22 #include <iostream>
23 #include <vector>
24 #ifdef _MSC_VER
25 #  include <vcl_msvc_warnings.h>
26 #endif
27 #include <vifa/vifa_bbox.h>
28 #include <vifa/vifa_group_pgram_params.h>
29 #include <vifa/vifa_histogram.h>
30 #include <vifa/vifa_line_cover.h>
31 #include <vifa/vifa_typedefs.h>
32 
33 
34 class vifa_group_pgram : public vifa_group_pgram_params
35 {
36   int         th_dim_;
37   double      angle_range_;
38 
39   //: Array of dominant theta indices
40   std::vector<int>  dominant_dirs_;
41 
42   vifa_bbox_sptr  bb_;
43   imp_line_table  curves_;
44   double          tmp1_;
45 
46  public:
47   // Constructors and Destructors
48   vifa_group_pgram(imp_line_list&                 lg,
49                    const vifa_group_pgram_params& old_params,
50                    double                         angle_range = 180.0
51                   );
52   ~vifa_group_pgram() override;
53 
54   // Index insertion
55   void    Index(const imp_line_sptr&    il);
56   void    Index(imp_line_list&  lg);
57   void    Clear();
58 
59   // Data accessors
60   vifa_histogram_sptr GetCoverageHist();
61   vifa_line_cover_sptr  GetLineCover(int  angle_bin);
62   double         LineCoverage(int  angle_bin);
63   void           CollectAdjacentLines(int      angle_bin,
64                                       imp_line_list&  lg
65                                      );
66   vifa_bbox_sptr GetBoundingBox();
SetTemp1(const double tmp)67   void           SetTemp1(const double  tmp) { tmp1_ = tmp; }
68   double         GetAdjacentPerimeter(int  bin);
69   double norm_parallel_line_length();
70 
71 protected:
72   int            AngleLoc(const imp_line_sptr&  il);
73   imp_line_sptr  LineAtAngle(int  angle_bin);
74   void CheckUpdateBoundingBox();
75   void ComputeBoundingBox();
76   void ComputeDominantDirs();
77 };
78 
79 // Test consistency of bound
CheckUpdateBoundingBox()80 inline void vifa_group_pgram::CheckUpdateBoundingBox() {
81   if (!bb_ )
82   {
83     bb_ = new vifa_bbox;
84     this->ComputeBoundingBox();
85     return;
86   }
87 
88   if (bb_->older(this))
89     this->ComputeBoundingBox();
90 }
91 
GetBoundingBox()92 inline vifa_bbox_sptr vifa_group_pgram::GetBoundingBox() {
93   this->CheckUpdateBoundingBox();
94   return bb_;
95 }
96 
97 #endif  // VIFA_GROUP_PGRAM_H
98