ArrayPlot.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. //
  2. // C++ Interface: ArrayPlot
  3. //
  4. // Description:
  5. //
  6. //
  7. // Author: Marcel Brueckner <brueckner [at] informatik [dot] uni-jena [dot] de>, (C) 2008
  8. //
  9. // Copyright: See COPYING file that comes with this distribution
  10. //
  11. //
  12. #ifndef IMAGEDISPLAY_ARRAYPLOT_H
  13. #define IMAGEDISPLAY_ARRAYPLOT_H
  14. #include <QWidget>
  15. #include <QMouseEvent>
  16. #include <QGLWidget>
  17. #include <core/basics/NonCopyable.h>
  18. #include <core/basics/numerictools.h>
  19. namespace NICE {
  20. class ArrayPlot : public QGLWidget, private NICE::NonCopyable {
  21. Q_OBJECT;
  22. public:
  23. ArrayPlot ( std::vector<double> probs,
  24. unsigned int width,
  25. unsigned int height,
  26. bool invertColors,
  27. QWidget* parent = NULL,
  28. const char* name = NULL,
  29. Qt::WFlags flags = 0 );
  30. virtual ~ArrayPlot(void);
  31. inline void setProb(unsigned int i, unsigned int j, double prob) {
  32. m_probs[i*m_width + j] = prob;
  33. if (prob > m_maxProb)
  34. m_maxProb = prob;
  35. if (prob < m_minProb)
  36. m_minProb = prob;
  37. }
  38. inline unsigned int img1(void) const {
  39. return m_xPos;
  40. }
  41. inline unsigned int img2(void) const {
  42. return m_yPos;
  43. }
  44. inline double prob (void) {
  45. return m_probs[m_xPos * m_height + m_yPos];
  46. }
  47. inline void reset (const std::vector<double>& newValues) {
  48. m_maxProb = -std::numeric_limits<double>::infinity();
  49. m_minProb = std::numeric_limits<double>::infinity();
  50. for (unsigned int i = 0; i < m_probs.size(); ++i) {
  51. m_probs[i] = newValues[i];
  52. m_maxProb = std::max(m_maxProb, m_probs[i]);
  53. m_minProb = std::min(m_minProb, m_probs[i]);
  54. }
  55. }
  56. inline void setMax (double max) {
  57. m_maxProb = max;
  58. }
  59. inline void setMin (double min) {
  60. m_minProb = min;
  61. }
  62. void loadFromFile (const char* path);
  63. public slots:
  64. /**
  65. * Repaint this widget.
  66. */
  67. void repaint();
  68. protected:
  69. virtual void paintGL(void);
  70. virtual void mousePressEvent(QMouseEvent* event);
  71. private:
  72. void toColor ( double x, double & r, double & g, double & b );
  73. unsigned int m_width;
  74. unsigned int m_height;
  75. double m_maxProb;
  76. double m_minProb;
  77. std::vector<double> m_probs;
  78. unsigned int m_xPos;
  79. unsigned int m_yPos;
  80. bool m_invertColors;
  81. };
  82. }//namespace NICE
  83. #endif