LArSoft  v10_04_05
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 75 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 95 of file HoughBaseAlg.cxx.

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

Definition at line 96 of file HoughBaseAlg.cxx.

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

Definition at line 99 of file HoughBaseAlg.cxx.

Member Function Documentation

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

Definition at line 647 of file HoughBaseAlg.cxx.

References DoAddPointReturnMax(), m_dx, and m_dy.

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

648 {
649  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) {
650  std::array<int, 3> max;
651  max.fill(0);
652  return max;
653  }
654  return DoAddPointReturnMax(x, y, false); // false = add
655 }
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 740 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().

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

References m_accum, and m_rowLength.

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

83  {
84  numRows = m_accum.size();
85  numCols = (int)m_rowLength;
86  }
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 639 of file HoughBaseAlg.cxx.

References col, and m_accum.

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

640 {
641  return m_accum[row][col];
642 } // 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 714 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().

715 {
716  theta = (TMath::Pi() * row) / m_numAngleCells;
717  rho = (col - (m_rowLength / 2.)) / m_rhoResolutionFactor;
718 } // 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 721 of file HoughBaseAlg.cxx.

References m_accum.

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

722 {
723  int maxVal = -1;
724  for (unsigned int i = 0; i < m_accum.size(); i++) {
725 
726  DistancesMap_t::PairValue_t max_counter = m_accum[i].get_max(maxVal);
727  if (max_counter.second > maxVal) {
728  maxVal = max_counter.second;
729  xmax = i;
730  ymax = max_counter.first.key();
731  }
732  } // for angle
733 
734  return maxVal;
735 }
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 666 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().

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

References m_accum.

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

81 { 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 658 of file HoughBaseAlg.cxx.

References DoAddPointReturnMax(), m_dx, and m_dy.

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

659 {
660  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) return false;
661  DoAddPointReturnMax(x, y, true); // true = subtract
662  return true;
663 }
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 109 of file HoughBaseAlg.cxx.

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

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

Definition at line 111 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), and Init().

unsigned int cluster::HoughTransform::m_dx
private

Definition at line 101 of file HoughBaseAlg.cxx.

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

unsigned int cluster::HoughTransform::m_dy
private

Definition at line 102 of file HoughBaseAlg.cxx.

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

int cluster::HoughTransform::m_numAccumulated
private

Definition at line 110 of file HoughBaseAlg.cxx.

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

unsigned int cluster::HoughTransform::m_numAngleCells
private

Definition at line 104 of file HoughBaseAlg.cxx.

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

float cluster::HoughTransform::m_rhoResolutionFactor
private

Definition at line 105 of file HoughBaseAlg.cxx.

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

unsigned int cluster::HoughTransform::m_rowLength
private

Definition at line 103 of file HoughBaseAlg.cxx.

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

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

Definition at line 112 of file HoughBaseAlg.cxx.

Referenced by DoAddPointReturnMax(), and Init().


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