00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00027 #ifndef EDITOR_H
00028 #define EDITOR_H
00029
00030
00031 #ifdef __APPLE__
00032 #include <OpenGL/gl.h>
00033 #else
00034 #include <GL/gl.h>
00035 #endif
00036
00037
00038 #include <tools/transferfunction/displayhistogram.h>
00039 #include <tools/transferfunction/displaycolor.h>
00040 #include <list>
00041
00042
00043 namespace Tools { namespace TransferFunction
00044 {
00084 class Editor
00085 {
00086 public:
00087 Editor();
00088 ~Editor();
00089
00091 template <typename DataType>
00092 void update(const DataType* data, unsigned int data_size);
00093
00095 void clamp(float min, float max);
00096
00102 void place(int x, int y, int width, int height, int win_width, int win_height);
00103
00117 template <typename Manip>
00118 void add(Manip* o);
00119
00123 void clear();
00124
00127 bool mouse(int x, int y);
00128
00131 bool motion(int x, int y);
00132
00134 bool lutchanged() const { return m_lutchanged; }
00135
00138 void contrast(float contrast) { m_contrast = contrast; }
00139
00141 float contrast() const { return m_contrast; }
00142
00145 void brightness(float brightness) { m_brightness = brightness; }
00146
00148 float brightness() const { return m_brightness; }
00149
00153 void colorMode();
00154
00156 void display() const;
00157
00160 void hide(bool status=true) { m_hide = status; }
00161
00163 bool status() const { return m_hide; }
00164
00166 void get(float intensity, float &r, float &g, float &b, float &a) const;
00167
00168 private:
00170 struct TFEobject {
00171 virtual ~TFEobject() {}
00172 virtual void clamp(float,float) = 0;
00173 virtual bool mouse(float,float) = 0;
00174 virtual bool motion(float,float) = 0;
00175 virtual void display() const = 0;
00176 virtual void reshape(int,int) = 0;
00177 virtual void get(float, float&, float&, float&, float&) const = 0;
00178 virtual void setColor(float, float, float) = 0;
00179 virtual void destroy() = 0;
00180 };
00181
00183 template <typename Manip>
00184 struct TFEobjectimpl : public TFEobject {
00185 TFEobjectimpl(Manip*o) : o(o) {}
00186 ~TFEobjectimpl() { if(o) delete o; }
00187 void clamp(float l, float r) { if(o) o->clamp(l,r); }
00188 bool mouse(float x, float y) { return (o) ? o->mouse(x,y):0; }
00189 bool motion(float x, float y) { return (o) ? o->motion(x,y):0; }
00190 void display() const { if(o) o->display(); }
00191 void reshape(int w, int h) { if(o) o->reshape(w,h); }
00192 void get(float i, float &r, float &g, float &b, float &a) const { if(o) o->get(i,r,g,b,a); }
00193 void setColor(float r, float g, float b) { if(o) o->setColor(r,g,b); }
00194 void destroy() { if(o) delete o; o=0; }
00195 Manip* o;
00196 };
00197
00198 private:
00199 DisplayHistogram m_histogram;
00200 std::list<TFEobject*> m_manips;
00201 float m_min;
00202 float m_max;
00203 float m_left;
00204 float m_right;
00205 int m_posx;
00206 int m_posy;
00207 int m_width;
00208 int m_height;
00209 int m_win_width;
00210 int m_win_height;
00211 bool m_lutchanged;
00212 float m_contrast;
00213 float m_brightness;
00214 bool m_colorMode;
00215 DisplayColor m_color;
00216 float m_colorSize;
00217 bool m_hide;
00218 };
00219
00220
00221 template <typename DataType>
00222 void Editor::update(const DataType* image, unsigned int image_size)
00223 {
00224 if(!image && image_size>0) throw LOCATE(Error("image is empty"));
00225
00226 float min = 1e6;
00227 float max = -1e6;
00228 for(const DataType* it = image; it!=&image[image_size]; ++it)
00229 {
00230 if((*it)<min) min = (*it);
00231 if((*it)>max) max = (*it);
00232 }
00233 unsigned int nbBins = (int)(max-min);
00234
00235
00236 m_histogram.update(image, image_size, min, max, nbBins);
00237 }
00238
00239
00240 template <typename Manip>
00241 void Editor::add(Manip* m)
00242 {
00243 TFEobject* o = new TFEobjectimpl<Manip>(m);
00244 m_manips.push_back(o);
00245
00246
00247 o->reshape(m_width, m_height);
00248 o->clamp(m_histogram.getLeft(),m_histogram.getRight());
00249 }
00250
00251 }}
00252
00253 #endif