LArSoft  v10_04_05
Liquid Argon Software toolkit - https://larsoft.org/
lar_dl_content::LArCanvasHelper Class Reference

LArCanvasHelper class. More...

#include "LArCanvasHelper.h"

Static Public Member Functions

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 predicted distance to the vertex and an outer radius based on the maximum predicted distance to the vertex. The centre of the ring is the location of the hit used to predict the distance to the vertex. Each pixel to be filled is augmented by the specified weight. In this way, once all hits have been considered, a consensus view emerges of the likely vertex location based on the overlap of various rings centred at different locations. More...
 
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 to determine the next pixel defining the inner and outer loci of the ring. This update function uses the Bresenham midpoint circle update function to determine this location. The row position is always incremented by 1 pixel, the column position is left unchanged, or decremented by 1 pixel to best follow the arc of the true underlying circle. More...
 

Detailed Description

LArCanvasHelper class.

Definition at line 17 of file LArCanvasHelper.h.

Member Function Documentation

void lar_dl_content::LArCanvasHelper::DrawRing ( float **  canvas,
const int  row,
const int  col,
const int  inner,
const int  outer,
const float  weight 
)
static

Add a filled ring to the specified canvas. The ring has an inner radius based on the minimum predicted distance to the vertex and an outer radius based on the maximum predicted distance to the vertex. The centre of the ring is the location of the hit used to predict the distance to the vertex. Each pixel to be filled is augmented by the specified weight. In this way, once all hits have been considered, a consensus view emerges of the likely vertex location based on the overlap of various rings centred at different locations.

The underlying implementation is a variant of the Bresenham midpoint circle algorithm and therefore only computes pixel coordinates for one octant of each circle (one of radius 'inner', one of radius 'outer') and interpolates the fill between points using integer arithmetic, guaranteeing each pixel of the ring is filled once and only once, and then mirrored to the remaining seven octants.

Parameters
networkOutputThe TorchOutput object populated by the network inference step
pixelVectorThe vector of populated pixels
thresholdsThe fractional distance thresholds representing the classes predicted by the network
columnOffsetThe output column offset for the canvas
rowOffsetThe output row offset for the canvas
widthThe output width for the canvas
heightThe output height for the canvas

Definition at line 14 of file LArCanvasHelper.cc.

References c1, c2, Update(), and weight.

Referenced by lar_dl_content::DlVertexingAlgorithm::Infer(), and lar_dl_content::DlSecondaryVertexingAlgorithm::Infer().

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 }
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
Int_t col[ntarg]
Definition: Style.C:29
double weight
Definition: plottest35.C:25
void lar_dl_content::LArCanvasHelper::Update ( const int  radius,
int &  col,
int &  row 
)
static

Update the coordinates along the loci of a circle. When drawing the ring we need an efficient means to determine the next pixel defining the inner and outer loci of the ring. This update function uses the Bresenham midpoint circle update function to determine this location. The row position is always incremented by 1 pixel, the column position is left unchanged, or decremented by 1 pixel to best follow the arc of the true underlying circle.

Parameters
radius2The squared radius of the circle under consideration
colThe input/output column position to (potentially) update
rowThe input/output row position to update

Definition at line 66 of file LArCanvasHelper.cc.

References col.

Referenced by DrawRing().

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 }
Int_t col[ntarg]
Definition: Style.C:29

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