All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
seaDBSCAN.cxx
Go to the documentation of this file.
2 
3 namespace seaview{
4 
5  std::vector<int> seaDBSCAN::Scan2D(std::vector<std::vector<double>> &pts){
6 
7  int cluster_count = 0;//we have no clusters
8  size_t N = pts.size();
9  int l_undef = -99;
10  int l_noise = 0;
11  std::vector<int> label(N,l_undef);
12 
13  for(size_t i=0; i<N; i++){
14  if(label[i]!=l_undef) continue;
15  std::vector<std::vector<double>> neighbours = this->GetNeighbours(i,pts,false);
16  //std::cout<<i<<" has neightbours "<<neighbours.size()<<std::endl;
17 
18  if((int)neighbours.size()+1 < m_minpts){ // if there is less than minpts, its a noise point
19  label[i]= l_noise;
20  // std::cout<<i<<" thats less than min, noise"<<std::endl;
21  continue;
22  }
23 
24  cluster_count+=1;
25  label[i] = cluster_count;
26 
27 
28  std::vector<std::vector<double>> seed_set = neighbours;
29  for(size_t q=0; q<seed_set.size(); q++){
30  size_t iq = (size_t)seed_set[q][2]; //This is original
31 
32  if(label[iq]==l_noise){
33  label[iq] = cluster_count;//Change noise to a border point;
34  }
35 
36  if(label[iq]!=l_undef){
37  continue; // previously processed, already identified to a cluster
38  }
39 
40  // if label[iq] is l_undef
41  label[iq]=cluster_count;// wasn't noise, new point, add to cluster
42 
43  std::vector<std::vector<double>> new_neighbours = this->GetNeighbours(iq,pts,true);//Get neighbours of this point, including itslef eh.
44 
45  if((int)new_neighbours.size() >= m_minpts ){ //expand the seed set
46  //Guanqun: change vector while looping over its elements
47  //new elements are pushed back to seed_set
48  this->UnionSets(seed_set, new_neighbours);
49  }
50  }
51  }
52  return label;
53 
54  }
55 
56 
57 
58  std::vector<std::vector<double>> seaDBSCAN::GetNeighbours(size_t ipoint, std::vector<std::vector<double>>&pts,bool include_self){
59  std::vector<std::vector<double>> neighbours;
60  std::vector<double> point = pts[ipoint];
61 
62  //VERY simple, will update soon to a DB
63 
64 
65  for(size_t ip=0; ip<pts.size(); ip++){
66  std::vector<double> p = pts[ip];
67 
68  double dist = this->SimpleDist( p[0], p[1], point[0], point[1]);
69 
70  if(include_self){
71  if(dist <= m_eps){
72  std::vector<double> tp = {p[0],p[1],(double)ip};//Push back original index too
73  neighbours.push_back(tp);
74  }
75  }else{
76  if(dist <= m_eps && p != point ){
77  std::vector<double> tp = {p[0],p[1],(double)ip};//Push back original index too
78  neighbours.push_back(tp);
79  }
80 
81  }
82  }
83  return neighbours;
84  }
85 
86  int seaDBSCAN::UnionSets(std::vector<std::vector<double>> &seed, std::vector<std::vector<double>> &pts){
87 
88  //VERY simple, will update soon if it works
89  for(auto &p:pts){
90 
91  bool is_in=false;
92  for(auto &s:seed){
93  if(s==p){
94  is_in = true;
95  break;
96  }
97  }
98 
99  if(is_in == false){
100  seed.push_back(p);
101  }
102 
103  }
104 
105 
106 
107  return 0;
108  }
109 
110  double seaDBSCAN::SimpleDist(double w1, double t1, double w2, double t2){
111  // Guanqun: wire and tick conversion to distance??, if so should only be done on plane 2
112  double wire_con = 0.3;
113  double tick_con = 1.0/25.0;
114 
115  return sqrt(pow(w1*wire_con-w2*wire_con,2)+pow(t1*tick_con-t2*tick_con,2));
116 
117  }
118 
119 
120 }
pdgs p
Definition: selectors.fcl:22
std::vector< std::vector< double > > GetNeighbours(size_t i, std::vector< std::vector< double >> &pts, bool)
Definition: seaDBSCAN.cxx:58
int UnionSets(std::vector< std::vector< double >> &seed, std::vector< std::vector< double >> &pts)
Definition: seaDBSCAN.cxx:86
Class def header for a class seaDBSCAN.
auto vector(Vector const &v)
Returns a manipulator which will print the specified array.
Definition: DumpUtils.h:265
unsigned int seed
std::vector< int > Scan2D(std::vector< std::vector< double >> &pts)
Definition: seaDBSCAN.cxx:5
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60
process_name largeant stream1 can override from command line with o or output physics producers generator N
double SimpleDist(double w1, double t1, double w2, double t2)
Definition: seaDBSCAN.cxx:110