All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Public Attributes | List of all members
seaview::seaDBSCAN Class Reference

#include <seaDBSCAN.h>

Public Member Functions

 seaDBSCAN (double in_eps, int in_minpts)
 constructor More...
 
 ~seaDBSCAN ()
 Default destructor. More...
 
std::vector< int > Scan2D (std::vector< std::vector< double >> &pts)
 
std::vector< std::vector
< double > > 
GetNeighbours (size_t i, std::vector< std::vector< double >> &pts, bool)
 
int UnionSets (std::vector< std::vector< double >> &seed, std::vector< std::vector< double >> &pts)
 
double SimpleDist (double w1, double t1, double w2, double t2)
 

Public Attributes

double m_eps
 
int m_minpts
 

Detailed Description

Definition at line 23 of file seaDBSCAN.h.

Constructor & Destructor Documentation

seaview::seaDBSCAN::seaDBSCAN ( double  in_eps,
int  in_minpts 
)
inline

constructor

Definition at line 30 of file seaDBSCAN.h.

30 : m_eps(in_eps), m_minpts(in_minpts) {}
seaview::seaDBSCAN::~seaDBSCAN ( )
inline

Default destructor.

Definition at line 33 of file seaDBSCAN.h.

33 {}

Member Function Documentation

std::vector< std::vector< double > > seaview::seaDBSCAN::GetNeighbours ( size_t  i,
std::vector< std::vector< double >> &  pts,
bool  include_self 
)

Definition at line 58 of file seaDBSCAN.cxx.

58  {
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  }
pdgs p
Definition: selectors.fcl:22
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
double SimpleDist(double w1, double t1, double w2, double t2)
Definition: seaDBSCAN.cxx:110
std::vector< int > seaview::seaDBSCAN::Scan2D ( std::vector< std::vector< double >> &  pts)

Definition at line 5 of file seaDBSCAN.cxx.

5  {
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  }
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
process_name largeant stream1 can override from command line with o or output physics producers generator N
double seaview::seaDBSCAN::SimpleDist ( double  w1,
double  t1,
double  w2,
double  t2 
)

Definition at line 110 of file seaDBSCAN.cxx.

110  {
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  }
int seaview::seaDBSCAN::UnionSets ( std::vector< std::vector< double >> &  seed,
std::vector< std::vector< double >> &  pts 
)

Definition at line 86 of file seaDBSCAN.cxx.

86  {
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  }
pdgs p
Definition: selectors.fcl:22
then echo File list $list not found else cat $list while read file do echo $file sed s
Definition: file_to_url.sh:60

Member Data Documentation

double seaview::seaDBSCAN::m_eps

Definition at line 26 of file seaDBSCAN.h.

int seaview::seaDBSCAN::m_minpts

Definition at line 27 of file seaDBSCAN.h.


The documentation for this class was generated from the following files: