LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
cluster::HoughTransform Class Reference

Public Member Functions

void Init (unsigned int dx, unsigned int dy, float rhores, unsigned int numACells)
 
std::array< int, 3 > AddPointReturnMax (int x, int y)
 
bool SubtractPoint (int x, int y)
 
int GetCell (int row, int col) const
 
void SetCell (int row, int col, int value)
 
void GetAccumSize (int &numRows, int &numCols)
 
int NumAccumulated ()
 
void GetEquation (float row, float col, float &rho, float &theta) const
 
int GetMax (int &xmax, int &ymax) const
 
void reconfigure (fhicl::ParameterSet const &pset)
 

Private Types

typedef HoughTransformCounters< int, signed char, 64 > BaseMap_t
 rho -> # hits (for convenience) More...
 
typedef HoughTransformCounters< int, signed char, 64 > DistancesMap_t
 
typedef std::vector< DistancesMap_tHoughImage_t
 Type of the Hough transform (angle, distance) map with custom allocator. More...
 

Private Member Functions

std::array< int, 3 > DoAddPointReturnMax (int x, int y, bool bSubtract=false)
 

Private Attributes

unsigned int m_dx
 
unsigned int m_dy
 
unsigned int m_rowLength
 
unsigned int m_numAngleCells
 
float m_rhoResolutionFactor
 
HoughImage_t m_accum
 column (map key)=rho, row (vector index)=theta More...
 
int m_numAccumulated
 
std::vector< double > m_cosTable
 
std::vector< double > m_sinTable
 

Detailed Description

Definition at line 74 of file HoughBaseAlg.cxx.

Member Typedef Documentation

typedef HoughTransformCounters<int, signed char, 64> cluster::HoughTransform::BaseMap_t
private

rho -> # hits (for convenience)

Definition at line 94 of file HoughBaseAlg.cxx.

typedef HoughTransformCounters<int, signed char, 64> cluster::HoughTransform::DistancesMap_t
private

Definition at line 95 of file HoughBaseAlg.cxx.

Type of the Hough transform (angle, distance) map with custom allocator.

Definition at line 98 of file HoughBaseAlg.cxx.

Member Function Documentation

std::array< int, 3 > cluster::HoughTransform::AddPointReturnMax ( int  x,
int  y 
)
inline

Definition at line 645 of file HoughBaseAlg.cxx.

References DoAddPointReturnMax(), m_dx, and m_dy.

Referenced by cluster::HoughBaseAlg::FastTransform(), cluster::HoughBaseAlg::HoughBaseAlg(), and cluster::HoughBaseAlg::Transform().

646 {
647  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) {
648  std::array<int, 3> max;
649  max.fill(0);
650  return max;
651  }
652  return DoAddPointReturnMax(x, y, false); // false = add
653 }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
std::array< int, 3 > DoAddPointReturnMax(int x, int y, bool bSubtract=false)
std::array< int, 3 > cluster::HoughTransform::DoAddPointReturnMax ( int  x,
int  y,
bool  bSubtract = false 
)
private

Definition at line 738 of file HoughBaseAlg.cxx.

References cluster::HoughTransformCounters< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::decrement(), larg4::dist(), cluster::HoughTransformCounters< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::increment_and_get_max(), m_accum, m_cosTable, m_numAccumulated, m_numAngleCells, m_rhoResolutionFactor, m_rowLength, and m_sinTable.

Referenced by AddPointReturnMax(), and SubtractPoint().

741 {
742  std::array<int, 3> max;
743  max.fill(-1);
744 
745  // max_val is the current maximum number of hits aligned on a line so far;
746  // currently the code ignores all the lines with just two aligned hits
747  int max_val = 2;
748 
749  const int distCenter = (int)(m_rowLength / 2.);
750 
751  // prime the lastDist variable so our linear fill works below
752  // lastDist represents next distance to be incremented (but see below)
753  int lastDist = (int)(distCenter + (m_rhoResolutionFactor * x));
754 
755  // loop through all angles a from 0 to 180 degrees
756  // (the value of the angle is established in definition of m_cosTable and
757  // m_sinTable in HoughTransform::Init()
758  for (size_t iAngleStep = 1; iAngleStep < m_numAngleCells; ++iAngleStep) {
759 
760  // Calculate the basic line equation dist = cos(a)*x + sin(a)*y.
761  // Shift to center of row to cover negative values;
762  // this math must also be coherent with the one in GetEquation()
763  const int dist = (int)(distCenter + m_rhoResolutionFactor * (m_cosTable[iAngleStep] * x +
764  m_sinTable[iAngleStep] * y));
765 
766  /*
767  * For this angle, we are going to increment all the cells starting from the
768  * last distance in the previous loop, up to the current one (dist),
769  * with the exception that if we are incrementing more than one cell,
770  * we do not increment dist cell itself (it will be incremented in the
771  * next angle).
772  * The cell of the last distance is always incremented,
773  * whether it was also for the previous angle (in case there was only one
774  * distance to be incremented) or not (if there was a sequence of distances
775  * to increment, and then the last distance was not).
776  * First we increment the last cell of our range; this provides us with a
777  * hint of where the immediate previous cell should be, which saves us a
778  * look up.
779  * We collect and return information about the local maximum among the cells
780  * we are increasing.
781  */
782 
783  // establish the range of cells to increase: [ first_dist, end_dist [ ;
784  // also set lastDist so that it points to the next cell to be incremented,
785  // according to the rules described above
786  int first_dist;
787  int end_dist;
788  if (lastDist == dist) {
789  // the range is [ dist, dist + 1 [ (that is, [ dist ]
790  first_dist = dist;
791  end_dist = dist + 1;
792  }
793  else {
794  // the range is [ lastDist, dist [ or ] dist, lastDist]
795  first_dist = dist > lastDist ? lastDist : dist + 1;
796  end_dist = dist > lastDist ? dist : lastDist + 1;
797  }
798 
799  DistancesMap_t& distMap = m_accum[iAngleStep];
800  if (bSubtract) { distMap.decrement(first_dist, end_dist); }
801  else {
802  DistancesMap_t::PairValue_t max_counter =
803  distMap.increment_and_get_max(first_dist, end_dist, max_val);
804 
805  if (max_counter.second > max_val) {
806  // DEBUG
807  // std::cout << " <NEW MAX " << max_val << " => " << max_counter.second << " >" << std::endl;
808  // BUG the double brace syntax is required to work around clang bug 21629
809  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
810  max = {{max_counter.second, max_counter.first.key(), (int)iAngleStep}};
811  max_val = max_counter.second;
812  }
813  }
814  lastDist = dist;
815 
816  // DEBUG
817  // std::cout << "\n (max " << max[1] << " => " << max[0] << ")" << std::endl;
818  // }
819  } // for angles
820  if (bSubtract)
822  else
824 
825  //mf::LogVerbatim("HoughBaseAlg") << "Add point says xmax: " << *xmax << " ymax: " << *ymax << std::endl;
826 
827  return max;
828 } // cluster::HoughTransform::DoAddPointReturnMax()
Float_t x
Definition: compare.C:6
std::vector< double > m_cosTable
Float_t y
Definition: compare.C:6
unsigned int m_numAngleCells
std::pair< const_iterator, SubCounter_t > PairValue_t
Pair identifying a counter and its current value.
Definition: HoughBaseAlg.h:295
constexpr double dist(const TReal *x, const TReal *y, const unsigned int dimension)
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
std::vector< double > m_sinTable
HoughTransformCounters< int, signed char, 64 > DistancesMap_t
void cluster::HoughTransform::GetAccumSize ( int &  numRows,
int &  numCols 
)
inline

Definition at line 81 of file HoughBaseAlg.cxx.

References m_accum, and m_rowLength.

Referenced by cluster::HoughBaseAlg::HoughBaseAlg(), and cluster::HoughBaseAlg::Transform().

82  {
83  numRows = m_accum.size();
84  numCols = (int)m_rowLength;
85  }
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
int cluster::HoughTransform::GetCell ( int  row,
int  col 
) const
inline

Definition at line 637 of file HoughBaseAlg.cxx.

References col, and m_accum.

Referenced by cluster::HoughBaseAlg::FastTransform(), cluster::HoughBaseAlg::HoughBaseAlg(), and cluster::HoughBaseAlg::Transform().

638 {
639  return m_accum[row][col];
640 } // cluster::HoughTransform::GetCell()
Int_t col[ntarg]
Definition: Style.C:29
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
void cluster::HoughTransform::GetEquation ( float  row,
float  col,
float &  rho,
float &  theta 
) const

Definition at line 712 of file HoughBaseAlg.cxx.

References m_numAngleCells, m_rhoResolutionFactor, and m_rowLength.

Referenced by cluster::HoughBaseAlg::FastTransform(), cluster::HoughBaseAlg::HoughBaseAlg(), NumAccumulated(), and cluster::HoughBaseAlg::Transform().

713 {
714  theta = (TMath::Pi() * row) / m_numAngleCells;
715  rho = (col - (m_rowLength / 2.)) / m_rhoResolutionFactor;
716 } // cluster::HoughTransform::GetEquation()
unsigned int m_numAngleCells
Int_t col[ntarg]
Definition: Style.C:29
int cluster::HoughTransform::GetMax ( int &  xmax,
int &  ymax 
) const

Definition at line 719 of file HoughBaseAlg.cxx.

References m_accum.

Referenced by NumAccumulated(), and cluster::HoughBaseAlg::Transform().

720 {
721  int maxVal = -1;
722  for (unsigned int i = 0; i < m_accum.size(); i++) {
723 
724  DistancesMap_t::PairValue_t max_counter = m_accum[i].get_max(maxVal);
725  if (max_counter.second > maxVal) {
726  maxVal = max_counter.second;
727  xmax = i;
728  ymax = max_counter.first.key();
729  }
730  } // for angle
731 
732  return maxVal;
733 }
std::pair< const_iterator, SubCounter_t > PairValue_t
Pair identifying a counter and its current value.
Definition: HoughBaseAlg.h:295
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
void cluster::HoughTransform::Init ( unsigned int  dx,
unsigned int  dy,
float  rhores,
unsigned int  numACells 
)

Definition at line 664 of file HoughBaseAlg.cxx.

References m_accum, m_cosTable, m_dx, m_dy, m_numAccumulated, m_numAngleCells, m_rhoResolutionFactor, m_rowLength, m_sinTable, and PI.

Referenced by cluster::HoughBaseAlg::FastTransform(), cluster::HoughBaseAlg::HoughBaseAlg(), and cluster::HoughBaseAlg::Transform().

668 {
669  m_numAngleCells = numACells;
670  m_rhoResolutionFactor = rhores;
671 
672  m_accum.clear();
673  //--- BEGIN issue #19494 -----------------------------------------------------
674  // BulkAllocator.h is currently broken; see issue #19494 and comment in header.
675 #if 0
676  // set the custom allocator for nodes to allocate large chunks of nodes;
677  // one node is 40 bytes plus the size of the counters block.
678  // The math over there sets a bit less than 10 MiB per chunk.
679  // to find out the right type name to put here, comment out this line
680  // (it will suppress some noise), set bDebug to true in
681  // lardata/Utilities/BulkAllocator.h and run this module;
682  // all BulkAllocator instances will advertise that they are being created,
683  // mentioning their referring type. You can also simplyfy it by using the
684  // available typedefs, like here:
686  std::_Rb_tree_node
687  <std::pair<const DistancesMap_t::Key_t, DistancesMap_t::CounterBlock_t>>
688  >::SetChunkSize(
689  10 * ((1048576 / (40 + sizeof(DistancesMap_t::CounterBlock_t))) & ~0x1FFU)
690  );
691 #endif // 0
692  //--- END issue #19494 -------------------------------------------------------
693 
694  m_numAccumulated = 0;
695  m_dx = dx;
696  m_dy = dy;
697  m_rowLength = (unsigned int)(m_rhoResolutionFactor * 2 * std::sqrt(dx * dx + dy * dy));
698  m_accum.resize(m_numAngleCells);
699 
700  // this math must be coherent with the one in GetEquation()
701  double angleStep = PI / m_numAngleCells;
702  m_cosTable.resize(m_numAngleCells);
703  m_sinTable.resize(m_numAngleCells);
704  for (size_t iAngleStep = 0; iAngleStep < m_numAngleCells; ++iAngleStep) {
705  double a = iAngleStep * angleStep;
706  m_cosTable[iAngleStep] = cos(a);
707  m_sinTable[iAngleStep] = sin(a);
708  }
709 }
std::vector< double > m_cosTable
unsigned int m_numAngleCells
constexpr double PI
Aggressive allocator reserving a lot of memory in advance.
Definition: BulkAllocator.h:89
typename Base_t::CounterBlock_t CounterBlock_t
Definition: HoughBaseAlg.h:291
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
std::vector< double > m_sinTable
int cluster::HoughTransform::NumAccumulated ( )
inline

Definition at line 86 of file HoughBaseAlg.cxx.

References GetEquation(), GetMax(), m_numAccumulated, and reconfigure().

void cluster::HoughTransform::reconfigure ( fhicl::ParameterSet const &  pset)

Referenced by NumAccumulated().

void cluster::HoughTransform::SetCell ( int  row,
int  col,
int  value 
)
inline

Definition at line 80 of file HoughBaseAlg.cxx.

References m_accum.

Referenced by cluster::HoughBaseAlg::FastTransform(), and cluster::HoughBaseAlg::HoughBaseAlg().

80 { m_accum[row].set(col, value); }
Int_t col[ntarg]
Definition: Style.C:29
double value
Definition: spectrum.C:18
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
bool cluster::HoughTransform::SubtractPoint ( int  x,
int  y 
)
inline

Definition at line 656 of file HoughBaseAlg.cxx.

References DoAddPointReturnMax(), m_dx, and m_dy.

Referenced by cluster::HoughBaseAlg::HoughBaseAlg().

657 {
658  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) return false;
659  DoAddPointReturnMax(x, y, true); // true = subtract
660  return true;
661 }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
std::array< int, 3 > DoAddPointReturnMax(int x, int y, bool bSubtract=false)

Member Data Documentation

HoughImage_t cluster::HoughTransform::m_accum
private

column (map key)=rho, row (vector index)=theta

Definition at line 108 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), GetAccumSize(), GetCell(), GetMax(), Init(), and SetCell().

std::vector<double> cluster::HoughTransform::m_cosTable
private

Definition at line 110 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), and Init().

unsigned int cluster::HoughTransform::m_dx
private

Definition at line 100 of file HoughBaseAlg.cxx.

Referenced by AddPointReturnMax(), Init(), and SubtractPoint().

unsigned int cluster::HoughTransform::m_dy
private

Definition at line 101 of file HoughBaseAlg.cxx.

Referenced by AddPointReturnMax(), Init(), and SubtractPoint().

int cluster::HoughTransform::m_numAccumulated
private

Definition at line 109 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), Init(), and NumAccumulated().

unsigned int cluster::HoughTransform::m_numAngleCells
private

Definition at line 103 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), GetEquation(), and Init().

float cluster::HoughTransform::m_rhoResolutionFactor
private

Definition at line 104 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), GetEquation(), and Init().

unsigned int cluster::HoughTransform::m_rowLength
private

Definition at line 102 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), GetAccumSize(), GetEquation(), and Init().

std::vector<double> cluster::HoughTransform::m_sinTable
private

Definition at line 111 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), and Init().


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