LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
LArCanvasHelper.cc
Go to the documentation of this file.
1 
10 
11 namespace lar_dl_content
12 {
13 
14 void LArCanvasHelper::DrawRing(float **canvas, const int row, const int col, const int inner, const int outer, const float weight)
15 {
16  // Set the starting position for each circle bounding the ring
17  int c1{inner}, r1{0}, c2{outer}, r2{0};
18  int inner2{inner * inner}, outer2{outer * outer};
19  while (c2 >= r2)
20  {
21  // Set the output pixel location
22  int rp2{r2}, cp2{c2};
23  // We're still within the octant for the inner ring, so use the inner pixel location (see Update comment below)
24  // Note also that the inner row is always the same as the outer row, so no need to define rp1
25  int cp1{c1};
26  if (c1 <= r1)
27  { // We've completed the arc of the inner ring already, so just move radially out from here (see Update comment below)
28  cp1 = r2;
29  }
30  // Fill the pixels from inner to outer in the current row and their mirror pixels in the other octants
31  for (int c = cp1; c <= cp2; ++c)
32  {
33  canvas[row + rp2][col + c] += weight;
34  if (rp2 != c)
35  canvas[row + c][col + rp2] += weight;
36  if (rp2 != 0 && cp2 != 0)
37  {
38  canvas[row - rp2][col - c] += weight;
39  if (rp2 != c)
40  canvas[row - c][col - rp2] += weight;
41  }
42  if (rp2 != 0)
43  {
44  canvas[row - rp2][col + c] += weight;
45  if (rp2 != c)
46  canvas[row + c][col - rp2] += weight;
47  }
48  if (cp2 != 0)
49  {
50  canvas[row + rp2][col - c] += weight;
51  if (rp2 != c)
52  canvas[row - c][col + rp2] += weight;
53  }
54  }
55  // Only update the inner location while it remains in the octant (outer ring also remains in the octant of course, but the logic of
56  // the update means that the inner ring can leave its octant before the outer ring is complete, so we need to stop that)
57  if (c1 > r1)
58  LArCanvasHelper::Update(inner2, c1, r1);
59  // Update the outer location - increase the row position with every step, decrease the column position if conditions are met
60  LArCanvasHelper::Update(outer2, c2, r2);
61  }
62 }
63 
64 //-----------------------------------------------------------------------------------------------------------------------------------------
65 
66 void LArCanvasHelper::Update(const int radius2, int &col, int &row)
67 {
68  // Bresenham midpoint circle algorithm to determine if we should update the column position
69  // This obscure looking block of code uses bit shifts and integer arithmetic to perform this check as efficiently as possible
70  const int a{1 - (col << 2)};
71  const int b{col * col + row * row - radius2 + (row << 2) + 1};
72  const int c{(a << 2) * b + a * a};
73  if (c < 0)
74  {
75  --col;
76  ++row;
77  }
78  else
79  ++row;
80 }
81 
82 } // namespace lar_dl_content
Header file for the lar deep learning helper helper class.
static void Update(const int radius, int &col, int &row)
Update the coordinates along the loci of a circle. When drawing the ring we need an efficient means t...
TCanvas * c1
Definition: plotHisto.C:7
TCanvas * c2
Definition: plot_hist.C:75
static void DrawRing(float **canvas, const int row, const int col, const int inner, const int outer, const float weight)
Add a filled ring to the specified canvas. The ring has an inner radius based on the minimum predicte...
Int_t col[ntarg]
Definition: Style.C:29
double weight
Definition: plottest35.C:25