Skip to content
Snippets Groups Projects
bsaccumulatoritem.h 3.56 KiB
#ifndef BS_ACCUMULATOR_ITEM_H
#define BS_ACCUMULATOR_ITEM_H

#include <QGraphicsItem>
#include "bsdetector.h"


/** 
 * @class BSAccumulatorItem bsaccumulatoritem.h
 * \brief Hough accumulator grid display and control.
 * \author {P. Even}
 */
class BSAccumulatorItem : public QGraphicsItem
{

public:

  /**
   * \brief Creates a Hough accumulator grid.
   * @param sd Associated blurred segment detector.
   * @param w Accumulator width.
   * @param h Accumulator height.
   */
  BSAccumulatorItem (BSDetector *sd, int w, int h);

  /** Deletes the Hough accumulator grid.
   */
  ~BSAccumulatorItem ();

  /** \brief Inquires if the pre-filter accumulator is displayed.
   */
  inline bool isPrefilterDisplayed () const {
    return (selaccu == BSDetector::STEP_INITIAL); }

  /** \brief Switches the displayed accumulator filter.
   */
  inline void switchAccumulator () {
    selaccu = (selaccu != BSDetector::STEP_INITIAL ?
               BSDetector::STEP_INITIAL : BSDetector::STEP_FINAL); }

  /** \brief Returns the size of the filter accumulator graphics item.
   */
  QRectF boundingRect () const;

  /** \brief Draws the accumulator of the selected filter.
   */
  void paint (QPainter *painter,
              const QStyleOptionGraphicsItem *option, QWidget *widget);

  /**
   * \brief Switches on or off the information text display modality.
   */
  inline void switchInfoDisplay () { verbose = ! verbose; }

  /** \brief Resizes the accumulator array.
   * @param larger Sets larger if true, smaller otherwise.
   */
  bool resizeAccumulator (bool larger);

  /** \brief Zooms in or out the accumulator array.
   * @param in Zooms in if true, out otherwise.
   */
  bool zoomAccumulator (bool in);

  /** \brief Modifies the subpixellisation of the accumulator array.
   * @param in Sets larger if true, smaller otherwise.
   */
  bool subpixellise (bool larger);

  /** \brief Modifies the filter selectivity.
   * @param larger Makes the filter more selective if true, less otherwise.
   */
  bool setFilterSelectivity (bool larger);


private:

  /** Default value for pen width. */
  static const int DEFAULT_PEN_WIDTH;
  /** Left margin for information text. */
  static const int LEFT_MARGIN;
  /** Information text height. */
  static const int TEXT_HEIGHT;


  /** Blurred segment detector. */
  BSDetector *detector;
  /** Accumulator displayed (1 = prefilter, 0 = final filter). */
  int selaccu;

  /** Accumulator width. */
  int width;
  /** Accumulator height. */
  int height;
  /** Contents of the accumulator.
    * The array of vote counts for each cell. */
  uchar *map[2];
  /** Coordinates of the cell with the highest vote. */
  int solution[2];
  /** Accumulator scale in pixels.
    * One radian for the angles, and one pixel for the distances. */
  double resol[2];
  /** Contents of the applied accumulator mask.
    * An array of booleans values for each cell,
    * that are set to true if the cell belongs to the mask. */
  bool *mask;

  /** Information text modality. */
  bool verbose;
  /** Information text style. */
  QPen infoPen;
  /** Information text vertical offset. */
  int textOffset;
  /** Scale display style. */
  QPen scalePen;
  /** Mark display style. */
  QPen markPen;


  /**
   * \brief Initializes the text display (color and position).
   * @param painter : Painter to be decorated.
   */
  void initText (QPainter *painter);

  /**
   * \brief Paints a new text in the graphics item (updates text position).
   * @param painter : Painter to be decorated.
   * @param text : Text to be displayed.
   */
  void addText (QPainter *painter, const QString &text);
};
#endif