ImageHolder.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. /*!
  2. * \file ImageHolder.h
  3. *
  4. * Created on: Oct 5, 2011
  5. * Author: Gapchich Vladislav
  6. */
  7. #ifndef __IMAGEHOLDER_H__
  8. #define __IMAGEHOLDER_H__
  9. #include <QLabel>
  10. //! enum indicating the figure of selection
  11. enum Figure {
  12. NoFigure,
  13. RectFigure,
  14. PolyFigure
  15. };
  16. //! structure containing rectangle and it's label ID
  17. struct BoundingBox {
  18. QRect rect;
  19. int label_ID_;
  20. };
  21. //! structure containing list of the polygon points and polygon's label ID
  22. struct Polygon {
  23. QPolygon poly;
  24. int label_ID_;
  25. };
  26. //! structure indicates hovered point and the object which belongs to this hovered point
  27. struct HoveredPoint {
  28. Figure figure; /*!< figure of the object which belongs to the hovered point */
  29. int figureID; /*!< ID of the object in list_bounding_box_ or list_polygon_ depend on figure */
  30. int pointID; /*!< number of the point in an object(rect or poly) */
  31. };
  32. //! enum indicating the direction of zooming
  33. enum ZoomDirection {
  34. NoZoom,
  35. ZoomIn,
  36. ZoomOut
  37. };
  38. class QListWidgetItem;
  39. class QPixmap;
  40. //! \brief Widget containing loaded image.
  41. //! It makes drawing rectangles and polygons on the image possible.
  42. /* \see paintEvent(QPaintEvent *)
  43. * \see ImageLabeler
  44. */
  45. class ImageHolder : public QLabel
  46. {
  47. Q_OBJECT
  48. protected:
  49. void keyPressEvent(QKeyEvent *anEvent);
  50. void mouseMoveEvent(QMouseEvent *anEvent);
  51. void mousePressEvent(QMouseEvent *anEvent);
  52. void mouseDoubleClickEvent(QMouseEvent *anEvent);
  53. void mouseReleaseEvent(QMouseEvent *anEvent);
  54. void paintEvent (QPaintEvent *anEvent);
  55. void triggerBoundBox(
  56. const QPoint &aNewPos,
  57. const QPoint &anOldPos,
  58. QRect *aNewBox
  59. );
  60. void triggerPolygon(
  61. const QPoint &aPoint,
  62. QPolygon *aNewPoly
  63. );
  64. void drawBoundingBoxes(
  65. QPainter *aPainter,
  66. QPen *aPen
  67. ) const;
  68. void drawPolygons(
  69. QPainter *aPainter,
  70. QPen *aPen
  71. ) const;
  72. void checkForPoints(QPoint *aPos);
  73. int posInPolygon(
  74. QPoint *aPos,
  75. QPolygon *aPoly
  76. ) const;
  77. public:
  78. enum Tool {
  79. NoTool,
  80. BoundingBoxTool,
  81. PolygonTool
  82. };
  83. enum State {
  84. StandBy,
  85. NewSelection
  86. };
  87. ImageHolder(QWidget *aParent = 0);
  88. virtual ~ImageHolder();
  89. void setTool(Tool aTool);
  90. void setBoundingBoxList(QList< BoundingBox * > *aBBoxList);
  91. void setPolygonList(QList< Polygon * > *aPolyList);
  92. void setLabelColorList(QList< uint > *aLabelColorList);
  93. void setMainLabelNum(int *aNum);
  94. void setImage(QPixmap *anImage);
  95. void scaleImage(ZoomDirection aDirection, double scaleFactor);
  96. int focusedSelection() const;
  97. Figure focusedSelectionType() const;
  98. State state() const;
  99. Tool tool() const;
  100. public slots:
  101. void clearAll();
  102. void clearLast();
  103. void confirmSelection();
  104. void focusOnArea(QListWidgetItem *anItem);
  105. void clearFocusOnArea();
  106. void clearHoveredPoint();
  107. void undo();
  108. void redo();
  109. void removeSelectedPoint();
  110. signals:
  111. void selectionStarted();
  112. void areaEdited();
  113. private:
  114. //! flag for the internal use
  115. bool repaint_needed_;
  116. //! \brief pointer to the list of ImageLabeler
  117. //! \see ImageLabeler::list_bounding_box_
  118. QList< BoundingBox * > *list_bounding_box_;
  119. //! \brief pointer to the list of ImageLabeler
  120. //! \see ImageLabeler::list_polygon_
  121. QList< Polygon * > *list_polygon_;
  122. //! \brief pointer to the list of ImageLabeler
  123. //! \see ImageLabeler::list_label_color_
  124. QList< uint > *list_label_color_;
  125. //! \brief list of points for the undo/redo methods
  126. //! \see undo()
  127. //! \see redo()
  128. QList< QPoint > list_poly_history_;
  129. //! \brief pointer to the object of ImageLabeler
  130. //! \see ImageLabeler::image_
  131. QPixmap *image_;
  132. //! \brief pointer to the variable of ImageLabeler
  133. //! \see ImageLabeler::main_label_
  134. int *main_label_;
  135. //! \brief a structure that keeps not confirmed rectangle selection
  136. //! \see paintEvent(QPaintEvent *)
  137. //! \see ImageLabeler::confirmSelection()
  138. BoundingBox bounding_box_;
  139. //! \brief a structure that keeps not confirmed polygon selection
  140. //! \see paintEvent(QPaintEvent *)
  141. //! \see ImageLabeler::confirmSelection()
  142. Polygon polygon_;
  143. //! keeps current keyboard modifier(like ctrl, shift, alt etc)
  144. int keyboard_modifier_;
  145. //! \brief keeps an information about current hovered point
  146. //! \see checkForPoints(QPoint *aPos)
  147. HoveredPoint hovered_point_;
  148. //! keeps the selected point number
  149. int selected_point_;
  150. //! \brief keeps the position of a mouse when it was clicked
  151. QPoint prev_cursor_pos_;
  152. //! enum indicating tool user applying currently
  153. Tool tool_;
  154. //! enum indicating the current state of image_holder_
  155. State state_;
  156. //! indicates which selection(selected area) is focused at the moment
  157. int focused_selection_;
  158. //! indicates the type of currently selected figure
  159. Figure focused_selection_type_;
  160. //! \brief indicates current scale
  161. //! \see scaleImage(ZoomDirection aDirection,double scaleFactor)
  162. double scale_;
  163. //! \brief declares the radius of the selecltable point
  164. //! \see drawBoundingBoxes(QPainter *aPainter,QPen *aPen)
  165. //! \see drawPolygons(QPainter *aPainter,QPen *aPen)
  166. int point_radius_;
  167. };
  168. #endif /* IMAGEHOLDER_H_ */
  169. /*
  170. *
  171. */