00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #ifndef DISPLAYHISTOGRAM_H
00028 #define DISPLAYHISTOGRAM_H
00029
00030
00031 #if __APPLE__
00032 #include <OpenGL/gl.h>
00033 #else
00034 #include <GL/gl.h>
00035 #endif
00036 #include <error.h>
00037
00038
00039 namespace Tools { namespace TransferFunction
00040 {
00062 class DisplayHistogram
00063 {
00064 public:
00065 DisplayHistogram();
00066 ~DisplayHistogram();
00067
00074 template <typename DataType>
00075 void update(const DataType* data, unsigned int data_size, float min, float max, unsigned int nbBins);
00076
00079 void clamp(float left, float right);
00080
00081
00082 float getLeft() const { return m_left; }
00083 float getRight() const { return m_right; }
00084
00086 void display() const;
00087
00091 bool mouse(float x, float y);
00092
00096 bool motion(float x, float y);
00097
00098 private:
00100 void updateTexture(unsigned int width, unsigned int height, float r, float g, float b, float a);
00101
00102 private:
00103 unsigned int* m_histogram;
00104 unsigned int m_nbBins;
00105 float m_min;
00106 float m_max;
00107 float m_left;
00108 float m_right;
00109 float m_height;
00110 unsigned int m_maxheight;
00111 bool m_selected;
00112 float m_lastx;
00113 float m_lasty;
00114
00115 GLuint m_textureName;
00116 };
00117
00118
00119 template <typename DataType>
00120 void DisplayHistogram::update(const DataType* image, unsigned int image_size, float min, float max, unsigned int nbBins)
00121 {
00122
00123 if(m_histogram && m_nbBins!=nbBins) delete [] m_histogram;
00124
00125
00126 m_min = min;
00127 m_max = max;
00128 m_nbBins = nbBins;
00129
00130 float binSize = (m_max - m_min) / m_nbBins;
00131
00132
00133 m_histogram = new unsigned int [m_nbBins];
00134 for(unsigned int i=0; i<m_nbBins; ++i) m_histogram[i] = 0;
00135
00136
00137 for(const DataType* it = image; it != &image[image_size]; ++it)
00138 {
00139
00140 int bin = static_cast<int>((*it-m_min) / binSize);
00141
00142 if(bin>=0 && bin<(int)m_nbBins)
00143 {
00144
00145 ++m_histogram[bin];
00146
00147
00148 if(m_histogram[bin] > m_maxheight) m_maxheight = m_histogram[bin];
00149 }
00150 }
00151
00152
00153 m_left = m_min;
00154 m_right = m_max;
00155 m_height = static_cast<float>(m_maxheight);
00156
00157
00158 updateTexture(1024,1024, 1,1,1, 0.8f);
00159 }
00160
00161 }}
00162
00163
00164 #endif