LArSoft  v06_85_00
Liquid Argon Software toolkit - http://larsoft.org/
cluster::HoughTransform Class Reference

#include "HoughBaseAlg.h"

Public Member Functions

 HoughTransform ()
 
 ~HoughTransform ()
 
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 481 of file HoughBaseAlg.h.

Member Typedef Documentation

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

rho -> # hits (for convenience)

Definition at line 507 of file HoughBaseAlg.h.

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

Definition at line 520 of file HoughBaseAlg.h.

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

Definition at line 525 of file HoughBaseAlg.h.

Constructor & Destructor Documentation

cluster::HoughTransform::HoughTransform ( )

Definition at line 241 of file HoughBaseAlg.cxx.

242 {
243  //m_accum=NULL;
244 }
cluster::HoughTransform::~HoughTransform ( )

Definition at line 787 of file HoughBaseAlg.cxx.

788 {
789 }

Member Function Documentation

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

Definition at line 801 of file HoughBaseAlg.cxx.

References max.

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

802 {
803  if ((x > (int) m_dx) || (y > (int) m_dy) || x<0.0 || y<0.0) {
804  std::array<int, 3> max;
805  max.fill(0);
806  return max;
807  }
808  return DoAddPointReturnMax(x, y, false); // false = add
809 }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Int_t max
Definition: plot.C:27
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 910 of file HoughBaseAlg.cxx.

References cluster::HoughTransformCounters< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::decrement(), cluster::HoughTransformCounters< KEY, COUNTER, SIZE, ALLOC, SUBCOUNTERS >::increment_and_get_max(), and max.

Referenced by GetMax().

911 {
912  std::array<int, 3> max;
913  max.fill(-1);
914 
915  // max_val is the current maximum number of hits aligned on a line so far;
916  // currently the code ignores all the lines with just two aligned hits
917  int max_val = 2;
918  //int max_val = minHits-1;
919 
920  const int distCenter = (int)(m_rowLength/2.);
921 
922  // prime the lastDist variable so our linear fill works below
923  // lastDist represents next distance to be incremented (but see below)
924  int lastDist = (int)(distCenter + (m_rhoResolutionFactor*x));
925 
926 
927  // loop through all angles a from 0 to 180 degrees
928  // (the value of the angle is established in definition of m_cosTable and
929  // m_sinTable in HoughTransform::Init()
930  for (size_t iAngleStep = 1; iAngleStep < m_numAngleCells; ++iAngleStep) {
931 
932  // Calculate the basic line equation dist = cos(a)*x + sin(a)*y.
933  // Shift to center of row to cover negative values;
934  // this math must also be coherent with the one in GetEquation()
935  const int dist = (int) (distCenter + m_rhoResolutionFactor
936  * (m_cosTable[iAngleStep]*x + m_sinTable[iAngleStep]*y)
937  );
938 
939  /*
940  * For this angle, we are going to increment all the cells starting from the
941  * last distance in the previous loop, up to the current one (dist),
942  * with the exception that if we are incrementing more than one cell,
943  * we do not increment dist cell itself (it will be incremented in the
944  * next angle).
945  * The cell of the last distance is always incremented,
946  * whether it was also for the previous angle (in case there was only one
947  * distance to be incremented) or not (if there was a sequence of distances
948  * to increment, and then the last distance was not).
949  * First we increment the last cell of our range; this provides us with a
950  * hint of where the immediate previous cell should be, which saves us a
951  * look up.
952  * We collect and return information about the local maximum among the cells
953  * we are increasing.
954  */
955 
956  // establish the range of cells to increase: [ first_dist, end_dist [ ;
957  // also set lastDist so that it points to the next cell to be incremented,
958  // according to the rules described above
959  int first_dist;
960  int end_dist;
961  if(lastDist == dist) {
962  // the range is [ dist, dist + 1 [ (that is, [ dist ]
963  first_dist = dist;
964  end_dist = dist + 1;
965  }
966  else {
967  // the range is [ lastDist, dist [ or ] dist, lastDist]
968  first_dist = dist > lastDist? lastDist: dist + 1;
969  end_dist = dist > lastDist? dist: lastDist + 1;
970  }
971 
972  // sanity check to make sure we stay within our row
973  // if (dist >= 0 && dist<m_rowLength){
974 
975  // DEBUG
976 // const float a = iAngleStep / m_numAngleCells * PI;
977 // std::cout << "AD " << iAngleStep << " " << dist
978 // << "\n" << a << " [ " << first_dist << " ; " << end_dist << " ["
979 // << std::endl;
980 
981  DistancesMap_t& distMap = m_accum[iAngleStep];
982  if (bSubtract) {
983  distMap.decrement(first_dist, end_dist);
984  }
985  else {
986  DistancesMap_t::PairValue_t max_counter
987  = distMap.increment_and_get_max(first_dist, end_dist, max_val);
988 
989  if (max_counter.second > max_val) {
990  // DEBUG
991  // std::cout << " <NEW MAX " << max_val << " => " << max_counter.second << " >" << std::endl;
992  // BUG the double brace syntax is required to work around clang bug 21629
993  // (https://bugs.llvm.org/show_bug.cgi?id=21629)
994  max = {{ max_counter.second, max_counter.first.key(), (int) iAngleStep }};
995  max_val = max_counter.second;
996  }
997  }
998  lastDist = dist;
999 
1000  // DEBUG
1001  // std::cout << "\n (max " << max[1] << " => " << max[0] << ")" << std::endl;
1002  // }
1003  } // for angles
1004  if (bSubtract) --m_numAccumulated;
1005  else ++m_numAccumulated;
1006 
1007  //mf::LogVerbatim("HoughBaseAlg") << "Add point says xmax: " << *xmax << " ymax: " << *ymax << std::endl;
1008 
1009  return max;
1010 } // cluster::HoughTransform::DoAddPointReturnMax()
Float_t x
Definition: compare.C:6
std::vector< double > m_cosTable
Definition: HoughBaseAlg.h:538
Float_t y
Definition: compare.C:6
unsigned int m_numAngleCells
Definition: HoughBaseAlg.h:531
std::pair< const_iterator, SubCounter_t > PairValue_t
Pair identifying a counter and its current value.
Definition: HoughBaseAlg.h:313
unsigned int m_rowLength
Definition: HoughBaseAlg.h:530
Int_t max
Definition: plot.C:27
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
Definition: HoughBaseAlg.h:536
std::vector< double > m_sinTable
Definition: HoughBaseAlg.h:539
HoughTransformCounters< int, signed char, 64 > DistancesMap_t
Definition: HoughBaseAlg.h:520
void cluster::HoughTransform::GetAccumSize ( int &  numRows,
int &  numCols 
)
inline

Definition at line 493 of file HoughBaseAlg.h.

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

494  {
495  numRows = m_accum.size();
496  numCols = (int) m_rowLength;
497  }
unsigned int m_rowLength
Definition: HoughBaseAlg.h:530
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
Definition: HoughBaseAlg.h:536
int cluster::HoughTransform::GetCell ( int  row,
int  col 
) const
inline

Definition at line 793 of file HoughBaseAlg.cxx.

References col.

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

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

Definition at line 883 of file HoughBaseAlg.cxx.

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

884 {
885  theta = (TMath::Pi()*row)/m_numAngleCells;
886  rho = (col - (m_rowLength/2.))/m_rhoResolutionFactor;
887 } // cluster::HoughTransform::GetEquation()
unsigned int m_numAngleCells
Definition: HoughBaseAlg.h:531
unsigned int m_rowLength
Definition: HoughBaseAlg.h:530
Int_t col[ntarg]
Definition: Style.C:29
int cluster::HoughTransform::GetMax ( int &  xmax,
int &  ymax 
) const

Definition at line 890 of file HoughBaseAlg.cxx.

References DoAddPointReturnMax().

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

891 {
892  int maxVal = -1;
893  for(unsigned int i = 0; i < m_accum.size(); i++){
894 
895  DistancesMap_t::PairValue_t max_counter = m_accum[i].get_max(maxVal);
896  if (max_counter.second > maxVal) {
897  maxVal = max_counter.second;
898  xmax = i;
899  ymax = max_counter.first.key();
900  }
901  } // for angle
902 
903  return maxVal;
904 }
std::pair< const_iterator, SubCounter_t > PairValue_t
Pair identifying a counter and its current value.
Definition: HoughBaseAlg.h:313
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
Definition: HoughBaseAlg.h:536
void cluster::HoughTransform::Init ( unsigned int  dx,
unsigned int  dy,
float  rhores,
unsigned int  numACells 
)

Definition at line 824 of file HoughBaseAlg.cxx.

References GetEquation(), and PI.

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

828 {
829  m_numAngleCells=numACells;
830  m_rhoResolutionFactor = rhores;
831 
832  m_accum.clear();
833  //--- BEGIN issue #19494 -----------------------------------------------------
834  // BulkAllocator.h is currently broken; see issue #19494 and comment in header.
835 #if 0
836  // set the custom allocator for nodes to allocate large chunks of nodes;
837  // one node is 40 bytes plus the size of the counters block.
838  // The math over there sets a bit less than 10 MiB per chunk.
839  // to find out the right type name to put here, comment out this line
840  // (it will suppress some noise), set bDebug to true in
841  // lardata/Utilities/BulkAllocator.h and run this module;
842  // all BulkAllocator instances will advertise that they are being created,
843  // mentioning their referring type. You can also simplyfy it by using the
844  // available typedefs, like here:
846  std::_Rb_tree_node
847  <std::pair<const DistancesMap_t::Key_t, DistancesMap_t::CounterBlock_t>>
848  >::SetChunkSize(
849  10 * ((1048576 / (40 + sizeof(DistancesMap_t::CounterBlock_t))) & ~0x1FFU)
850  );
851 #endif // 0
852  //--- END issue #19494 -------------------------------------------------------
853 
854  //m_accum.resize(m_numAngleCells);
855  m_numAccumulated = 0;
856  // m_cosTable.clear();
857  // m_sinTable.clear();
858  //m_cosTable.resize(m_numAngleCells);
859  //m_sinTable.resize(m_numAngleCells);
860  //if (dx == m_dx && dy == m_dy)
861  //return;
862  m_dx = dx;
863  m_dy = dy;
864  m_rowLength = (unsigned int)(m_rhoResolutionFactor*2 * std::sqrt(dx*dx + dy*dy));
865  m_accum.resize(m_numAngleCells);
866  //for(int i = 0; i < m_numAngleCells; i++)
867  //m_accum[i].resize((unsigned int)(m_rowLength));
868 
869  // this math must be coherent with the one in GetEquation()
870  double angleStep = PI/m_numAngleCells;
871  m_cosTable.resize(m_numAngleCells);
872  m_sinTable.resize(m_numAngleCells);
873  for (size_t iAngleStep = 0; iAngleStep < m_numAngleCells; ++iAngleStep) {
874  double a = iAngleStep * angleStep;
875  m_cosTable[iAngleStep] = cos(a);
876  m_sinTable[iAngleStep] = sin(a);
877  }
878 }
std::vector< double > m_cosTable
Definition: HoughBaseAlg.h:538
unsigned int m_numAngleCells
Definition: HoughBaseAlg.h:531
unsigned int m_rowLength
Definition: HoughBaseAlg.h:530
constexpr double PI
Aggressive allocator reserving a lot of memory in advance.
Definition: BulkAllocator.h:92
typename Base_t::CounterBlock_t CounterBlock_t
Definition: HoughBaseAlg.h:309
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
Definition: HoughBaseAlg.h:536
std::vector< double > m_sinTable
Definition: HoughBaseAlg.h:539
int cluster::HoughTransform::NumAccumulated ( )
inline

Definition at line 498 of file HoughBaseAlg.h.

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

Definition at line 492 of file HoughBaseAlg.h.

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

492 { m_accum[row].set(col, value); }
Int_t col[ntarg]
Definition: Style.C:29
std::string value(boost::any const &)
HoughImage_t m_accum
column (map key)=rho, row (vector index)=theta
Definition: HoughBaseAlg.h:536
bool cluster::HoughTransform::SubtractPoint ( int  x,
int  y 
)
inline

Definition at line 814 of file HoughBaseAlg.cxx.

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

815 {
816  if ((x > (int) m_dx) || (y > (int) m_dy) || x<0.0 || y<0.0)
817  return false;
818  DoAddPointReturnMax(x, y, true); // true = subtract
819  return true;
820 }
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 536 of file HoughBaseAlg.h.

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

Definition at line 538 of file HoughBaseAlg.h.

unsigned int cluster::HoughTransform::m_dx
private

Definition at line 528 of file HoughBaseAlg.h.

unsigned int cluster::HoughTransform::m_dy
private

Definition at line 529 of file HoughBaseAlg.h.

int cluster::HoughTransform::m_numAccumulated
private

Definition at line 537 of file HoughBaseAlg.h.

unsigned int cluster::HoughTransform::m_numAngleCells
private

Definition at line 531 of file HoughBaseAlg.h.

float cluster::HoughTransform::m_rhoResolutionFactor
private

Definition at line 532 of file HoughBaseAlg.h.

unsigned int cluster::HoughTransform::m_rowLength
private

Definition at line 530 of file HoughBaseAlg.h.

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

Definition at line 539 of file HoughBaseAlg.h.


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