Listing 2: An accumulation function for line search.
bool LineHoughAccum::DoAddPoint(int x, int y) { int a; int distCenter = m_rowLength/2; // calculate rho for angle 0 int lastDist = distCenter + ((m_cosTable[0]*x + m_sinTable[0]*y) >> 10); // loop through angles 1 through 180 for (a=1; a<m_cosTable.size(); a++) { int dist = distCenter + ((m_cosTable[a]*x + m_sinTable[a]*y) >> 10); if (dist >= 0 && dist<m_rowLength) { // accumulate cells filling in multiple values for one angle int stepDir = dist>lastDist ? 1 : -1; for (int cell=lastDist; cell!=dist; cell+=stepDir) m_accum[a*m_rowLength + cell] += 1; } lastDist = dist; } m_numAccumulated += 1; return true; }