00001 #ifndef GRADIENTS_H
00002 #define GRADIENTS_H
00003
00004 #include "tfglwidget.h"
00005
00006 class tfGLWidget;
00007
00008 #include "arthurwidgets.h"
00009
00010 #include <QtGui>
00011
00012 class HoverPoints;
00013
00014
00015 class ShadeWidget : public QWidget
00016 {
00017 Q_OBJECT
00018 public:
00019 enum ShadeType {
00020 RedShade,
00021 GreenShade,
00022 BlueShade,
00023 ARGBShade
00024 };
00025
00026 ShadeWidget(ShadeType type, QWidget *parent);
00027
00028 void setGradientStops(const QGradientStops &stops);
00029
00030 void setHistogram(QList<int> &histogram);
00031
00032 void paintEvent(QPaintEvent *e);
00033
00034 QSize sizeHint() const { return QSize(256, 100); }
00035 QPolygonF points() const;
00036
00037 HoverPoints *hoverPoints() const { return m_hoverPoints; }
00038
00039 uint colorAt(int x);
00040
00041 signals:
00042 void colorsChanged();
00043
00044 private:
00045 void generateShade();
00046 void drawHistogram();
00047
00048 ShadeType m_shade_type;
00049 QImage m_shade;
00050 HoverPoints *m_hoverPoints;
00051 QLinearGradient m_alpha_gradient;
00052
00053 QList<int> m_histogram;
00054 QList<float> m_norm_histogram;
00055 QList<float> m_norm_exp_histogram;
00056 int max_histogram_bin;
00057 };
00058
00059 class GradientEditor : public QWidget
00060 {
00061 Q_OBJECT
00062 public:
00063 GradientEditor(QWidget *parent);
00064
00065 void setGradientStops(const QGradientStops &stops);
00066
00067 public slots:
00068 void pointsUpdated();
00069 void setHistogram(QList<int> &histogram_list);
00070
00071 signals:
00072 void gradientStopsChanged(const QGradientStops &stops);
00073
00074
00075 private:
00076 ShadeWidget *m_red_shade;
00077 ShadeWidget *m_green_shade;
00078 ShadeWidget *m_blue_shade;
00079 ShadeWidget *m_alpha_shade;
00080
00081 QList<int> m_histogram;
00082 };
00083
00084
00085
00086 class GradientRenderer : public QGLWidget
00087 {
00088 Q_OBJECT
00089 public:
00090 GradientRenderer(QWidget *parent);
00091
00092 QSize sizeHint() const { return QSize(256, 512); }
00093
00094 public slots:
00095 void setGradientStops(const QGradientStops &stops);
00096
00097 signals:
00098
00099 void tfTextureGenerated(QImage &tf_img);
00100
00101 protected:
00102 void initializeGL();
00103 void paintGL();
00104 void resizeGL(int width, int height);
00105 void mousePressEvent(QMouseEvent *event);
00106 void mouseMoveEvent(QMouseEvent *event);
00107
00108 private:
00109 QGradientStops m_stops;
00110 };
00111
00112
00113 class GradientWidget : public QWidget
00114 {
00115 Q_OBJECT
00116 public:
00117 GradientWidget(QWidget *parent);
00118
00119 QSize sizeHint() const { return QSize(300, 100); }
00120
00121
00122 public slots:
00123 void setTransferFunction(QImage &tf_img);
00124
00125 void setDefault1() { setDefault(1); }
00126 void setDefault2() { setDefault(2); }
00127 void setDefault3() { setDefault(3); }
00128 void setDefault4() { setDefault(4); }
00129 void setDefault5() { setDefault(5); }
00130 void setDefault6() { setDefault(6); }
00131 void setDefault7() { setDefault(7); }
00132 void setDefault8() { setDefault(8); }
00133
00134 void rendertf(const QGradientStops &stops);
00135
00136 void setGradientStops(const QGradientStops &stops);
00137
00138 signals:
00139
00140 void tfready(QImage &tf_img);
00141 void gradientStopsChanged(const QGradientStops &stops);
00142 void histogram_changed(QList<int> &histogram_list);
00143
00144 private:
00145
00146 void setDefault(int i);
00147
00148
00149 GradientEditor *m_editor;
00150 tfGLWidget *tf_widget;
00151
00152 QImage m_transfer_function;
00153
00154 QGradientStops m_stops;
00155
00156 QPushButton *m_linearButton;
00157 QPushButton *m_zerosButton;
00158 QPushButton *m_rainbowButton;
00159 QPushButton *m_blackButton;
00160 QPushButton *m_redButton;
00161 QPushButton *m_greenButton;
00162 QPushButton *m_blueButton;
00163 QPushButton *m_whiteButton;
00164
00165 };
00166
00167 #endif // GRADIENTS_H