Line data Source code
1 : #include "triggeralgs/dbscan/Hit.hpp"
2 :
3 : #include <algorithm>
4 :
5 : namespace triggeralgs {
6 : namespace dbscan {
7 :
8 : //======================================================================
9 0 : HitSet::HitSet()
10 : {
11 0 : hits.reserve(10);
12 0 : }
13 :
14 : //======================================================================
15 : void
16 0 : HitSet::insert(Hit* h)
17 : {
18 : // We're typically inserting hits at or near the end, so do a
19 : // linear scan instead of full binary search. This turns out to be much
20 : // faster in our case
21 0 : auto it = hits.rbegin();
22 0 : while (it != hits.rend() && (*it)->time >= h->time) {
23 : // Don't insert the hit if we already have it
24 0 : if (*it == h) {
25 0 : return;
26 : }
27 0 : ++it;
28 : }
29 :
30 0 : if (it == hits.rend() || *it != h) {
31 0 : hits.insert(it.base(), h);
32 : }
33 : }
34 :
35 : //======================================================================
36 0 : Hit::Hit(float _time, int _chan, const triggeralgs::TriggerPrimitive* _prim)
37 : {
38 0 : reset(_time, _chan, _prim);
39 0 : }
40 :
41 : //======================================================================
42 :
43 : void
44 0 : Hit::reset(float _time, int _chan, const triggeralgs::TriggerPrimitive* _prim)
45 : {
46 0 : time=_time;
47 0 : chan=_chan;
48 0 : cluster=kUndefined;
49 0 : connectedness=Connectedness::kUndefined;
50 0 : neighbours.clear();
51 0 : if(_prim){
52 0 : primitive=*_prim;
53 : }
54 0 : }
55 :
56 : //======================================================================
57 :
58 : // Return true if hit was indeed a neighbour
59 : bool
60 0 : Hit::add_potential_neighbour(Hit* other, float eps, int minPts)
61 : {
62 0 : if (other != this && euclidean_distance_sqr(*this, *other) < eps*eps) {
63 0 : neighbours.insert(other);
64 0 : if (neighbours.size() + 1 >= minPts) {
65 0 : connectedness = Connectedness::kCore;
66 : }
67 : // Neighbourliness is symmetric
68 0 : other->neighbours.insert(this);
69 0 : if (other->neighbours.size() + 1 >= minPts) {
70 0 : other->connectedness = Connectedness::kCore;
71 : }
72 0 : return true;
73 : }
74 : return false;
75 : }
76 :
77 : }
78 : }
79 : // Local Variables:
80 : // mode: c++
81 : // c-basic-offset: 4
82 : // c-file-style: "linux"
83 : // End:
|