CBAlgoPolyShortestDist.cxx
Go to the documentation of this file.
2 
3 #include <math.h>
4 
5 namespace cmtool {
6 
7  //-------------------------------------------------------
9  //-------------------------------------------------------
10  {
12  SetMinNumHits(0);
13  SetMaxNumHits(99999);
14  SetDebug(false);
15  }
16 
17  //-----------------------------
19  //-----------------------------
20  {
21 
22  }
23 
24  //------------------------------------------------------------------------------------------
25  void CBAlgoPolyShortestDist::EventBegin(const std::vector<cluster::ClusterParamsAlg> &clusters)
26  //------------------------------------------------------------------------------------------
27  {
28  if(clusters.size())
29  tmp_min_dist = 99999;
30  }
31 
32  //-------------------------------
33  //void CBAlgoPolyShortestDist::EventEnd()
34  //-------------------------------
35  //{
36  //
37  //}
38 
39  //-----------------------------------------------------------------------------------------------
40  //void CBAlgoPolyShortestDist::IterationBegin(const std::vector<cluster::ClusterParamsAlg> &clusters)
41  //-----------------------------------------------------------------------------------------------
42  //{
43  //
44  //}
45 
46  //------------------------------------
47  //void CBAlgoPolyShortestDist::IterationEnd()
48  //------------------------------------
49  //{
50  //
51  //}
52 
53  //----------------------------------------------------------------
54  bool CBAlgoPolyShortestDist::Bool(const ::cluster::ClusterParamsAlg &cluster1,
55  const ::cluster::ClusterParamsAlg &cluster2)
56  //----------------------------------------------------------------
57  {
58  if( (cluster1.GetHitVector().size() < _min_hits) ||
59  (cluster2.GetHitVector().size() < _min_hits) )
60  return false;
61 
62  if( (cluster1.GetHitVector().size() > _max_hits) ||
63  (cluster2.GetHitVector().size() > _max_hits) )
64  return false;
65 
66  //if either has < 3 sides do not merge!
67  if ( (cluster1.GetParams().PolyObject.Size() < 2) or
68  (cluster2.GetParams().PolyObject.Size() < 2) ){
69  return false;
70  }
71 
72  //loop over the points on the first polygon and calculate
73  //distance to each point on the second polygon
74  //if any two points are close enough to each other,
75  //merge the two clusters
76 
77  unsigned int npoints1 = cluster1.GetParams().PolyObject.Size();
78  unsigned int npoints2 = cluster2.GetParams().PolyObject.Size();
79  //loop over points on first polygon
80  for(unsigned int i = 0; i < npoints1; ++i){
81  float pt1w = cluster1.GetParams().PolyObject.Point(i).first;
82  float pt1t = cluster1.GetParams().PolyObject.Point(i).second;
83  //loop over points on second polygon
84  for(unsigned int j = 0; j < npoints2; ++j){
85  float pt2w = cluster2.GetParams().PolyObject.Point(j).first;
86  float pt2t = cluster2.GetParams().PolyObject.Point(j).second;
87  double distsqrd = pow(pt2w-pt1w,2)+pow(pt2t-pt1t,2);
88 
89  if(distsqrd < tmp_min_dist) tmp_min_dist = distsqrd;
90 
91  if(_debug){
92  std::cout<<"two polygon points dist2 is "<<distsqrd<<std::endl;
93  std::cout<<"minimum dist was "<<tmp_min_dist<<std::endl;
94  }
95  if(distsqrd<_dist_sqrd_cut)
96  return true;
97  }
98 
99  }
100 
101  return false;
102  }
103 
104  //------------------------------
106  //------------------------------
107  {
108 
109  }
110 
111 }
constexpr T pow(T x)
Definition: pow.h:72
virtual void Reset()
Function to reset the algorithm instance ... maybe implemented via child class.
virtual bool Bool(const ::cluster::ClusterParamsAlg &cluster1, const ::cluster::ClusterParamsAlg &cluster2)
Class def header for a class CBAlgoPolyShortestDist.
virtual void EventBegin(const std::vector< cluster::ClusterParamsAlg > &clusters)
CBAlgoPolyShortestDist()
Default constructor.
QTextStream & endl(QTextStream &s)