All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
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_t
HoughImage_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 103 of file HoughBaseAlg.cxx.

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

Definition at line 104 of file HoughBaseAlg.cxx.

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

Definition at line 107 of file HoughBaseAlg.cxx.

Member Function Documentation

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

Definition at line 660 of file HoughBaseAlg.cxx.

661 {
662  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) {
663  std::array<int, 3> max;
664  max.fill(0);
665  return max;
666  }
667  return DoAddPointReturnMax(x, y, false); // false = add
668 }
process_name opflash particleana ie x
process_name opflash particleana ie ie y
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 758 of file HoughBaseAlg.cxx.

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

87  {
88  numRows = m_accum.size();
89  numCols = (int)m_rowLength;
90  }
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 651 of file HoughBaseAlg.cxx.

652 {
653  return m_accum[row][col];
654 } // cluster::HoughTransform::GetCell()
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 730 of file HoughBaseAlg.cxx.

731 {
732  theta = (TMath::Pi() * row) / m_numAngleCells;
733  rho = (col - (m_rowLength / 2.)) / m_rhoResolutionFactor;
734 } // cluster::HoughTransform::GetEquation()
unsigned int m_numAngleCells
int cluster::HoughTransform::GetMax ( int &  xmax,
int &  ymax 
) const

Definition at line 738 of file HoughBaseAlg.cxx.

739 {
740  int maxVal = -1;
741  for (unsigned int i = 0; i < m_accum.size(); i++) {
742 
743  DistancesMap_t::PairValue_t max_counter = m_accum[i].get_max(maxVal);
744  if (max_counter.second > maxVal) {
745  maxVal = max_counter.second;
746  xmax = i;
747  ymax = max_counter.first.key();
748  }
749  } // for angle
750 
751  return maxVal;
752 }
std::pair< const_iterator, SubCounter_t > PairValue_t
Pair identifying a counter and its current value.
Definition: HoughBaseAlg.h:297
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 681 of file HoughBaseAlg.cxx.

685 {
686  m_numAngleCells = numACells;
687  m_rhoResolutionFactor = rhores;
688 
689  m_accum.clear();
690  //--- BEGIN issue #19494 -----------------------------------------------------
691  // BulkAllocator.h is currently broken; see issue #19494 and comment in header.
692 #if 0
693  // set the custom allocator for nodes to allocate large chunks of nodes;
694  // one node is 40 bytes plus the size of the counters block.
695  // The math over there sets a bit less than 10 MiB per chunk.
696  // to find out the right type name to put here, comment out this line
697  // (it will suppress some noise), set bDebug to true in
698  // lardata/Utilities/BulkAllocator.h and run this module;
699  // all BulkAllocator instances will advertise that they are being created,
700  // mentioning their referring type. You can also simplyfy it by using the
701  // available typedefs, like here:
703  std::_Rb_tree_node
704  <std::pair<const DistancesMap_t::Key_t, DistancesMap_t::CounterBlock_t>>
705  >::SetChunkSize(
706  10 * ((1048576 / (40 + sizeof(DistancesMap_t::CounterBlock_t))) & ~0x1FFU)
707  );
708 #endif // 0
709  //--- END issue #19494 -------------------------------------------------------
710 
711  m_numAccumulated = 0;
712  m_dx = dx;
713  m_dy = dy;
714  m_rowLength = (unsigned int)(m_rhoResolutionFactor * 2 * std::sqrt(dx * dx + dy * dy));
715  m_accum.resize(m_numAngleCells);
716 
717  // this math must be coherent with the one in GetEquation()
718  double angleStep = PI / m_numAngleCells;
719  m_cosTable.resize(m_numAngleCells);
720  m_sinTable.resize(m_numAngleCells);
721  for (size_t iAngleStep = 0; iAngleStep < m_numAngleCells; ++iAngleStep) {
722  double a = iAngleStep * angleStep;
723  m_cosTable[iAngleStep] = cos(a);
724  m_sinTable[iAngleStep] = sin(a);
725  }
726 }
std::vector< double > m_cosTable
unsigned int m_numAngleCells
constexpr double PI
process_name gaushit a
Aggressive allocator reserving a lot of memory in advance.
Definition: BulkAllocator.h:92
typename Base_t::CounterBlock_t CounterBlock_t
Definition: HoughBaseAlg.h:293
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 92 of file HoughBaseAlg.cxx.

93  {
94  return m_numAccumulated;
95  }
void cluster::HoughTransform::reconfigure ( fhicl::ParameterSet const &  pset)
void cluster::HoughTransform::SetCell ( int  row,
int  col,
int  value 
)
inline

Definition at line 81 of file HoughBaseAlg.cxx.

82  {
83  m_accum[row].set(col, value);
84  }
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
temporary value
bool cluster::HoughTransform::SubtractPoint ( int  x,
int  y 
)
inline

Definition at line 672 of file HoughBaseAlg.cxx.

673 {
674  if ((x > (int)m_dx) || (y > (int)m_dy) || x < 0.0 || y < 0.0) return false;
675  DoAddPointReturnMax(x, y, true); // true = subtract
676  return true;
677 }
process_name opflash particleana ie x
process_name opflash particleana ie ie y
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 117 of file HoughBaseAlg.cxx.

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

Definition at line 119 of file HoughBaseAlg.cxx.

unsigned int cluster::HoughTransform::m_dx
private

Definition at line 109 of file HoughBaseAlg.cxx.

unsigned int cluster::HoughTransform::m_dy
private

Definition at line 110 of file HoughBaseAlg.cxx.

int cluster::HoughTransform::m_numAccumulated
private

Definition at line 118 of file HoughBaseAlg.cxx.

unsigned int cluster::HoughTransform::m_numAngleCells
private

Definition at line 112 of file HoughBaseAlg.cxx.

float cluster::HoughTransform::m_rhoResolutionFactor
private

Definition at line 113 of file HoughBaseAlg.cxx.

unsigned int cluster::HoughTransform::m_rowLength
private

Definition at line 111 of file HoughBaseAlg.cxx.

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

Definition at line 120 of file HoughBaseAlg.cxx.


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