RayClustering.cxx
Go to the documentation of this file.
2 
3 using namespace WireCell;
4 using namespace WireCell::RayGrid;
5 
7 {
8  blobproj_t ret;
9  for (blobref_t blob : blobs) {
10  const auto bounds = blob->strips()[layer].bounds;
11  for (auto gi = bounds.first; gi != bounds.second; ++gi) {
12  if ((int)ret.size() <= gi) {
13  ret.resize(gi+1);
14  }
15  ret[gi].push_back(blob);
16  }
17  }
18  return ret;
19 }
20 
21 
23 {
24  if (proj.empty()) {
26  }
27 
28  blobset_t uniq;
29  int nproj = std::min((int)proj.size(), gr.second);
30  for (grid_index_t gind = gr.first; gind < nproj; ++gind) {
31  const auto& some = proj[gind];
32  uniq.insert(some.begin(), some.end());
33  }
34  return blobvec_t(uniq.begin(), uniq.end());
35 }
36 
37 
39 {
40  const auto& strip = blob->strips()[layer];
41  auto blobs = select(proj, strip.bounds);
42  if (blobs.empty()) {
43  return blobs;
44  }
45  if (layer == 0) {
46  return blobs;
47  }
48 
49  --layer;
50  auto newproj = projection(blobs, layer);
51  return overlap(blob, newproj, layer);
52 }
53 
54 
56 {
57  const size_t siz = blobs.size();
58  blobvec_t ret(siz);
59  for (size_t ind=0; ind<siz; ++ind) {
60  ret[ind] = blobs.begin()+ind;
61  }
62  return ret;
63 }
64 
66 {
67  const auto& astrips = a->strips();
68  const auto& bstrips = b->strips();
69  const int nlayers = astrips.size();
70 
71  int ainb = 0, bina = 0;
72  for (int ilayer=0; ilayer<nlayers; ++ilayer) {
73  const auto& astrip = astrips[ilayer];
74  const auto& bstrip = bstrips[ilayer];
75  const auto& abounds = astrip.bounds;
76  const auto& bbounds = bstrip.bounds;
77  if (abounds.first <= bbounds.first and bbounds.second <= abounds.second) {
78  ++bina;
79  }
80  if (bbounds.first <= abounds.first and abounds.second <= bbounds.second) {
81  ++ainb;
82  }
83  }
84  if (ainb == nlayers or bina == nlayers) {
85  return true;
86  }
87  return false;
88 }
89 
90 
92 {
93  if (one.empty() or two.empty()) {
94  return;
95  }
96  const size_t nlayers = two[0].strips().size();
97  const size_t ilayer = nlayers-1;
98  const auto proj = projection(references(two), ilayer);
99  for (blobref_t blob = one.begin(); blob != one.end(); ++blob) {
100  auto assoc = overlap(blob, proj, ilayer); // recursive call
101  for (blobref_t other : assoc) {
102  func(blob, other);
103  }
104  }
105 }
106 
107 
108 
109 /*
110 for blob in slice[i]:
111 
112  other_blobs = slice[i+1];
113  for strip in blob.strips:
114  other_blobs = overlapping_blobs(other_blobs, strip)
115 
116  if other_blobs.empty():
117  continue
118 
119  mark(blob)
120  for other in other_blobs:
121  mark(other)
122 */
std::vector< blobref_t > blobvec_t
Definition: RayClustering.h:14
blobvec_t select(const blobproj_t &proj, grid_range_t range)
def blobs(cm, hist)
Definition: plots.py:79
std::vector< blobvec_t > blobproj_t
Definition: RayClustering.h:15
void associate(const blobs_t &one, const blobs_t &two, associator_t func)
std::function< void(blobref_t &a, blobref_t &b)> associator_t
Definition: RayClustering.h:44
std::pair< grid_index_t, grid_index_t > grid_range_t
Definition: RayGrid.h:58
blobs_t::const_iterator blobref_t
Definition: RayClustering.h:13
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
Definition: Main.h:22
std::vector< Blob > blobs_t
Definition: RayTiling.h:134
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
Definition: statistics.h:55
blobvec_t references(const blobs_t &blobs)
blobvec_t overlap(const blobref_t &blob, const blobproj_t &proj, layer_index_t layer)
def func()
Definition: docstring.py:7
static bool * b
Definition: config.cpp:1043
blobproj_t projection(const blobvec_t &blobs, layer_index_t layer)
bool surrounding(const blobref_t &a, const blobref_t &b)
const Ray & bounds() const
Return the ray representing the bounds.
Definition: BoundingBox.h:36
std::unordered_set< blobref_t, blobref_hash > blobset_t
Definition: RayClustering.h:22